diff --git a/Configurations.md b/Configurations.md index a13fe062d89..727e25bd5b1 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2352,7 +2352,7 @@ Replace uses of the try! macro by the ? shorthand ```rust fn main() { - let lorem = try!(ipsum.map(|dolor| dolor.sit())); + let lorem = r#try!(ipsum.map(|dolor| dolor.sit())); } ``` diff --git a/src/config/mod.rs b/src/config/mod.rs index 698a3224591..27db11c2280 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -107,7 +107,7 @@ create_config! { "Maximum number of blank lines which can be put between items"; blank_lines_lower_bound: usize, 0, false, "Minimum number of blank lines which must be put between items"; - edition: Edition, Edition::Edition2015, true, "The edition of the parser (RFC 2052)"; + edition: Edition, Edition::Edition2018, true, "The edition of the parser (RFC 2052)"; version: Version, Version::One, false, "Version of formatting rules"; inline_attribute_width: usize, 0, false, "Write an item and its attribute on the same line \ @@ -531,7 +531,7 @@ trailing_comma = "Vertical" match_block_trailing_comma = false blank_lines_upper_bound = 1 blank_lines_lower_bound = 0 -edition = "2015" +edition = "2018" version = "One" inline_attribute_width = 0 merge_derives = true diff --git a/src/config/options.rs b/src/config/options.rs index 4a136f4b180..605198ab05b 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -380,7 +380,7 @@ pub enum Edition { impl Default for Edition { fn default() -> Edition { - Edition::Edition2015 + Edition::Edition2018 } } diff --git a/src/macros.rs b/src/macros.rs index 4c01bd9532e..e13845ed9ac 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1190,7 +1190,12 @@ fn next_space(tok: &TokenKind) -> SpaceState { /// when the macro is not an instance of `try!` (or parsing the inner expression /// failed). pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> Option { - if &mac.path.to_string() == "try" { + // The `try!` macro was deprecated in Rust 1.39.0 and `try` is a + // reserved keyword in the 2018 Edition so the raw identifier + // `r#try!` must be used in the 2018 Edition. + // https://doc.rust-lang.org/std/macro.try.html + // https://github.com/rust-lang/rust/pull/62672 + if &mac.path.to_string() == "try" || &mac.path.to_string() == "r#try" { let ts: TokenStream = mac.tts.clone(); let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect()); diff --git a/tests/source/configs/indent_style/block_call.rs b/tests/source/configs/indent_style/block_call.rs index c82b6b8e38f..109c6571fcc 100644 --- a/tests/source/configs/indent_style/block_call.rs +++ b/tests/source/configs/indent_style/block_call.rs @@ -18,8 +18,8 @@ fn main() { } // nesting macro and function call - try!(foo(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)); - try!(foo(try!(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx))); + r#try!(foo(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)); + r#try!(foo(r#try!(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx))); } // #1521 diff --git a/tests/source/configs/use_try_shorthand/false.rs b/tests/source/configs/use_try_shorthand/false.rs index de7f8b4a5e2..a3bb39231bc 100644 --- a/tests/source/configs/use_try_shorthand/false.rs +++ b/tests/source/configs/use_try_shorthand/false.rs @@ -2,5 +2,5 @@ // Use try! shorthand fn main() { - let lorem = try!(ipsum.map(|dolor| dolor.sit())); + let lorem = r#try!(ipsum.map(|dolor| dolor.sit())); } diff --git a/tests/source/configs/use_try_shorthand/true.rs b/tests/source/configs/use_try_shorthand/true.rs index 9015ec41e5e..167178789de 100644 --- a/tests/source/configs/use_try_shorthand/true.rs +++ b/tests/source/configs/use_try_shorthand/true.rs @@ -2,5 +2,5 @@ // Use try! shorthand fn main() { - let lorem = try!(ipsum.map(|dolor| dolor.sit())); + let lorem = r#try!(ipsum.map(|dolor| dolor.sit())); } diff --git a/tests/source/configs/use_try_shorthand/true_2015_edition.rs b/tests/source/configs/use_try_shorthand/true_2015_edition.rs new file mode 100644 index 00000000000..4baf7c6a169 --- /dev/null +++ b/tests/source/configs/use_try_shorthand/true_2015_edition.rs @@ -0,0 +1,7 @@ +// rustfmt-use_try_shorthand: true +// rustfmt-edition: 2015 +// Use try! shorthand + +fn main() { + let lorem = try!(ipsum.map(|dolor| dolor.sit())); +} diff --git a/tests/source/imports.rs b/tests/source/imports.rs index d0bdeda595d..30b10af144e 100644 --- a/tests/source/imports.rs +++ b/tests/source/imports.rs @@ -62,7 +62,7 @@ use foo::{baz, qux as bar}; use ::foo; use ::foo::{Bar}; use ::foo::{Bar, Baz}; -use ::{Foo}; +use ::{qux}; use ::{Bar, Baz}; // Root globs @@ -104,4 +104,4 @@ use std::f64::consts::{SQRT_2, E, PI}; // #3273 #[rustfmt::skip] -use std::fmt::{self, {Display, Formatter}}; +use std::fmt::{self, {Display, Formatter}}; \ No newline at end of file diff --git a/tests/source/imports_2015_edition.rs b/tests/source/imports_2015_edition.rs new file mode 100644 index 00000000000..9292660e1d2 --- /dev/null +++ b/tests/source/imports_2015_edition.rs @@ -0,0 +1,108 @@ +// rustfmt-normalize_comments: true +// rustfmt-edition: 2015 + +// Imports. + +// Long import. +use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, ItemDefaultImpl}; +use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB}; +use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB}; + +use list::{ + // Some item + SomeItem /* Comment */, /* Another item */ AnotherItem /* Another Comment */, // Last Item + LastItem +}; + +use test::{ Other /* C */ , /* A */ self /* B */ }; + +use syntax::{self}; +use {/* Pre-comment! */ + Foo, Bar /* comment */}; +use Foo::{Bar, Baz}; +pub use syntax::ast::{Expr_, Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath}; + +use syntax::some::{}; + +use self; +use std::io::{self}; +use std::io::self; + +mod Foo { + pub use syntax::ast::{ + ItemForeignMod, + ItemImpl, + ItemMac, + ItemMod, + ItemStatic, + ItemDefaultImpl + }; + + mod Foo2 { + pub use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, self, ItemDefaultImpl}; + } +} + +fn test() { +use Baz::*; + use Qux; +} + +// Simple imports +use foo::bar::baz as baz ; +use bar::quux as kaas; +use foo; + +// With aliases. +use foo::{self as bar, baz}; +use foo::{self as bar}; +use foo::{qux as bar}; +use foo::{baz, qux as bar}; + +// With absolute paths +use ::foo; +use ::foo::{Bar}; +use ::foo::{Bar, Baz}; +use ::{Foo}; +use ::{Bar, Baz}; + +// Root globs +use *; +use ::*; + +// spaces used to cause glob imports to disappear (#1356) +use super:: * ; +use foo::issue_1356:: * ; + +// We shouldn't remove imports which have attributes attached (#1858) +#[cfg(unix)] +use self::unix::{}; + +// nested imports +use foo::{a, bar::{baz, qux, xxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}}, b, boo, c,}; + +use fooo::{baar::{foobar::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}}, z, bar, bar::*, x, y}; + +use exonum::{api::{Api, ApiError}, blockchain::{self, BlockProof, Blockchain, Transaction, TransactionSet}, crypto::{Hash, PublicKey}, helpers::Height, node::TransactionSend, storage::{ListProof, MapProof}}; + +// nested imports with a single sub-tree. +use a::{b::{c::*}}; +use a::{b::{c::{}}}; +use a::{b::{c::d}}; +use a::{b::{c::{xxx, yyy, zzz}}}; + +// #2645 +/// This line is not affected. +// This line is deleted. +use c; + +// #2670 +#[macro_use] +use imports_with_attr; + +// #2888 +use std::f64::consts::{SQRT_2, E, PI}; + +// #3273 +#[rustfmt::skip] +use std::fmt::{self, {Display, Formatter}}; \ No newline at end of file diff --git a/tests/source/trait.rs b/tests/source/trait.rs index 80ee0188a6b..6b08469fa97 100644 --- a/tests/source/trait.rs +++ b/tests/source/trait.rs @@ -21,7 +21,7 @@ fn increment(& mut self, x: i32 ); } pub trait WriteMessage { - fn write_message (&mut self, &FrontendMessage) -> io::Result<()>; + fn write_message (&mut self, fm: &FrontendMessage) -> io::Result<()>; } trait Runnable { @@ -173,4 +173,4 @@ Send + DDDDDDD + DDDDDDDD + DDDDDDDDD - + EEEEEEE; + + EEEEEEE; \ No newline at end of file diff --git a/tests/source/trait_2015_edition.rs b/tests/source/trait_2015_edition.rs new file mode 100644 index 00000000000..b0de90ba88c --- /dev/null +++ b/tests/source/trait_2015_edition.rs @@ -0,0 +1,179 @@ +// rustfmt-edition: 2015 +// Test traits + +trait Foo { + fn bar(x: i32 ) -> Baz< U> { Baz::new() + } + + fn baz(a: AAAAAAAAAAAAAAAAAAAAAA, +b: BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB) +-> RetType; + + fn foo(a: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Another comment +b: BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB) + -> RetType ; // Some comment + + fn baz(&mut self ) -> i32 ; + +fn increment(& mut self, x: i32 ); + + fn read(&mut self, x: BufReader /* Used to be MemReader */) + where R: Read; +} + +pub trait WriteMessage { + // Note that support for anonymous trait parameters was dropped in the 2018 Edition + // https://doc.rust-lang.org/nightly/edition-guide/rust-2018/trait-system/no-anon-params.html + fn write_message (&mut self, &FrontendMessage) -> io::Result<()>; +} + +trait Runnable { + fn handler(self: & Runnable ); +} + +trait TraitWithExpr { + fn fn_with_expr(x: [i32; 1]); +} + +trait Test { + fn read_struct(&mut self, s_name: &str, len: usize, f: F) -> Result where F: FnOnce(&mut Self) -> Result; +} + +trait T<> {} + +trait Foo { type Bar: Baz; type Inner: Foo = Box< Foo >; } + +trait ConstCheck:Foo where T: Baz { + const J: i32; +} + +trait Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttt + where T: Foo {} + +trait Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt where T: Foo {} + +trait FooBar : Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt where J: Bar { fn test(); } + +trait WhereList where T: Foo, J: Bar {} + +trait X /* comment */ {} +trait Y // comment +{ +} + +// #2055 +pub trait Foo: +// A and C +A + C +// and B + + B +{} + +// #2158 +trait Foo { + type ItRev = > as UntypedTimeSeries>::IterRev; + type IteRev = > as UntypedTimeSeries>::IterRev; +} + +// #2331 +trait MyTrait { + fn foo() {} +} + +// Trait aliases +trait FooBar = + Foo + + Bar; +trait FooBar = + Foo + + Bar; +pub trait FooBar = + Foo + + Bar; +pub trait FooBar = + Foo + + Bar; +trait AAAAAAAAAAAAAAAAAA = BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDD; +pub trait AAAAAAAAAAAAAAAAAA = BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDD; +trait AAAAAAAAAAAAAAAAAAA = BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDD; +trait AAAAAAAAAAAAAAAAAA = BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDDD; +trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = FooBar; +trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = FooBar; +#[rustfmt::skip] +trait FooBar = Foo + + Bar; + +// #2637 +auto trait Example {} +pub auto trait PubExample {} +pub unsafe auto trait PubUnsafeExample {} + +// #3006 +trait Foo<'a> { + type Bar< 'a >; +} + +impl<'a> Foo<'a> for i32 { + type Bar< 'a > = i32; +} + +// #3092 +pub mod test { + pub trait ATraitWithALooongName {} + pub trait ATrait + :ATraitWithALooongName + ATraitWithALooongName + ATraitWithALooongName + ATraitWithALooongName +{ +} +} + +// Trait aliases with where clauses. +trait A = where for<'b> &'b Self: Send; + +trait B = where for<'b> &'b Self: Send + Clone + Copy + SomeTrait + AAAAAAAA + BBBBBBB + CCCCCCCCCC; +trait B = where for<'b> &'b Self: Send + Clone + Copy + SomeTrait + AAAAAAAA + BBBBBBB + CCCCCCCCCCC; +trait B = where + for<'b> &'b Self: +Send + Clone + Copy + SomeTrait + AAAAAAAA + BBBBBBB + CCCCCCCCCCCCCCCCCCCCCCC; +trait B = where + for<'b> &'b Self: +Send + Clone + Copy + SomeTrait + AAAAAAAA + BBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC; + +trait B = where + for<'b> &'b Self: +Send + + Clone + + Copy + + SomeTrait + + AAAAAAAA + + BBBBBBB + + CCCCCCCCC + + DDDDDDD + + DDDDDDDD + + DDDDDDDDD + + EEEEEEE; + +trait A<'a, 'b, 'c> = Debug + Foo where for<'b> &'b Self: Send; + +trait B<'a, 'b, 'c> = Debug +Foo +where for<'b> &'b Self: +Send + + Clone + + Copy + + SomeTrait + + AAAAAAAA + + BBBBBBB + + CCCCCCCCC + + DDDDDDD; + +trait B<'a, 'b, 'c,T> = Debug<'a, T> where for<'b> &'b Self: +Send + + Clone + + Copy + + SomeTrait + + AAAAAAAA + + BBBBBBB + + CCCCCCCCC + + DDDDDDD + + DDDDDDDD + + DDDDDDDDD + + EEEEEEE; \ No newline at end of file diff --git a/tests/source/try-conversion.rs b/tests/source/try-conversion.rs index ed83ee9e101..91ac8282c2d 100644 --- a/tests/source/try-conversion.rs +++ b/tests/source/try-conversion.rs @@ -1,9 +1,9 @@ // rustfmt-use_try_shorthand: true fn main() { - let x = try!(some_expr()); + let x = r#try!(some_expr()); - let y = try!(a.very.loooooooooooooooooooooooooooooooooooooong().chain().inside().weeeeeeeeeeeeeee()).test().0.x; + let y = r#try!(a.very.loooooooooooooooooooooooooooooooooooooong().chain().inside().weeeeeeeeeeeeeee()).test().0.x; } fn test() { @@ -11,7 +11,7 @@ fn test() { } fn issue1291() { - try!(fs::create_dir_all(&gitfiledir).chain_err(|| { + r#try!(fs::create_dir_all(&gitfiledir).chain_err(|| { format!("failed to create the {} submodule directory for the workarea", name) })); diff --git a/tests/target/configs/indent_style/block_call.rs b/tests/target/configs/indent_style/block_call.rs index 19c44dc019a..caf7b41e596 100644 --- a/tests/target/configs/indent_style/block_call.rs +++ b/tests/target/configs/indent_style/block_call.rs @@ -32,11 +32,11 @@ fn main() { } // nesting macro and function call - try!(foo( + r#try!(foo( xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx )); - try!(foo(try!( + r#try!(foo(r#try!( xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ))); diff --git a/tests/target/configs/use_try_shorthand/false.rs b/tests/target/configs/use_try_shorthand/false.rs index de7f8b4a5e2..a3bb39231bc 100644 --- a/tests/target/configs/use_try_shorthand/false.rs +++ b/tests/target/configs/use_try_shorthand/false.rs @@ -2,5 +2,5 @@ // Use try! shorthand fn main() { - let lorem = try!(ipsum.map(|dolor| dolor.sit())); + let lorem = r#try!(ipsum.map(|dolor| dolor.sit())); } diff --git a/tests/target/configs/use_try_shorthand/true_2015_edition.rs b/tests/target/configs/use_try_shorthand/true_2015_edition.rs new file mode 100644 index 00000000000..03609c4084b --- /dev/null +++ b/tests/target/configs/use_try_shorthand/true_2015_edition.rs @@ -0,0 +1,7 @@ +// rustfmt-use_try_shorthand: true +// rustfmt-edition: 2015 +// Use try! shorthand + +fn main() { + let lorem = ipsum.map(|dolor| dolor.sit())?; +} diff --git a/tests/target/imports.rs b/tests/target/imports.rs index c497a375b59..521346ce458 100644 --- a/tests/target/imports.rs +++ b/tests/target/imports.rs @@ -59,14 +59,14 @@ use foo::{self as bar, baz}; use foo::{baz, qux as bar}; // With absolute paths -use foo; -use foo::Bar; -use foo::{Bar, Baz}; -use Foo; -use {Bar, Baz}; +use ::foo; +use ::foo::Bar; +use ::foo::{Bar, Baz}; +use ::qux; +use ::{Bar, Baz}; // Root globs -use *; +use ::*; use *; // spaces used to cause glob imports to disappear (#1356) diff --git a/tests/target/imports_2015_edition.rs b/tests/target/imports_2015_edition.rs new file mode 100644 index 00000000000..474ecdb8bcf --- /dev/null +++ b/tests/target/imports_2015_edition.rs @@ -0,0 +1,130 @@ +// rustfmt-normalize_comments: true +// rustfmt-edition: 2015 + +// Imports. + +// Long import. +use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ + ItemA, ItemB, +}; +use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ + ItemA, ItemB, +}; +use syntax::ast::{ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic}; + +use list::{ + // Another item + AnotherItem, // Another Comment + // Last Item + LastItem, + // Some item + SomeItem, // Comment +}; + +use test::{/* A */ self /* B */, Other /* C */}; + +pub use syntax::ast::{Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath, Expr_}; +use syntax::{self}; +use Foo::{Bar, Baz}; +use {Bar /* comment */, /* Pre-comment! */ Foo}; + +use std::io; +use std::io::{self}; + +mod Foo { + pub use syntax::ast::{ + ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, + }; + + mod Foo2 { + pub use syntax::ast::{ + self, ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, + }; + } +} + +fn test() { + use Baz::*; + use Qux; +} + +// Simple imports +use bar::quux as kaas; +use foo; +use foo::bar::baz; + +// With aliases. +use foo::qux as bar; +use foo::{self as bar}; +use foo::{self as bar, baz}; +use foo::{baz, qux as bar}; + +// With absolute paths +use foo; +use foo::Bar; +use foo::{Bar, Baz}; +use Foo; +use {Bar, Baz}; + +// Root globs +use *; +use *; + +// spaces used to cause glob imports to disappear (#1356) +use super::*; +use foo::issue_1356::*; + +// We shouldn't remove imports which have attributes attached (#1858) +#[cfg(unix)] +use self::unix::{}; + +// nested imports +use foo::{ + a, b, + bar::{ + baz, + foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}, + qux, xxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, + }, + boo, c, +}; + +use fooo::{ + baar::foobar::{ + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, + zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, + }, + bar, + bar::*, + x, y, z, +}; + +use exonum::{ + api::{Api, ApiError}, + blockchain::{self, BlockProof, Blockchain, Transaction, TransactionSet}, + crypto::{Hash, PublicKey}, + helpers::Height, + node::TransactionSend, + storage::{ListProof, MapProof}, +}; + +// nested imports with a single sub-tree. +use a::b::c::d; +use a::b::c::*; +use a::b::c::{xxx, yyy, zzz}; + +// #2645 +/// This line is not affected. +// This line is deleted. +use c; + +// #2670 +#[macro_use] +use imports_with_attr; + +// #2888 +use std::f64::consts::{E, PI, SQRT_2}; + +// #3273 +#[rustfmt::skip] +use std::fmt::{self, {Display, Formatter}}; diff --git a/tests/target/issue-1681.rs b/tests/target/issue-1681.rs index 902765302ea..b817a95f46b 100644 --- a/tests/target/issue-1681.rs +++ b/tests/target/issue-1681.rs @@ -9,11 +9,11 @@ fn foo() { Occupied(entry) => Ok(entry.into_mut()), Vacant(entry) => { let statement = { - let sql = try!(entry.key().sql(source)); + let sql = r#try!(entry.key().sql(source)); prepare_fn(&sql) }; - Ok(entry.insert(try!(statement))) + Ok(entry.insert(r#try!(statement))) } } }) diff --git a/tests/target/trait.rs b/tests/target/trait.rs index 620046a71b2..7bfab72fb73 100644 --- a/tests/target/trait.rs +++ b/tests/target/trait.rs @@ -22,7 +22,7 @@ trait Foo { } pub trait WriteMessage { - fn write_message(&mut self, &FrontendMessage) -> io::Result<()>; + fn write_message(&mut self, fm: &FrontendMessage) -> io::Result<()>; } trait Runnable { diff --git a/tests/target/trait_2015_edition.rs b/tests/target/trait_2015_edition.rs new file mode 100644 index 00000000000..4a2ee0d0088 --- /dev/null +++ b/tests/target/trait_2015_edition.rs @@ -0,0 +1,216 @@ +// rustfmt-edition: 2015 +// Test traits + +trait Foo { + fn bar(x: i32) -> Baz { + Baz::new() + } + + fn baz(a: AAAAAAAAAAAAAAAAAAAAAA, b: BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB) -> RetType; + + fn foo( + a: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Another comment + b: BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, + ) -> RetType; // Some comment + + fn baz(&mut self) -> i32; + + fn increment(&mut self, x: i32); + + fn read(&mut self, x: BufReader /* Used to be MemReader */) + where + R: Read; +} + +pub trait WriteMessage { + // Note that support for anonymous trait parameters was dropped in the 2018 Edition + // https://doc.rust-lang.org/nightly/edition-guide/rust-2018/trait-system/no-anon-params.html + fn write_message(&mut self, &FrontendMessage) -> io::Result<()>; +} + +trait Runnable { + fn handler(self: &Runnable); +} + +trait TraitWithExpr { + fn fn_with_expr(x: [i32; 1]); +} + +trait Test { + fn read_struct(&mut self, s_name: &str, len: usize, f: F) -> Result + where + F: FnOnce(&mut Self) -> Result; +} + +trait T {} + +trait Foo { + type Bar: Baz; + type Inner: Foo = Box; +} + +trait ConstCheck: Foo +where + T: Baz, +{ + const J: i32; +} + +trait Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttt +where + T: Foo, +{ +} + +trait Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt +where + T: Foo, +{ +} + +trait FooBar: Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt +where + J: Bar, +{ + fn test(); +} + +trait WhereList +where + T: Foo, + J: Bar, +{ +} + +trait X /* comment */ {} +trait Y // comment +{ +} + +// #2055 +pub trait Foo: +// A and C +A + C +// and B + + B +{} + +// #2158 +trait Foo { + type ItRev = > as UntypedTimeSeries>::IterRev; + type IteRev = + > as UntypedTimeSeries>::IterRev; +} + +// #2331 +trait MyTrait< + AAAAAAAAAAAAAAAAAAAA, + BBBBBBBBBBBBBBBBBBBB, + CCCCCCCCCCCCCCCCCCCC, + DDDDDDDDDDDDDDDDDDDD, +> +{ + fn foo() {} +} + +// Trait aliases +trait FooBar = Foo + Bar; +trait FooBar = Foo + Bar; +pub trait FooBar = Foo + Bar; +pub trait FooBar = Foo + Bar; +trait AAAAAAAAAAAAAAAAAA = BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDD; +pub trait AAAAAAAAAAAAAAAAAA = + BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDD; +trait AAAAAAAAAAAAAAAAAAA = + BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDD; +trait AAAAAAAAAAAAAAAAAA = + BBBBBBBBBBBBBBBBBBB + CCCCCCCCCCCCCCCCCCCCCCCCCCCCC + DDDDDDDDDDDDDDDDDDD; +trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = + FooBar; +trait AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA< + A, + B, + C, + D, + E, +> = FooBar; +#[rustfmt::skip] +trait FooBar = Foo + + Bar; + +// #2637 +auto trait Example {} +pub auto trait PubExample {} +pub unsafe auto trait PubUnsafeExample {} + +// #3006 +trait Foo<'a> { + type Bar<'a>; +} + +impl<'a> Foo<'a> for i32 { + type Bar<'a> = i32; +} + +// #3092 +pub mod test { + pub trait ATraitWithALooongName {} + pub trait ATrait: + ATraitWithALooongName + + ATraitWithALooongName + + ATraitWithALooongName + + ATraitWithALooongName + { + } +} + +// Trait aliases with where clauses. +trait A = where for<'b> &'b Self: Send; + +trait B = where for<'b> &'b Self: Send + Clone + Copy + SomeTrait + AAAAAAAA + BBBBBBB + CCCCCCCCCC; +trait B = + where for<'b> &'b Self: Send + Clone + Copy + SomeTrait + AAAAAAAA + BBBBBBB + CCCCCCCCCCC; +trait B = where + for<'b> &'b Self: + Send + Clone + Copy + SomeTrait + AAAAAAAA + BBBBBBB + CCCCCCCCCCCCCCCCCCCCCCC; +trait B = where + for<'b> &'b Self: Send + + Clone + + Copy + + SomeTrait + + AAAAAAAA + + BBBBBBB + + CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC; + +trait B = where + for<'b> &'b Self: Send + + Clone + + Copy + + SomeTrait + + AAAAAAAA + + BBBBBBB + + CCCCCCCCC + + DDDDDDD + + DDDDDDDD + + DDDDDDDDD + + EEEEEEE; + +trait A<'a, 'b, 'c> = Debug + Foo where for<'b> &'b Self: Send; + +trait B<'a, 'b, 'c> = Debug + Foo +where + for<'b> &'b Self: Send + Clone + Copy + SomeTrait + AAAAAAAA + BBBBBBB + CCCCCCCCC + DDDDDDD; + +trait B<'a, 'b, 'c, T> = Debug<'a, T> +where + for<'b> &'b Self: Send + + Clone + + Copy + + SomeTrait + + AAAAAAAA + + BBBBBBB + + CCCCCCCCC + + DDDDDDD + + DDDDDDDD + + DDDDDDDDD + + EEEEEEE;