add more tests where the rulesets disagree
These come directly from the "Compare" tab of Typing Rust Patterns, though they had to be split across multiple files. They're not comprehensive, but they do provide some previously-missing coverage and are easier to check against the spec. Possibly they should be split up some more, since `pattern-errors.rs` is getting a bit unwieldy, but I'm not sure how best to go about that.
This commit is contained in:
parent
a56f9ad574
commit
c57708a58d
11 changed files with 659 additions and 6 deletions
|
@ -25,7 +25,55 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
|
||||||
LL | if let &Some(Some(x)) = &Some(&mut Some(0)) {
|
LL | if let &Some(Some(x)) = &Some(&mut Some(0)) {
|
||||||
| ^ cannot borrow as mutable
|
| ^ 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`.
|
For more information about an error, try `rustc --explain E0507`.
|
||||||
|
|
|
@ -18,4 +18,20 @@ pub fn main() {
|
||||||
//[classic]~^ ERROR: cannot borrow data in a `&` reference as mutable
|
//[classic]~^ ERROR: cannot borrow data in a `&` reference as mutable
|
||||||
let _: &u32 = x;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,54 @@ help: replace this `&mut` pattern with `&`
|
||||||
LL | if let Some(&Some(x)) = &Some(Some(0)) {
|
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`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
|
|
|
@ -44,3 +44,95 @@ pub fn main() {
|
||||||
//~^ ERROR: mismatched types
|
//~^ 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;
|
||||||
|
}
|
||||||
|
|
|
@ -84,6 +84,321 @@ LL | if let Some(&mut Some(x)) = &Some(Some(0)) {
|
||||||
= note: expected enum `Option<{integer}>`
|
= note: expected enum `Option<{integer}>`
|
||||||
found mutable reference `&mut _`
|
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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
|
||||||
|
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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
|
||||||
|
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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
|
||||||
|
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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
|
||||||
|
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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
|
||||||
|
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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
|
||||||
|
help: make the implied reference pattern explicit
|
||||||
|
|
|
||||||
|
LL | let &mut [&mut ref mut x] = &mut [&mut 0];
|
||||||
|
| ++++
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
|
@ -30,4 +30,8 @@ pub fn main() {
|
||||||
//~| ERROR: cannot borrow as mutable inside an `&` pattern
|
//~| ERROR: cannot borrow as mutable inside an `&` pattern
|
||||||
let _: &mut bool = a;
|
let _: &mut bool = a;
|
||||||
let _: &mut bool = b;
|
let _: &mut bool = b;
|
||||||
|
|
||||||
|
let &mut [x] = &mut &mut [0];
|
||||||
|
//[classic]~^ ERROR: cannot borrow as mutable inside an `&` pattern
|
||||||
|
let _: &u32 = x;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,14 @@ LL | let &(ref mut a, ref mut b) = &mut (true, false);
|
||||||
| |
|
| |
|
||||||
| help: replace this `&` with `&mut`: `&mut`
|
| 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`.
|
For more information about this error, try `rustc --explain E0596`.
|
||||||
|
|
|
@ -30,4 +30,8 @@ pub fn main() {
|
||||||
//~| ERROR: cannot borrow as mutable inside an `&` pattern
|
//~| ERROR: cannot borrow as mutable inside an `&` pattern
|
||||||
let _: &mut bool = a;
|
let _: &mut bool = a;
|
||||||
let _: &mut bool = b;
|
let _: &mut bool = b;
|
||||||
|
|
||||||
|
let &[x] = &mut &mut [0];
|
||||||
|
//[classic]~^ ERROR: cannot borrow as mutable inside an `&` pattern
|
||||||
|
let _: &u32 = x;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,4 +30,8 @@ pub fn main() {
|
||||||
//~| ERROR: cannot borrow as mutable inside an `&` pattern
|
//~| ERROR: cannot borrow as mutable inside an `&` pattern
|
||||||
let _: &mut bool = a;
|
let _: &mut bool = a;
|
||||||
let _: &mut bool = b;
|
let _: &mut bool = b;
|
||||||
|
|
||||||
|
let &[x] = &mut &mut [0];
|
||||||
|
//[classic]~^ ERROR: cannot borrow as mutable inside an `&` pattern
|
||||||
|
let _: &u32 = x;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue