From ee941126274d5469d796c653c8ff4eb46302e91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 30 Jan 2025 20:47:05 +0100 Subject: [PATCH 1/5] Rollup merge of #135852 - lukas-code:asyncfn-prelude-core, r=compiler-errors Add `AsyncFn*` to `core` prelude In https://github.com/rust-lang/rust/pull/132611 these got added to the `std` prelude only, which looks like an oversight. r? libs-api cc `@compiler-errors` --- library/core/src/prelude/common.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/core/src/prelude/common.rs b/library/core/src/prelude/common.rs index e38ef1e147c76..8b116cecb5295 100644 --- a/library/core/src/prelude/common.rs +++ b/library/core/src/prelude/common.rs @@ -12,6 +12,9 @@ pub use crate::marker::{Copy, Send, Sized, Sync, Unpin}; #[stable(feature = "core_prelude", since = "1.4.0")] #[doc(no_inline)] pub use crate::ops::{Drop, Fn, FnMut, FnOnce}; +#[stable(feature = "async_closure", since = "1.85.0")] +#[doc(no_inline)] +pub use crate::ops::{AsyncFn, AsyncFnMut, AsyncFnOnce}; // Re-exported functions #[stable(feature = "core_prelude", since = "1.4.0")] From 2fa9d47dfe3f999d66f0abd2ce4a4925abda0a8f Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 29 Jan 2025 11:41:19 +0100 Subject: [PATCH 2/5] Disable some incorrect rust-analyzer diagnostics on beta --- src/tools/rust-analyzer/crates/hir-def/src/data.rs | 2 +- src/tools/rust-analyzer/crates/hir-ty/src/lower.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/data.rs b/src/tools/rust-analyzer/crates/hir-def/src/data.rs index 15dd6aba311fc..e3041cd91fe5f 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/data.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/data.rs @@ -94,7 +94,7 @@ impl FunctionData { .map(Box::new); let rustc_allow_incoherent_impl = attrs.by_key(&sym::rustc_allow_incoherent_impl).exists(); if flags.contains(FnFlags::HAS_UNSAFE_KW) - && !crate_graph[krate].edition.at_least_2024() + // && !crate_graph[krate].edition.at_least_2024() && attrs.by_key(&sym::rustc_deprecated_safe_2024).exists() { flags.remove(FnFlags::HAS_UNSAFE_KW); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs index b23f2749ab285..42c030dfc6c1c 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs @@ -226,8 +226,8 @@ impl<'a> TyLoweringContext<'a> { self } - pub fn push_diagnostic(&mut self, type_ref: TypeRefId, kind: TyLoweringDiagnosticKind) { - let source = match self.types_source_map { + pub fn push_diagnostic(&mut self, type_ref: TypeRefId, _kind: TyLoweringDiagnosticKind) { + let _source = match self.types_source_map { Some(source_map) => { let Ok(source) = source_map.type_syntax(type_ref) else { stdx::never!("error in synthetic type"); @@ -237,7 +237,7 @@ impl<'a> TyLoweringContext<'a> { } None => Either::Left(type_ref), }; - self.diagnostics.push(TyLoweringDiagnostic { source, kind }); + // self.diagnostics.push(TyLoweringDiagnostic { source, kind }); } } From fdc22dc54cdaa173c52cf00f30b8ac3071459991 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Fri, 31 Jan 2025 00:26:33 -0500 Subject: [PATCH 3/5] Rollup merge of #136312 - compiler-errors:overflow_delimited_expr-2024, r=ytmimi Disable `overflow_delimited_expr` in edition 2024 This reverts the style guide changes and sets the default to "false" in rustfmt for style edition 2024. r? `@ytmimi` cc `@rust-lang/style` `@rust-lang/rustfmt` --- src/doc/style-guide/src/editions.md | 4 - src/doc/style-guide/src/expressions.md | 55 ++------------ src/tools/rustfmt/src/bin/main.rs | 9 +-- src/tools/rustfmt/src/config/mod.rs | 2 +- src/tools/rustfmt/src/config/options.rs | 4 +- .../style_edition/overflow_delim_expr_2024.rs | 73 +++++++++++-------- 6 files changed, 58 insertions(+), 89 deletions(-) diff --git a/src/doc/style-guide/src/editions.md b/src/doc/style-guide/src/editions.md index b9a89c20cee40..19e62c4867c99 100644 --- a/src/doc/style-guide/src/editions.md +++ b/src/doc/style-guide/src/editions.md @@ -36,10 +36,6 @@ For a full history of changes in the Rust 2024 style edition, see the git history of the style guide. Notable changes in the Rust 2024 style edition include: -- [#114764](https://github.com/rust-lang/rust/pull/114764) As the last member - of a delimited expression, delimited expressions are generally combinable, - regardless of the number of members. Previously only applied with exactly - one member (except for closures with explicit blocks). - Miscellaneous `rustfmt` bugfixes. - Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order). - Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase". diff --git a/src/doc/style-guide/src/expressions.md b/src/doc/style-guide/src/expressions.md index 171a24cd89d73..12037b5992ec0 100644 --- a/src/doc/style-guide/src/expressions.md +++ b/src/doc/style-guide/src/expressions.md @@ -818,11 +818,11 @@ E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not. ## Combinable expressions -When the last argument in a function call is formatted across -multiple-lines, format the outer call as if it were a single-line call, +Where a function call has a single argument, and that argument is formatted +across multiple-lines, format the outer call as if it were a single-line call, if the result fits. Apply the same combining behaviour to any similar expressions which have multi-line, block-indented lists of sub-expressions -delimited by parentheses, brackets, or braces. E.g., +delimited by parentheses (e.g., macros or tuple struct literals). E.g., ```rust foo(bar( @@ -848,61 +848,20 @@ let arr = [combinable( an_expr, another_expr, )]; - -let x = Thing(an_expr, another_expr, match cond { - A => 1, - B => 2, -}); - -let x = format!("Stuff: {}", [ - an_expr, - another_expr, -]); - -let x = func(an_expr, another_expr, SomeStruct { - field: this_is_long, - another_field: 123, -}); ``` Apply this behavior recursively. -If the last argument is a multi-line closure with an explicit block, -only apply the combining behavior if there are no other closure arguments. +For a function with multiple arguments, if the last argument is a multi-line +closure with an explicit block, there are no other closure arguments, and all +the arguments and the first line of the closure fit on the first line, use the +same combining behavior: ```rust -// Combinable foo(first_arg, x, |param| { action(); foo(param) }) -// Not combinable, because the closure is not the last argument -foo( - first_arg, - |param| { - action(); - foo(param) - }, - whatever, -) -// Not combinable, because the first line of the closure does not fit -foo( - first_arg, - x, - move |very_long_param_causing_line_to_overflow| -> Bar { - action(); - foo(param) - }, -) -// Not combinable, because there is more than one closure argument -foo( - first_arg, - |x| x.bar(), - |param| { - action(); - foo(param) - }, -) ``` ## Ranges diff --git a/src/tools/rustfmt/src/bin/main.rs b/src/tools/rustfmt/src/bin/main.rs index 34984798ae60e..28df49b9304c5 100644 --- a/src/tools/rustfmt/src/bin/main.rs +++ b/src/tools/rustfmt/src/bin/main.rs @@ -817,7 +817,6 @@ mod test { options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]); let config = get_config(None, Some(options)); assert_eq!(config.style_edition(), StyleEdition::Edition2024); - assert_eq!(config.overflow_delimited_expr(), true); } #[nightly_only_test] @@ -827,7 +826,6 @@ mod test { let config_file = Some(Path::new("tests/config/style-edition/just-version")); let config = get_config(config_file, Some(options)); assert_eq!(config.style_edition(), StyleEdition::Edition2024); - assert_eq!(config.overflow_delimited_expr(), true); } #[nightly_only_test] @@ -872,7 +870,6 @@ mod test { ]); let config = get_config(None, Some(options)); assert_eq!(config.style_edition(), StyleEdition::Edition2024); - assert_eq!(config.overflow_delimited_expr(), true); } #[nightly_only_test] @@ -938,7 +935,6 @@ mod test { options.style_edition = Some(StyleEdition::Edition2024); let config = get_config(None, Some(options)); assert_eq!(config.style_edition(), StyleEdition::Edition2024); - assert_eq!(config.overflow_delimited_expr(), true); } #[nightly_only_test] @@ -948,6 +944,8 @@ mod test { let config_file = Some(Path::new("tests/config/style-edition/overrides")); let config = get_config(config_file, Some(options)); assert_eq!(config.style_edition(), StyleEdition::Edition2024); + // FIXME: this test doesn't really exercise anything, since + // `overflow_delimited_expr` is disabled by default in edition 2024. assert_eq!(config.overflow_delimited_expr(), false); } @@ -959,7 +957,8 @@ mod test { options.inline_config = HashMap::from([("overflow_delimited_expr".to_owned(), "false".to_owned())]); let config = get_config(config_file, Some(options)); - assert_eq!(config.style_edition(), StyleEdition::Edition2024); + // FIXME: this test doesn't really exercise anything, since + // `overflow_delimited_expr` is disabled by default in edition 2024. assert_eq!(config.overflow_delimited_expr(), false); } } diff --git a/src/tools/rustfmt/src/config/mod.rs b/src/tools/rustfmt/src/config/mod.rs index 7355adc9f9df1..6b63108c037eb 100644 --- a/src/tools/rustfmt/src/config/mod.rs +++ b/src/tools/rustfmt/src/config/mod.rs @@ -848,7 +848,7 @@ binop_separator = "Front" remove_nested_parens = true combine_control_expr = true short_array_element_width_threshold = 10 -overflow_delimited_expr = true +overflow_delimited_expr = false struct_field_align_threshold = 0 enum_discrim_align_threshold = 0 match_arm_blocks = true diff --git a/src/tools/rustfmt/src/config/options.rs b/src/tools/rustfmt/src/config/options.rs index bbc99a2dced2b..71865ec75ce6e 100644 --- a/src/tools/rustfmt/src/config/options.rs +++ b/src/tools/rustfmt/src/config/options.rs @@ -627,7 +627,7 @@ config_option_with_style_edition_default!( RemoveNestedParens, bool, _ => true; CombineControlExpr, bool, _ => true; ShortArrayElementWidthThreshold, usize, _ => 10; - OverflowDelimitedExpr, bool, Edition2024 => true, _ => false; + OverflowDelimitedExpr, bool, _ => false; StructFieldAlignThreshold, usize, _ => 0; EnumDiscrimAlignThreshold, usize, _ => 0; MatchArmBlocks, bool, _ => true; @@ -644,7 +644,7 @@ config_option_with_style_edition_default!( BlankLinesLowerBound, usize, _ => 0; EditionConfig, Edition, _ => Edition::Edition2015; StyleEditionConfig, StyleEdition, - Edition2024 => StyleEdition::Edition2024, _ => StyleEdition::Edition2015; + Edition2024 => StyleEdition::Edition2024, _ => StyleEdition::Edition2015; VersionConfig, Version, Edition2024 => Version::Two, _ => Version::One; InlineAttributeWidth, usize, _ => 0; FormatGeneratedFiles, bool, _ => true; diff --git a/src/tools/rustfmt/tests/target/configs/style_edition/overflow_delim_expr_2024.rs b/src/tools/rustfmt/tests/target/configs/style_edition/overflow_delim_expr_2024.rs index ecd2e8ca79708..1b2d12ce32019 100644 --- a/src/tools/rustfmt/tests/target/configs/style_edition/overflow_delim_expr_2024.rs +++ b/src/tools/rustfmt/tests/target/configs/style_edition/overflow_delim_expr_2024.rs @@ -25,10 +25,13 @@ fn combine_blocklike() { y: value2, }); - do_thing(x, Bar { - x: value, - y: value2, - }); + do_thing( + x, + Bar { + x: value, + y: value2, + }, + ); do_thing( x, @@ -46,12 +49,15 @@ fn combine_blocklike() { value4_with_longer_name, ]); - do_thing(x, &[ - value_with_longer_name, - value2_with_longer_name, - value3_with_longer_name, - value4_with_longer_name, - ]); + do_thing( + x, + &[ + value_with_longer_name, + value2_with_longer_name, + value3_with_longer_name, + value4_with_longer_name, + ], + ); do_thing( x, @@ -71,12 +77,15 @@ fn combine_blocklike() { value4_with_longer_name, ]); - do_thing(x, vec![ - value_with_longer_name, - value2_with_longer_name, - value3_with_longer_name, - value4_with_longer_name, - ]); + do_thing( + x, + vec![ + value_with_longer_name, + value2_with_longer_name, + value3_with_longer_name, + value4_with_longer_name, + ], + ); do_thing( x, @@ -99,22 +108,28 @@ fn combine_blocklike() { } fn combine_struct_sample() { - let identity = verify(&ctx, VerifyLogin { - type_: LoginType::Username, - username: args.username.clone(), - password: Some(args.password.clone()), - domain: None, - })?; + let identity = verify( + &ctx, + VerifyLogin { + type_: LoginType::Username, + username: args.username.clone(), + password: Some(args.password.clone()), + domain: None, + }, + )?; } fn combine_macro_sample() { rocket::ignite() - .mount("/", routes![ - http::auth::login, - http::auth::logout, - http::cors::options, - http::action::dance, - http::action::sleep, - ]) + .mount( + "/", + routes![ + http::auth::login, + http::auth::logout, + http::cors::options, + http::action::dance, + http::action::sleep, + ], + ) .launch(); } From b5a02ff689e8ab4220602c898c961e9c19da844a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 1 Feb 2025 07:29:04 -0800 Subject: [PATCH 4/5] Update edition-guide --- src/doc/edition-guide | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/edition-guide b/src/doc/edition-guide index d56e0f3a0656b..888950147385f 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit d56e0f3a0656b7702ca466d4b191e16c28262b82 +Subproject commit 888950147385fb48076c492a2202e6c1a19d1228 From cfe3de22e8ff0d53e312e6df2593513b9103128b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 1 Feb 2025 07:42:21 -0800 Subject: [PATCH 5/5] Fix core AsyncFn stability attribute --- library/core/src/prelude/common.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/core/src/prelude/common.rs b/library/core/src/prelude/common.rs index 8b116cecb5295..b8640bc381502 100644 --- a/library/core/src/prelude/common.rs +++ b/library/core/src/prelude/common.rs @@ -12,7 +12,8 @@ pub use crate::marker::{Copy, Send, Sized, Sync, Unpin}; #[stable(feature = "core_prelude", since = "1.4.0")] #[doc(no_inline)] pub use crate::ops::{Drop, Fn, FnMut, FnOnce}; -#[stable(feature = "async_closure", since = "1.85.0")] +#[cfg_attr(bootstrap, unstable(feature = "async_closure", issue = "62290"))] +#[cfg_attr(not(bootstrap), stable(feature = "async_closure", since = "1.85.0"))] #[doc(no_inline)] pub use crate::ops::{AsyncFn, AsyncFnMut, AsyncFnOnce};