From 05d6e55fab21e76627b3e5e793c062ad4d2b485a Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 11 Jul 2018 01:08:15 +0300 Subject: [PATCH 1/3] use the adjusted type for cat_pattern in tuple patterns This looks like a typo introduced in #51686. Fixes #52213. --- src/librustc/middle/mem_categorization.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index c3a2d3ce0c27f..3b89a9d2de512 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -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)?; From df33cf4cb07fbab7fe1831635892da9b4405dd93 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 11 Jul 2018 01:09:48 +0300 Subject: [PATCH 2/3] add a debug log for more MC failures I don't see why MC should fail on well-formed code, so it might be a better idea to just add a `delay_span_bug` there (anyone remember the `cat_expr Errd` bug from the 1.0 days?). However, I don't think this is a good idea to backport a new delay_span_bug into stable and this code is going away soon-ish anyway. --- src/librustc_typeck/check/regionck.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 68fcde0b1657a..79ee322d1095a 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -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 () + }}) } /////////////////////////////////////////////////////////////////////////// @@ -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 @@ -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 From 4c044537ce11b5e291e341d90ee112a70b92b040 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 11 Jul 2018 01:11:59 +0300 Subject: [PATCH 3/3] add test for #52213 --- src/test/compile-fail/issue-52213.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/test/compile-fail/issue-52213.rs diff --git a/src/test/compile-fail/issue-52213.rs b/src/test/compile-fail/issue-52213.rs new file mode 100644 index 0000000000000..810379c63d3e1 --- /dev/null +++ b/src/test/compile-fail/issue-52213.rs @@ -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 or the MIT license +// , 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); +}