diff options
Diffstat (limited to 'src/test/pretty')
83 files changed, 1844 insertions, 0 deletions
diff --git a/src/test/pretty/asm.pp b/src/test/pretty/asm.pp new file mode 100644 index 000000000..5eade2933 --- /dev/null +++ b/src/test/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/src/test/pretty/asm.rs b/src/test/pretty/asm.rs new file mode 100644 index 000000000..1a3f972c8 --- /dev/null +++ b/src/test/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/src/test/pretty/ast-stmt-expr-attr.rs b/src/test/pretty/ast-stmt-expr-attr.rs new file mode 100644 index 000000000..27c86ec22 --- /dev/null +++ b/src/test/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/src/test/pretty/async.rs b/src/test/pretty/async.rs new file mode 100644 index 000000000..573e79bff --- /dev/null +++ b/src/test/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/src/test/pretty/attr-derive.rs b/src/test/pretty/attr-derive.rs new file mode 100644 index 000000000..0eb403c6b --- /dev/null +++ b/src/test/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/src/test/pretty/attr-fn-inner.rs b/src/test/pretty/attr-fn-inner.rs new file mode 100644 index 000000000..6d9cb89f0 --- /dev/null +++ b/src/test/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/src/test/pretty/attr-literals.rs b/src/test/pretty/attr-literals.rs new file mode 100644 index 000000000..d13201442 --- /dev/null +++ b/src/test/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/src/test/pretty/attr-tokens-raw-ident.rs b/src/test/pretty/attr-tokens-raw-ident.rs new file mode 100644 index 000000000..8486342b0 --- /dev/null +++ b/src/test/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/src/test/pretty/auto-trait.rs b/src/test/pretty/auto-trait.rs new file mode 100644 index 000000000..c3c47cff5 --- /dev/null +++ b/src/test/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/src/test/pretty/auxiliary/derive-foo.rs b/src/test/pretty/auxiliary/derive-foo.rs new file mode 100644 index 000000000..675a93b3d --- /dev/null +++ b/src/test/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/src/test/pretty/blank-lines.rs b/src/test/pretty/blank-lines.rs new file mode 100644 index 000000000..b9153d048 --- /dev/null +++ b/src/test/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/src/test/pretty/block-comment-multiple-asterisks.rs b/src/test/pretty/block-comment-multiple-asterisks.rs new file mode 100644 index 000000000..bb090b746 --- /dev/null +++ b/src/test/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/src/test/pretty/block-comment-trailing-whitespace.rs b/src/test/pretty/block-comment-trailing-whitespace.rs new file mode 100644 index 000000000..4d502f603 --- /dev/null +++ b/src/test/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/src/test/pretty/block-comment-trailing-whitespace2.rs b/src/test/pretty/block-comment-trailing-whitespace2.rs new file mode 100644 index 000000000..e53d51e34 --- /dev/null +++ b/src/test/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/src/test/pretty/block-comment-wchar.pp b/src/test/pretty/block-comment-wchar.pp new file mode 100644 index 000000000..8c8580b07 --- /dev/null +++ b/src/test/pretty/block-comment-wchar.pp @@ -0,0 +1,101 @@ +// This is meant as a test case for Issue 3961. +// +// Test via: rustc -Zunpretty normal src/test/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/src/test/pretty/block-comment-wchar.rs b/src/test/pretty/block-comment-wchar.rs new file mode 100644 index 000000000..e0606e497 --- /dev/null +++ b/src/test/pretty/block-comment-wchar.rs @@ -0,0 +1,100 @@ +// This is meant as a test case for Issue 3961. +// +// Test via: rustc -Zunpretty normal src/test/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/src/test/pretty/block-disambig.rs b/src/test/pretty/block-disambig.rs new file mode 100644 index 000000000..ac9b84a5d --- /dev/null +++ b/src/test/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<isize> { if true { } vec![1, 2] } diff --git a/src/test/pretty/cast-lt.pp b/src/test/pretty/cast-lt.pp new file mode 100644 index 000000000..e6c4d1956 --- /dev/null +++ b/src/test/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/src/test/pretty/cast-lt.rs b/src/test/pretty/cast-lt.rs new file mode 100644 index 000000000..e14bdd1f3 --- /dev/null +++ b/src/test/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/src/test/pretty/closure-reform-pretty.rs b/src/test/pretty/closure-reform-pretty.rs new file mode 100644 index 000000000..1eba1e6bd --- /dev/null +++ b/src/test/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<FnMut(String) -> String>) {} + +fn call_this<F>(f: F) where F: Fn(&str) + Send {} + +fn call_that<F>(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/src/test/pretty/delimited-token-groups.rs b/src/test/pretty/delimited-token-groups.rs new file mode 100644 index 000000000..c7c9277fa --- /dev/null +++ b/src/test/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/src/test/pretty/disamb-stmt-expr.rs b/src/test/pretty/disamb-stmt-expr.rs new file mode 100644 index 000000000..734f9fa12 --- /dev/null +++ b/src/test/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: F) -> isize where F: Fn() -> isize { f() } + +fn wsucc(_n: isize) -> isize { id(|| { 1 }) - 0 } +fn main() {} diff --git a/src/test/pretty/do1.rs b/src/test/pretty/do1.rs new file mode 100644 index 000000000..233ccdb00 --- /dev/null +++ b/src/test/pretty/do1.rs @@ -0,0 +1,5 @@ +// pp-exact + +fn f<F>(f: F) where F: Fn(isize) { f(10) } + +fn main() { f(|i| { assert_eq!(i, 10) }) } diff --git a/src/test/pretty/doc-comments.rs b/src/test/pretty/doc-comments.rs new file mode 100644 index 000000000..a49860daa --- /dev/null +++ b/src/test/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/src/test/pretty/dollar-crate.pp b/src/test/pretty/dollar-crate.pp new file mode 100644 index 000000000..3af37955f --- /dev/null +++ b/src/test/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/src/test/pretty/dollar-crate.rs b/src/test/pretty/dollar-crate.rs new file mode 100644 index 000000000..e46bc7f48 --- /dev/null +++ b/src/test/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/src/test/pretty/empty-impl.rs b/src/test/pretty/empty-impl.rs new file mode 100644 index 000000000..d57093359 --- /dev/null +++ b/src/test/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/src/test/pretty/empty-lines.rs b/src/test/pretty/empty-lines.rs new file mode 100644 index 000000000..15d7625d4 --- /dev/null +++ b/src/test/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/src/test/pretty/enum-variant-vis.rs b/src/test/pretty/enum-variant-vis.rs new file mode 100644 index 000000000..fc646c295 --- /dev/null +++ b/src/test/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/src/test/pretty/example1.rs b/src/test/pretty/example1.rs new file mode 100644 index 000000000..8df74e8e1 --- /dev/null +++ b/src/test/pretty/example1.rs @@ -0,0 +1,3 @@ +// pp-exact + +fn main() {} diff --git a/src/test/pretty/example2.pp b/src/test/pretty/example2.pp new file mode 100644 index 000000000..3f7129afd --- /dev/null +++ b/src/test/pretty/example2.pp @@ -0,0 +1,3 @@ +// pp-exact:example2.pp + +fn main() {} diff --git a/src/test/pretty/example2.rs b/src/test/pretty/example2.rs new file mode 100644 index 000000000..3f7129afd --- /dev/null +++ b/src/test/pretty/example2.rs @@ -0,0 +1,3 @@ +// pp-exact:example2.pp + +fn main() {} diff --git a/src/test/pretty/expanded-and-path-remap-80832.pp b/src/test/pretty/expanded-and-path-remap-80832.pp new file mode 100644 index 000000000..8385c5fa8 --- /dev/null +++ b/src/test/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/src/test/pretty/expanded-and-path-remap-80832.rs b/src/test/pretty/expanded-and-path-remap-80832.rs new file mode 100644 index 000000000..f48441fbc --- /dev/null +++ b/src/test/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/src/test/pretty/fn-return.rs b/src/test/pretty/fn-return.rs new file mode 100644 index 000000000..b932e83aa --- /dev/null +++ b/src/test/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/src/test/pretty/fn-types.rs b/src/test/pretty/fn-types.rs new file mode 100644 index 000000000..f012763c3 --- /dev/null +++ b/src/test/pretty/fn-types.rs @@ -0,0 +1,5 @@ +// pp-exact + +fn from_foreign_fn(_x: fn()) {} +fn from_stack_closure<F>(_x: F) where F: Fn() {} +fn main() {} diff --git a/src/test/pretty/fn-variadic.rs b/src/test/pretty/fn-variadic.rs new file mode 100644 index 000000000..59e477cfa --- /dev/null +++ b/src/test/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::<usize>() +} + +fn main() {} diff --git a/src/test/pretty/for-comment.rs b/src/test/pretty/for-comment.rs new file mode 100644 index 000000000..447e7f918 --- /dev/null +++ b/src/test/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/src/test/pretty/gat-bounds.rs b/src/test/pretty/gat-bounds.rs new file mode 100644 index 000000000..8877c6cc9 --- /dev/null +++ b/src/test/pretty/gat-bounds.rs @@ -0,0 +1,18 @@ +// Check that associated types print generic parameters and where clauses. +// See issue #67509. + +// pretty-compare-only + +#![feature(generic_associated_types)] + +trait X { + type Y<T>: Trait where Self: Sized; +} + +impl X for () { + type Y<T> where Self: Sized = u32; +} + +fn f<T: X<Y<()> = i32>>() {} + +fn main() { } diff --git a/src/test/pretty/hir-pretty-loop.pp b/src/test/pretty/hir-pretty-loop.pp new file mode 100644 index 000000000..a59a3002c --- /dev/null +++ b/src/test/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/src/test/pretty/hir-pretty-loop.rs b/src/test/pretty/hir-pretty-loop.rs new file mode 100644 index 000000000..87a3ef8b8 --- /dev/null +++ b/src/test/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/src/test/pretty/if-attr.rs b/src/test/pretty/if-attr.rs new file mode 100644 index 000000000..7b90b0bec --- /dev/null +++ b/src/test/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/src/test/pretty/import-renames.rs b/src/test/pretty/import-renames.rs new file mode 100644 index 000000000..ce6b5058b --- /dev/null +++ b/src/test/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/src/test/pretty/issue-12590-a.rs b/src/test/pretty/issue-12590-a.rs new file mode 100644 index 000000000..3c88f5cb8 --- /dev/null +++ b/src/test/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/src/test/pretty/issue-12590-b.rs b/src/test/pretty/issue-12590-b.rs new file mode 100644 index 000000000..b14c7afa2 --- /dev/null +++ b/src/test/pretty/issue-12590-b.rs @@ -0,0 +1,5 @@ +// Second part of two-file test + +fn b() { } + +fn main() { } diff --git a/src/test/pretty/issue-12590-c.pp b/src/test/pretty/issue-12590-c.pp new file mode 100644 index 000000000..07b3f5653 --- /dev/null +++ b/src/test/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/src/test/pretty/issue-12590-c.rs b/src/test/pretty/issue-12590-c.rs new file mode 100644 index 000000000..0ec05f9a8 --- /dev/null +++ b/src/test/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/src/test/pretty/issue-19077.rs b/src/test/pretty/issue-19077.rs new file mode 100644 index 000000000..0d2702804 --- /dev/null +++ b/src/test/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/src/test/pretty/issue-25031.rs b/src/test/pretty/issue-25031.rs new file mode 100644 index 000000000..d91494891 --- /dev/null +++ b/src/test/pretty/issue-25031.rs @@ -0,0 +1,8 @@ +// +// Testing that type items with where clauses output correctly. + +// pp-exact + +fn main() { + type Foo<T> where T: Copy = Box<T>; +} diff --git a/src/test/pretty/issue-30731.rs b/src/test/pretty/issue-30731.rs new file mode 100644 index 000000000..607cbebee --- /dev/null +++ b/src/test/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/src/test/pretty/issue-31073.pp b/src/test/pretty/issue-31073.pp new file mode 100644 index 000000000..75795f6d5 --- /dev/null +++ b/src/test/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/src/test/pretty/issue-31073.rs b/src/test/pretty/issue-31073.rs new file mode 100644 index 000000000..75795f6d5 --- /dev/null +++ b/src/test/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/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp new file mode 100644 index 000000000..752c36a0f --- /dev/null +++ b/src/test/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<'r> fn(Arguments<'r>) -> 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<T>(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/src/test/pretty/issue-4264.rs b/src/test/pretty/issue-4264.rs new file mode 100644 index 000000000..3dea81129 --- /dev/null +++ b/src/test/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<T>(x: T) -> T { x } + +pub fn use_id() { + let _ = id::<[i32; 3]>([1,2,3]); +} + + +fn main() {} diff --git a/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs b/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs new file mode 100644 index 000000000..80f739f4f --- /dev/null +++ b/src/test/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/src/test/pretty/issue-73626.rs b/src/test/pretty/issue-73626.rs new file mode 100644 index 000000000..a002f09be --- /dev/null +++ b/src/test/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/src/test/pretty/issue-74745.rs b/src/test/pretty/issue-74745.rs new file mode 100644 index 000000000..e255cd6ca --- /dev/null +++ b/src/test/pretty/issue-74745.rs @@ -0,0 +1,5 @@ +// ignore-tidy-trailing-newlines +// pretty-compare-only + +/* +*/
\ No newline at end of file diff --git a/src/test/pretty/let.rs b/src/test/pretty/let.rs new file mode 100644 index 000000000..20ffb7578 --- /dev/null +++ b/src/test/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/src/test/pretty/lifetime.rs b/src/test/pretty/lifetime.rs new file mode 100644 index 000000000..34eae849b --- /dev/null +++ b/src/test/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/src/test/pretty/macro.rs b/src/test/pretty/macro.rs new file mode 100644 index 000000000..b88ae7039 --- /dev/null +++ b/src/test/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/src/test/pretty/macro_rules.rs b/src/test/pretty/macro_rules.rs new file mode 100644 index 000000000..01adb1413 --- /dev/null +++ b/src/test/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/src/test/pretty/match-block-expr.rs b/src/test/pretty/match-block-expr.rs new file mode 100644 index 000000000..10903e928 --- /dev/null +++ b/src/test/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/src/test/pretty/match-naked-expr-medium.rs b/src/test/pretty/match-naked-expr-medium.rs new file mode 100644 index 000000000..836af9900 --- /dev/null +++ b/src/test/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/src/test/pretty/match-naked-expr.rs b/src/test/pretty/match-naked-expr.rs new file mode 100644 index 000000000..7c16bbefe --- /dev/null +++ b/src/test/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/src/test/pretty/nested-item-vis-defaultness.rs b/src/test/pretty/nested-item-vis-defaultness.rs new file mode 100644 index 000000000..b094ba577 --- /dev/null +++ b/src/test/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/src/test/pretty/path-type-bounds.rs b/src/test/pretty/path-type-bounds.rs new file mode 100644 index 000000000..f1970de6f --- /dev/null +++ b/src/test/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<Tr + Sync + 'a>) -> Box<Tr + Sync + 'a> { x } + +fn main() { + let x: Box<Tr + Sync>; + + Box::new(1isize) as Box<Tr + Sync>; +} diff --git a/src/test/pretty/qpath-associated-type-bound.rs b/src/test/pretty/qpath-associated-type-bound.rs new file mode 100644 index 000000000..67a5d1dd8 --- /dev/null +++ b/src/test/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<T: m::Tr>() { <T as m::Tr>::Ts::dummy(); } + +fn main() {} diff --git a/src/test/pretty/raw-address-of.rs b/src/test/pretty/raw-address-of.rs new file mode 100644 index 000000000..6ccc434a1 --- /dev/null +++ b/src/test/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/src/test/pretty/raw-str-nonexpr.rs b/src/test/pretty/raw-str-nonexpr.rs new file mode 100644 index 000000000..7af80979b --- /dev/null +++ b/src/test/pretty/raw-str-nonexpr.rs @@ -0,0 +1,8 @@ +// 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/src/test/pretty/stmt_expr_attributes.rs b/src/test/pretty/stmt_expr_attributes.rs new file mode 100644 index 000000000..c01379065 --- /dev/null +++ b/src/test/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/src/test/pretty/struct-pattern.rs b/src/test/pretty/struct-pattern.rs new file mode 100644 index 000000000..6acb2e27f --- /dev/null +++ b/src/test/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/src/test/pretty/struct-tuple.rs b/src/test/pretty/struct-tuple.rs new file mode 100644 index 000000000..77e064b4f --- /dev/null +++ b/src/test/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/src/test/pretty/tag-blank-lines.rs b/src/test/pretty/tag-blank-lines.rs new file mode 100644 index 000000000..d53f6e4b5 --- /dev/null +++ b/src/test/pretty/tag-blank-lines.rs @@ -0,0 +1,8 @@ +// pp-exact + +enum foo { + bar, // a bar. + baz, +} + +fn main() {} diff --git a/src/test/pretty/top-level-doc-comments.rs b/src/test/pretty/top-level-doc-comments.rs new file mode 100644 index 000000000..b97927124 --- /dev/null +++ b/src/test/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/src/test/pretty/trait-inner-attr.rs b/src/test/pretty/trait-inner-attr.rs new file mode 100644 index 000000000..6cb0e4136 --- /dev/null +++ b/src/test/pretty/trait-inner-attr.rs @@ -0,0 +1,7 @@ +// pp-exact + +trait Foo { + #![allow(bar)] +} + +fn main() {} diff --git a/src/test/pretty/trait-polarity.rs b/src/test/pretty/trait-polarity.rs new file mode 100644 index 000000000..310506eab --- /dev/null +++ b/src/test/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/src/test/pretty/trait-safety.rs b/src/test/pretty/trait-safety.rs new file mode 100644 index 000000000..c4ae76069 --- /dev/null +++ b/src/test/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/src/test/pretty/unary-op-disambig.rs b/src/test/pretty/unary-op-disambig.rs new file mode 100644 index 000000000..0c57e0a33 --- /dev/null +++ b/src/test/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/src/test/pretty/use-tree.rs b/src/test/pretty/use-tree.rs new file mode 100644 index 000000000..5da952352 --- /dev/null +++ b/src/test/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/src/test/pretty/vec-comments.pp b/src/test/pretty/vec-comments.pp new file mode 100644 index 000000000..f2f807c59 --- /dev/null +++ b/src/test/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/src/test/pretty/vec-comments.rs b/src/test/pretty/vec-comments.rs new file mode 100644 index 000000000..a150cf0b8 --- /dev/null +++ b/src/test/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/src/test/pretty/where-clauses.rs b/src/test/pretty/where-clauses.rs new file mode 100644 index 000000000..418379945 --- /dev/null +++ b/src/test/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/src/test/pretty/yeet-expr.rs b/src/test/pretty/yeet-expr.rs new file mode 100644 index 000000000..c899f11b7 --- /dev/null +++ b/src/test/pretty/yeet-expr.rs @@ -0,0 +1,12 @@ +// pp-exact +#![feature(yeet_expr)] + +fn yeet_no_expr() -> Option<String> { do yeet } + +fn yeet_no_expr_with_semicolon() -> Option<String> { do yeet; } + +fn yeet_with_expr() -> Result<String, i32> { do yeet 1 + 2 } + +fn yeet_with_expr_with_semicolon() -> Result<String, i32> { do yeet 1 + 2; } + +fn main() {} |