Skip to content

Commit

Permalink
Auto merge of #52232 - arielb1:ill-adjusted-tuples, r=pnkfelix
Browse files Browse the repository at this point in the history
 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.
  • Loading branch information
bors committed Jul 11, 2018
2 parents b9f1a07 + 4c04453 commit 4700e11
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
ref ty => span_bug!(pat.span, "tuple pattern unexpected type {:?}", ty),
};
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {
let subpat_ty = self.pat_ty_unadjusted(&subpat)?; // see (*2)
let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2)
let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string())));
let subcmt = Rc::new(self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior));
self.cat_pattern_(subcmt, &subpat, op)?;
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ use rustc::hir::{self, PatKind};

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

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1034,7 +1037,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
debug!("link_pattern(discr_cmt={:?}, root_pat={:?})",
discr_cmt,
root_pat);
let _ = self.with_mc(|mc| {
ignore_err!(self.with_mc(|mc| {
mc.cat_pattern(discr_cmt, root_pat, |sub_cmt, sub_pat| {
match sub_pat.node {
// `ref x` pattern
Expand All @@ -1051,7 +1054,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
_ => {}
}
})
});
}));
}

/// Link lifetime of borrowed pointer resulting from autoref to lifetimes in the value being
Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/issue-52213.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.

fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) { //~ ERROR cannot infer an appropriate lifetime
((u,),) => u,
}
}

fn main() {
let x = {
let y = Box::new((42,));
transmute_lifetime(&y)
};

println!("{}", x);
}

0 comments on commit 4700e11

Please sign in to comment.