From 51df533d06286cf509dd76b4a604db09fbc85c41 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 27 Jun 2024 14:56:57 -0400 Subject: [PATCH 1/8] Tighten spans for async blocks --- src/expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index 8266f95fd70..c7c4b680b07 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -372,7 +372,7 @@ pub(crate) fn format_expr( )) } } - ast::ExprKind::Gen(capture_by, ref block, ref kind) => { + ast::ExprKind::Gen(capture_by, ref block, ref kind, _) => { let mover = if matches!(capture_by, ast::CaptureBy::Value { .. }) { "move " } else { From 88f98c2929eebf2c4547dc5adbdaaf3ec651906a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 28 Jun 2024 14:18:36 -0400 Subject: [PATCH 2/8] Implement RTN support in rustfmt --- src/types.rs | 34 ++++++++++++++++------------ tests/target/return-type-notation.rs | 10 ++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 tests/target/return-type-notation.rs diff --git a/src/types.rs b/src/types.rs index c0bf9482b11..c826547e9d0 100644 --- a/src/types.rs +++ b/src/types.rs @@ -484,21 +484,25 @@ fn rewrite_generic_args( span: Span, ) -> Option { match gen_args { - ast::GenericArgs::AngleBracketed(ref data) if !data.args.is_empty() => { - let args = data - .args - .iter() - .map(|x| match x { - ast::AngleBracketedArg::Arg(generic_arg) => { - SegmentParam::from_generic_arg(generic_arg) - } - ast::AngleBracketedArg::Constraint(constraint) => { - SegmentParam::Binding(constraint) - } - }) - .collect::>(); + ast::GenericArgs::AngleBracketed(ref data) => { + if data.args.is_empty() { + Some("".to_owned()) + } else { + let args = data + .args + .iter() + .map(|x| match x { + ast::AngleBracketedArg::Arg(generic_arg) => { + SegmentParam::from_generic_arg(generic_arg) + } + ast::AngleBracketedArg::Constraint(constraint) => { + SegmentParam::Binding(constraint) + } + }) + .collect::>(); - overflow::rewrite_with_angle_brackets(context, "", args.iter(), shape, span) + overflow::rewrite_with_angle_brackets(context, "", args.iter(), shape, span) + } } ast::GenericArgs::Parenthesized(ref data) => format_function_type( data.inputs.iter().map(|x| &**x), @@ -508,7 +512,7 @@ fn rewrite_generic_args( context, shape, ), - _ => Some("".to_owned()), + ast::GenericArgs::ParenthesizedElided(..) => Some("(..)".to_owned()), } } diff --git a/tests/target/return-type-notation.rs b/tests/target/return-type-notation.rs new file mode 100644 index 00000000000..0f26e7e272b --- /dev/null +++ b/tests/target/return-type-notation.rs @@ -0,0 +1,10 @@ +fn rtn() +where + T: Trait, + T::method(..): Send + 'static, +{ +} + +fn test() { + let x: T::method(..); +} From 163d26ea9d4ba35242974254a9281d0714c76705 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 11 Jul 2024 21:59:28 -0400 Subject: [PATCH 3/8] Remove rustdoc tests which no longer parse --- tests/source/type.rs | 2 -- tests/target/negative-bounds.rs | 6 ------ tests/target/type.rs | 2 -- 3 files changed, 10 deletions(-) diff --git a/tests/source/type.rs b/tests/source/type.rs index 61ef73a3cab..7a232f85198 100644 --- a/tests/source/type.rs +++ b/tests/source/type.rs @@ -146,8 +146,6 @@ trait T: ~ const Super {} const fn not_quite_const() -> i32 { ::CONST } -struct S(std::marker::PhantomData); - impl ~ const T {} fn apit(_: impl ~ const T) {} diff --git a/tests/target/negative-bounds.rs b/tests/target/negative-bounds.rs index 4fb35cccf66..9fcb86ef4a4 100644 --- a/tests/target/negative-bounds.rs +++ b/tests/target/negative-bounds.rs @@ -3,9 +3,3 @@ where i32: !Copy, { } - -fn maybe_const_negative() -where - i32: ~const !Copy, -{ -} diff --git a/tests/target/type.rs b/tests/target/type.rs index c789ecb055a..325adb52f3f 100644 --- a/tests/target/type.rs +++ b/tests/target/type.rs @@ -153,8 +153,6 @@ const fn not_quite_const() -> i32 { ::CONST } -struct S(std::marker::PhantomData); - impl ~const T {} fn apit(_: impl ~const T) {} From 90a86a78d267242fcf4a7933547697aadb3c0b83 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 30 Jul 2024 10:10:36 -0400 Subject: [PATCH 4/8] Suppress must_use on eat calls in rustfmt --- src/parse/macros/lazy_static.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/parse/macros/lazy_static.rs b/src/parse/macros/lazy_static.rs index 7baac247e22..b6de5f8691c 100644 --- a/src/parse/macros/lazy_static.rs +++ b/src/parse/macros/lazy_static.rs @@ -33,15 +33,17 @@ pub(crate) fn parse_lazy_static( } while parser.token.kind != TokenKind::Eof { // Parse a `lazy_static!` item. + // FIXME: These `eat_*` calls should be converted to `parse_or` to avoid + // silently formatting malformed lazy-statics. let vis = parse_or!(parse_visibility, rustc_parse::parser::FollowedByType::No); - parser.eat_keyword(kw::Static); - parser.eat_keyword(kw::Ref); + let _ = parser.eat_keyword(kw::Static); + let _ = parser.eat_keyword(kw::Ref); let id = parse_or!(parse_ident); - parser.eat(&TokenKind::Colon); + let _ = parser.eat(&TokenKind::Colon); let ty = parse_or!(parse_ty); - parser.eat(&TokenKind::Eq); + let _ = parser.eat(&TokenKind::Eq); let expr = parse_or!(parse_expr); - parser.eat(&TokenKind::Semi); + let _ = parser.eat(&TokenKind::Semi); result.push((vis, id, ty, expr)); } From 6159460963f472ab89eac839ab2344a29b51849a Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 2 Aug 2024 02:12:29 -0700 Subject: [PATCH 5/8] rustfmt: Remove `has_cpuid` from test --- tests/source/cfg_if/detect/os/x86.rs | 9 --------- tests/target/cfg_if/detect/os/x86.rs | 9 --------- 2 files changed, 18 deletions(-) diff --git a/tests/source/cfg_if/detect/os/x86.rs b/tests/source/cfg_if/detect/os/x86.rs index 9257b8a4be6..b9adc67221a 100644 --- a/tests/source/cfg_if/detect/os/x86.rs +++ b/tests/source/cfg_if/detect/os/x86.rs @@ -34,15 +34,6 @@ pub fn check_for(x: Feature) -> bool { fn detect_features() -> cache::Initializer { let mut value = cache::Initializer::default(); - // If the x86 CPU does not support the CPUID instruction then it is too - // old to support any of the currently-detectable features. - if !has_cpuid() { - return value; - } - - // Calling `__cpuid`/`__cpuid_count` from here on is safe because the CPU - // has `cpuid` support. - // 0. EAX = 0: Basic Information: // - EAX returns the "Highest Function Parameter", that is, the maximum // leaf value for subsequent calls of `cpuinfo` in range [0, diff --git a/tests/target/cfg_if/detect/os/x86.rs b/tests/target/cfg_if/detect/os/x86.rs index 2e228aa3745..944b51615f8 100644 --- a/tests/target/cfg_if/detect/os/x86.rs +++ b/tests/target/cfg_if/detect/os/x86.rs @@ -34,15 +34,6 @@ pub fn check_for(x: Feature) -> bool { fn detect_features() -> cache::Initializer { let mut value = cache::Initializer::default(); - // If the x86 CPU does not support the CPUID instruction then it is too - // old to support any of the currently-detectable features. - if !has_cpuid() { - return value; - } - - // Calling `__cpuid`/`__cpuid_count` from here on is safe because the CPU - // has `cpuid` support. - // 0. EAX = 0: Basic Information: // - EAX returns the "Highest Function Parameter", that is, the maximum // leaf value for subsequent calls of `cpuinfo` in range [0, From 57af02c9c4867a47b0f42d33d842d7754b980929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Tue, 12 Mar 2024 02:12:28 +0100 Subject: [PATCH 6/8] Link `std` statically in `rustc_driver` --- src/git-rustfmt/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/git-rustfmt/main.rs b/src/git-rustfmt/main.rs index 3059d917c6b..5674f40bef9 100644 --- a/src/git-rustfmt/main.rs +++ b/src/git-rustfmt/main.rs @@ -1,3 +1,7 @@ +// We need this feature as it changes `dylib` linking behavior and allows us to link to +// `rustc_driver`. +#![feature(rustc_private)] + #[macro_use] extern crate tracing; From 7b2299a2d210c71cd8f40b4e94af4bcd0aa8381c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 9 Aug 2024 17:44:47 +1000 Subject: [PATCH 7/8] Use `impl PartialEq for Token` more. This lets us compare a `Token` with a `TokenKind`. It's used a lot, but can be used even more, avoiding the need for some `.kind` uses. --- src/parse/macros/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/parse/macros/mod.rs b/src/parse/macros/mod.rs index 60c827fd03b..8d5f7f90958 100644 --- a/src/parse/macros/mod.rs +++ b/src/parse/macros/mod.rs @@ -84,9 +84,7 @@ pub(crate) struct ParsedMacroArgs { fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { for &keyword in RUST_KW.iter() { if parser.token.is_keyword(keyword) - && parser.look_ahead(1, |t| { - t.kind == TokenKind::Eof || t.kind == TokenKind::Comma - }) + && parser.look_ahead(1, |t| *t == TokenKind::Eof || *t == TokenKind::Comma) { parser.bump(); return Some(MacroArg::Keyword( @@ -131,7 +129,7 @@ pub(crate) fn parse_macro_args( Some(arg) => { args.push(arg); parser.bump(); - if parser.token.kind == TokenKind::Eof && args.len() == 2 { + if parser.token == TokenKind::Eof && args.len() == 2 { vec_with_semi = true; break; } @@ -150,7 +148,7 @@ pub(crate) fn parse_macro_args( parser.bump(); - if parser.token.kind == TokenKind::Eof { + if parser.token == TokenKind::Eof { trailing_comma = true; break; } From d34fca4f017eae6b08b2ba582dcad7f88da3c494 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Sat, 17 Aug 2024 14:38:27 -0400 Subject: [PATCH 8/8] bump toolchain to nightly-2024-08-17 --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index d04c524861a..7b7081bfe81 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-06-25" +channel = "nightly-2024-08-17" components = ["llvm-tools", "rustc-dev"]