From ef1d084c0b5b0ff7143bbca966442cd24151313b Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Fri, 5 Apr 2024 23:27:29 -0400 Subject: Match ergonomics 2024: `mut` doesn't reset binding mode --- compiler/rustc_feature/src/unstable.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'compiler/rustc_feature/src') diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index e6b19817de3..2a753af9387 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -533,6 +533,8 @@ declare_features! ( (unstable, more_qualified_paths, "1.54.0", Some(86935)), /// Allows the `#[must_not_suspend]` attribute. (unstable, must_not_suspend, "1.57.0", Some(83310)), + /// Make `mut` not reset the binding mode on edition >= 2024. + (unstable, mut_dont_reset_binding_mode_2024, "CURRENT_RUSTC_VERSION", Some(123076)), /// Allows `mut ref` and `mut ref mut` identifier patterns. (incomplete, mut_ref, "CURRENT_RUSTC_VERSION", Some(123076)), /// Allows using `#[naked]` on functions. -- cgit 1.4.1-3-g733a5 From e13911e6e8d0d85802789a2d75aeb0e4b49ebb33 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Sun, 14 Apr 2024 11:12:52 -0400 Subject: Rename feature gate --- compiler/rustc_feature/src/unstable.rs | 2 +- compiler/rustc_hir_typeck/src/pat.rs | 2 +- compiler/rustc_lint_defs/src/builtin.rs | 2 +- compiler/rustc_span/src/symbol.rs | 2 +- ...eature-gate-mut_dont_reset_binding_mode_2024.rs | 14 ---------- ...re-gate-mut_dont_reset_binding_mode_2024.stderr | 31 ---------------------- .../feature-gate-mut_preserve_binding_mode_2024.rs | 14 ++++++++++ ...ture-gate-mut_preserve_binding_mode_2024.stderr | 31 ++++++++++++++++++++++ .../ui/pattern/mut_dont_reset_binding_mode_2021.rs | 15 ----------- .../mut_dont_reset_binding_mode_2021.stderr | 31 ---------------------- .../ui/pattern/mut_dont_reset_binding_mode_2024.rs | 15 ----------- .../mut_dont_reset_binding_mode_2024_lint.rs | 16 ----------- .../mut_dont_reset_binding_mode_2024_lint.stderr | 31 ---------------------- tests/ui/pattern/mut_preserve_binding_mode_2021.rs | 15 +++++++++++ .../pattern/mut_preserve_binding_mode_2021.stderr | 31 ++++++++++++++++++++++ tests/ui/pattern/mut_preserve_binding_mode_2024.rs | 15 +++++++++++ .../pattern/mut_preserve_binding_mode_2024_lint.rs | 16 +++++++++++ .../mut_preserve_binding_mode_2024_lint.stderr | 31 ++++++++++++++++++++++ 18 files changed, 157 insertions(+), 157 deletions(-) delete mode 100644 tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.rs delete mode 100644 tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.stderr create mode 100644 tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.rs create mode 100644 tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.stderr delete mode 100644 tests/ui/pattern/mut_dont_reset_binding_mode_2021.rs delete mode 100644 tests/ui/pattern/mut_dont_reset_binding_mode_2021.stderr delete mode 100644 tests/ui/pattern/mut_dont_reset_binding_mode_2024.rs delete mode 100644 tests/ui/pattern/mut_dont_reset_binding_mode_2024_lint.rs delete mode 100644 tests/ui/pattern/mut_dont_reset_binding_mode_2024_lint.stderr create mode 100644 tests/ui/pattern/mut_preserve_binding_mode_2021.rs create mode 100644 tests/ui/pattern/mut_preserve_binding_mode_2021.stderr create mode 100644 tests/ui/pattern/mut_preserve_binding_mode_2024.rs create mode 100644 tests/ui/pattern/mut_preserve_binding_mode_2024_lint.rs create mode 100644 tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr (limited to 'compiler/rustc_feature/src') diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 2a753af9387..3fc05752dd1 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -534,7 +534,7 @@ declare_features! ( /// Allows the `#[must_not_suspend]` attribute. (unstable, must_not_suspend, "1.57.0", Some(83310)), /// Make `mut` not reset the binding mode on edition >= 2024. - (unstable, mut_dont_reset_binding_mode_2024, "CURRENT_RUSTC_VERSION", Some(123076)), + (unstable, mut_preserve_binding_mode_2024, "CURRENT_RUSTC_VERSION", Some(123076)), /// Allows `mut ref` and `mut ref mut` identifier patterns. (incomplete, mut_ref, "CURRENT_RUSTC_VERSION", Some(123076)), /// Allows using `#[naked]` on functions. diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 252125aba7c..cdc6c4d809d 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -636,7 +636,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let bm = match ba { BindingAnnotation(ByRef::No, Mutability::Mut) if !(pat.span.at_least_rust_2024() - && self.tcx.features().mut_dont_reset_binding_mode_2024) + && self.tcx.features().mut_preserve_binding_mode_2024) && matches!(def_br, ByRef::Yes(_)) => { // `mut x` resets the binding mode in edition <= 2021. diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 3d80eb1cec9..e74cc388cab 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1656,7 +1656,7 @@ declare_lint! { pub DEREFERENCING_MUT_BINDING, Allow, "detects `mut x` bindings that change the type of `x`", - @feature_gate = sym::mut_dont_reset_binding_mode_2024; + @feature_gate = sym::mut_preserve_binding_mode_2024; // FIXME uncomment below upon stabilization /*@future_incompatible = FutureIncompatibleInfo { reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 02550fd655c..0a95d86ccc8 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1194,7 +1194,7 @@ symbols! { multiple_supertrait_upcastable, must_not_suspend, must_use, - mut_dont_reset_binding_mode_2024, + mut_preserve_binding_mode_2024, mut_ref, naked, naked_functions, diff --git a/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.rs b/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.rs deleted file mode 100644 index 15c542e6bf1..00000000000 --- a/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ edition: 2024 -//@ compile-flags: -Zunstable-options - -struct Foo(u8); - -fn main() { - let Foo(mut a) = &Foo(0); - a = &42; - //~^ ERROR: mismatched types - - let Foo(mut a) = &mut Foo(0); - a = &mut 42; - //~^ ERROR: mismatched types -} diff --git a/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.stderr b/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.stderr deleted file mode 100644 index 1624883de60..00000000000 --- a/tests/ui/pattern/feature-gate-mut_dont_reset_binding_mode_2024.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/feature-gate-mut_dont_reset_binding_mode_2024.rs:8:9 - | -LL | let Foo(mut a) = &Foo(0); - | ----- expected due to the type of this binding -LL | a = &42; - | ^^^ expected `u8`, found `&{integer}` - | -help: consider removing the borrow - | -LL - a = &42; -LL + a = 42; - | - -error[E0308]: mismatched types - --> $DIR/feature-gate-mut_dont_reset_binding_mode_2024.rs:12:9 - | -LL | let Foo(mut a) = &mut Foo(0); - | ----- expected due to the type of this binding -LL | a = &mut 42; - | ^^^^^^^ expected `u8`, found `&mut {integer}` - | -help: consider removing the borrow - | -LL - a = &mut 42; -LL + a = 42; - | - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.rs b/tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.rs new file mode 100644 index 00000000000..15c542e6bf1 --- /dev/null +++ b/tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.rs @@ -0,0 +1,14 @@ +//@ edition: 2024 +//@ compile-flags: -Zunstable-options + +struct Foo(u8); + +fn main() { + let Foo(mut a) = &Foo(0); + a = &42; + //~^ ERROR: mismatched types + + let Foo(mut a) = &mut Foo(0); + a = &mut 42; + //~^ ERROR: mismatched types +} diff --git a/tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.stderr b/tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.stderr new file mode 100644 index 00000000000..6d0a034be21 --- /dev/null +++ b/tests/ui/pattern/feature-gate-mut_preserve_binding_mode_2024.stderr @@ -0,0 +1,31 @@ +error[E0308]: mismatched types + --> $DIR/feature-gate-mut_preserve_binding_mode_2024.rs:8:9 + | +LL | let Foo(mut a) = &Foo(0); + | ----- expected due to the type of this binding +LL | a = &42; + | ^^^ expected `u8`, found `&{integer}` + | +help: consider removing the borrow + | +LL - a = &42; +LL + a = 42; + | + +error[E0308]: mismatched types + --> $DIR/feature-gate-mut_preserve_binding_mode_2024.rs:12:9 + | +LL | let Foo(mut a) = &mut Foo(0); + | ----- expected due to the type of this binding +LL | a = &mut 42; + | ^^^^^^^ expected `u8`, found `&mut {integer}` + | +help: consider removing the borrow + | +LL - a = &mut 42; +LL + a = 42; + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/pattern/mut_dont_reset_binding_mode_2021.rs b/tests/ui/pattern/mut_dont_reset_binding_mode_2021.rs deleted file mode 100644 index a9e12472734..00000000000 --- a/tests/ui/pattern/mut_dont_reset_binding_mode_2021.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ edition: 2021 -//@ compile-flags: -Zunstable-options -#![feature(mut_dont_reset_binding_mode_2024)] - -struct Foo(u8); - -fn main() { - let Foo(mut a) = &Foo(0); - a = &42; - //~^ ERROR: mismatched types - - let Foo(mut a) = &mut Foo(0); - a = &mut 42; - //~^ ERROR: mismatched types -} diff --git a/tests/ui/pattern/mut_dont_reset_binding_mode_2021.stderr b/tests/ui/pattern/mut_dont_reset_binding_mode_2021.stderr deleted file mode 100644 index 16818c900b3..00000000000 --- a/tests/ui/pattern/mut_dont_reset_binding_mode_2021.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/mut_dont_reset_binding_mode_2021.rs:9:9 - | -LL | let Foo(mut a) = &Foo(0); - | ----- expected due to the type of this binding -LL | a = &42; - | ^^^ expected `u8`, found `&{integer}` - | -help: consider removing the borrow - | -LL - a = &42; -LL + a = 42; - | - -error[E0308]: mismatched types - --> $DIR/mut_dont_reset_binding_mode_2021.rs:13:9 - | -LL | let Foo(mut a) = &mut Foo(0); - | ----- expected due to the type of this binding -LL | a = &mut 42; - | ^^^^^^^ expected `u8`, found `&mut {integer}` - | -help: consider removing the borrow - | -LL - a = &mut 42; -LL + a = 42; - | - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/pattern/mut_dont_reset_binding_mode_2024.rs b/tests/ui/pattern/mut_dont_reset_binding_mode_2024.rs deleted file mode 100644 index 9ac5ec50c74..00000000000 --- a/tests/ui/pattern/mut_dont_reset_binding_mode_2024.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ run-pass -//@ edition: 2024 -//@ compile-flags: -Zunstable-options -#![feature(mut_dont_reset_binding_mode_2024)] -#![allow(unused)] - -struct Foo(u8); - -fn main() { - let Foo(mut a) = &Foo(0); - a = &42; - - let Foo(mut a) = &mut Foo(0); - a = &mut 42; -} diff --git a/tests/ui/pattern/mut_dont_reset_binding_mode_2024_lint.rs b/tests/ui/pattern/mut_dont_reset_binding_mode_2024_lint.rs deleted file mode 100644 index 2e8a82d12cd..00000000000 --- a/tests/ui/pattern/mut_dont_reset_binding_mode_2024_lint.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ edition: 2021 -#![feature(mut_dont_reset_binding_mode_2024)] -#![allow(unused)] -#![forbid(dereferencing_mut_binding)] - -struct Foo(u8); - -fn main() { - let Foo(mut a) = &Foo(0); - //~^ ERROR: dereferencing `mut` binding - a = 42; - - let Foo(mut a) = &mut Foo(0); - //~^ ERROR: dereferencing `mut` binding - a = 42; -} diff --git a/tests/ui/pattern/mut_dont_reset_binding_mode_2024_lint.stderr b/tests/ui/pattern/mut_dont_reset_binding_mode_2024_lint.stderr deleted file mode 100644 index 4db775f0f51..00000000000 --- a/tests/ui/pattern/mut_dont_reset_binding_mode_2024_lint.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error: dereferencing `mut` binding - --> $DIR/mut_dont_reset_binding_mode_2024_lint.rs:9:13 - | -LL | let Foo(mut a) = &Foo(0); - | ^^^^^ `mut` dereferences the type of this binding - | -help: this will change in edition 2024 - --> $DIR/mut_dont_reset_binding_mode_2024_lint.rs:9:13 - | -LL | let Foo(mut a) = &Foo(0); - | ^^^^^ -note: the lint level is defined here - --> $DIR/mut_dont_reset_binding_mode_2024_lint.rs:4:11 - | -LL | #![forbid(dereferencing_mut_binding)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: dereferencing `mut` binding - --> $DIR/mut_dont_reset_binding_mode_2024_lint.rs:13:13 - | -LL | let Foo(mut a) = &mut Foo(0); - | ^^^^^ `mut` dereferences the type of this binding - | -help: this will change in edition 2024 - --> $DIR/mut_dont_reset_binding_mode_2024_lint.rs:13:13 - | -LL | let Foo(mut a) = &mut Foo(0); - | ^^^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/pattern/mut_preserve_binding_mode_2021.rs b/tests/ui/pattern/mut_preserve_binding_mode_2021.rs new file mode 100644 index 00000000000..658ba2851cc --- /dev/null +++ b/tests/ui/pattern/mut_preserve_binding_mode_2021.rs @@ -0,0 +1,15 @@ +//@ edition: 2021 +//@ compile-flags: -Zunstable-options +#![feature(mut_preserve_binding_mode_2024)] + +struct Foo(u8); + +fn main() { + let Foo(mut a) = &Foo(0); + a = &42; + //~^ ERROR: mismatched types + + let Foo(mut a) = &mut Foo(0); + a = &mut 42; + //~^ ERROR: mismatched types +} diff --git a/tests/ui/pattern/mut_preserve_binding_mode_2021.stderr b/tests/ui/pattern/mut_preserve_binding_mode_2021.stderr new file mode 100644 index 00000000000..9487aa64b4f --- /dev/null +++ b/tests/ui/pattern/mut_preserve_binding_mode_2021.stderr @@ -0,0 +1,31 @@ +error[E0308]: mismatched types + --> $DIR/mut_preserve_binding_mode_2021.rs:9:9 + | +LL | let Foo(mut a) = &Foo(0); + | ----- expected due to the type of this binding +LL | a = &42; + | ^^^ expected `u8`, found `&{integer}` + | +help: consider removing the borrow + | +LL - a = &42; +LL + a = 42; + | + +error[E0308]: mismatched types + --> $DIR/mut_preserve_binding_mode_2021.rs:13:9 + | +LL | let Foo(mut a) = &mut Foo(0); + | ----- expected due to the type of this binding +LL | a = &mut 42; + | ^^^^^^^ expected `u8`, found `&mut {integer}` + | +help: consider removing the borrow + | +LL - a = &mut 42; +LL + a = 42; + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/pattern/mut_preserve_binding_mode_2024.rs b/tests/ui/pattern/mut_preserve_binding_mode_2024.rs new file mode 100644 index 00000000000..a5d7ac9d8e6 --- /dev/null +++ b/tests/ui/pattern/mut_preserve_binding_mode_2024.rs @@ -0,0 +1,15 @@ +//@ run-pass +//@ edition: 2024 +//@ compile-flags: -Zunstable-options +#![feature(mut_preserve_binding_mode_2024)] +#![allow(unused)] + +struct Foo(u8); + +fn main() { + let Foo(mut a) = &Foo(0); + a = &42; + + let Foo(mut a) = &mut Foo(0); + a = &mut 42; +} diff --git a/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.rs b/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.rs new file mode 100644 index 00000000000..d3e3ffffcc5 --- /dev/null +++ b/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.rs @@ -0,0 +1,16 @@ +//@ edition: 2021 +#![feature(mut_preserve_binding_mode_2024)] +#![allow(unused)] +#![forbid(dereferencing_mut_binding)] + +struct Foo(u8); + +fn main() { + let Foo(mut a) = &Foo(0); + //~^ ERROR: dereferencing `mut` binding + a = 42; + + let Foo(mut a) = &mut Foo(0); + //~^ ERROR: dereferencing `mut` binding + a = 42; +} diff --git a/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr b/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr new file mode 100644 index 00000000000..e8d11acd83e --- /dev/null +++ b/tests/ui/pattern/mut_preserve_binding_mode_2024_lint.stderr @@ -0,0 +1,31 @@ +error: dereferencing `mut` binding + --> $DIR/mut_preserve_binding_mode_2024_lint.rs:9:13 + | +LL | let Foo(mut a) = &Foo(0); + | ^^^^^ `mut` dereferences the type of this binding + | +help: this will change in edition 2024 + --> $DIR/mut_preserve_binding_mode_2024_lint.rs:9:13 + | +LL | let Foo(mut a) = &Foo(0); + | ^^^^^ +note: the lint level is defined here + --> $DIR/mut_preserve_binding_mode_2024_lint.rs:4:11 + | +LL | #![forbid(dereferencing_mut_binding)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: dereferencing `mut` binding + --> $DIR/mut_preserve_binding_mode_2024_lint.rs:13:13 + | +LL | let Foo(mut a) = &mut Foo(0); + | ^^^^^ `mut` dereferences the type of this binding + | +help: this will change in edition 2024 + --> $DIR/mut_preserve_binding_mode_2024_lint.rs:13:13 + | +LL | let Foo(mut a) = &mut Foo(0); + | ^^^^^ + +error: aborting due to 2 previous errors + -- cgit 1.4.1-3-g733a5 From 1b6d435cf3e94548f3da6a0409c5786c4accfaa4 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Sun, 14 Apr 2024 11:17:58 -0400 Subject: Mark gate as incomplete --- compiler/rustc_feature/src/unstable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/rustc_feature/src') diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 3fc05752dd1..eaaf4026cd7 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -534,7 +534,7 @@ declare_features! ( /// Allows the `#[must_not_suspend]` attribute. (unstable, must_not_suspend, "1.57.0", Some(83310)), /// Make `mut` not reset the binding mode on edition >= 2024. - (unstable, mut_preserve_binding_mode_2024, "CURRENT_RUSTC_VERSION", Some(123076)), + (incomplete, mut_preserve_binding_mode_2024, "CURRENT_RUSTC_VERSION", Some(123076)), /// Allows `mut ref` and `mut ref mut` identifier patterns. (incomplete, mut_ref, "CURRENT_RUSTC_VERSION", Some(123076)), /// Allows using `#[naked]` on functions. -- cgit 1.4.1-3-g733a5