mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
reset default binding mode when we pass through a &
pattern
Fixes #46688.
This commit is contained in:
parent
b1f8e6fb06
commit
31f66a060c
@ -151,6 +151,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
} else if let PatKind::Ref(..) = pat.node {
|
||||
// When you encounter a `&pat` pattern, reset to "by
|
||||
// value". This is so that `x` and `y` here are by value,
|
||||
// as they appear to be:
|
||||
//
|
||||
// ```
|
||||
// match &(&22, &44) {
|
||||
// (&x, &y) => ...
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// cc #46688
|
||||
def_bm = ty::BindByValue(hir::MutImmutable);
|
||||
}
|
||||
|
||||
// Lose mutability now that we know binding mode and discriminant type.
|
||||
|
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(match_default_bindings)]
|
||||
|
||||
// Test that we "reset" the mode as we pass through a `&` pattern.
|
||||
//
|
||||
// cc #46688
|
||||
|
||||
fn surprise(x: i32) {
|
||||
assert_eq!(x, 2);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = &(1, &2);
|
||||
let (_, &b) = x;
|
||||
surprise(b);
|
||||
}
|
Loading…
Reference in New Issue
Block a user