Skip to content

Commit

Permalink
Auto merge of rust-lang#136391 - ehuss:rust-1.85-beta-backports, r=ehuss
Browse files Browse the repository at this point in the history
[beta-1.85] backports

* [Add `AsyncFn*` to `core` prelude](rust-lang#135852)
* [Disable `overflow_delimited_expr` in edition 2024](rust-lang#136312)
* [Disable some incorrect rust-analyzer diagnostics on beta](rust-lang#136236)
    * [fix: Fix #[rustc_deprecated_safe_2024]](rust-lang/rust-analyzer#19044)
    * [fix: Fix a bug where enum variants were not considered properly in type ns resolution](rust-lang/rust-analyzer#18976)
* Update edition-guide
    * [Add alternatives for static-mut-refs](rust-lang/edition-guide#354)
    * [Remove rustfmt-overflow-delimited-expr](rust-lang/edition-guide#357)
  • Loading branch information
bors committed Feb 1, 2025
2 parents 14445aa + cfe3de2 commit 0277061
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 94 deletions.
4 changes: 4 additions & 0 deletions library/core/src/prelude/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ 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};
#[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};

// Re-exported functions
#[stable(feature = "core_prelude", since = "1.4.0")]
Expand Down
4 changes: 0 additions & 4 deletions src/doc/style-guide/src/editions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
55 changes: 7 additions & 48 deletions src/doc/style-guide/src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 });
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/tools/rustfmt/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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);
}

Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/tools/rustfmt/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rustfmt/src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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();
}

0 comments on commit 0277061

Please sign in to comment.