Auto merge of #30279 - Aatch:dst-ref-binding, r=pnkfelix
We shouldn't load DSTs when recursing into the sub-pattern of `& ref ident`. Fixes #30277
This commit is contained in:
commit
e583ab6281
@ -1944,8 +1944,16 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||||||
}
|
}
|
||||||
hir::PatBox(ref inner) => {
|
hir::PatBox(ref inner) => {
|
||||||
let pat_ty = node_id_type(bcx, inner.id);
|
let pat_ty = node_id_type(bcx, inner.id);
|
||||||
// Don't load DSTs, instead pass along a fat ptr
|
// Pass along DSTs as fat pointers.
|
||||||
let val = if type_is_sized(tcx, pat_ty) {
|
let val = if type_is_fat_ptr(tcx, pat_ty) {
|
||||||
|
// We need to check for this, as the pattern could be binding
|
||||||
|
// a fat pointer by-value.
|
||||||
|
if let hir::PatIdent(hir::BindByRef(_),_,_) = inner.node {
|
||||||
|
val.val
|
||||||
|
} else {
|
||||||
|
Load(bcx, val.val)
|
||||||
|
}
|
||||||
|
} else if type_is_sized(tcx, pat_ty) {
|
||||||
Load(bcx, val.val)
|
Load(bcx, val.val)
|
||||||
} else {
|
} else {
|
||||||
val.val
|
val.val
|
||||||
@ -1955,8 +1963,16 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||||||
}
|
}
|
||||||
hir::PatRegion(ref inner, _) => {
|
hir::PatRegion(ref inner, _) => {
|
||||||
let pat_ty = node_id_type(bcx, inner.id);
|
let pat_ty = node_id_type(bcx, inner.id);
|
||||||
// Don't load DSTs, instead pass along a fat ptr
|
// Pass along DSTs as fat pointers.
|
||||||
let val = if type_is_sized(tcx, pat_ty) {
|
let val = if type_is_fat_ptr(tcx, pat_ty) {
|
||||||
|
// We need to check for this, as the pattern could be binding
|
||||||
|
// a fat pointer by-value.
|
||||||
|
if let hir::PatIdent(hir::BindByRef(_),_,_) = inner.node {
|
||||||
|
val.val
|
||||||
|
} else {
|
||||||
|
Load(bcx, val.val)
|
||||||
|
}
|
||||||
|
} else if type_is_sized(tcx, pat_ty) {
|
||||||
Load(bcx, val.val)
|
Load(bcx, val.val)
|
||||||
} else {
|
} else {
|
||||||
val.val
|
val.val
|
||||||
|
24
src/test/run-pass/dst-irrefutable-bind.rs
Normal file
24
src/test/run-pass/dst-irrefutable-bind.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2015 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.
|
||||||
|
|
||||||
|
struct Test<T: ?Sized>(T);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = Test([1,2,3]);
|
||||||
|
let x : &Test<[i32]> = &x;
|
||||||
|
|
||||||
|
let & ref _y = x;
|
||||||
|
|
||||||
|
// Make sure binding to a fat pointer behind a reference
|
||||||
|
// still works
|
||||||
|
let slice = &[1,2,3];
|
||||||
|
let x = Test(&slice);
|
||||||
|
let Test(&_slice) = x;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user