From d65b56440de20c42ac2cc42cbffc2e28d7bb8a92 Mon Sep 17 00:00:00 2001 From: Shunpoco Date: Tue, 4 Feb 2025 23:20:57 +0000 Subject: [PATCH] Add comment for regression #136223 on borrowck-errors.rs Signed-off-by: Shunpoco --- compiler/rustc_hir_typeck/src/pat.rs | 2 +- ...mut-inside-ref-not-pattern-mutability-cap-violated.rs | 6 ------ ...inside-ref-not-pattern-mutability-cap-violated.stderr | 9 --------- .../experimental/borrowck-errors.classic2024.stderr | 6 +++--- .../experimental/borrowck-errors.rs | 2 ++ .../experimental/borrowck-errors.stable2021.stderr | 4 ++-- 6 files changed, 8 insertions(+), 21 deletions(-) delete mode 100644 tests/ui/match/ref-mut-inside-ref-not-pattern-mutability-cap-violated.rs delete mode 100644 tests/ui/match/ref-mut-inside-ref-not-pattern-mutability-cap-violated.stderr diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 8f6fe5529eb36..c947ecde65605 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -2400,7 +2400,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if (ref_pat_matches_mut_ref && r_mutbl >= pat_mutbl) || r_mutbl == pat_mutbl => { - if ref_pat_matches_mut_ref && r_mutbl == Mutability::Not { + if r_mutbl == Mutability::Not { pat_info.max_ref_mutbl = MutblCap::Not; } diff --git a/tests/ui/match/ref-mut-inside-ref-not-pattern-mutability-cap-violated.rs b/tests/ui/match/ref-mut-inside-ref-not-pattern-mutability-cap-violated.rs deleted file mode 100644 index 093d9bc943dec..0000000000000 --- a/tests/ui/match/ref-mut-inside-ref-not-pattern-mutability-cap-violated.rs +++ /dev/null @@ -1,6 +0,0 @@ -// This test is for https://github.com/rust-lang/rust/issues/136223. -// `&mut` inside `&` should not panic by `Pattern mutability cap violdated` debug assertion. -fn main() { - if let &Some(Some(x)) = &Some(&mut Some(0)) {} - //~^ ERROR: cannot borrow data in a `&` reference as mutable -} diff --git a/tests/ui/match/ref-mut-inside-ref-not-pattern-mutability-cap-violated.stderr b/tests/ui/match/ref-mut-inside-ref-not-pattern-mutability-cap-violated.stderr deleted file mode 100644 index 46b0ae33f50e9..0000000000000 --- a/tests/ui/match/ref-mut-inside-ref-not-pattern-mutability-cap-violated.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/ref-mut-inside-ref-not-pattern-mutability-cap-violated.rs:4:21 - | -LL | if let &Some(Some(x)) = &Some(&mut Some(0)) {} - | ^ cannot borrow as mutable - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0596`. diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr index 331b86736a0ba..1c44617830828 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr @@ -48,19 +48,19 @@ LL | let &ref mut x = &0; | ^^^^^^^^^ cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-errors.rs:35:23 + --> $DIR/borrowck-errors.rs:37:23 | LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { | ^ cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-errors.rs:40:11 + --> $DIR/borrowck-errors.rs:42:11 | LL | let &[x] = &&mut [0]; | ^ cannot borrow as mutable error[E0508]: cannot move out of type `[&mut i32; 1]`, a non-copy array - --> $DIR/borrowck-errors.rs:44:20 + --> $DIR/borrowck-errors.rs:46:20 | LL | let [&mut x] = &mut [&mut 0]; | - ^^^^^^^^^^^^^ cannot move out of here 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 3f5d9c8db5d87..59cafc50d8661 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 @@ -32,6 +32,8 @@ pub fn main() { let &ref mut x = &0; //~^ cannot borrow data in a `&` reference as mutable [E0596] + // For 2021 edition, this is also a regression test for #136223 + // since the maximum mutability is downgraded during the pattern check process. if let &Some(Some(x)) = &Some(&mut Some(0)) { //[stable2021,classic2024]~^ ERROR: cannot borrow data in a `&` reference as mutable let _: &u32 = x; diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr index 65c98e2da9c38..deefe21ca7d45 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr @@ -52,13 +52,13 @@ LL | let &ref mut x = &0; | ^^^^^^^^^ cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-errors.rs:35:23 + --> $DIR/borrowck-errors.rs:37:23 | LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { | ^ cannot borrow as mutable error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-errors.rs:40:11 + --> $DIR/borrowck-errors.rs:42:11 | LL | let &[x] = &&mut [0]; | ^ cannot borrow as mutable