diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic.stderr index f26151fe4f7..65b03f7a610 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic.stderr @@ -25,7 +25,55 @@ error[E0596]: cannot borrow data in a `&` reference as mutable LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { | ^ cannot borrow as mutable -error: aborting due to 3 previous errors +error[E0596]: cannot borrow data in a `&` reference as mutable + --> $DIR/borrowck-errors.rs:22:11 + | +LL | let &[x] = &&mut [0]; + | ^ cannot borrow as mutable -Some errors have detailed explanations: E0507, E0596. +error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array + --> $DIR/borrowck-errors.rs:26:16 + | +LL | let [&x] = &[&mut 0]; + | - ^^^^^^^^^ cannot move out of here + | | + | data moved here + | move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let [&ref x] = &[&mut 0]; + | +++ + +error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array + --> $DIR/borrowck-errors.rs:31:16 + | +LL | let [&x] = &mut [&mut 0]; + | - ^^^^^^^^^^^^^ cannot move out of here + | | + | data moved here + | move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let [&ref x] = &mut [&mut 0]; + | +++ + +error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array + --> $DIR/borrowck-errors.rs:34:20 + | +LL | let [&mut x] = &mut [&mut 0]; + | - ^^^^^^^^^^^^^ cannot move out of here + | | + | data moved here + | move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait + | +help: consider borrowing the pattern binding + | +LL | let [&mut ref x] = &mut [&mut 0]; + | +++ + +error: aborting due to 7 previous errors + +Some errors have detailed explanations: E0507, E0508, E0596. For more information about an error, try `rustc --explain E0507`. diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.rs index 79581936418..7645c145b65 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.rs @@ -18,4 +18,20 @@ pub fn main() { //[classic]~^ ERROR: cannot borrow data in a `&` reference as mutable let _: &u32 = x; } + + let &[x] = &&mut [0]; + //[classic]~^ ERROR: cannot borrow data in a `&` reference as mutable + let _: &u32 = x; + + let [&x] = &[&mut 0]; + //[classic]~^ ERROR: cannot move out of type + let _: &u32 = x; + + #[cfg(classic)] // TODO: this should pass on `structural` but doesn't + let [&x] = &mut [&mut 0]; //[classic]~ ERROR: cannot move out of type + let _: &u32 = x; + + let [&mut x] = &mut [&mut 0]; + //[classic]~^ ERROR: cannot move out of type + let _: &mut u32 = x; } diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.classic.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.classic.stderr index 9b8a1e0ff39..fbb9a35443a 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.classic.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.classic.stderr @@ -82,6 +82,54 @@ help: replace this `&mut` pattern with `&` LL | if let Some(&Some(x)) = &Some(Some(0)) { | ~ -error: aborting due to 7 previous errors +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:119:10 + | +LL | let [&mut x] = &[&mut 0]; + | ^^^^^ + | + = note: cannot match inherited `&` with `&mut` pattern +help: replace this `&mut` pattern with `&` + | +LL | let [&x] = &[&mut 0]; + | ~ + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:124:10 + | +LL | let [&mut &x] = &[&mut 0]; + | ^^^^^ + | + = note: cannot match inherited `&` with `&mut` pattern +help: replace this `&mut` pattern with `&` + | +LL | let [&&x] = &[&mut 0]; + | ~ + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:129:10 + | +LL | let [&mut &ref x] = &[&mut 0]; + | ^^^^^ + | + = note: cannot match inherited `&` with `&mut` pattern +help: replace this `&mut` pattern with `&` + | +LL | let [&&ref x] = &[&mut 0]; + | ~ + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:134:10 + | +LL | let [&mut &(mut x)] = &[&mut 0]; + | ^^^^^ + | + = note: cannot match inherited `&` with `&mut` pattern +help: replace this `&mut` pattern with `&` + | +LL | let [&&(mut x)] = &[&mut 0]; + | ~ + +error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.rs index f9cc8504d55..b5e8bd112aa 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.rs @@ -44,3 +44,95 @@ pub fn main() { //~^ ERROR: mismatched types } } + +// TODO: these should be mutability mismatches on `structural` +fn structural_errors_0() { + let &[&mut x] = &&mut [0]; + //[structural]~^ ERROR: mismatched types + let _: u32 = x; + //[structural]~^ ERROR: mismatched types + + let &[&mut x] = &mut &mut [0]; + //[structural]~^ ERROR: mismatched types + let _: u32 = x; + //[structural]~^ ERROR: mismatched types + + let &[&mut ref x] = &&mut [0]; + //[structural]~^ ERROR: mismatched types + let _: &u32 = x; + + let &[&mut ref x] = &mut &mut [0]; + //[structural]~^ ERROR: mismatched types + let _: &u32 = x; + + let &[&mut mut x] = &&mut [0]; + //[structural]~^ ERROR: mismatched types + //[structural]~| ERROR: binding cannot be both mutable and by-reference + let _: u32 = x; + //[structural]~^ ERROR: mismatched types + + let &[&mut mut x] = &mut &mut [0]; + //[structural]~^ ERROR: mismatched types + //[structural]~| ERROR: binding cannot be both mutable and by-reference + let _: u32 = x; + //[structural]~^ ERROR: mismatched types +} + +fn structural_errors_1() { + let [&(mut x)] = &[&0]; + //[structural]~^ ERROR: binding cannot be both mutable and by-reference + let _: &u32 = x; + + let [&(mut x)] = &mut [&0]; + //[structural]~^ ERROR: binding cannot be both mutable and by-reference + let _: &u32 = x; +} + +// TODO: these should be mutability mismatches on `structural` +fn structural_errors_2() { + let [&&mut x] = &[&mut 0]; + //[structural]~^ ERROR: mismatched types + let _: u32 = x; + //[structural]~^ ERROR: mismatched types + + let [&&mut x] = &mut [&mut 0]; + let _: u32 = x; + + let [&&mut ref x] = &[&mut 0]; + //[structural]~^ ERROR: mismatched types + let _: &u32 = x; + + let [&&mut ref x] = &mut [&mut 0]; + let _: &u32 = x; + + let [&&mut mut x] = &[&mut 0]; + //[structural]~^ ERROR: binding cannot be both mutable and by-reference + //[structural]~| ERROR: mismatched types + let _: u32 = x; + //[structural]~^ ERROR: mismatched types + + let [&&mut mut x] = &mut [&mut 0]; + let _: u32 = x; +} + +fn classic_errors_0() { + let [&mut x] = &[&mut 0]; + //[classic]~^ ERROR: mismatched types + //[classic]~| cannot match inherited `&` with `&mut` pattern + let _: &u32 = x; + + let [&mut &x] = &[&mut 0]; + //[classic]~^ ERROR: mismatched types + //[classic]~| cannot match inherited `&` with `&mut` pattern + let _: u32 = x; + + let [&mut &ref x] = &[&mut 0]; + //[classic]~^ ERROR: mismatched types + //[classic]~| cannot match inherited `&` with `&mut` pattern + let _: &u32 = x; + + let [&mut &(mut x)] = &[&mut 0]; + //[classic]~^ ERROR: mismatched types + //[classic]~| cannot match inherited `&` with `&mut` pattern + let _: u32 = x; +} diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.structural.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.structural.stderr index 59d65553fae..4eabb8b1b0a 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.structural.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/pattern-errors.structural.stderr @@ -84,6 +84,321 @@ LL | if let Some(&mut Some(x)) = &Some(Some(0)) { = note: expected enum `Option<{integer}>` found mutable reference `&mut _` -error: aborting due to 7 previous errors +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:50:11 + | +LL | let &[&mut x] = &&mut [0]; + | ^^^^^^ --------- this expression has type `&&mut [{integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +note: to declare a mutable binding use: `mut x` + --> $DIR/pattern-errors.rs:50:11 + | +LL | let &[&mut x] = &&mut [0]; + | ^^^^^^ +help: consider removing `&mut` from the pattern + | +LL - let &[&mut x] = &&mut [0]; +LL + let &[x] = &&mut [0]; + | -For more information about this error, try `rustc --explain E0308`. +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:52:18 + | +LL | let _: u32 = x; + | --- ^ expected `u32`, found `&_` + | | + | expected due to this + | + = note: expected type `u32` + found reference `&_` +help: consider dereferencing the borrow + | +LL | let _: u32 = *x; + | + + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:55:11 + | +LL | let &[&mut x] = &mut &mut [0]; + | ^^^^^^ ------------- this expression has type `&mut &mut [{integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +note: to declare a mutable binding use: `mut x` + --> $DIR/pattern-errors.rs:55:11 + | +LL | let &[&mut x] = &mut &mut [0]; + | ^^^^^^ +help: consider removing `&mut` from the pattern + | +LL - let &[&mut x] = &mut &mut [0]; +LL + let &[x] = &mut &mut [0]; + | + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:57:18 + | +LL | let _: u32 = x; + | --- ^ expected `u32`, found `&_` + | | + | expected due to this + | + = note: expected type `u32` + found reference `&_` +help: consider dereferencing the borrow + | +LL | let _: u32 = *x; + | + + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:60:11 + | +LL | let &[&mut ref x] = &&mut [0]; + | ^^^^^^^^^^ --------- this expression has type `&&mut [{integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +note: to declare a mutable binding use: `mut x` + --> $DIR/pattern-errors.rs:60:11 + | +LL | let &[&mut ref x] = &&mut [0]; + | ^^^^^^^^^^ +help: consider removing `&mut` from the pattern + | +LL - let &[&mut ref x] = &&mut [0]; +LL + let &[ref x] = &&mut [0]; + | + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:64:11 + | +LL | let &[&mut ref x] = &mut &mut [0]; + | ^^^^^^^^^^ ------------- this expression has type `&mut &mut [{integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +note: to declare a mutable binding use: `mut x` + --> $DIR/pattern-errors.rs:64:11 + | +LL | let &[&mut ref x] = &mut &mut [0]; + | ^^^^^^^^^^ +help: consider removing `&mut` from the pattern + | +LL - let &[&mut ref x] = &mut &mut [0]; +LL + let &[ref x] = &mut &mut [0]; + | + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:68:11 + | +LL | let &[&mut mut x] = &&mut [0]; + | ^^^^^^^^^^ --------- this expression has type `&&mut [{integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +note: to declare a mutable binding use: `mut x` + --> $DIR/pattern-errors.rs:68:11 + | +LL | let &[&mut mut x] = &&mut [0]; + | ^^^^^^^^^^ +help: consider removing `&mut` from the pattern + | +LL - let &[&mut mut x] = &&mut [0]; +LL + let &[mut x] = &&mut [0]; + | + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/pattern-errors.rs:68:16 + | +LL | let &[&mut mut x] = &&mut [0]; + | ^^^^ + | + = note: see issue #123076 for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:71:18 + | +LL | let _: u32 = x; + | --- ^ expected `u32`, found `&_` + | | + | expected due to this + | + = note: expected type `u32` + found reference `&_` +help: consider dereferencing the borrow + | +LL | let _: u32 = *x; + | + + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:74:11 + | +LL | let &[&mut mut x] = &mut &mut [0]; + | ^^^^^^^^^^ ------------- this expression has type `&mut &mut [{integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +note: to declare a mutable binding use: `mut x` + --> $DIR/pattern-errors.rs:74:11 + | +LL | let &[&mut mut x] = &mut &mut [0]; + | ^^^^^^^^^^ +help: consider removing `&mut` from the pattern + | +LL - let &[&mut mut x] = &mut &mut [0]; +LL + let &[mut x] = &mut &mut [0]; + | + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/pattern-errors.rs:74:16 + | +LL | let &[&mut mut x] = &mut &mut [0]; + | ^^^^ + | + = note: see issue #123076 for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:77:18 + | +LL | let _: u32 = x; + | --- ^ expected `u32`, found `&_` + | | + | expected due to this + | + = note: expected type `u32` + found reference `&_` +help: consider dereferencing the borrow + | +LL | let _: u32 = *x; + | + + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/pattern-errors.rs:82:12 + | +LL | let [&(mut x)] = &[&0]; + | ^^^^ + | + = note: see issue #123076 for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/pattern-errors.rs:86:12 + | +LL | let [&(mut x)] = &mut [&0]; + | ^^^^ + | + = note: see issue #123076 for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:93:11 + | +LL | let [&&mut x] = &[&mut 0]; + | ^^^^^^ --------- this expression has type `&[&mut {integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +help: consider removing `&mut` from the pattern + | +LL - let [&&mut x] = &[&mut 0]; +LL + let [&x] = &[&mut 0]; + | + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:95:18 + | +LL | let _: u32 = x; + | --- ^ expected `u32`, found `&_` + | | + | expected due to this + | + = note: expected type `u32` + found reference `&_` +help: consider dereferencing the borrow + | +LL | let _: u32 = *x; + | + + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:101:11 + | +LL | let [&&mut ref x] = &[&mut 0]; + | ^^^^^^^^^^ --------- this expression has type `&[&mut {integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +help: consider removing `&mut` from the pattern + | +LL - let [&&mut ref x] = &[&mut 0]; +LL + let [&ref x] = &[&mut 0]; + | + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:108:11 + | +LL | let [&&mut mut x] = &[&mut 0]; + | ^^^^^^^^^^ --------- this expression has type `&[&mut {integer}; 1]` + | | + | expected integer, found `&mut _` + | + = note: expected type `{integer}` + found mutable reference `&mut _` +help: consider removing `&mut` from the pattern + | +LL - let [&&mut mut x] = &[&mut 0]; +LL + let [&mut x] = &[&mut 0]; + | + +error[E0658]: binding cannot be both mutable and by-reference + --> $DIR/pattern-errors.rs:108:16 + | +LL | let [&&mut mut x] = &[&mut 0]; + | ^^^^ + | + = note: see issue #123076 for more information + = help: add `#![feature(mut_ref)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0308]: mismatched types + --> $DIR/pattern-errors.rs:111:18 + | +LL | let _: u32 = x; + | --- ^ expected `u32`, found `&_` + | | + | expected due to this + | + = note: expected type `u32` + found reference `&_` +help: consider dereferencing the borrow + | +LL | let _: u32 = *x; + | + + +error: aborting due to 27 previous errors + +Some errors have detailed explanations: E0308, E0658. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.rs new file mode 100644 index 00000000000..3b27aa0f6ac --- /dev/null +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.rs @@ -0,0 +1,40 @@ +//@ edition: 2024 +//@ revisions: classic structural +//@[classic] run-pass +//! Tests for errors from binding with `ref x` under a by-ref default binding mode. These can't be +//! in the same body as tests for other errors, since they're emitted during THIR construction. +#![allow(incomplete_features)] +#![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))] +#![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))] + +pub fn main() { + let [&ref x] = &[&0]; + //[structural]~^ ERROR: this pattern relies on behavior which may change in edition 2024 + //[structural]~| cannot override to bind by-reference when that is the implicit default + #[cfg(classic)] let _: &&u32 = x; + + let [&ref x] = &[&mut 0]; + //[structural]~^ ERROR: this pattern relies on behavior which may change in edition 2024 + //[structural]~| cannot override to bind by-reference when that is the implicit default + #[cfg(classic)] let _: &&mut u32 = x; + + let [&ref x] = &mut [&0]; + //[structural]~^ ERROR: this pattern relies on behavior which may change in edition 2024 + //[structural]~| cannot override to bind by-reference when that is the implicit default + #[cfg(classic)] let _: &&u32 = x; + + let [&ref x] = &mut [&mut 0]; + //[structural]~^ ERROR: this pattern relies on behavior which may change in edition 2024 + //[structural]~| cannot override to bind by-reference when that is the implicit default + #[cfg(classic)] let _: &&mut u32 = x; + + let [&mut ref x] = &mut [&mut 0]; + //[structural]~^ ERROR: this pattern relies on behavior which may change in edition 2024 + //[structural]~| cannot override to bind by-reference when that is the implicit default + #[cfg(classic)] let _: &&mut u32 = x; + + let [&mut ref mut x] = &mut [&mut 0]; + //[structural]~^ ERROR: this pattern relies on behavior which may change in edition 2024 + //[structural]~| cannot override to bind by-reference when that is the implicit default + #[cfg(classic)] let _: &mut &mut u32 = x; +} diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural.stderr new file mode 100644 index 00000000000..a952f72f08e --- /dev/null +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural.stderr @@ -0,0 +1,74 @@ +error: this pattern relies on behavior which may change in edition 2024 + --> $DIR/ref-binding-on-inh-ref-errors.rs:11:11 + | +LL | let [&ref x] = &[&0]; + | ^^^ cannot override to bind by-reference when that is the implicit default + | + = note: for more information, see +help: make the implied reference pattern explicit + | +LL | let &[&ref x] = &[&0]; + | + + +error: this pattern relies on behavior which may change in edition 2024 + --> $DIR/ref-binding-on-inh-ref-errors.rs:16:11 + | +LL | let [&ref x] = &[&mut 0]; + | ^^^ cannot override to bind by-reference when that is the implicit default + | + = note: for more information, see +help: make the implied reference pattern explicit + | +LL | let &[&ref x] = &[&mut 0]; + | + + +error: this pattern relies on behavior which may change in edition 2024 + --> $DIR/ref-binding-on-inh-ref-errors.rs:21:11 + | +LL | let [&ref x] = &mut [&0]; + | ^^^ cannot override to bind by-reference when that is the implicit default + | + = note: for more information, see +help: make the implied reference pattern explicit + | +LL | let &mut [&ref x] = &mut [&0]; + | ++++ + +error: this pattern relies on behavior which may change in edition 2024 + --> $DIR/ref-binding-on-inh-ref-errors.rs:26:11 + | +LL | let [&ref x] = &mut [&mut 0]; + | ^^^ cannot override to bind by-reference when that is the implicit default + | + = note: for more information, see +help: make the implied reference pattern explicit + | +LL | let &mut [&ref x] = &mut [&mut 0]; + | ++++ + +error: this pattern relies on behavior which may change in edition 2024 + --> $DIR/ref-binding-on-inh-ref-errors.rs:31:15 + | +LL | let [&mut ref x] = &mut [&mut 0]; + | ^^^ cannot override to bind by-reference when that is the implicit default + | + = note: for more information, see +help: make the implied reference pattern explicit + | +LL | let &mut [&mut ref x] = &mut [&mut 0]; + | ++++ + +error: this pattern relies on behavior which may change in edition 2024 + --> $DIR/ref-binding-on-inh-ref-errors.rs:36:15 + | +LL | let [&mut ref mut x] = &mut [&mut 0]; + | ^^^^^^^ cannot override to bind by-reference when that is the implicit default + | + = note: for more information, see +help: make the implied reference pattern explicit + | +LL | let &mut [&mut ref mut x] = &mut [&mut 0]; + | ++++ + +error: aborting due to 6 previous errors + diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.classic.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.classic.fixed index 4f4941975d8..c7216d06bb7 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.classic.fixed +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.classic.fixed @@ -30,4 +30,8 @@ pub fn main() { //~| ERROR: cannot borrow as mutable inside an `&` pattern let _: &mut bool = a; let _: &mut bool = b; + + let &mut [x] = &mut &mut [0]; + //[classic]~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &u32 = x; } diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.classic.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.classic.stderr index 6c384a51fac..42a4a8597f7 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.classic.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.classic.stderr @@ -38,6 +38,14 @@ LL | let &(ref mut a, ref mut b) = &mut (true, false); | | | help: replace this `&` with `&mut`: `&mut` -error: aborting due to 5 previous errors +error[E0596]: cannot borrow as mutable inside an `&` pattern + --> $DIR/ref-mut-inside-shared-ref-pat.rs:34:11 + | +LL | let &[x] = &mut &mut [0]; + | - ^ + | | + | help: replace this `&` with `&mut`: `&mut` + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.rs index b29bff7603f..138de4f8eac 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.rs @@ -30,4 +30,8 @@ pub fn main() { //~| ERROR: cannot borrow as mutable inside an `&` pattern let _: &mut bool = a; let _: &mut bool = b; + + let &[x] = &mut &mut [0]; + //[classic]~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &u32 = x; } diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.structural.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.structural.fixed index 4f4941975d8..24fb99ae029 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.structural.fixed +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-mut-inside-shared-ref-pat.structural.fixed @@ -30,4 +30,8 @@ pub fn main() { //~| ERROR: cannot borrow as mutable inside an `&` pattern let _: &mut bool = a; let _: &mut bool = b; + + let &[x] = &mut &mut [0]; + //[classic]~^ ERROR: cannot borrow as mutable inside an `&` pattern + let _: &u32 = x; }