From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/pretty/asm.pp | 34 +++ tests/pretty/asm.rs | 31 +++ tests/pretty/ast-stmt-expr-attr.rs | 175 +++++++++++++ tests/pretty/async.rs | 9 + tests/pretty/attr-derive.rs | 32 +++ tests/pretty/attr-fn-inner.rs | 16 ++ tests/pretty/attr-literals.rs | 14 ++ tests/pretty/attr-tokens-raw-ident.rs | 7 + tests/pretty/auto-trait.rs | 9 + tests/pretty/auxiliary/derive-foo.rs | 13 + tests/pretty/blank-lines.rs | 17 ++ tests/pretty/block-comment-multiple-asterisks.rs | 6 + tests/pretty/block-comment-trailing-whitespace.rs | 10 + tests/pretty/block-comment-trailing-whitespace2.rs | 8 + tests/pretty/block-comment-wchar.pp | 101 ++++++++ tests/pretty/block-comment-wchar.rs | 100 ++++++++ tests/pretty/block-disambig.rs | 59 +++++ tests/pretty/cast-lt.pp | 13 + tests/pretty/cast-lt.rs | 11 + tests/pretty/closure-reform-pretty.rs | 16 ++ tests/pretty/delimited-token-groups.rs | 48 ++++ tests/pretty/disamb-stmt-expr.rs | 10 + tests/pretty/do1.rs | 5 + tests/pretty/doc-comments.rs | 53 ++++ tests/pretty/dollar-crate.pp | 13 + tests/pretty/dollar-crate.rs | 7 + tests/pretty/empty-impl.rs | 7 + tests/pretty/empty-lines.rs | 9 + tests/pretty/enum-variant-vis.rs | 8 + tests/pretty/example1.rs | 3 + tests/pretty/example2.pp | 3 + tests/pretty/example2.rs | 3 + tests/pretty/expanded-and-path-remap-80832.pp | 13 + tests/pretty/expanded-and-path-remap-80832.rs | 7 + tests/pretty/fn-return.rs | 7 + tests/pretty/fn-types.rs | 5 + tests/pretty/fn-variadic.rs | 15 ++ tests/pretty/for-comment.rs | 11 + tests/pretty/gat-bounds.rs | 16 ++ tests/pretty/hir-pretty-loop.pp | 9 + tests/pretty/hir-pretty-loop.rs | 9 + tests/pretty/if-attr.rs | 37 +++ tests/pretty/import-renames.rs | 6 + tests/pretty/issue-12590-a.rs | 9 + tests/pretty/issue-12590-b.rs | 5 + tests/pretty/issue-12590-c.pp | 19 ++ tests/pretty/issue-12590-c.rs | 10 + tests/pretty/issue-19077.rs | 11 + tests/pretty/issue-25031.rs | 8 + tests/pretty/issue-30731.rs | 8 + tests/pretty/issue-31073.pp | 7 + tests/pretty/issue-31073.rs | 7 + tests/pretty/issue-4264.pp | 57 +++++ tests/pretty/issue-4264.rs | 39 +++ .../pretty/issue-68710-field-attr-proc-mac-lost.rs | 17 ++ tests/pretty/issue-73626.rs | 34 +++ tests/pretty/issue-74745.rs | 5 + tests/pretty/issue-85089.pp | 20 ++ tests/pretty/issue-85089.rs | 16 ++ tests/pretty/let.rs | 9 + tests/pretty/lifetime.rs | 5 + tests/pretty/macro.rs | 7 + tests/pretty/macro_rules.rs | 19 ++ tests/pretty/match-block-expr.rs | 6 + tests/pretty/match-naked-expr-medium.rs | 14 ++ tests/pretty/match-naked-expr.rs | 10 + tests/pretty/nested-item-vis-defaultness.rs | 47 ++++ tests/pretty/path-type-bounds.rs | 15 ++ tests/pretty/qpath-associated-type-bound.rs | 16 ++ tests/pretty/raw-address-of.rs | 12 + tests/pretty/raw-str-nonexpr.rs | 9 + tests/pretty/stmt_expr_attributes.rs | 271 +++++++++++++++++++++ tests/pretty/struct-pattern.rs | 5 + tests/pretty/struct-tuple.rs | 10 + tests/pretty/tag-blank-lines.rs | 8 + tests/pretty/tests-are-sorted.pp | 69 ++++++ tests/pretty/tests-are-sorted.rs | 13 + tests/pretty/top-level-doc-comments.rs | 8 + tests/pretty/trait-inner-attr.rs | 7 + tests/pretty/trait-polarity.rs | 9 + tests/pretty/trait-safety.rs | 15 ++ tests/pretty/unary-op-disambig.rs | 19 ++ tests/pretty/use-tree.rs | 23 ++ tests/pretty/vec-comments.pp | 29 +++ tests/pretty/vec-comments.rs | 29 +++ tests/pretty/where-clauses.rs | 8 + tests/pretty/yeet-expr.rs | 12 + 87 files changed, 1961 insertions(+) create mode 100644 tests/pretty/asm.pp create mode 100644 tests/pretty/asm.rs create mode 100644 tests/pretty/ast-stmt-expr-attr.rs create mode 100644 tests/pretty/async.rs create mode 100644 tests/pretty/attr-derive.rs create mode 100644 tests/pretty/attr-fn-inner.rs create mode 100644 tests/pretty/attr-literals.rs create mode 100644 tests/pretty/attr-tokens-raw-ident.rs create mode 100644 tests/pretty/auto-trait.rs create mode 100644 tests/pretty/auxiliary/derive-foo.rs create mode 100644 tests/pretty/blank-lines.rs create mode 100644 tests/pretty/block-comment-multiple-asterisks.rs create mode 100644 tests/pretty/block-comment-trailing-whitespace.rs create mode 100644 tests/pretty/block-comment-trailing-whitespace2.rs create mode 100644 tests/pretty/block-comment-wchar.pp create mode 100644 tests/pretty/block-comment-wchar.rs create mode 100644 tests/pretty/block-disambig.rs create mode 100644 tests/pretty/cast-lt.pp create mode 100644 tests/pretty/cast-lt.rs create mode 100644 tests/pretty/closure-reform-pretty.rs create mode 100644 tests/pretty/delimited-token-groups.rs create mode 100644 tests/pretty/disamb-stmt-expr.rs create mode 100644 tests/pretty/do1.rs create mode 100644 tests/pretty/doc-comments.rs create mode 100644 tests/pretty/dollar-crate.pp create mode 100644 tests/pretty/dollar-crate.rs create mode 100644 tests/pretty/empty-impl.rs create mode 100644 tests/pretty/empty-lines.rs create mode 100644 tests/pretty/enum-variant-vis.rs create mode 100644 tests/pretty/example1.rs create mode 100644 tests/pretty/example2.pp create mode 100644 tests/pretty/example2.rs create mode 100644 tests/pretty/expanded-and-path-remap-80832.pp create mode 100644 tests/pretty/expanded-and-path-remap-80832.rs create mode 100644 tests/pretty/fn-return.rs create mode 100644 tests/pretty/fn-types.rs create mode 100644 tests/pretty/fn-variadic.rs create mode 100644 tests/pretty/for-comment.rs create mode 100644 tests/pretty/gat-bounds.rs create mode 100644 tests/pretty/hir-pretty-loop.pp create mode 100644 tests/pretty/hir-pretty-loop.rs create mode 100644 tests/pretty/if-attr.rs create mode 100644 tests/pretty/import-renames.rs create mode 100644 tests/pretty/issue-12590-a.rs create mode 100644 tests/pretty/issue-12590-b.rs create mode 100644 tests/pretty/issue-12590-c.pp create mode 100644 tests/pretty/issue-12590-c.rs create mode 100644 tests/pretty/issue-19077.rs create mode 100644 tests/pretty/issue-25031.rs create mode 100644 tests/pretty/issue-30731.rs create mode 100644 tests/pretty/issue-31073.pp create mode 100644 tests/pretty/issue-31073.rs create mode 100644 tests/pretty/issue-4264.pp create mode 100644 tests/pretty/issue-4264.rs create mode 100644 tests/pretty/issue-68710-field-attr-proc-mac-lost.rs create mode 100644 tests/pretty/issue-73626.rs create mode 100644 tests/pretty/issue-74745.rs create mode 100644 tests/pretty/issue-85089.pp create mode 100644 tests/pretty/issue-85089.rs create mode 100644 tests/pretty/let.rs create mode 100644 tests/pretty/lifetime.rs create mode 100644 tests/pretty/macro.rs create mode 100644 tests/pretty/macro_rules.rs create mode 100644 tests/pretty/match-block-expr.rs create mode 100644 tests/pretty/match-naked-expr-medium.rs create mode 100644 tests/pretty/match-naked-expr.rs create mode 100644 tests/pretty/nested-item-vis-defaultness.rs create mode 100644 tests/pretty/path-type-bounds.rs create mode 100644 tests/pretty/qpath-associated-type-bound.rs create mode 100644 tests/pretty/raw-address-of.rs create mode 100644 tests/pretty/raw-str-nonexpr.rs create mode 100644 tests/pretty/stmt_expr_attributes.rs create mode 100644 tests/pretty/struct-pattern.rs create mode 100644 tests/pretty/struct-tuple.rs create mode 100644 tests/pretty/tag-blank-lines.rs create mode 100644 tests/pretty/tests-are-sorted.pp create mode 100644 tests/pretty/tests-are-sorted.rs create mode 100644 tests/pretty/top-level-doc-comments.rs create mode 100644 tests/pretty/trait-inner-attr.rs create mode 100644 tests/pretty/trait-polarity.rs create mode 100644 tests/pretty/trait-safety.rs create mode 100644 tests/pretty/unary-op-disambig.rs create mode 100644 tests/pretty/use-tree.rs create mode 100644 tests/pretty/vec-comments.pp create mode 100644 tests/pretty/vec-comments.rs create mode 100644 tests/pretty/where-clauses.rs create mode 100644 tests/pretty/yeet-expr.rs (limited to 'tests/pretty') diff --git a/tests/pretty/asm.pp b/tests/pretty/asm.pp new file mode 100644 index 000000000..5eade2933 --- /dev/null +++ b/tests/pretty/asm.pp @@ -0,0 +1,34 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// pretty-mode:expanded +// pp-exact:asm.pp +// only-x86_64 + +use std::arch::asm; + +pub fn main() { + let a: i32; + let mut b = 4i32; + unsafe { + asm!(""); + asm!(""); + asm!("", options(nomem, nostack)); + asm!("{0}", in(reg) 4); + asm!("{0}", out(reg) a); + asm!("{0}", inout(reg) b); + asm!("{0} {1}", out(reg) _, inlateout(reg) b => _); + asm!("", out("al") _, lateout("rcx") _); + asm!("inst1\ninst2"); + asm!("inst1 {0}, 42\ninst2 {1}, 24", in(reg) a, out(reg) b); + asm!("inst2 {1}, 24\ninst1 {0}, 42", in(reg) a, out(reg) b); + asm!("inst1 {0}, 42\ninst2 {1}, 24", in(reg) a, out(reg) b); + asm!("inst1\ninst2"); + asm!("inst1\ninst2"); + asm!("inst1\n\tinst2"); + asm!("inst1\ninst2\ninst3\ninst4"); + } +} diff --git a/tests/pretty/asm.rs b/tests/pretty/asm.rs new file mode 100644 index 000000000..1a3f972c8 --- /dev/null +++ b/tests/pretty/asm.rs @@ -0,0 +1,31 @@ +// pretty-mode:expanded +// pp-exact:asm.pp +// only-x86_64 + +use std::arch::asm; + +pub fn main() { + let a: i32; + let mut b = 4i32; + unsafe { + asm!(""); + asm!("", options()); + asm!("", options(nostack, nomem)); + asm!("{}", in(reg) 4); + asm!("{0}", out(reg) a); + asm!("{name}", name = inout(reg) b); + asm!("{} {}", out(reg) _, inlateout(reg) b => _); + asm!("", out("al") _, lateout("rcx") _); + asm!("inst1", "inst2"); + asm!("inst1 {}, 42", "inst2 {}, 24", in(reg) a, out(reg) b); + asm!("inst2 {1}, 24", "inst1 {0}, 42", in(reg) a, out(reg) b); + asm!("inst1 {}, 42", "inst2 {name}, 24", in(reg) a, name = out(reg) b); + asm!( + "inst1 +inst2" + ); + asm!("inst1\ninst2"); + asm!("inst1\n\tinst2"); + asm!("inst1\ninst2", "inst3\ninst4"); + } +} diff --git a/tests/pretty/ast-stmt-expr-attr.rs b/tests/pretty/ast-stmt-expr-attr.rs new file mode 100644 index 000000000..27c86ec22 --- /dev/null +++ b/tests/pretty/ast-stmt-expr-attr.rs @@ -0,0 +1,175 @@ +// pp-exact + +fn main() {} + +#[cfg(FALSE)] +fn syntax() { + let _ = #[attr] box 0; + let _ = #[attr] []; + let _ = #[attr] [0]; + let _ = #[attr] [0; 0]; + let _ = #[attr] [0, 0, 0]; + let _ = #[attr] foo(); + let _ = #[attr] x.foo(); + let _ = #[attr] (); + let _ = #[attr] (#[attr] 0,); + let _ = #[attr] (#[attr] 0, 0); + let _ = #[attr] 0 + #[attr] 0; + let _ = #[attr] 0 / #[attr] 0; + let _ = #[attr] 0 & #[attr] 0; + let _ = #[attr] 0 % #[attr] 0; + let _ = #[attr] (0 + 0); + let _ = #[attr] !0; + let _ = #[attr] -0; + let _ = #[attr] false; + let _ = #[attr] 0; + let _ = #[attr] 'c'; + let _ = #[attr] x as Y; + let _ = #[attr] (x as Y); + let _ = + #[attr] while true { + #![attr] + }; + let _ = + #[attr] while let Some(false) = true { + #![attr] + }; + let _ = + #[attr] for x in y { + #![attr] + }; + let _ = + #[attr] loop { + #![attr] + }; + let _ = + #[attr] match true { + #![attr] + #[attr] + _ => false, + }; + let _ = #[attr] || #[attr] foo; + let _ = #[attr] move || #[attr] foo; + let _ = + #[attr] || + #[attr] { + #![attr] + foo + }; + let _ = + #[attr] move || + #[attr] { + #![attr] + foo + }; + let _ = + #[attr] || + { + #![attr] + foo + }; + let _ = + #[attr] move || + { + #![attr] + foo + }; + let _ = + #[attr] { + #![attr] + }; + let _ = + #[attr] { + #![attr] + let _ = (); + }; + let _ = + #[attr] { + #![attr] + let _ = (); + foo + }; + let _ = #[attr] x = y; + let _ = #[attr] (x = y); + let _ = #[attr] x += y; + let _ = #[attr] (x += y); + let _ = #[attr] foo.bar; + let _ = (#[attr] foo).bar; + let _ = #[attr] foo.0; + let _ = (#[attr] foo).0; + let _ = #[attr] foo[bar]; + let _ = (#[attr] foo)[bar]; + let _ = #[attr] 0..#[attr] 0; + let _ = #[attr] 0..; + let _ = #[attr] (0..0); + let _ = #[attr] (0..); + let _ = #[attr] (..0); + let _ = #[attr] (..); + let _ = #[attr] foo::bar::baz; + let _ = #[attr] &0; + let _ = #[attr] &mut 0; + let _ = #[attr] &#[attr] 0; + let _ = #[attr] &mut #[attr] 0; + let _ = #[attr] break; + let _ = #[attr] continue; + let _ = #[attr] return; + let _ = #[attr] foo!(); + let _ = #[attr] foo!(#! [attr]); + let _ = #[attr] foo![]; + let _ = #[attr] foo![#! [attr]]; + let _ = #[attr] foo! {}; + let _ = #[attr] foo! { #! [attr] }; + let _ = #[attr] Foo { bar: baz }; + let _ = #[attr] Foo { ..foo }; + let _ = #[attr] Foo { bar: baz, ..foo }; + let _ = #[attr] (0); + + { + #[attr] + let _ = 0; + + #[attr] + 0; + + #[attr] + foo!(); + + #[attr] + foo! {} + + #[attr] + foo![]; + } + + { + #[attr] + let _ = 0; + } + { + + #[attr] + 0 + } + { + + #[attr] + { + #![attr] + } + } + { + + #[attr] + foo!() + } + { + + #[attr] + foo![] + } + { + + #[attr] + foo! {} + } +} diff --git a/tests/pretty/async.rs b/tests/pretty/async.rs new file mode 100644 index 000000000..573e79bff --- /dev/null +++ b/tests/pretty/async.rs @@ -0,0 +1,9 @@ +// pp-exact +// pretty-compare-only +// edition:2021 + +async fn f() { + let first = async { 1 }; + let second = async move { 2 }; + join(first, second).await +} diff --git a/tests/pretty/attr-derive.rs b/tests/pretty/attr-derive.rs new file mode 100644 index 000000000..0eb403c6b --- /dev/null +++ b/tests/pretty/attr-derive.rs @@ -0,0 +1,32 @@ +// aux-build:derive-foo.rs +// pp-exact +// Testing that both the inner item and next outer item are +// preserved, and that the first outer item parsed in main is not +// accidentally carried over to each inner function + +#[macro_use] +extern crate derive_foo; + +#[derive(Foo)] +struct X; + +#[derive(Foo)] +#[Bar] +struct Y; + +#[derive(Foo)] +struct WithRef { + x: X, + #[Bar] + y: Y, +} + +#[derive(Foo)] +enum Enum { + + #[Bar] + Asdf, + Qwerty, +} + +fn main() {} diff --git a/tests/pretty/attr-fn-inner.rs b/tests/pretty/attr-fn-inner.rs new file mode 100644 index 000000000..6d9cb89f0 --- /dev/null +++ b/tests/pretty/attr-fn-inner.rs @@ -0,0 +1,16 @@ +// Testing that both the inner item and next outer item are +// preserved, and that the first outer item parsed in main is not +// accidentally carried over to each inner function + +// pp-exact + +#![feature(rustc_attrs)] + +fn main() { + #![rustc_dummy] + #[rustc_dummy] + fn f() {} + + #[rustc_dummy] + fn g() {} +} diff --git a/tests/pretty/attr-literals.rs b/tests/pretty/attr-literals.rs new file mode 100644 index 000000000..d13201442 --- /dev/null +++ b/tests/pretty/attr-literals.rs @@ -0,0 +1,14 @@ +// Tests literals in attributes. + +// pp-exact + +#![feature(rustc_attrs)] + +fn main() { + #![rustc_dummy("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))] + #[rustc_dummy = 8] + fn f() {} + + #[rustc_dummy(1, 2, 3)] + fn g() {} +} diff --git a/tests/pretty/attr-tokens-raw-ident.rs b/tests/pretty/attr-tokens-raw-ident.rs new file mode 100644 index 000000000..8486342b0 --- /dev/null +++ b/tests/pretty/attr-tokens-raw-ident.rs @@ -0,0 +1,7 @@ +// Keywords in attribute paths are printed as raw idents, +// but keywords in attribute arguments are not. + +// pp-exact + +#[rustfmt::r#final(final)] +fn main() {} diff --git a/tests/pretty/auto-trait.rs b/tests/pretty/auto-trait.rs new file mode 100644 index 000000000..c3c47cff5 --- /dev/null +++ b/tests/pretty/auto-trait.rs @@ -0,0 +1,9 @@ +#![feature(auto_traits)] + +// pp-exact + +auto trait MyTrait {} + +unsafe auto trait UnsafeMyTrait {} + +pub fn main() {} diff --git a/tests/pretty/auxiliary/derive-foo.rs b/tests/pretty/auxiliary/derive-foo.rs new file mode 100644 index 000000000..675a93b3d --- /dev/null +++ b/tests/pretty/auxiliary/derive-foo.rs @@ -0,0 +1,13 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_derive(Foo, attributes(Bar))] +pub fn derive(input: TokenStream) -> TokenStream { + "".parse().unwrap() +} diff --git a/tests/pretty/blank-lines.rs b/tests/pretty/blank-lines.rs new file mode 100644 index 000000000..b9153d048 --- /dev/null +++ b/tests/pretty/blank-lines.rs @@ -0,0 +1,17 @@ +// compile-flags: --crate-type=lib + +// pp-exact +fn f() -> [isize; 3] { + let picard = 0; + + let data = 1; + + let worf = 2; + + + let enterprise = [picard, data, worf]; + + + + return enterprise; +} diff --git a/tests/pretty/block-comment-multiple-asterisks.rs b/tests/pretty/block-comment-multiple-asterisks.rs new file mode 100644 index 000000000..bb090b746 --- /dev/null +++ b/tests/pretty/block-comment-multiple-asterisks.rs @@ -0,0 +1,6 @@ +// compile-flags: --crate-type=lib + +// pp-exact +/*** +More than two asterisks means that it isn't a doc comment. +*/ diff --git a/tests/pretty/block-comment-trailing-whitespace.rs b/tests/pretty/block-comment-trailing-whitespace.rs new file mode 100644 index 000000000..4d502f603 --- /dev/null +++ b/tests/pretty/block-comment-trailing-whitespace.rs @@ -0,0 +1,10 @@ +// compile-flags: --crate-type=lib + +// pp-exact +fn f() { + /* + The next line should not be indented. + + That one. It shouldn't have been indented. + */ +} diff --git a/tests/pretty/block-comment-trailing-whitespace2.rs b/tests/pretty/block-comment-trailing-whitespace2.rs new file mode 100644 index 000000000..e53d51e34 --- /dev/null +++ b/tests/pretty/block-comment-trailing-whitespace2.rs @@ -0,0 +1,8 @@ +// compile-flags: --crate-type=lib + +// pp-exact +fn f() {} /* + The next line should not be indented. + + That one. It shouldn't have been indented. + */ diff --git a/tests/pretty/block-comment-wchar.pp b/tests/pretty/block-comment-wchar.pp new file mode 100644 index 000000000..9d64fb415 --- /dev/null +++ b/tests/pretty/block-comment-wchar.pp @@ -0,0 +1,101 @@ +// This is meant as a test case for Issue 3961. +// +// Test via: rustc -Zunpretty normal tests/pretty/block-comment-wchar.rs +// ignore-tidy-cr +// ignore-tidy-tab +// pp-exact:block-comment-wchar.pp +fn f() { + fn nested() { + /* + Spaced2 + */ + /* + Spaced10 + */ + /* + Tabbed8+2 + */ + /* + CR8+2 + */ + } + /* + Spaced2: (prefixed so start of space aligns with comment) + */ + /* + Tabbed2: (more indented b/c *start* of space will align with comment) + */ + /* + Spaced6: (Alignment removed and realigning spaces inserted) + */ + /* + Tabbed4+2: (Alignment removed and realigning spaces inserted) + */ + + /* + VT4+2: (should align) + */ + /* + FF4+2: (should align) + */ + /* + CR4+2: (should align) + */ + /* + NEL4+2: (should align) + */ + /* + Ogham Space Mark 4+2: (should align) + */ + /* + Ogham Space Mark 4+2: (should align) + */ + /* + Four-per-em space 4+2: (should align) + */ + + /* + Ogham Space Mark count 1: (should align) + Ogham Space Mark count 2: (should align) + Ogham Space Mark count 3: (should align) + Ogham Space Mark count 4: (should align) + Ogham Space Mark count 5: (should align) + Ogham Space Mark count 6: (should align) + Ogham Space Mark count 7: (should align) + Ogham Space Mark count 8: (should align) + Ogham Space Mark count 9: (should align) + Ogham Space Mark count A: (should align) + Ogham Space Mark count B: (should align) + Ogham Space Mark count C: (should align) + Ogham Space Mark count D: (should align) + Ogham Space Mark count E: (should align) + Ogham Space Mark count F: (should align) + */ + + + /* */ + + /* + Hello from offset 6 + Space 6+2: compare A + Ogham Space Mark 6+2: compare B + */ + /* */ + + /* + Hello from another offset 6 with wchars establishing column offset + Space 6+2: compare C + Ogham Space Mark 6+2: compare D + */ +} + +fn main() { + // Taken from https://www.unicode.org/Public/UNIDATA/PropList.txt + let chars = + ['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}', + '\u{1680}', '\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}', + '\u{2004}', '\u{2005}', '\u{2006}', '\u{2007}', '\u{2008}', + '\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}', + '\u{205F}', '\u{3000}']; + for c in &chars { let ws = c.is_whitespace(); println!("{} {}", c, ws); } +} diff --git a/tests/pretty/block-comment-wchar.rs b/tests/pretty/block-comment-wchar.rs new file mode 100644 index 000000000..c042ea685 --- /dev/null +++ b/tests/pretty/block-comment-wchar.rs @@ -0,0 +1,100 @@ +// This is meant as a test case for Issue 3961. +// +// Test via: rustc -Zunpretty normal tests/pretty/block-comment-wchar.rs +// ignore-tidy-cr +// ignore-tidy-tab +// pp-exact:block-comment-wchar.pp +fn f() { + fn nested() { + /* + Spaced2 + */ + /* + Spaced10 + */ + /* + Tabbed8+2 + */ + /* + CR8+2 + */ + } + /* + Spaced2: (prefixed so start of space aligns with comment) + */ + /* + Tabbed2: (more indented b/c *start* of space will align with comment) + */ + /* + Spaced6: (Alignment removed and realigning spaces inserted) + */ + /* + Tabbed4+2: (Alignment removed and realigning spaces inserted) + */ + + /* + VT4+2: (should align) + */ + /* + FF4+2: (should align) + */ + /* + CR4+2: (should align) + */ + /* +………… NEL4+2: (should align) + */ + /* +     Ogham Space Mark 4+2: (should align) + */ + /* +     Ogham Space Mark 4+2: (should align) + */ + /* +     Four-per-em space 4+2: (should align) + */ + + /* +   Ogham Space Mark count 1: (should align) +   Ogham Space Mark count 2: (should align) +    Ogham Space Mark count 3: (should align) +   Ogham Space Mark count 4: (should align) +     Ogham Space Mark count 5: (should align) +    Ogham Space Mark count 6: (should align) +     Ogham Space Mark count 7: (should align) +  Ogham Space Mark count 8: (should align) +    Ogham Space Mark count 9: (should align) +    Ogham Space Mark count A: (should align) +     Ogham Space Mark count B: (should align) +   Ogham Space Mark count C: (should align) +     Ogham Space Mark count D: (should align) +    Ogham Space Mark count E: (should align) +     Ogham Space Mark count F: (should align) + */ + + +/* */ /* + Hello from offset 6 + Space 6+2: compare A +       Ogham Space Mark 6+2: compare B + */ +/* */ /* + Hello from another offset 6 with wchars establishing column offset + Space 6+2: compare C +       Ogham Space Mark 6+2: compare D + */ +} + +fn main() { + // Taken from https://www.unicode.org/Public/UNIDATA/PropList.txt + let chars = + ['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}', + '\u{1680}', '\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}', + '\u{2004}', '\u{2005}', '\u{2006}', '\u{2007}', '\u{2008}', + '\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}', + '\u{205F}', '\u{3000}']; + for c in &chars { + let ws = c.is_whitespace(); + println!("{} {}", c , ws); + } +} diff --git a/tests/pretty/block-disambig.rs b/tests/pretty/block-disambig.rs new file mode 100644 index 000000000..ac9b84a5d --- /dev/null +++ b/tests/pretty/block-disambig.rs @@ -0,0 +1,59 @@ +// compile-flags: --crate-type=lib + +// A bunch of tests for syntactic forms involving blocks that were +// previously ambiguous (e.g., 'if true { } *val;' gets parsed as a +// binop) + + +use std::cell::Cell; + +fn test1() { let val = &0; { } *val; } + +fn test2() -> isize { let val = &0; { } *val } + +#[derive(Copy, Clone)] +struct S { eax: isize } + +fn test3() { + let regs = &Cell::new(S {eax: 0}); + match true { true => { } _ => { } } + regs.set(S {eax: 1}); +} + +fn test4() -> bool { let regs = &true; if true { } *regs || false } + +fn test5() -> (isize, isize) { { } (0, 1) } + +fn test6() -> bool { { } (true || false) && true } + +fn test7() -> usize { + let regs = &0; + match true { true => { } _ => { } } + (*regs < 2) as usize +} + +fn test8() -> isize { + let val = &0; + match true { + true => { } + _ => { } + } + if *val < 1 { + 0 + } else { + 1 + } +} + +fn test9() { + let regs = &Cell::new(0); + match true { true => { } _ => { } } regs.set(regs.get() + 1); +} + +fn test10() -> isize { + let regs = vec![0]; + match true { true => { } _ => { } } + regs[0] +} + +fn test11() -> Vec { if true { } vec![1, 2] } diff --git a/tests/pretty/cast-lt.pp b/tests/pretty/cast-lt.pp new file mode 100644 index 000000000..e6c4d1956 --- /dev/null +++ b/tests/pretty/cast-lt.pp @@ -0,0 +1,13 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// pretty-compare-only +// pretty-mode:expanded +// pp-exact:cast-lt.pp + +macro_rules! negative { ($e : expr) => { $e < 0 } } + +fn main() { (1 as i32) < 0; } diff --git a/tests/pretty/cast-lt.rs b/tests/pretty/cast-lt.rs new file mode 100644 index 000000000..e14bdd1f3 --- /dev/null +++ b/tests/pretty/cast-lt.rs @@ -0,0 +1,11 @@ +// pretty-compare-only +// pretty-mode:expanded +// pp-exact:cast-lt.pp + +macro_rules! negative { + ($e:expr) => { $e < 0 } +} + +fn main() { + negative!(1 as i32); +} diff --git a/tests/pretty/closure-reform-pretty.rs b/tests/pretty/closure-reform-pretty.rs new file mode 100644 index 000000000..1eba1e6bd --- /dev/null +++ b/tests/pretty/closure-reform-pretty.rs @@ -0,0 +1,16 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/publicdomain/zero/1.0/ + +// pp-exact + +fn call_it(f: Box String>) {} + +fn call_this(f: F) where F: Fn(&str) + Send {} + +fn call_that(f: F) where F: for<'a> Fn(&'a isize, &'a isize) -> isize {} + +fn call_extern(f: fn() -> isize) {} + +fn call_abid_extern(f: extern "C" fn() -> isize) {} + +pub fn main() {} diff --git a/tests/pretty/delimited-token-groups.rs b/tests/pretty/delimited-token-groups.rs new file mode 100644 index 000000000..c7c9277fa --- /dev/null +++ b/tests/pretty/delimited-token-groups.rs @@ -0,0 +1,48 @@ +// pp-exact + +#![feature(rustc_attrs)] + +macro_rules! mac { ($($tt : tt) *) => () } + +mac! { + struct S { field1 : u8, field2 : u16, } impl Clone for S + { + fn clone() -> S + { + panic! () ; + + } + } +} + +mac! { + a(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa + aaaaaaaa aaaaaaaa) a + [aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa + aaaaaaaa aaaaaaaa] a + { + aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa + aaaaaaaa aaaaaaaa aaaaaaaa + } a +} + +mac!(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa +aaaaaaaa aaaaaaaa); +mac![aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa +aaaaaaaa aaaaaaaa]; +mac! { + aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa + aaaaaaaa aaaaaaaa +} + +#[rustc_dummy(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa +aaaaaaaa aaaaaaaa aaaaaaaa)] +#[rustc_dummy[aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa +aaaaaaaa aaaaaaaa aaaaaaaa]] +#[rustc_dummy { + aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa + aaaaaaaa aaaaaaaa +}] +#[rustc_dummy = +"aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa"] +fn main() {} diff --git a/tests/pretty/disamb-stmt-expr.rs b/tests/pretty/disamb-stmt-expr.rs new file mode 100644 index 000000000..734f9fa12 --- /dev/null +++ b/tests/pretty/disamb-stmt-expr.rs @@ -0,0 +1,10 @@ +// pp-exact + +// Here we check that the parentheses around the body of `wsucc()` are +// preserved. They are needed to disambiguate `{return n+1}; - 0` from +// `({return n+1}-0)`. + +fn id(f: F) -> isize where F: Fn() -> isize { f() } + +fn wsucc(_n: isize) -> isize { id(|| { 1 }) - 0 } +fn main() {} diff --git a/tests/pretty/do1.rs b/tests/pretty/do1.rs new file mode 100644 index 000000000..233ccdb00 --- /dev/null +++ b/tests/pretty/do1.rs @@ -0,0 +1,5 @@ +// pp-exact + +fn f(f: F) where F: Fn(isize) { f(10) } + +fn main() { f(|i| { assert_eq!(i, 10) }) } diff --git a/tests/pretty/doc-comments.rs b/tests/pretty/doc-comments.rs new file mode 100644 index 000000000..a49860daa --- /dev/null +++ b/tests/pretty/doc-comments.rs @@ -0,0 +1,53 @@ +// compile-flags: --crate-type=lib + +// pp-exact + +// some single-line non-doc comment + +/// some single line outer-docs +fn a() {} + +fn b() { + //! some single line inner-docs +} + +////////////////////////////////// +// some single-line non-doc comment preceded by a separator + +////////////////////////////////// +/// some single-line outer-docs preceded by a separator +/// (and trailing whitespaces) +fn c() {} + +/* + * some multi-line non-doc comment + */ + +/** + * some multi-line outer-docs + */ +fn d() {} + +fn e() { + /*! + * some multi-line inner-docs + */ +} + +/********************************/ +/* + * some multi-line non-doc comment preceded by a separator + */ + +/********************************/ +/** + * some multi-line outer-docs preceded by a separator + */ +fn f() {} + +#[doc = "unsugared outer doc-comments work also"] +fn g() {} + +fn h() { + #![doc = "as do inner ones"] +} diff --git a/tests/pretty/dollar-crate.pp b/tests/pretty/dollar-crate.pp new file mode 100644 index 000000000..3af37955f --- /dev/null +++ b/tests/pretty/dollar-crate.pp @@ -0,0 +1,13 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// pretty-compare-only +// pretty-mode:expanded +// pp-exact:dollar-crate.pp + +fn main() { + { ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &[])); }; +} diff --git a/tests/pretty/dollar-crate.rs b/tests/pretty/dollar-crate.rs new file mode 100644 index 000000000..e46bc7f48 --- /dev/null +++ b/tests/pretty/dollar-crate.rs @@ -0,0 +1,7 @@ +// pretty-compare-only +// pretty-mode:expanded +// pp-exact:dollar-crate.pp + +fn main() { + println!("rust"); +} diff --git a/tests/pretty/empty-impl.rs b/tests/pretty/empty-impl.rs new file mode 100644 index 000000000..d57093359 --- /dev/null +++ b/tests/pretty/empty-impl.rs @@ -0,0 +1,7 @@ +// compile-flags: --crate-type=lib + +trait X { fn dummy(&self) { } } +impl X for usize { } + +trait Y { fn dummy(&self) { } } +impl Y for usize { } diff --git a/tests/pretty/empty-lines.rs b/tests/pretty/empty-lines.rs new file mode 100644 index 000000000..15d7625d4 --- /dev/null +++ b/tests/pretty/empty-lines.rs @@ -0,0 +1,9 @@ +// compile-flags: --crate-type=lib + +// Issue #759 +// Whitespace under block opening should not expand forever + +fn a() -> usize { + + 1 +} diff --git a/tests/pretty/enum-variant-vis.rs b/tests/pretty/enum-variant-vis.rs new file mode 100644 index 000000000..fc646c295 --- /dev/null +++ b/tests/pretty/enum-variant-vis.rs @@ -0,0 +1,8 @@ +// pp-exact + +// Check that the visibility is printed on an enum variant. + +fn main() {} + +#[cfg(FALSE)] +enum Foo { pub V, } diff --git a/tests/pretty/example1.rs b/tests/pretty/example1.rs new file mode 100644 index 000000000..8df74e8e1 --- /dev/null +++ b/tests/pretty/example1.rs @@ -0,0 +1,3 @@ +// pp-exact + +fn main() {} diff --git a/tests/pretty/example2.pp b/tests/pretty/example2.pp new file mode 100644 index 000000000..3f7129afd --- /dev/null +++ b/tests/pretty/example2.pp @@ -0,0 +1,3 @@ +// pp-exact:example2.pp + +fn main() {} diff --git a/tests/pretty/example2.rs b/tests/pretty/example2.rs new file mode 100644 index 000000000..3f7129afd --- /dev/null +++ b/tests/pretty/example2.rs @@ -0,0 +1,3 @@ +// pp-exact:example2.pp + +fn main() {} diff --git a/tests/pretty/expanded-and-path-remap-80832.pp b/tests/pretty/expanded-and-path-remap-80832.pp new file mode 100644 index 000000000..8385c5fa8 --- /dev/null +++ b/tests/pretty/expanded-and-path-remap-80832.pp @@ -0,0 +1,13 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// Test for issue 80832 +// +// pretty-mode:expanded +// pp-exact:expanded-and-path-remap-80832.pp +// compile-flags: --remap-path-prefix {{src-base}}=the/src + +fn main() {} diff --git a/tests/pretty/expanded-and-path-remap-80832.rs b/tests/pretty/expanded-and-path-remap-80832.rs new file mode 100644 index 000000000..f48441fbc --- /dev/null +++ b/tests/pretty/expanded-and-path-remap-80832.rs @@ -0,0 +1,7 @@ +// Test for issue 80832 +// +// pretty-mode:expanded +// pp-exact:expanded-and-path-remap-80832.pp +// compile-flags: --remap-path-prefix {{src-base}}=the/src + +fn main() {} diff --git a/tests/pretty/fn-return.rs b/tests/pretty/fn-return.rs new file mode 100644 index 000000000..b932e83aa --- /dev/null +++ b/tests/pretty/fn-return.rs @@ -0,0 +1,7 @@ +// pp-exact + +// Check that `fn f() -> () {}` does not print as `fn f() {}`. + +fn f() -> () {} + +fn main() {} diff --git a/tests/pretty/fn-types.rs b/tests/pretty/fn-types.rs new file mode 100644 index 000000000..f012763c3 --- /dev/null +++ b/tests/pretty/fn-types.rs @@ -0,0 +1,5 @@ +// pp-exact + +fn from_foreign_fn(_x: fn()) {} +fn from_stack_closure(_x: F) where F: Fn() {} +fn main() {} diff --git a/tests/pretty/fn-variadic.rs b/tests/pretty/fn-variadic.rs new file mode 100644 index 000000000..59e477cfa --- /dev/null +++ b/tests/pretty/fn-variadic.rs @@ -0,0 +1,15 @@ +// Check that `fn foo(x: i32, ...)` does not print as `fn foo(x: i32, ..., ...)`. +// See issue #58853. + +// pp-exact +#![feature(c_variadic)] + +extern "C" { + pub fn foo(x: i32, ...); +} + +pub unsafe extern "C" fn bar(_: i32, mut ap: ...) -> usize { + ap.arg::() +} + +fn main() {} diff --git a/tests/pretty/for-comment.rs b/tests/pretty/for-comment.rs new file mode 100644 index 000000000..447e7f918 --- /dev/null +++ b/tests/pretty/for-comment.rs @@ -0,0 +1,11 @@ +// compile-flags: --crate-type=lib + +// pp-exact + +fn f(v: &[isize]) -> isize { + let mut n = 0; + for e in v { + n = *e; // This comment once triggered pretty printer bug + } + n +} diff --git a/tests/pretty/gat-bounds.rs b/tests/pretty/gat-bounds.rs new file mode 100644 index 000000000..0a361a383 --- /dev/null +++ b/tests/pretty/gat-bounds.rs @@ -0,0 +1,16 @@ +// Check that associated types print generic parameters and where clauses. +// See issue #67509. + +// pretty-compare-only + +trait X { + type Y: Trait where Self: Sized; +} + +impl X for () { + type Y where Self: Sized = u32; +} + +fn f = i32>>() {} + +fn main() { } diff --git a/tests/pretty/hir-pretty-loop.pp b/tests/pretty/hir-pretty-loop.pp new file mode 100644 index 000000000..a59a3002c --- /dev/null +++ b/tests/pretty/hir-pretty-loop.pp @@ -0,0 +1,9 @@ +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// pretty-compare-only +// pretty-mode:hir +// pp-exact:hir-pretty-loop.pp + +fn foo() { loop { break; } } diff --git a/tests/pretty/hir-pretty-loop.rs b/tests/pretty/hir-pretty-loop.rs new file mode 100644 index 000000000..87a3ef8b8 --- /dev/null +++ b/tests/pretty/hir-pretty-loop.rs @@ -0,0 +1,9 @@ +// pretty-compare-only +// pretty-mode:hir +// pp-exact:hir-pretty-loop.pp + +pub fn foo(){ + loop{ + break; + } +} diff --git a/tests/pretty/if-attr.rs b/tests/pretty/if-attr.rs new file mode 100644 index 000000000..7b90b0bec --- /dev/null +++ b/tests/pretty/if-attr.rs @@ -0,0 +1,37 @@ +// pp-exact + +#[cfg(FALSE)] +fn simple_attr() { + + #[attr] + if true {} + + #[allow_warnings] + if true {} +} + +#[cfg(FALSE)] +fn if_else_chain() { + + #[first_attr] + if true {} else if false {} else {} +} + +#[cfg(FALSE)] +fn if_let() { + + #[attr] + if let Some(_) = Some(true) {} +} + +#[cfg(FALSE)] +fn let_attr_if() { + let _ = #[attr] if let _ = 0 {}; + let _ = #[attr] if true {}; + + let _ = #[attr] if let _ = 0 {} else {}; + let _ = #[attr] if true {} else {}; +} + + +fn main() {} diff --git a/tests/pretty/import-renames.rs b/tests/pretty/import-renames.rs new file mode 100644 index 000000000..ce6b5058b --- /dev/null +++ b/tests/pretty/import-renames.rs @@ -0,0 +1,6 @@ +// compile-flags: --crate-type=lib + +// pp-exact + +use std::io::{self, Error as IoError}; +use std::net::{self as stdnet, TcpStream}; diff --git a/tests/pretty/issue-12590-a.rs b/tests/pretty/issue-12590-a.rs new file mode 100644 index 000000000..3c88f5cb8 --- /dev/null +++ b/tests/pretty/issue-12590-a.rs @@ -0,0 +1,9 @@ +// pp-exact +// pretty-compare-only + +// The next line should not be expanded + +#[path = "issue-12590-b.rs"] +mod issue_12590_b; + +fn main() {} diff --git a/tests/pretty/issue-12590-b.rs b/tests/pretty/issue-12590-b.rs new file mode 100644 index 000000000..b14c7afa2 --- /dev/null +++ b/tests/pretty/issue-12590-b.rs @@ -0,0 +1,5 @@ +// Second part of two-file test + +fn b() { } + +fn main() { } diff --git a/tests/pretty/issue-12590-c.pp b/tests/pretty/issue-12590-c.pp new file mode 100644 index 000000000..07b3f5653 --- /dev/null +++ b/tests/pretty/issue-12590-c.pp @@ -0,0 +1,19 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// pretty-compare-only +// pretty-mode:expanded +// pp-exact:issue-12590-c.pp + +// The next line should be expanded + +#[path = "issue-12590-b.rs"] +mod issue_12590_b { + + fn b() {} + fn main() {} +} +fn main() {} diff --git a/tests/pretty/issue-12590-c.rs b/tests/pretty/issue-12590-c.rs new file mode 100644 index 000000000..0ec05f9a8 --- /dev/null +++ b/tests/pretty/issue-12590-c.rs @@ -0,0 +1,10 @@ +// pretty-compare-only +// pretty-mode:expanded +// pp-exact:issue-12590-c.pp + +// The next line should be expanded + +#[path = "issue-12590-b.rs"] +mod issue_12590_b; + +fn main() {} diff --git a/tests/pretty/issue-19077.rs b/tests/pretty/issue-19077.rs new file mode 100644 index 000000000..0d2702804 --- /dev/null +++ b/tests/pretty/issue-19077.rs @@ -0,0 +1,11 @@ +// +// Testing that unsafe blocks in match arms are followed by a comma +// pp-exact +fn main() { + match true { + true if true => (), + false if false => unsafe {}, + true => {} + false => (), + } +} diff --git a/tests/pretty/issue-25031.rs b/tests/pretty/issue-25031.rs new file mode 100644 index 000000000..d91494891 --- /dev/null +++ b/tests/pretty/issue-25031.rs @@ -0,0 +1,8 @@ +// +// Testing that type items with where clauses output correctly. + +// pp-exact + +fn main() { + type Foo where T: Copy = Box; +} diff --git a/tests/pretty/issue-30731.rs b/tests/pretty/issue-30731.rs new file mode 100644 index 000000000..607cbebee --- /dev/null +++ b/tests/pretty/issue-30731.rs @@ -0,0 +1,8 @@ +// +// Test pretty printing of macro with braces but without terminating semicolon, +// this used to panic before fix. + +// pretty-compare-only +// pp-exact + +fn main() { b! {} c } diff --git a/tests/pretty/issue-31073.pp b/tests/pretty/issue-31073.pp new file mode 100644 index 000000000..75795f6d5 --- /dev/null +++ b/tests/pretty/issue-31073.pp @@ -0,0 +1,7 @@ +// pp-exact:issue-31073.pp + +fn main() { + fn f1(x: i32, y: i32) -> i32 { y } + let f: fn(_, i32) -> i32 = f1; + f(1, 2); +} diff --git a/tests/pretty/issue-31073.rs b/tests/pretty/issue-31073.rs new file mode 100644 index 000000000..75795f6d5 --- /dev/null +++ b/tests/pretty/issue-31073.rs @@ -0,0 +1,7 @@ +// pp-exact:issue-31073.pp + +fn main() { + fn f1(x: i32, y: i32) -> i32 { y } + let f: fn(_, i32) -> i32 = f1; + f(1, 2); +} diff --git a/tests/pretty/issue-4264.pp b/tests/pretty/issue-4264.pp new file mode 100644 index 000000000..18e6d75b1 --- /dev/null +++ b/tests/pretty/issue-4264.pp @@ -0,0 +1,57 @@ +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// pretty-compare-only +// pretty-mode:hir,typed +// pp-exact:issue-4264.pp + +// #4264 fixed-length vector types + +fn foo(_: [i32; (3 as usize)]) ({ } as ()) + +fn bar() ({ + const FOO: usize = ((5 as usize) - (4 as usize) as usize); + let _: [(); (FOO as usize)] = ([(() as ())] as [(); 1]); + + let _: [(); (1 as usize)] = ([(() as ())] as [(); 1]); + + let _ = + (((&([(1 as i32), (2 as i32), (3 as i32)] as [i32; 3]) as + &[i32; 3]) as *const _ as *const [i32; 3]) as + *const [i32; (3 as usize)] as *const [i32; 3]); + + + + + + + + + + ({ + let res = + ((::alloc::fmt::format as + for<'a> fn(Arguments<'a>) -> String {format})(((::core::fmt::Arguments::new_v1 + as + fn(&[&'static str], &[ArgumentV1<'_>]) -> Arguments<'_> {Arguments::<'_>::new_v1})((&([("test" + as &str)] as [&str; 1]) as &[&str; 1]), + (&([] as [ArgumentV1<'_>; 0]) as &[ArgumentV1<'_>; 0])) as + Arguments<'_>)) as String); + (res as String) + } as String); + } as ()) +type Foo = [i32; (3 as usize)]; +struct Bar { + x: [i32; (3 as usize)], +} +struct TupleBar([i32; (4 as usize)]); +enum Baz { BazVariant([i32; (5 as usize)]), } +fn id(x: T) -> T ({ (x as T) } as T) +fn use_id() ({ + let _ = + ((id::<[i32; (3 as usize)]> as + fn([i32; 3]) -> [i32; 3] {id::<[i32; 3]>})(([(1 as i32), + (2 as i32), (3 as i32)] as [i32; 3])) as [i32; 3]); + } as ()) +fn main() ({ } as ()) diff --git a/tests/pretty/issue-4264.rs b/tests/pretty/issue-4264.rs new file mode 100644 index 000000000..3dea81129 --- /dev/null +++ b/tests/pretty/issue-4264.rs @@ -0,0 +1,39 @@ +// pretty-compare-only +// pretty-mode:hir,typed +// pp-exact:issue-4264.pp + +// #4264 fixed-length vector types + +pub fn foo(_: [i32; 3]) {} + +pub fn bar() { + const FOO: usize = 5 - 4; + let _: [(); FOO] = [()]; + + let _ : [(); 1] = [()]; + + let _ = &([1,2,3]) as *const _ as *const [i32; 3]; + + format!("test"); +} + +pub type Foo = [i32; 3]; + +pub struct Bar { + pub x: [i32; 3] +} + +pub struct TupleBar([i32; 4]); + +pub enum Baz { + BazVariant([i32; 5]) +} + +pub fn id(x: T) -> T { x } + +pub fn use_id() { + let _ = id::<[i32; 3]>([1,2,3]); +} + + +fn main() {} diff --git a/tests/pretty/issue-68710-field-attr-proc-mac-lost.rs b/tests/pretty/issue-68710-field-attr-proc-mac-lost.rs new file mode 100644 index 000000000..80f739f4f --- /dev/null +++ b/tests/pretty/issue-68710-field-attr-proc-mac-lost.rs @@ -0,0 +1,17 @@ +// pp-exact + +fn main() {} + +struct C { + field: u8, +} + +#[allow()] +const C: C = + C { + #[cfg(debug_assertions)] + field: 0, + + #[cfg(not(debug_assertions))] + field: 1, + }; diff --git a/tests/pretty/issue-73626.rs b/tests/pretty/issue-73626.rs new file mode 100644 index 000000000..a002f09be --- /dev/null +++ b/tests/pretty/issue-73626.rs @@ -0,0 +1,34 @@ +fn main(/* + --- +*/) { + let x /* this is one line */ = 3; + + let x /* + * this + * is + * multiple + * lines + */ = 3; + + let x = /* + * this + * is + * multiple + * lines + * after + * the + * = + */ 3; + + let x /* + * this + * is + * multiple + * lines + * including + * a + + * blank + * line + */ = 3; +} diff --git a/tests/pretty/issue-74745.rs b/tests/pretty/issue-74745.rs new file mode 100644 index 000000000..e255cd6ca --- /dev/null +++ b/tests/pretty/issue-74745.rs @@ -0,0 +1,5 @@ +// ignore-tidy-trailing-newlines +// pretty-compare-only + +/* +*/ \ No newline at end of file diff --git a/tests/pretty/issue-85089.pp b/tests/pretty/issue-85089.pp new file mode 100644 index 000000000..f84e9df04 --- /dev/null +++ b/tests/pretty/issue-85089.pp @@ -0,0 +1,20 @@ +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// Test to print lifetimes on HIR pretty-printing. + +// pretty-compare-only +// pretty-mode:hir +// pp-exact:issue-85089.pp + +trait A<'x> { } +trait B<'x> { } + +struct Foo<'b> { + bar: &'b dyn for<'a> A<'a>, +} + +impl <'a> B<'a> for dyn for<'b> A<'b> { } + +impl <'a> A<'a> for Foo<'a> { } diff --git a/tests/pretty/issue-85089.rs b/tests/pretty/issue-85089.rs new file mode 100644 index 000000000..eb45d4731 --- /dev/null +++ b/tests/pretty/issue-85089.rs @@ -0,0 +1,16 @@ +// Test to print lifetimes on HIR pretty-printing. + +// pretty-compare-only +// pretty-mode:hir +// pp-exact:issue-85089.pp + +trait A<'x> {} +trait B<'x> {} + +struct Foo<'b> { + pub bar: &'b dyn for<'a> A<'a>, +} + +impl<'a> B<'a> for dyn for<'b> A<'b> {} + +impl<'a> A<'a> for Foo<'a> {} diff --git a/tests/pretty/let.rs b/tests/pretty/let.rs new file mode 100644 index 000000000..20ffb7578 --- /dev/null +++ b/tests/pretty/let.rs @@ -0,0 +1,9 @@ +// pp-exact + +// Check that `let x: _ = 0;` does not print as `let x = 0;`. + +fn main() { + let x: _ = 0; + + let _ = x; +} diff --git a/tests/pretty/lifetime.rs b/tests/pretty/lifetime.rs new file mode 100644 index 000000000..34eae849b --- /dev/null +++ b/tests/pretty/lifetime.rs @@ -0,0 +1,5 @@ +// pp-exact + +fn f1<'a, 'b, 'c>(_x: &'a u32, _y: &'b u32, _z: &'c u32) where 'c: 'a + 'b {} + +fn main() {} diff --git a/tests/pretty/macro.rs b/tests/pretty/macro.rs new file mode 100644 index 000000000..b88ae7039 --- /dev/null +++ b/tests/pretty/macro.rs @@ -0,0 +1,7 @@ +// pp-exact + +#![feature(decl_macro)] + +pub(crate) macro mac { ($arg : expr) => { $arg + $arg } } + +fn main() {} diff --git a/tests/pretty/macro_rules.rs b/tests/pretty/macro_rules.rs new file mode 100644 index 000000000..01adb1413 --- /dev/null +++ b/tests/pretty/macro_rules.rs @@ -0,0 +1,19 @@ +// pp-exact + +macro_rules! brace { () => {} ; } + +macro_rules! bracket[() => {} ;]; + +macro_rules! paren(() => {} ;); + +macro_rules! matcher_brackets { + (paren) => {} ; (bracket) => {} ; (brace) => {} ; +} + +macro_rules! all_fragments { + ($b : block, $e : expr, $i : ident, $it : item, $l : lifetime, $lit : + literal, $m : meta, $p : pat, $pth : path, $s : stmt, $tt : tt, $ty : ty, + $vis : vis) => {} ; +} + +fn main() {} diff --git a/tests/pretty/match-block-expr.rs b/tests/pretty/match-block-expr.rs new file mode 100644 index 000000000..10903e928 --- /dev/null +++ b/tests/pretty/match-block-expr.rs @@ -0,0 +1,6 @@ +// pp-exact + +fn main() { + let x = match { 5 } { 1 => 5, 2 => 6, _ => 7, }; + assert_eq!(x, 7); +} diff --git a/tests/pretty/match-naked-expr-medium.rs b/tests/pretty/match-naked-expr-medium.rs new file mode 100644 index 000000000..836af9900 --- /dev/null +++ b/tests/pretty/match-naked-expr-medium.rs @@ -0,0 +1,14 @@ +// pp-exact + +fn main() { + let x = Some(3); + let _y = + match x { + Some(_) => + ["some(_)".to_string(), "not".to_string(), "SO".to_string(), + "long".to_string(), "string".to_string()], + None => + ["none".to_string(), "a".to_string(), "a".to_string(), + "a".to_string(), "a".to_string()], + }; +} diff --git a/tests/pretty/match-naked-expr.rs b/tests/pretty/match-naked-expr.rs new file mode 100644 index 000000000..7c16bbefe --- /dev/null +++ b/tests/pretty/match-naked-expr.rs @@ -0,0 +1,10 @@ +// pp-exact + +fn main() { + let x = Some(3); + let _y = + match x { + Some(_) => "some(_)".to_string(), + None => "none".to_string(), + }; +} diff --git a/tests/pretty/nested-item-vis-defaultness.rs b/tests/pretty/nested-item-vis-defaultness.rs new file mode 100644 index 000000000..b094ba577 --- /dev/null +++ b/tests/pretty/nested-item-vis-defaultness.rs @@ -0,0 +1,47 @@ +// Check that nested items have their visibility and `default`nesses in the right order. + +// pp-exact + +fn main() {} + +#[cfg(FALSE)] +extern "C" { + static X: u8; + type X; + fn foo(); + pub static X: u8; + pub type X; + pub fn foo(); +} + +#[cfg(FALSE)] +trait T { + const X: u8; + type X; + fn foo(); + default const X: u8; + default type X; + default fn foo(); + pub const X: u8; + pub type X; + pub fn foo(); + pub default const X: u8; + pub default type X; + pub default fn foo(); +} + +#[cfg(FALSE)] +impl T for S { + const X: u8; + type X; + fn foo(); + default const X: u8; + default type X; + default fn foo(); + pub const X: u8; + pub type X; + pub fn foo(); + pub default const X: u8; + pub default type X; + pub default fn foo(); +} diff --git a/tests/pretty/path-type-bounds.rs b/tests/pretty/path-type-bounds.rs new file mode 100644 index 000000000..f1970de6f --- /dev/null +++ b/tests/pretty/path-type-bounds.rs @@ -0,0 +1,15 @@ +// pp-exact + + +trait Tr { + fn dummy(&self) {} +} +impl Tr for isize {} + +fn foo<'a>(x: Box) -> Box { x } + +fn main() { + let x: Box; + + Box::new(1isize) as Box; +} diff --git a/tests/pretty/qpath-associated-type-bound.rs b/tests/pretty/qpath-associated-type-bound.rs new file mode 100644 index 000000000..67a5d1dd8 --- /dev/null +++ b/tests/pretty/qpath-associated-type-bound.rs @@ -0,0 +1,16 @@ +// pp-exact + + +mod m { + pub trait Tr { + type Ts: super::Tu; + } +} + +trait Tu { + fn dummy() {} +} + +fn foo() { ::Ts::dummy(); } + +fn main() {} diff --git a/tests/pretty/raw-address-of.rs b/tests/pretty/raw-address-of.rs new file mode 100644 index 000000000..6ccc434a1 --- /dev/null +++ b/tests/pretty/raw-address-of.rs @@ -0,0 +1,12 @@ +// pp-exact +#![feature(raw_ref_op)] + +const C_PTR: () = { let a = 1; &raw const a; }; +static S_PTR: () = { let b = false; &raw const b; }; + +fn main() { + let x = 123; + let mut y = 345; + let c_p = &raw const x; + let parens = unsafe { *(&raw mut (y)) }; +} diff --git a/tests/pretty/raw-str-nonexpr.rs b/tests/pretty/raw-str-nonexpr.rs new file mode 100644 index 000000000..12440b5ae --- /dev/null +++ b/tests/pretty/raw-str-nonexpr.rs @@ -0,0 +1,9 @@ +// needs-asm-support +// pp-exact + +#[cfg(foo = r#"just parse this"#)] +extern crate blah as blah; + +use std::arch::asm; + +fn main() { unsafe { asm!(r###"blah"###); } } diff --git a/tests/pretty/stmt_expr_attributes.rs b/tests/pretty/stmt_expr_attributes.rs new file mode 100644 index 000000000..c01379065 --- /dev/null +++ b/tests/pretty/stmt_expr_attributes.rs @@ -0,0 +1,271 @@ +// pp-exact + +#![feature(box_syntax)] +#![feature(inline_const)] +#![feature(inline_const_pat)] +#![feature(rustc_attrs)] +#![feature(stmt_expr_attributes)] + +fn main() {} + +fn _0() { + + #[rustc_dummy] + foo(); +} + +fn _1() { + + #[rustc_dummy] + unsafe { + #![rustc_dummy] + // code + } +} + +fn _2() { + + #[rustc_dummy] + { foo(); } + + { + #![rustc_dummy] + + foo() + } +} + +fn _3() { + + #[rustc_dummy] + match () { _ => {} } +} + +fn _4() { + + #[rustc_dummy] + match () { + #![rustc_dummy] + _ => (), + } + + let _ = + #[rustc_dummy] match () { + #![rustc_dummy] + () => (), + }; +} + +fn _5() { + + #[rustc_dummy] + let x = 1; + + let x = #[rustc_dummy] 1; + + let y = (); + let z = (); + + foo3(x, #[rustc_dummy] y, z); + + qux(3 + #[rustc_dummy] 2); +} + +fn _6() { + + #[rustc_dummy] + [1, 2, 3]; + + let _ = #[rustc_dummy] [1, 2, 3]; + + #[rustc_dummy] + [1; 4]; + + let _ = #[rustc_dummy] [1; 4]; +} + +struct Foo { + data: (), +} + +struct Bar(()); + +fn _7() { + + #[rustc_dummy] + Foo { data: () }; + + let _ = #[rustc_dummy] Foo { data: () }; +} + +fn _8() { + + #[rustc_dummy] + (); + + #[rustc_dummy] + (0); + + #[rustc_dummy] + (0,); + + #[rustc_dummy] + (0, 1); +} + +fn _9() { + macro_rules! stmt_mac { () => { let _ = () ; } } + + #[rustc_dummy] + stmt_mac!(); + + #[rustc_dummy] + stmt_mac! {}; + + #[rustc_dummy] + stmt_mac![]; + + #[rustc_dummy] + stmt_mac! {} + + let _ = (); +} + +macro_rules! expr_mac { () => { () } } + +fn _10() { + let _ = #[rustc_dummy] expr_mac!(); + let _ = #[rustc_dummy] expr_mac![]; + let _ = #[rustc_dummy] expr_mac! {}; +} + +fn _11() { + let _ = #[rustc_dummy] box 0; + let _: [(); 0] = #[rustc_dummy] []; + let _ = #[rustc_dummy] [0, 0]; + let _ = #[rustc_dummy] [0; 0]; + let _ = #[rustc_dummy] foo(); + let _ = #[rustc_dummy] 1i32.clone(); + let _ = #[rustc_dummy] (); + let _ = #[rustc_dummy] (0); + let _ = #[rustc_dummy] (0,); + let _ = #[rustc_dummy] (0, 0); + let _ = #[rustc_dummy] 0 + #[rustc_dummy] 0; + let _ = #[rustc_dummy] !0; + let _ = #[rustc_dummy] -0i32; + let _ = #[rustc_dummy] false; + let _ = #[rustc_dummy] 'c'; + let _ = #[rustc_dummy] 0; + let _ = #[rustc_dummy] 0 as usize; + let _ = + #[rustc_dummy] while false { + #![rustc_dummy] + }; + let _ = + #[rustc_dummy] while let None = Some(()) { + #![rustc_dummy] + }; + let _ = + #[rustc_dummy] for _ in 0..0 { + #![rustc_dummy] + }; + let _ = + #[rustc_dummy] loop { + #![rustc_dummy] + }; + let _ = + #[rustc_dummy] match false { + #![rustc_dummy] + _ => (), + }; + let _ = #[rustc_dummy] || #[rustc_dummy] (); + let _ = #[rustc_dummy] move || #[rustc_dummy] (); + let _ = + #[rustc_dummy] || + { + #![rustc_dummy] + #[rustc_dummy] + () + }; + let _ = + #[rustc_dummy] move || + { + #![rustc_dummy] + #[rustc_dummy] + () + }; + let _ = + #[rustc_dummy] { + #![rustc_dummy] + }; + let _ = + #[rustc_dummy] { + #![rustc_dummy] + let _ = (); + }; + let _ = + #[rustc_dummy] { + #![rustc_dummy] + let _ = (); + () + }; + let const { + #![rustc_dummy] + } = + #[rustc_dummy] const { + #![rustc_dummy] + }; + let mut x = 0; + let _ = #[rustc_dummy] x = 15; + let _ = #[rustc_dummy] x += 15; + let s = Foo { data: () }; + let _ = #[rustc_dummy] s.data; + let _ = (#[rustc_dummy] s).data; + let t = Bar(()); + let _ = #[rustc_dummy] t.0; + let _ = (#[rustc_dummy] t).0; + let v = vec!(0); + let _ = #[rustc_dummy] v[0]; + let _ = (#[rustc_dummy] v)[0]; + let _ = #[rustc_dummy] 0..#[rustc_dummy] 0; + let _ = #[rustc_dummy] 0..; + let _ = #[rustc_dummy] (0..0); + let _ = #[rustc_dummy] (0..); + let _ = #[rustc_dummy] (..0); + let _ = #[rustc_dummy] (..); + let _: fn(&u32) -> u32 = #[rustc_dummy] std::clone::Clone::clone; + let _ = #[rustc_dummy] &0; + let _ = #[rustc_dummy] &mut 0; + let _ = #[rustc_dummy] &#[rustc_dummy] 0; + let _ = #[rustc_dummy] &mut #[rustc_dummy] 0; + while false { let _ = #[rustc_dummy] continue; } + while true { let _ = #[rustc_dummy] break; } + || #[rustc_dummy] return; + let _ = #[rustc_dummy] expr_mac!(); + let _ = #[rustc_dummy] expr_mac![]; + let _ = #[rustc_dummy] expr_mac! {}; + let _ = #[rustc_dummy] Foo { data: () }; + let _ = #[rustc_dummy] Foo { ..s }; + let _ = #[rustc_dummy] Foo { data: (), ..s }; + let _ = #[rustc_dummy] (0); +} + +fn _12() { + #[rustc_dummy] + let _ = 0; + + #[rustc_dummy] + 0; + + #[rustc_dummy] + expr_mac!(); + + #[rustc_dummy] + { + #![rustc_dummy] + } +} + +fn foo() {} +fn foo3(_: i32, _: (), _: ()) {} +fn qux(_: i32) {} diff --git a/tests/pretty/struct-pattern.rs b/tests/pretty/struct-pattern.rs new file mode 100644 index 000000000..6acb2e27f --- /dev/null +++ b/tests/pretty/struct-pattern.rs @@ -0,0 +1,5 @@ +// pp-exact +// pretty-compare-only +// Testing that shorthand struct patterns are preserved + +fn main() { let Foo { a, ref b, mut c, x: y, z: z } = foo; } diff --git a/tests/pretty/struct-tuple.rs b/tests/pretty/struct-tuple.rs new file mode 100644 index 000000000..77e064b4f --- /dev/null +++ b/tests/pretty/struct-tuple.rs @@ -0,0 +1,10 @@ +// pp-exact +struct Foo; +struct Bar(isize, isize); + +fn main() { + struct Foo2; + struct Bar2(isize, isize, isize); + let _a = Bar(5, 5); + let _b = Foo; +} diff --git a/tests/pretty/tag-blank-lines.rs b/tests/pretty/tag-blank-lines.rs new file mode 100644 index 000000000..d53f6e4b5 --- /dev/null +++ b/tests/pretty/tag-blank-lines.rs @@ -0,0 +1,8 @@ +// pp-exact + +enum foo { + bar, // a bar. + baz, +} + +fn main() {} diff --git a/tests/pretty/tests-are-sorted.pp b/tests/pretty/tests-are-sorted.pp new file mode 100644 index 000000000..15dcd4ed9 --- /dev/null +++ b/tests/pretty/tests-are-sorted.pp @@ -0,0 +1,69 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// compile-flags: --crate-type=lib --test +// pretty-compare-only +// pretty-mode:expanded +// pp-exact:tests-are-sorted.pp + +extern crate test; +#[cfg(test)] +#[rustc_test_marker = "m_test"] +pub const m_test: test::TestDescAndFn = + test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("m_test"), + ignore: false, + ignore_message: ::core::option::Option::None, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::Unknown, + }, + testfn: test::StaticTestFn(|| test::assert_test_result(m_test())), + }; +fn m_test() {} + +extern crate test; +#[cfg(test)] +#[rustc_test_marker = "z_test"] +pub const z_test: test::TestDescAndFn = + test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("z_test"), + ignore: false, + ignore_message: ::core::option::Option::None, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::Unknown, + }, + testfn: test::StaticTestFn(|| test::assert_test_result(z_test())), + }; +fn z_test() {} + +extern crate test; +#[cfg(test)] +#[rustc_test_marker = "a_test"] +pub const a_test: test::TestDescAndFn = + test::TestDescAndFn { + desc: test::TestDesc { + name: test::StaticTestName("a_test"), + ignore: false, + ignore_message: ::core::option::Option::None, + compile_fail: false, + no_run: false, + should_panic: test::ShouldPanic::No, + test_type: test::TestType::Unknown, + }, + testfn: test::StaticTestFn(|| test::assert_test_result(a_test())), + }; +fn a_test() {} +#[rustc_main] +pub fn main() -> () { + extern crate test; + test::test_main_static(&[&a_test, &m_test, &z_test]) +} diff --git a/tests/pretty/tests-are-sorted.rs b/tests/pretty/tests-are-sorted.rs new file mode 100644 index 000000000..1f737d547 --- /dev/null +++ b/tests/pretty/tests-are-sorted.rs @@ -0,0 +1,13 @@ +// compile-flags: --crate-type=lib --test +// pretty-compare-only +// pretty-mode:expanded +// pp-exact:tests-are-sorted.pp + +#[test] +fn m_test() {} + +#[test] +fn z_test() {} + +#[test] +fn a_test() {} diff --git a/tests/pretty/top-level-doc-comments.rs b/tests/pretty/top-level-doc-comments.rs new file mode 100644 index 000000000..b97927124 --- /dev/null +++ b/tests/pretty/top-level-doc-comments.rs @@ -0,0 +1,8 @@ +/// Some doc comment. +struct X; + +// pp-exact + +// Test that rust can properly pretty print a doc comment if it's the first line in a file. some + +fn main() { let x = X; } diff --git a/tests/pretty/trait-inner-attr.rs b/tests/pretty/trait-inner-attr.rs new file mode 100644 index 000000000..6cb0e4136 --- /dev/null +++ b/tests/pretty/trait-inner-attr.rs @@ -0,0 +1,7 @@ +// pp-exact + +trait Foo { + #![allow(bar)] +} + +fn main() {} diff --git a/tests/pretty/trait-polarity.rs b/tests/pretty/trait-polarity.rs new file mode 100644 index 000000000..310506eab --- /dev/null +++ b/tests/pretty/trait-polarity.rs @@ -0,0 +1,9 @@ +#![feature(negative_impls)] + +// pp-exact + +struct Test; + +impl !Send for Test {} + +pub fn main() {} diff --git a/tests/pretty/trait-safety.rs b/tests/pretty/trait-safety.rs new file mode 100644 index 000000000..c4ae76069 --- /dev/null +++ b/tests/pretty/trait-safety.rs @@ -0,0 +1,15 @@ +// pp-exact + +unsafe trait UnsafeTrait { + fn foo(&self); +} + +unsafe impl UnsafeTrait for isize { + fn foo(&self) {} +} + +pub unsafe trait PubUnsafeTrait { + fn foo(&self); +} + +fn main() {} diff --git a/tests/pretty/unary-op-disambig.rs b/tests/pretty/unary-op-disambig.rs new file mode 100644 index 000000000..0c57e0a33 --- /dev/null +++ b/tests/pretty/unary-op-disambig.rs @@ -0,0 +1,19 @@ +// compile-flags: --crate-type=lib + +// Preserve semicolons that disambiguate unops + +fn f() { } + +fn block_semi() -> isize { { f() }; -1 } + +fn block_nosemi() -> isize { ({ 0 }) - 1 } + +fn if_semi() -> isize { if true { f() } else { f() }; -1 } + +fn if_nosemi() -> isize { (if true { 0 } else { 0 }) - 1 } + +fn alt_semi() -> isize { match true { true => { f() } _ => { } }; -1 } + +fn alt_no_semi() -> isize { (match true { true => { 0 } _ => { 1 } }) - 1 } + +fn stmt() { { f() }; -1; } diff --git a/tests/pretty/use-tree.rs b/tests/pretty/use-tree.rs new file mode 100644 index 000000000..5da952352 --- /dev/null +++ b/tests/pretty/use-tree.rs @@ -0,0 +1,23 @@ +// pp-exact +// edition:2021 + +#![allow(unused_imports)] + +use ::std::fmt::{self, Debug, Display, Write as _}; + +use core::option::Option::*; + +use core::{ + cmp::{Eq, Ord, PartialEq, PartialOrd}, + convert::{AsMut, AsRef, From, Into}, + iter::{ + DoubleEndedIterator, ExactSizeIterator, Extend, FromIterator, + IntoIterator, Iterator, + }, + marker::{ + Copy as Copy, Send as Send, Sized as Sized, Sync as Sync, Unpin as U, + }, + ops::{*, Drop, Fn, FnMut, FnOnce}, +}; + +fn main() {} diff --git a/tests/pretty/vec-comments.pp b/tests/pretty/vec-comments.pp new file mode 100644 index 000000000..f2f807c59 --- /dev/null +++ b/tests/pretty/vec-comments.pp @@ -0,0 +1,29 @@ +// Issue #679 +// Testing that comments are correctly interleaved +// pp-exact:vec-comments.pp +fn main() { + let _v1 = + [ + // Comment + 0, + // Comment + 1, + // Comment + 2]; + let _v2 = + [0, // Comment + 1, // Comment + 2]; // Comment + let _v3 = + [ + /* Comment */ + 0, + /* Comment */ + 1, + /* Comment */ + 2]; + let _v4 = + [0, /* Comment */ + 1, /* Comment */ + 2]; /* Comment */ +} diff --git a/tests/pretty/vec-comments.rs b/tests/pretty/vec-comments.rs new file mode 100644 index 000000000..a150cf0b8 --- /dev/null +++ b/tests/pretty/vec-comments.rs @@ -0,0 +1,29 @@ +// Issue #679 +// Testing that comments are correctly interleaved +// pp-exact:vec-comments.pp +fn main() { + let _v1 = + [ + // Comment + 0, + // Comment + 1, + // Comment + 2]; + let _v2 = + [0, // Comment + 1, // Comment + 2]; // Comment + let _v3 = + [ + /* Comment */ + 0, + /* Comment */ + 1, + /* Comment */ + 2]; + let _v4 = + [0, /* Comment */ + 1, /* Comment */ + 2]; /* Comment */ +} diff --git a/tests/pretty/where-clauses.rs b/tests/pretty/where-clauses.rs new file mode 100644 index 000000000..418379945 --- /dev/null +++ b/tests/pretty/where-clauses.rs @@ -0,0 +1,8 @@ +// pp-exact + +fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a: 'b, T: Eq { 0 } + +// This is legal syntax, sometimes generated by macros. `where T: $($bound+)*` +fn zero_bounds<'a, T>() where 'a:, T: {} + +fn main() {} diff --git a/tests/pretty/yeet-expr.rs b/tests/pretty/yeet-expr.rs new file mode 100644 index 000000000..c899f11b7 --- /dev/null +++ b/tests/pretty/yeet-expr.rs @@ -0,0 +1,12 @@ +// pp-exact +#![feature(yeet_expr)] + +fn yeet_no_expr() -> Option { do yeet } + +fn yeet_no_expr_with_semicolon() -> Option { do yeet; } + +fn yeet_with_expr() -> Result { do yeet 1 + 2 } + +fn yeet_with_expr_with_semicolon() -> Result { do yeet 1 + 2; } + +fn main() {} -- cgit v1.2.3