Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change error message
Browse files Browse the repository at this point in the history
Nadrieril committed Oct 7, 2024

Verified

This commit was signed with the committer’s verified signature.
addaleax Anna Henningsen
1 parent 81e717d commit bf3b7f3
Showing 6 changed files with 57 additions and 58 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/messages.ftl
Original file line number Diff line number Diff line change
@@ -265,7 +265,7 @@ mir_build_pointer_pattern = function pointers and raw pointers not derived from
mir_build_privately_uninhabited = pattern `{$witness_1}` is currently uninhabited, but this variant contains private fields which may become inhabited in the future
mir_build_rust_2024_incompatible_pat = the semantics of this pattern will change in edition 2024
mir_build_rust_2024_incompatible_pat = patterns are not allowed to reset the default binding mode in edition 2024
mir_build_rustc_box_attribute_error = `#[rustc_box]` attribute used incorrectly
.attributes = no other attributes may be applied
7 changes: 3 additions & 4 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ use tracing::{debug, instrument};

pub(crate) use self::check_match::check_match;
use crate::errors::*;
use crate::fluent_generated as fluent;
use crate::thir::util::UserAnnotatedTyHelpers;

struct PatCtxt<'a, 'tcx> {
@@ -58,10 +59,8 @@ pub(super) fn pat_from_hir<'a, 'tcx>(
debug!("pat_from_hir({:?}) = {:?}", pat, result);
if let Some(sugg) = pcx.rust_2024_migration_suggestion {
if sugg.is_hard_error {
let mut err = tcx.dcx().struct_span_err(
pat.span,
"patterns are not allowed to reset the default binding mode in rust 2024",
);
let mut err =
tcx.dcx().struct_span_err(pat.span, fluent::mir_build_rust_2024_incompatible_pat);
err.subdiagnostic(sugg);
err.emit();
} else {
Original file line number Diff line number Diff line change
@@ -23,22 +23,22 @@ fn main() {
assert_type_eq(x, &mut 0u8);

let &Foo(mut x) = &Foo(0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let &mut Foo(mut x) = &mut Foo(0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let &Foo(ref x) = &Foo(0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, &0u8);

let &mut Foo(ref x) = &mut Foo(0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, &0u8);

@@ -55,22 +55,22 @@ fn main() {
assert_type_eq(x, &0u8);

let &Foo(&x) = &Foo(&0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let &Foo(&mut x) = &Foo(&mut 0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let &mut Foo(&x) = &mut Foo(&0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let &mut Foo(&mut x) = &mut Foo(&mut 0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

@@ -79,25 +79,25 @@ fn main() {
}

if let &&&&&Some(&x) = &&&&&Some(&0u8) {
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);
}

if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) {
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);
}

if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) {
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);
}

if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) {
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, &mut 0u8);
}
@@ -109,20 +109,20 @@ fn main() {
}

let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 };
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(a, &0u32);
assert_type_eq(b, 0u32);

let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 };
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(a, 0u32);
assert_type_eq(b, &&0u32);
assert_type_eq(c, &&0u32);

if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } =
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
&(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) })
{
30 changes: 15 additions & 15 deletions tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs
Original file line number Diff line number Diff line change
@@ -23,22 +23,22 @@ fn main() {
assert_type_eq(x, &mut 0u8);

let Foo(mut x) = &Foo(0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let Foo(mut x) = &mut Foo(0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let Foo(ref x) = &Foo(0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, &0u8);

let Foo(ref x) = &mut Foo(0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, &0u8);

@@ -55,22 +55,22 @@ fn main() {
assert_type_eq(x, &0u8);

let Foo(&x) = &Foo(&0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let Foo(&mut x) = &Foo(&mut 0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let Foo(&x) = &mut Foo(&0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

let Foo(&mut x) = &mut Foo(&mut 0);
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);

@@ -79,25 +79,25 @@ fn main() {
}

if let Some(&x) = &&&&&Some(&0u8) {
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);
}

if let Some(&mut x) = &&&&&Some(&mut 0u8) {
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);
}

if let Some(&x) = &&&&&mut Some(&0u8) {
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, 0u8);
}

if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) {
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(x, &mut 0u8);
}
@@ -109,20 +109,20 @@ fn main() {
}

let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 };
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(a, &0u32);
assert_type_eq(b, 0u32);

let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 };
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
assert_type_eq(a, 0u32);
assert_type_eq(b, &&0u32);
assert_type_eq(c, &&0u32);

if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } =
//~^ ERROR: the semantics of this pattern will change in edition 2024
//~^ ERROR: patterns are not allowed to reset the default binding mode
//~| WARN: this changes meaning in Rust 2024
&(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) })
{
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:25:9
|
LL | let Foo(mut x) = &Foo(0);
@@ -14,7 +14,7 @@ note: the lint level is defined here
LL | #![deny(rust_2024_incompatible_pat)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:30:9
|
LL | let Foo(mut x) = &mut Foo(0);
@@ -25,7 +25,7 @@ LL | let Foo(mut x) = &mut Foo(0);
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:35:9
|
LL | let Foo(ref x) = &Foo(0);
@@ -36,7 +36,7 @@ LL | let Foo(ref x) = &Foo(0);
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:40:9
|
LL | let Foo(ref x) = &mut Foo(0);
@@ -47,7 +47,7 @@ LL | let Foo(ref x) = &mut Foo(0);
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:57:9
|
LL | let Foo(&x) = &Foo(&0);
@@ -58,7 +58,7 @@ LL | let Foo(&x) = &Foo(&0);
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:62:9
|
LL | let Foo(&mut x) = &Foo(&mut 0);
@@ -69,7 +69,7 @@ LL | let Foo(&mut x) = &Foo(&mut 0);
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:67:9
|
LL | let Foo(&x) = &mut Foo(&0);
@@ -80,7 +80,7 @@ LL | let Foo(&x) = &mut Foo(&0);
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:72:9
|
LL | let Foo(&mut x) = &mut Foo(&mut 0);
@@ -91,7 +91,7 @@ LL | let Foo(&mut x) = &mut Foo(&mut 0);
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:81:12
|
LL | if let Some(&x) = &&&&&Some(&0u8) {
@@ -102,7 +102,7 @@ LL | if let Some(&x) = &&&&&Some(&0u8) {
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:87:12
|
LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) {
@@ -113,7 +113,7 @@ LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) {
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:93:12
|
LL | if let Some(&x) = &&&&&mut Some(&0u8) {
@@ -124,7 +124,7 @@ LL | if let Some(&x) = &&&&&mut Some(&0u8) {
= warning: this changes meaning in Rust 2024
= note: for more information, see 123076

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:99:12
|
LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) {
@@ -137,7 +137,7 @@ help: desugar the match ergonomics
LL | if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) {
| ++++ ++++ +++++++

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:111:9
|
LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 };
@@ -150,7 +150,7 @@ help: desugar the match ergonomics
LL | let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 };
| + +++ +++

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:117:9
|
LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 };
@@ -163,7 +163,7 @@ help: desugar the match ergonomics
LL | let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 };
| + +++

error: the semantics of this pattern will change in edition 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:124:12
|
LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } =
@@ -176,7 +176,7 @@ help: desugar the match ergonomics
LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } =
| + + + +++

error: patterns are not allowed to reset the default binding mode in rust 2024
error: patterns are not allowed to reset the default binding mode in edition 2024
--> $DIR/migration_lint.rs:137:9
|
LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => {
Loading

0 comments on commit bf3b7f3

Please sign in to comment.