Skip to content

Commit 4700e11

Browse files
committed
Auto merge of #52232 - arielb1:ill-adjusted-tuples, r=pnkfelix
use the adjusted type for cat_pattern in tuple patterns This looks like a typo introduced in #51686. Fixes #52213. r? @pnkfelix beta + stable nominating because regression + unsoundness.
2 parents b9f1a07 + 4c04453 commit 4700e11

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13471347
ref ty => span_bug!(pat.span, "tuple pattern unexpected type {:?}", ty),
13481348
};
13491349
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
1350-
let subpat_ty = self.pat_ty_unadjusted(&subpat)?; // see (*2)
1350+
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
13511351
let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string())));
13521352
let subcmt = Rc::new(self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
13531353
self.cat_pattern_(subcmt, &subpat, op)?;

src/librustc_typeck/check/regionck.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ use rustc::hir::{self, PatKind};
105105

106106
// a variation on try that just returns unit
107107
macro_rules! ignore_err {
108-
($e:expr) => (match $e { Ok(e) => e, Err(_) => return () })
108+
($e:expr) => (match $e { Ok(e) => e, Err(_) => {
109+
debug!("ignoring mem-categorization error!");
110+
return ()
111+
}})
109112
}
110113

111114
///////////////////////////////////////////////////////////////////////////
@@ -1034,7 +1037,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
10341037
debug!("link_pattern(discr_cmt={:?}, root_pat={:?})",
10351038
discr_cmt,
10361039
root_pat);
1037-
let _ = self.with_mc(|mc| {
1040+
ignore_err!(self.with_mc(|mc| {
10381041
mc.cat_pattern(discr_cmt, root_pat, |sub_cmt, sub_pat| {
10391042
match sub_pat.node {
10401043
// `ref x` pattern
@@ -1051,7 +1054,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
10511054
_ => {}
10521055
}
10531056
})
1054-
});
1057+
}));
10551058
}
10561059

10571060
/// Link lifetime of borrowed pointer resulting from autoref to lifetimes in the value being

src/test/compile-fail/issue-52213.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
12+
match (&t,) { //~ ERROR cannot infer an appropriate lifetime
13+
((u,),) => u,
14+
}
15+
}
16+
17+
fn main() {
18+
let x = {
19+
let y = Box::new((42,));
20+
transmute_lifetime(&y)
21+
};
22+
23+
println!("{}", x);
24+
}

0 commit comments

Comments
 (0)