Match ergonomics 2024: `&` matches `&mut` on old editions

This commit is contained in:
Jules Bertholet 2024-07-05 11:16:48 -04:00
parent 5fd5b65093
commit 5a35fc446e
No known key found for this signature in database
GPG Key ID: 32034DAFC38C1BFC
2 changed files with 16 additions and 1 deletions

View File

@ -2217,7 +2217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("check_pat_ref: expected={:?}", expected);
match *expected.kind() {
ty::Ref(_, r_ty, r_mutbl)
if (new_match_ergonomics && r_mutbl >= pat_mutbl)
if (no_ref_mut_behind_and && r_mutbl >= pat_mutbl)
|| r_mutbl == pat_mutbl =>
{
if no_ref_mut_behind_and && r_mutbl == Mutability::Not {

View File

@ -0,0 +1,15 @@
//@ run-pass
//@ edition: 2021
//@ revisions: classic structural both
#![allow(incomplete_features)]
#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))]
#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))]
pub fn main() {
if let &Some(Some(x)) = &Some(&mut Some(0)) {
let _: &u32 = x;
}
if let Some(&x) = Some(&mut 0) {
let _: u32 = x;
}
}