diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /src/tools/rustfmt/tests | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rustfmt/tests')
60 files changed, 1769 insertions, 8 deletions
diff --git a/src/tools/rustfmt/tests/cargo-fmt/main.rs b/src/tools/rustfmt/tests/cargo-fmt/main.rs index 701c36fad..63573bf34 100644 --- a/src/tools/rustfmt/tests/cargo-fmt/main.rs +++ b/src/tools/rustfmt/tests/cargo-fmt/main.rs @@ -26,7 +26,7 @@ fn cargo_fmt(args: &[&str]) -> (String, String) { String::from_utf8(output.stdout).expect("utf-8"), String::from_utf8(output.stderr).expect("utf-8"), ), - Err(e) => panic!("failed to run `{:?} {:?}`: {}", cmd, args, e), + Err(e) => panic!("failed to run `{cmd:?} {args:?}`: {e}"), } } diff --git a/src/tools/rustfmt/tests/config/issue-5816.toml b/src/tools/rustfmt/tests/config/issue-5816.toml new file mode 100644 index 000000000..00375746e --- /dev/null +++ b/src/tools/rustfmt/tests/config/issue-5816.toml @@ -0,0 +1 @@ +skip_macro_invocations=["*", "println"] diff --git a/src/tools/rustfmt/tests/rustfmt/main.rs b/src/tools/rustfmt/tests/rustfmt/main.rs index 4936a7174..7dcf7c841 100644 --- a/src/tools/rustfmt/tests/rustfmt/main.rs +++ b/src/tools/rustfmt/tests/rustfmt/main.rs @@ -27,7 +27,7 @@ fn rustfmt(args: &[&str]) -> (String, String) { String::from_utf8(output.stdout).expect("utf-8"), String::from_utf8(output.stderr).expect("utf-8"), ), - Err(e) => panic!("failed to run `{:?} {:?}`: {}", cmd, args, e), + Err(e) => panic!("failed to run `{cmd:?} {args:?}`: {e}"), } } @@ -71,9 +71,7 @@ fn print_config() { ]); assert!( Path::new("minimal-config").exists(), - "stdout:\n{}\nstderr:\n{}", - stdout, - stderr + "stdout:\n{stdout}\nstderr:\n{stderr}" ); remove_file("minimal-config").unwrap(); } diff --git a/src/tools/rustfmt/tests/source/immovable_generators.rs b/src/tools/rustfmt/tests/source/immovable_coroutines.rs index c57a1e144..3b94af0c9 100644 --- a/src/tools/rustfmt/tests/source/immovable_generators.rs +++ b/src/tools/rustfmt/tests/source/immovable_coroutines.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] unsafe fn foo() { let mut ga = static || { diff --git a/src/tools/rustfmt/tests/source/issue-3984.rs b/src/tools/rustfmt/tests/source/issue-3984.rs new file mode 100644 index 000000000..c9bcfa406 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-3984.rs @@ -0,0 +1,12 @@ +use a::{item /* comment */}; +use b::{ + a, + // comment + item, +}; +use c::item /* comment */; +use d::item; // really long comment (with `use` exactly 100 characters) ____________________________ + +use std::e::{/* it's a comment! */ bar /* and another */}; +use std::f::{/* it's a comment! */ bar}; +use std::g::{bar /* and another */}; diff --git a/src/tools/rustfmt/tests/source/issue-4808.rs b/src/tools/rustfmt/tests/source/issue-4808.rs new file mode 100644 index 000000000..93076edcd --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-4808.rs @@ -0,0 +1,13 @@ +trait Trait { + fn method(&self) {} +} + +impl<F: Fn() -> T, T> Trait for F {} + +impl Trait for f32 {} + +fn main() { + || 10. .method(); + || .. .method(); + || 1.. .method(); +} diff --git a/src/tools/rustfmt/tests/source/issue-5655/one.rs b/src/tools/rustfmt/tests/source/issue-5655/one.rs new file mode 100644 index 000000000..1758ec56f --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5655/one.rs @@ -0,0 +1,9 @@ +// rustfmt-version: One + +fn foo<T>(_: T) +where + T: std::fmt::Debug, + + T: std::fmt::Display, +{ +} diff --git a/src/tools/rustfmt/tests/source/issue-5655/two.rs b/src/tools/rustfmt/tests/source/issue-5655/two.rs new file mode 100644 index 000000000..e37ebbea8 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5655/two.rs @@ -0,0 +1,9 @@ +// rustfmt-version: Two + +fn foo<T>(_: T) +where + T: std::fmt::Debug, + + T: std::fmt::Display, +{ +} diff --git a/src/tools/rustfmt/tests/source/issue-5791.rs b/src/tools/rustfmt/tests/source/issue-5791.rs new file mode 100644 index 000000000..40bc6daa9 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5791.rs @@ -0,0 +1,3 @@ +pub fn main() { + 0. .to_string(); +} diff --git a/src/tools/rustfmt/tests/source/issue-5835.rs b/src/tools/rustfmt/tests/source/issue-5835.rs new file mode 100644 index 000000000..3e4da3492 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5835.rs @@ -0,0 +1,8 @@ +// rustfmt-wrap_comments: true + +/// . a +pub fn foo() {} + +pub fn main() { + // . a +} diff --git a/src/tools/rustfmt/tests/source/issue-5852/default.rs b/src/tools/rustfmt/tests/source/issue-5852/default.rs new file mode 100644 index 000000000..df84f8f58 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5852/default.rs @@ -0,0 +1,104 @@ +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self // this is important +}; + +use foo :: bar +; + +use foo::{bar}; + +use foo::{ + bar + // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar +}; + +use foo::{ + self + // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self +}; + +use foo::{ + self // a + , +}; + +use foo::{ self /* a */ }; + +use foo::{ self /* a */, }; + +use foo::{ + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + // abc + bar, + abc +}; + +use foo::{ + bar, + // abc + abc +}; + +use foo::{ + bar, + abc + // abc +}; + +use foo::{ + bar, + abc, + // abc +}; + +use foo::{ + self, + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz + } +}; + +use path::{self /*comment*/,}; diff --git a/src/tools/rustfmt/tests/source/issue-5852/horizontal.rs b/src/tools/rustfmt/tests/source/issue-5852/horizontal.rs new file mode 100644 index 000000000..63bfb7e57 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5852/horizontal.rs @@ -0,0 +1,106 @@ +// rustfmt-imports_layout: Horizontal + +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self // this is important +}; + +use foo :: bar +; + +use foo::{bar}; + +use foo::{ + bar + // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar +}; + +use foo::{ + self + // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self +}; + +use foo::{ + self // a + , +}; + +use foo::{ self /* a */ }; + +use foo::{ self /* a */, }; + +use foo::{ + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + // abc + bar, + abc +}; + +use foo::{ + bar, + // abc + abc +}; + +use foo::{ + bar, + abc + // abc +}; + +use foo::{ + bar, + abc, + // abc +}; + +use foo::{ + self, + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz + } +}; + +use path::{self /*comment*/,}; diff --git a/src/tools/rustfmt/tests/source/issue-5852/horizontal_vertical.rs b/src/tools/rustfmt/tests/source/issue-5852/horizontal_vertical.rs new file mode 100644 index 000000000..3f3ce0669 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5852/horizontal_vertical.rs @@ -0,0 +1,106 @@ +// rustfmt-imports_layout: HorizontalVertical + +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self // this is important +}; + +use foo :: bar +; + +use foo::{bar}; + +use foo::{ + bar + // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar +}; + +use foo::{ + self + // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self +}; + +use foo::{ + self // a + , +}; + +use foo::{ self /* a */ }; + +use foo::{ self /* a */, }; + +use foo::{ + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + // abc + bar, + abc +}; + +use foo::{ + bar, + // abc + abc +}; + +use foo::{ + bar, + abc + // abc +}; + +use foo::{ + bar, + abc, + // abc +}; + +use foo::{ + self, + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz + } +}; + +use path::{self /*comment*/,}; diff --git a/src/tools/rustfmt/tests/source/issue-5852/issue_example.rs b/src/tools/rustfmt/tests/source/issue-5852/issue_example.rs new file mode 100644 index 000000000..20c2b7640 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5852/issue_example.rs @@ -0,0 +1,8 @@ +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self // this is important +}; diff --git a/src/tools/rustfmt/tests/source/issue-5852/split.rs b/src/tools/rustfmt/tests/source/issue-5852/split.rs new file mode 100644 index 000000000..14e9ea1b6 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5852/split.rs @@ -0,0 +1,111 @@ +// rustfmt-imports_granularity: Item + +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self // this is important +}; + +use foo :: bar +; + +use foo::{bar}; + +use foo::{ + bar + // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar +}; + +use foo::{ + self + // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self +}; + +use foo::{ + self // a + , +}; + +use foo::{ self /* a */ }; + +use foo::{ self /* a */, }; + +use foo::{ + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + bar, + abc +}; + +use foo::{ + // abc + bar, + abc +}; + +use foo::{ + bar, + // abc + abc +}; + +use foo::{ + bar, + abc + // abc +}; + +use foo::{ + bar, + abc, + // abc +}; + +use foo::{ + self, + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz + } +}; + +use path::{self /*comment*/,}; diff --git a/src/tools/rustfmt/tests/source/issue-5852/vertical.rs b/src/tools/rustfmt/tests/source/issue-5852/vertical.rs new file mode 100644 index 000000000..b9ba99889 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5852/vertical.rs @@ -0,0 +1,106 @@ +// rustfmt-imports_layout: Vertical + +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self // this is important +}; + +use foo :: bar +; + +use foo::{bar}; + +use foo::{ + bar + // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar +}; + +use foo::{ + self + // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self +}; + +use foo::{ + self // a + , +}; + +use foo::{ self /* a */ }; + +use foo::{ self /* a */, }; + +use foo::{ + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + // abc + bar, + abc +}; + +use foo::{ + bar, + // abc + abc +}; + +use foo::{ + bar, + abc + // abc +}; + +use foo::{ + bar, + abc, + // abc +}; + +use foo::{ + self, + // abc + abc::{ + xyz + // 123 + } +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz + } +}; + +use path::{self /*comment*/,}; diff --git a/src/tools/rustfmt/tests/source/issue-5935.rs b/src/tools/rustfmt/tests/source/issue-5935.rs new file mode 100644 index 000000000..a1aac0562 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue-5935.rs @@ -0,0 +1,9 @@ +struct Regs< + const BEGIN: u64, + const END: u64, + const DIM: usize, + const N: usize = { (END - BEGIN) as usize / (8 * DIM) + 1 }, +> +{ + _foo: u64, +}
\ No newline at end of file diff --git a/src/tools/rustfmt/tests/source/issue_5721.rs b/src/tools/rustfmt/tests/source/issue_5721.rs new file mode 100644 index 000000000..e5ae9612c --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue_5721.rs @@ -0,0 +1,8 @@ +#![feature(non_lifetime_binders)] +#![allow(incomplete_features)] + +trait Other<U: ?Sized> {} + +trait Trait<U> +where + for<T> U: Other<T> {} diff --git a/src/tools/rustfmt/tests/source/issue_5730.rs b/src/tools/rustfmt/tests/source/issue_5730.rs new file mode 100644 index 000000000..9a3f4f0d0 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue_5730.rs @@ -0,0 +1,3 @@ +macro_rules! statement { + () => {;}; +} diff --git a/src/tools/rustfmt/tests/source/issue_5735.rs b/src/tools/rustfmt/tests/source/issue_5735.rs new file mode 100644 index 000000000..7708d028b --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue_5735.rs @@ -0,0 +1,6 @@ +fn find_errors(mut self) { + let errors: Vec<> = vec!{ + #[debug_format = "A({})"] + struct A {} + }; +} diff --git a/src/tools/rustfmt/tests/source/issue_5882.rs b/src/tools/rustfmt/tests/source/issue_5882.rs new file mode 100644 index 000000000..e36f99654 --- /dev/null +++ b/src/tools/rustfmt/tests/source/issue_5882.rs @@ -0,0 +1,7 @@ +macro_rules!foo{} +macro_rules!bar{/*comment*/} +macro_rules!baz{//comment +} +macro_rules!foobar{ +//comment +} diff --git a/src/tools/rustfmt/tests/source/let_chains.rs b/src/tools/rustfmt/tests/source/let_chains.rs new file mode 100644 index 000000000..b7c1f8110 --- /dev/null +++ b/src/tools/rustfmt/tests/source/let_chains.rs @@ -0,0 +1,121 @@ +fn main() { + if let x = x && x {} + + if xxx && let x = x {} + + if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa && aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {} + + if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa && aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {} + + if let Some(Struct { x:TS(1,2) }) = path::to::<_>(hehe) + && let [Simple, people] = /* get ready */ create_universe(/* hi */ GreatPowers).initialize_badminton().populate_swamps() && + let everybody = (Loops { hi /*hi*/ , ..loopy() }) && summons::triumphantly() { todo!() } + + if let XXXXXXXXX { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzz} = xxxxxxx() + && let Foo = bar() { todo!() } +} + +fn test_single_line_let_chain() { + // first item in let-chain is an ident + if a && let Some(b) = foo() { + } + + // first item in let-chain is a unary ! with an ident + let unary_not = if !from_hir_call + && let Some(p) = parent + { + }; + + // first item in let-chain is a unary * with an ident + let unary_deref = if *some_deref + && let Some(p) = parent + { + }; + + // first item in let-chain is a unary - (neg) with an ident + let unary_neg = if -some_ident + && let Some(p) = parent + { + }; + + // first item in let-chain is a try (?) with an ident + let try_ = if some_try? + && let Some(p) = parent + { + }; + + // first item in let-chain is an ident wrapped in parens + let in_parens = if (some_ident) + && let Some(p) = parent + { + }; + + // first item in let-chain is a ref & with an ident + let _ref = if &some_ref + && let Some(p) = parent + { + }; + + // first item in let-chain is a ref &mut with an ident + let mut_ref = if &mut some_ref + && let Some(p) = parent + { + }; + + // chain unary ref and try + let chain_of_unary_ref_and_try = if !&*some_ref? + && let Some(p) = parent { + }; +} + +fn test_multi_line_let_chain() { + // Can only single line the let-chain if the first item is an ident + if let Some(x) = y && a { + + } + + // More than one let-chain must be formatted on multiple lines + if let Some(x) = y && let Some(a) = b { + + } + + // The ident isn't long enough so we don't wrap the first let-chain + if a && let Some(x) = y && let Some(a) = b { + + } + + // The ident is long enough so both let-chains are wrapped + if aaa && let Some(x) = y && let Some(a) = b { + + } + + // function call + if a() && let Some(x) = y { + + } + + // bool literal + if true && let Some(x) = y { + + } + + // cast to a bool + if 1 as bool && let Some(x) = y { + + } + + // matches! macro call + if matches!(a, some_type) && let Some(x) = y { + + } + + // block expression returning bool + if { true } && let Some(x) = y { + + } + + // field access + if a.x && let Some(x) = y { + + } +} diff --git a/src/tools/rustfmt/tests/source/let_else.rs b/src/tools/rustfmt/tests/source/let_else.rs index 85b3604ad..cb2859e80 100644 --- a/src/tools/rustfmt/tests/source/let_else.rs +++ b/src/tools/rustfmt/tests/source/let_else.rs @@ -160,3 +160,23 @@ fn with_trailing_try_operator() { // Maybe this is a workaround? let Ok(Some(next_bucket)) = ranking_rules[cur_ranking_rule_index].next_bucket(ctx, logger, &ranking_rule_universes[cur_ranking_rule_index]) else { return }; } + +fn issue5901() { + #[cfg(target_os = "linux")] + let Some(x) = foo else { todo!() }; + + #[cfg(target_os = "linux")] + // Some comments between attributes and let-else statement + let Some(x) = foo else { todo!() }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = foo else { todo!() }; + + // The else block will be multi-lined because attributes and comments before `let` + // are included when calculating max width + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + // Some comments between attributes and let-else statement + let Some(x) = foo() else { todo!() }; +} diff --git a/src/tools/rustfmt/tests/source/let_else_v2.rs b/src/tools/rustfmt/tests/source/let_else_v2.rs new file mode 100644 index 000000000..a420fbcf9 --- /dev/null +++ b/src/tools/rustfmt/tests/source/let_else_v2.rs @@ -0,0 +1,56 @@ +// rustfmt-version: Two +// rustfmt-single_line_let_else_max_width: 100 + +fn issue5901() { + #[cfg(target_os = "linux")] + let Some(x) = foo else { todo!() }; + + #[cfg(target_os = "linux")] + // Some comments between attributes and let-else statement + let Some(x) = foo else { todo!() }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = foo else { todo!() }; + + // The else block is multi-lined + #[cfg(target_os = "linux")] + let Some(x) = foo else { return; }; + + // The else block will be single-lined because attributes and comments before `let` + // are no longer included when calculating max width + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + // Some comments between attributes and let-else statement + let Some(x) = foo else { todo!() }; + + // Some more test cases for v2 formatting with attributes + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = opt + // pre else keyword line-comment + else { return; }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = opt else + // post else keyword line-comment + { return; }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Foo {x: Bar(..), y: FooBar(..), z: Baz(..)} = opt else { + return; + }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(Ok((Message::ChangeColor(super::color::Color::Rgb(r, g, b)), Point { x, y, z }))) = opt else { + return; + }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = very_very_very_very_very_very_very_very_very_very_very_very_long_expression_in_assign_rhs() else { return; }; +} diff --git a/src/tools/rustfmt/tests/source/match.rs b/src/tools/rustfmt/tests/source/match.rs index b5dc9957a..d1d8d7f2c 100644 --- a/src/tools/rustfmt/tests/source/match.rs +++ b/src/tools/rustfmt/tests/source/match.rs @@ -292,6 +292,9 @@ fn guards() { aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if fooooooooooooooooooooo && (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || cccccccccccccccccccccccccccccccccccccccc) => {} + Hi { friend } if let None = friend => {} + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if let Some(foooooooooooooo) = hiiiiiiiiiiiiiii => {} + aaaaaaaaaaaaaaaaa if let Superman { powers: Some(goteem), .. } = all::get_random_being::<Super>() => {} } } diff --git a/src/tools/rustfmt/tests/source/non-lifetime-binders.rs b/src/tools/rustfmt/tests/source/non-lifetime-binders.rs new file mode 100644 index 000000000..c26393c8f --- /dev/null +++ b/src/tools/rustfmt/tests/source/non-lifetime-binders.rs @@ -0,0 +1,10 @@ +fn main() where for<'a, T: Sized + 'a, const C: usize> [&'a T; C]: Sized { + let x = for<T> + || {}; + + let y: dyn + for<T> Into<T>; + + let z: for<T> + fn(T); +} diff --git a/src/tools/rustfmt/tests/source/skip_macro_invocations/config_file.rs b/src/tools/rustfmt/tests/source/skip_macro_invocations/config_file.rs new file mode 100644 index 000000000..e0f5ddf52 --- /dev/null +++ b/src/tools/rustfmt/tests/source/skip_macro_invocations/config_file.rs @@ -0,0 +1,9 @@ +// rustfmt-unstable: true +// rustfmt-config: issue-5816.toml + +fn main() { + println!( "Hello, world!"); + let x = +7 +; +} diff --git a/src/tools/rustfmt/tests/target/extern-rust.rs b/src/tools/rustfmt/tests/target/extern-rust.rs new file mode 100644 index 000000000..32824c912 --- /dev/null +++ b/src/tools/rustfmt/tests/target/extern-rust.rs @@ -0,0 +1 @@ +extern "Rust" fn uwu() {} diff --git a/src/tools/rustfmt/tests/target/immovable_generators.rs b/src/tools/rustfmt/tests/target/immovable_coroutines.rs index 0bf7a2d91..f52cfa00f 100644 --- a/src/tools/rustfmt/tests/target/immovable_generators.rs +++ b/src/tools/rustfmt/tests/target/immovable_coroutines.rs @@ -1,4 +1,4 @@ -#![feature(generators)] +#![feature(coroutines)] unsafe fn foo() { let mut ga = static || { diff --git a/src/tools/rustfmt/tests/target/issue-3984.rs b/src/tools/rustfmt/tests/target/issue-3984.rs new file mode 100644 index 000000000..9e700c0f7 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-3984.rs @@ -0,0 +1,12 @@ +use a::{item /* comment */}; +use b::{ + a, + // comment + item, +}; +use c::item; /* comment */ +use d::item; // really long comment (with `use` exactly 100 characters) ____________________________ + +use std::e::{/* it's a comment! */ bar /* and another */}; +use std::f::{/* it's a comment! */ bar}; +use std::g::{bar /* and another */}; diff --git a/src/tools/rustfmt/tests/target/issue-4808.rs b/src/tools/rustfmt/tests/target/issue-4808.rs new file mode 100644 index 000000000..cdef53a1b --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-4808.rs @@ -0,0 +1,13 @@ +trait Trait { + fn method(&self) {} +} + +impl<F: Fn() -> T, T> Trait for F {} + +impl Trait for f32 {} + +fn main() { + || (10.).method(); + (|| ..).method(); + (|| 1..).method(); +} diff --git a/src/tools/rustfmt/tests/target/issue-5568.rs b/src/tools/rustfmt/tests/target/issue-5568.rs new file mode 100644 index 000000000..03ca3a452 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5568.rs @@ -0,0 +1,14 @@ +// rustfmt-max_width: 119 +// rustfmt-format_code_in_doc_comments: true + +mod libs { + fn mrbgems_sources() { + [ + "mrbgems/mruby-compiler/core/codegen.c", // Ruby parser and bytecode generation + "mrbgems/mruby-compiler/core/y.tab.c", // Ruby parser and bytecode generation + "mrbgems/mruby-metaprog/src/metaprog.c", // APIs on Kernel and Module for accessing classes and variables + "mrbgems/mruby-method/src/method.c", // `Method`, `UnboundMethod`, and method APIs on Kernel and Module + "mrbgems/mruby-pack/src/pack.c", // Array#pack and String#unpack + ] + } +} diff --git a/src/tools/rustfmt/tests/target/issue-5655/one.rs b/src/tools/rustfmt/tests/target/issue-5655/one.rs new file mode 100644 index 000000000..1758ec56f --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5655/one.rs @@ -0,0 +1,9 @@ +// rustfmt-version: One + +fn foo<T>(_: T) +where + T: std::fmt::Debug, + + T: std::fmt::Display, +{ +} diff --git a/src/tools/rustfmt/tests/target/issue-5655/two.rs b/src/tools/rustfmt/tests/target/issue-5655/two.rs new file mode 100644 index 000000000..14fbc3d13 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5655/two.rs @@ -0,0 +1,8 @@ +// rustfmt-version: Two + +fn foo<T>(_: T) +where + T: std::fmt::Debug, + T: std::fmt::Display, +{ +} diff --git a/src/tools/rustfmt/tests/target/issue-5791.rs b/src/tools/rustfmt/tests/target/issue-5791.rs new file mode 100644 index 000000000..3a44cf19a --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5791.rs @@ -0,0 +1,3 @@ +pub fn main() { + (0.).to_string(); +} diff --git a/src/tools/rustfmt/tests/target/issue-5797/retain_trailing_semicolon.rs b/src/tools/rustfmt/tests/target/issue-5797/retain_trailing_semicolon.rs new file mode 100644 index 000000000..851073971 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5797/retain_trailing_semicolon.rs @@ -0,0 +1,7 @@ +// rustfmt-trailing_semicolon: false + +fn foo() {} +fn main() { + return; + foo() +} diff --git a/src/tools/rustfmt/tests/target/issue-5835.rs b/src/tools/rustfmt/tests/target/issue-5835.rs new file mode 100644 index 000000000..3e4da3492 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5835.rs @@ -0,0 +1,8 @@ +// rustfmt-wrap_comments: true + +/// . a +pub fn foo() {} + +pub fn main() { + // . a +} diff --git a/src/tools/rustfmt/tests/target/issue-5852/default.rs b/src/tools/rustfmt/tests/target/issue-5852/default.rs new file mode 100644 index 000000000..a86872a68 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5852/default.rs @@ -0,0 +1,97 @@ +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self, // this is important +}; + +use foo::bar; + +use foo::bar; + +use foo::{ + bar, // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar, +}; + +use foo::{ + self, // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self, +}; + +use foo::{ + self, // a +}; + +use foo::{self /* a */}; + +use foo::{self /* a */}; + +use foo::{ + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + // abc + abc, + bar, +}; + +use foo::{ + abc, // abc + bar, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + self, + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz, + }, +}; + +use path::{self /*comment*/}; diff --git a/src/tools/rustfmt/tests/target/issue-5852/horizontal.rs b/src/tools/rustfmt/tests/target/issue-5852/horizontal.rs new file mode 100644 index 000000000..017d83c9f --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5852/horizontal.rs @@ -0,0 +1,99 @@ +// rustfmt-imports_layout: Horizontal + +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self, // this is important +}; + +use foo::bar; + +use foo::bar; + +use foo::{ + bar, // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar, +}; + +use foo::{ + self, // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self, +}; + +use foo::{ + self, // a +}; + +use foo::{self /* a */}; + +use foo::{self /* a */}; + +use foo::{ + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + // abc + abc, + bar, +}; + +use foo::{ + abc, // abc + bar, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + self, + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz, + }, +}; + +use path::{self /*comment*/}; diff --git a/src/tools/rustfmt/tests/target/issue-5852/horizontal_vertical.rs b/src/tools/rustfmt/tests/target/issue-5852/horizontal_vertical.rs new file mode 100644 index 000000000..35e2d0a26 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5852/horizontal_vertical.rs @@ -0,0 +1,99 @@ +// rustfmt-imports_layout: HorizontalVertical + +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self, // this is important +}; + +use foo::bar; + +use foo::bar; + +use foo::{ + bar, // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar, +}; + +use foo::{ + self, // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self, +}; + +use foo::{ + self, // a +}; + +use foo::{self /* a */}; + +use foo::{self /* a */}; + +use foo::{ + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + // abc + abc, + bar, +}; + +use foo::{ + abc, // abc + bar, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + self, + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz, + }, +}; + +use path::{self /*comment*/}; diff --git a/src/tools/rustfmt/tests/target/issue-5852/issue_example.rs b/src/tools/rustfmt/tests/target/issue-5852/issue_example.rs new file mode 100644 index 000000000..463262914 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5852/issue_example.rs @@ -0,0 +1,8 @@ +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self, // this is important +}; diff --git a/src/tools/rustfmt/tests/target/issue-5852/split.rs b/src/tools/rustfmt/tests/target/issue-5852/split.rs new file mode 100644 index 000000000..e00086dd4 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5852/split.rs @@ -0,0 +1,102 @@ +// rustfmt-imports_granularity: Item + +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self, // this is important +}; + +use foo::bar; + +use foo::bar; + +use foo::{ + bar, // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar, +}; + +use foo::{ + self, // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self, +}; + +use foo::{ + self, // a +}; + +use foo::{self /* a */}; + +use foo::{self /* a */}; + +use foo::{ + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::abc; +use foo::bar; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + // abc + abc, + bar, +}; + +use foo::{ + abc, // abc + bar, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + self, + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz, + }, +}; + +use path::{self /*comment*/}; diff --git a/src/tools/rustfmt/tests/target/issue-5852/vertical.rs b/src/tools/rustfmt/tests/target/issue-5852/vertical.rs new file mode 100644 index 000000000..f53a68c94 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5852/vertical.rs @@ -0,0 +1,105 @@ +// rustfmt-imports_layout: Vertical + +use std::{ + fs, + // (temporarily commented, we'll need this again in a second) io, +}; + +use foo::{ + self, // this is important +}; + +use foo::bar; + +use foo::bar; + +use foo::{ + bar, // abc +}; + +use foo::{ + bar, + // abc +}; + +use foo::{ + // 345 + bar, +}; + +use foo::{ + self, // abc +}; + +use foo::{ + self, + // abc +}; + +use foo::{ + // 345 + self, +}; + +use foo::{ + self, // a +}; + +use foo::{ + self, /* a */ +}; + +use foo::{ + self, /* a */ +}; + +use foo::{ + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + // abc + abc, + bar, +}; + +use foo::{ + abc, // abc + bar, +}; + +use foo::{ + abc, + // abc + bar, +}; + +use foo::{ + self, + // abc + abc::{ + xyz, // 123 + }, +}; + +use foo::{ + self, + // abc + abc::{ + // 123 + xyz, + }, +}; + +use path::{ + self, /*comment*/ +}; diff --git a/src/tools/rustfmt/tests/target/issue-5871.rs b/src/tools/rustfmt/tests/target/issue-5871.rs new file mode 100644 index 000000000..3116533bc --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5871.rs @@ -0,0 +1,8 @@ +#![feature(stmt_expr_attributes)] +fn okay() -> u32 { + ( + // Comments in parentheses-expressions caused attributes to be duplicated. + #[allow(unused_variables)] + 0 + ) +} diff --git a/src/tools/rustfmt/tests/target/issue-5935.rs b/src/tools/rustfmt/tests/target/issue-5935.rs new file mode 100644 index 000000000..ebc62c464 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue-5935.rs @@ -0,0 +1,8 @@ +struct Regs< + const BEGIN: u64, + const END: u64, + const DIM: usize, + const N: usize = { (END - BEGIN) as usize / (8 * DIM) + 1 }, +> { + _foo: u64, +} diff --git a/src/tools/rustfmt/tests/target/issue_4110.rs b/src/tools/rustfmt/tests/target/issue_4110.rs index d3734e90b..ea8fa3b73 100644 --- a/src/tools/rustfmt/tests/target/issue_4110.rs +++ b/src/tools/rustfmt/tests/target/issue_4110.rs @@ -12,7 +12,7 @@ fn bindings() { span, .. }, - ) if borrow_spans.for_generator() | borrow_spans.for_closure() => self + ) if borrow_spans.for_coroutine() | borrow_spans.for_closure() => self .report_escaping_closure_capture( borrow_spans, borrow_span, diff --git a/src/tools/rustfmt/tests/target/issue_5533.rs b/src/tools/rustfmt/tests/target/issue_5533.rs new file mode 100644 index 000000000..c3095a440 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_5533.rs @@ -0,0 +1,6 @@ +// rustfmt-format_code_in_doc_comments: true + +struct TestStruct { + position_currency: String, // Currency for position of this contract. If not null, 1 contract = 1 positionCurrency. + pu: Option<i64>, // Previous event update sequense ("u" of previous message), -1 also means None +} diff --git a/src/tools/rustfmt/tests/target/issue_5542.rs b/src/tools/rustfmt/tests/target/issue_5542.rs new file mode 100644 index 000000000..730bb7b68 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_5542.rs @@ -0,0 +1,10 @@ +#![feature(dyn_star)] +#![allow(incomplete_features)] + +use core::fmt::Debug; + +fn main() { + let i = 42; + let dyn_i = i as dyn* Debug; + dbg!(dyn_i); +} diff --git a/src/tools/rustfmt/tests/target/issue_5676.rs b/src/tools/rustfmt/tests/target/issue_5676.rs new file mode 100644 index 000000000..258771105 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_5676.rs @@ -0,0 +1,8 @@ +fn main() { + match true { + true => 'a: { + break 'a; + } + _ => (), + } +} diff --git a/src/tools/rustfmt/tests/target/issue_5721.rs b/src/tools/rustfmt/tests/target/issue_5721.rs new file mode 100644 index 000000000..d073b09ca --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_5721.rs @@ -0,0 +1,10 @@ +#![feature(non_lifetime_binders)] +#![allow(incomplete_features)] + +trait Other<U: ?Sized> {} + +trait Trait<U> +where + for<T> U: Other<T>, +{ +} diff --git a/src/tools/rustfmt/tests/target/issue_5730.rs b/src/tools/rustfmt/tests/target/issue_5730.rs new file mode 100644 index 000000000..7922fdcc9 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_5730.rs @@ -0,0 +1,3 @@ +macro_rules! statement { + () => {}; +} diff --git a/src/tools/rustfmt/tests/target/issue_5735.rs b/src/tools/rustfmt/tests/target/issue_5735.rs new file mode 100644 index 000000000..2d1376303 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_5735.rs @@ -0,0 +1,6 @@ +fn find_errors(mut self) { + let errors: Vec = vec![ + #[debug_format = "A({})"] + struct A {} + ]; +} diff --git a/src/tools/rustfmt/tests/target/issue_5882.rs b/src/tools/rustfmt/tests/target/issue_5882.rs new file mode 100644 index 000000000..565fb434a --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_5882.rs @@ -0,0 +1,7 @@ +macro_rules! foo {} +macro_rules! bar { /*comment*/ } +macro_rules! baz { //comment +} +macro_rules! foobar { + //comment +} diff --git a/src/tools/rustfmt/tests/target/issue_5907.rs b/src/tools/rustfmt/tests/target/issue_5907.rs new file mode 100644 index 000000000..144de636b --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_5907.rs @@ -0,0 +1,6 @@ +// rustfmt-format_code_in_doc_comments: true + +// ``` +// [ +// ] +// ``` diff --git a/src/tools/rustfmt/tests/target/let_chains.rs b/src/tools/rustfmt/tests/target/let_chains.rs new file mode 100644 index 000000000..1ceecac8a --- /dev/null +++ b/src/tools/rustfmt/tests/target/let_chains.rs @@ -0,0 +1,129 @@ +fn main() { + if let x = x + && x + {} + + if xxx && let x = x {} + + if aaaaaaaaaaaaaaaaaaaaa + && aaaaaaaaaaaaaaa + && aaaaaaaaa + && let Some(x) = xxxxxxxxxxxx + && aaaaaaa + && let None = aaaaaaaaaa + {} + + if aaaaaaaaaaaaaaaaaaaaa + && aaaaaaaaaaaaaaa + && aaaaaaaaa + && let Some(x) = xxxxxxxxxxxx + && aaaaaaa + && let None = aaaaaaaaaa + {} + + if let Some(Struct { x: TS(1, 2) }) = path::to::<_>(hehe) + && let [Simple, people] = /* get ready */ + create_universe(/* hi */ GreatPowers) + .initialize_badminton() + .populate_swamps() + && let everybody = (Loops { + hi, /*hi*/ + ..loopy() + }) + && summons::triumphantly() + { + todo!() + } + + if let XXXXXXXXX { + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, + yyyyyyyyyyyyy, + zzzzzzzzzzzzz, + } = xxxxxxx() + && let Foo = bar() + { + todo!() + } +} + +fn test_single_line_let_chain() { + // first item in let-chain is an ident + if a && let Some(b) = foo() {} + + // first item in let-chain is a unary ! with an ident + let unary_not = if !from_hir_call && let Some(p) = parent {}; + + // first item in let-chain is a unary * with an ident + let unary_deref = if *some_deref && let Some(p) = parent {}; + + // first item in let-chain is a unary - (neg) with an ident + let unary_neg = if -some_ident && let Some(p) = parent {}; + + // first item in let-chain is a try (?) with an ident + let try_ = if some_try? && let Some(p) = parent {}; + + // first item in let-chain is an ident wrapped in parens + let in_parens = if (some_ident) && let Some(p) = parent {}; + + // first item in let-chain is a ref & with an ident + let _ref = if &some_ref && let Some(p) = parent {}; + + // first item in let-chain is a ref &mut with an ident + let mut_ref = if &mut some_ref && let Some(p) = parent {}; + + // chain unary ref and try + let chain_of_unary_ref_and_try = if !&*some_ref? && let Some(p) = parent {}; +} + +fn test_multi_line_let_chain() { + // Can only single line the let-chain if the first item is an ident + if let Some(x) = y + && a + {} + + // More than one let-chain must be formatted on multiple lines + if let Some(x) = y + && let Some(a) = b + {} + + // The ident isn't long enough so we don't wrap the first let-chain + if a && let Some(x) = y + && let Some(a) = b + {} + + // The ident is long enough so both let-chains are wrapped + if aaa + && let Some(x) = y + && let Some(a) = b + {} + + // function call + if a() + && let Some(x) = y + {} + + // bool literal + if true + && let Some(x) = y + {} + + // cast to a bool + if 1 as bool + && let Some(x) = y + {} + + // matches! macro call + if matches!(a, some_type) + && let Some(x) = y + {} + + // block expression returning bool + if { true } + && let Some(x) = y + {} + + // field access + if a.x + && let Some(x) = y + {} +} diff --git a/src/tools/rustfmt/tests/target/let_else.rs b/src/tools/rustfmt/tests/target/let_else.rs index 6554a0961..f6560e854 100644 --- a/src/tools/rustfmt/tests/target/let_else.rs +++ b/src/tools/rustfmt/tests/target/let_else.rs @@ -252,3 +252,34 @@ fn with_trailing_try_operator() { return; }; } + +fn issue5901() { + #[cfg(target_os = "linux")] + let Some(x) = foo + else { + todo!() + }; + + #[cfg(target_os = "linux")] + // Some comments between attributes and let-else statement + let Some(x) = foo + else { + todo!() + }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = foo + else { + todo!() + }; + + // The else block will be multi-lined because attributes and comments before `let` + // are included when calculating max width + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + // Some comments between attributes and let-else statement + let Some(x) = foo() else { + todo!() + }; +} diff --git a/src/tools/rustfmt/tests/target/let_else_v2.rs b/src/tools/rustfmt/tests/target/let_else_v2.rs new file mode 100644 index 000000000..b25ac1609 --- /dev/null +++ b/src/tools/rustfmt/tests/target/let_else_v2.rs @@ -0,0 +1,73 @@ +// rustfmt-version: Two +// rustfmt-single_line_let_else_max_width: 100 + +fn issue5901() { + #[cfg(target_os = "linux")] + let Some(x) = foo else { todo!() }; + + #[cfg(target_os = "linux")] + // Some comments between attributes and let-else statement + let Some(x) = foo else { todo!() }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = foo else { todo!() }; + + // The else block is multi-lined + #[cfg(target_os = "linux")] + let Some(x) = foo else { + return; + }; + + // The else block will be single-lined because attributes and comments before `let` + // are no longer included when calculating max width + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + // Some comments between attributes and let-else statement + let Some(x) = foo else { todo!() }; + + // Some more test cases for v2 formatting with attributes + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = opt + // pre else keyword line-comment + else { + return; + }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = opt else + // post else keyword line-comment + { + return; + }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Foo { + x: Bar(..), + y: FooBar(..), + z: Baz(..), + } = opt + else { + return; + }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(Ok((Message::ChangeColor(super::color::Color::Rgb(r, g, b)), Point { x, y, z }))) = + opt + else { + return; + }; + + #[cfg(target_os = "linux")] + #[cfg(target_arch = "x86_64")] + let Some(x) = + very_very_very_very_very_very_very_very_very_very_very_very_long_expression_in_assign_rhs() + else { + return; + }; +} diff --git a/src/tools/rustfmt/tests/target/match.rs b/src/tools/rustfmt/tests/target/match.rs index 1bf3fb758..0e7815a81 100644 --- a/src/tools/rustfmt/tests/target/match.rs +++ b/src/tools/rustfmt/tests/target/match.rs @@ -317,6 +317,14 @@ fn guards() { if fooooooooooooooooooooo && (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || cccccccccccccccccccccccccccccccccccccccc) => {} + Hi { friend } if let None = friend => {} + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + if let Some(foooooooooooooo) = hiiiiiiiiiiiiiii => {} + aaaaaaaaaaaaaaaaa + if let Superman { + powers: Some(goteem), + .. + } = all::get_random_being::<Super>() => {} } } diff --git a/src/tools/rustfmt/tests/target/non-lifetime-binders.rs b/src/tools/rustfmt/tests/target/non-lifetime-binders.rs new file mode 100644 index 000000000..ca6941a0c --- /dev/null +++ b/src/tools/rustfmt/tests/target/non-lifetime-binders.rs @@ -0,0 +1,10 @@ +fn main() +where + for<'a, T: Sized + 'a, const C: usize> [&'a T; C]: Sized, +{ + let x = for<T> || {}; + + let y: dyn for<T> Into<T>; + + let z: for<T> fn(T); +} diff --git a/src/tools/rustfmt/tests/target/skip_macro_invocations/config_file.rs b/src/tools/rustfmt/tests/target/skip_macro_invocations/config_file.rs new file mode 100644 index 000000000..008e28db4 --- /dev/null +++ b/src/tools/rustfmt/tests/target/skip_macro_invocations/config_file.rs @@ -0,0 +1,7 @@ +// rustfmt-unstable: true +// rustfmt-config: issue-5816.toml + +fn main() { + println!( "Hello, world!"); + let x = 7; +} |