rename and comment the test for "Rule 5"-related mutability errors
This also makes it test the "structural" ruleset, in preparation for additional tests where the rulesets disagree.
This commit is contained in:
parent
b350d94877
commit
d8f975cc23
5 changed files with 91 additions and 7 deletions
|
@ -1,7 +1,11 @@
|
|||
//@ edition: 2024
|
||||
//@ run-rustfix
|
||||
//@ revisions: classic structural
|
||||
//! Tests for `&` patterns matched against `&mut` reference types where the inner pattern attempts
|
||||
//! to bind by mutable reference.
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(ref_pat_eat_one_layer_2024)]
|
||||
#![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))]
|
||||
#![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
|
||||
|
||||
pub fn main() {
|
||||
if let Some(&mut Some(ref mut x)) = &mut Some(Some(0)) {
|
|
@ -1,5 +1,5 @@
|
|||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:7:31
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:11:31
|
||||
|
|
||||
LL | if let Some(&Some(ref mut x)) = &mut Some(Some(0)) {
|
||||
| - ^
|
||||
|
@ -7,7 +7,7 @@ LL | if let Some(&Some(ref mut x)) = &mut Some(Some(0)) {
|
|||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:12:31
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:16:31
|
||||
|
|
||||
LL | if let &Some(Some(ref mut x)) = &mut Some(Some(0)) {
|
||||
| - ^
|
||||
|
@ -15,7 +15,7 @@ LL | if let &Some(Some(ref mut x)) = &mut Some(Some(0)) {
|
|||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:20:15
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:24:15
|
||||
|
|
||||
LL | let &pat!(x) = &mut 0;
|
||||
| - ^
|
||||
|
@ -23,7 +23,7 @@ LL | let &pat!(x) = &mut 0;
|
|||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:24:19
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:28:19
|
||||
|
|
||||
LL | let &(ref mut a, ref mut b) = &mut (true, false);
|
||||
| - ^
|
||||
|
@ -31,7 +31,7 @@ LL | let &(ref mut a, ref mut b) = &mut (true, false);
|
|||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref_pat_eat_one_layer_2024_ref_mut_inside_and.rs:24:30
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:28:30
|
||||
|
|
||||
LL | let &(ref mut a, ref mut b) = &mut (true, false);
|
||||
| - ^
|
|
@ -1,7 +1,11 @@
|
|||
//@ edition: 2024
|
||||
//@ run-rustfix
|
||||
//@ revisions: classic structural
|
||||
//! Tests for `&` patterns matched against `&mut` reference types where the inner pattern attempts
|
||||
//! to bind by mutable reference.
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(ref_pat_eat_one_layer_2024)]
|
||||
#![cfg_attr(classic, feature(ref_pat_eat_one_layer_2024))]
|
||||
#![cfg_attr(structural, feature(ref_pat_eat_one_layer_2024_structural))]
|
||||
|
||||
pub fn main() {
|
||||
if let Some(&Some(ref mut x)) = &mut Some(Some(0)) {
|
|
@ -0,0 +1,33 @@
|
|||
//@ edition: 2024
|
||||
//@ run-rustfix
|
||||
//@ revisions: classic structural
|
||||
//! Tests for `&` patterns matched against `&mut` reference types where the inner pattern attempts
|
||||
//! to bind by mutable reference.
|
||||
#![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() {
|
||||
if let Some(&mut Some(ref mut x)) = &mut Some(Some(0)) {
|
||||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern
|
||||
let _: &mut u8 = x;
|
||||
}
|
||||
|
||||
if let &mut Some(Some(ref mut x)) = &mut Some(Some(0)) {
|
||||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern
|
||||
let _: &mut u8 = x;
|
||||
}
|
||||
|
||||
macro_rules! pat {
|
||||
($var:ident) => { ref mut $var };
|
||||
}
|
||||
let &mut pat!(x) = &mut 0;
|
||||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern
|
||||
let _: &mut u8 = x;
|
||||
|
||||
let &mut (ref mut a, ref mut b) = &mut (true, false);
|
||||
//~^ ERROR: cannot borrow as mutable inside an `&` pattern
|
||||
//~| ERROR: cannot borrow as mutable inside an `&` pattern
|
||||
let _: &mut bool = a;
|
||||
let _: &mut bool = b;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:11:31
|
||||
|
|
||||
LL | if let Some(&Some(ref mut x)) = &mut Some(Some(0)) {
|
||||
| - ^
|
||||
| |
|
||||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:16:31
|
||||
|
|
||||
LL | if let &Some(Some(ref mut x)) = &mut Some(Some(0)) {
|
||||
| - ^
|
||||
| |
|
||||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:24:15
|
||||
|
|
||||
LL | let &pat!(x) = &mut 0;
|
||||
| - ^
|
||||
| |
|
||||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:28:19
|
||||
|
|
||||
LL | let &(ref mut a, ref mut b) = &mut (true, false);
|
||||
| - ^
|
||||
| |
|
||||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error[E0596]: cannot borrow as mutable inside an `&` pattern
|
||||
--> $DIR/ref-mut-inside-shared-ref-pat.rs:28:30
|
||||
|
|
||||
LL | let &(ref mut a, ref mut b) = &mut (true, false);
|
||||
| - ^
|
||||
| |
|
||||
| help: replace this `&` with `&mut`: `&mut`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0596`.
|
Loading…
Add table
Add a link
Reference in a new issue