diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index 19c22d7017dc00be18ecb36f99b7d51f3a74555a..e722e583ad2a648fea0592ec7443d76d23702087 100644 --- a/src/librustc_mir/transform/type_check.rs +++ b/src/librustc_mir/transform/type_check.rs @@ -59,7 +59,10 @@ pub fn type_check<'a, 'gcx, 'tcx>( } fn mirbug(tcx: TyCtxt, span: Span, msg: &str) { - tcx.sess.diagnostic().span_bug(span, msg); + // We sometimes see MIR failures (notably predicate failures) due to + // the fact that we check rvalue sized predicates here. So use `delay_span_bug` + // to avoid reporting bugs in those cases. + tcx.sess.diagnostic().delay_span_bug(span, msg); } macro_rules! span_mirbug { @@ -171,7 +174,44 @@ fn sanitize_constant(&mut self, constant: &Constant<'tcx>, location: Location) { ); let expected_ty = match constant.literal { - Literal::Value { value } => value.ty, + Literal::Value { value } => { + if let ConstVal::Function(def_id, ..) = value.val { + let tcx = self.tcx(); + let type_checker = &mut self.cx; + + // FIXME -- For now, use the substitutions from + // `value.ty` rather than `value.val`. The + // renumberer will rewrite them to independent + // sets of regions; in principle, we ought to + // derive the type of the `value.val` from "first + // principles" and equate with value.ty, but as we + // are transitioning to the miri-based system, we + // don't have a handy function for that, so for + // now we just ignore `value.val` regions. + let substs = match value.ty.sty { + ty::TyFnDef(ty_def_id, substs) => { + assert_eq!(def_id, ty_def_id); + substs + } + _ => { + span_bug!( + self.last_span, + "unexpected type for constant function: {:?}", + value.ty + ) + } + }; + + let instantiated_predicates = + tcx.predicates_of(def_id).instantiate(tcx, substs); + let predicates = + type_checker.normalize(&instantiated_predicates.predicates, location); + type_checker.prove_predicates(&predicates, location); + } + + value.ty + } + Literal::Promoted { .. } => { // FIXME -- promoted MIR return types reference // various "free regions" (e.g., scopes and things) diff --git a/src/test/compile-fail/nll/where_clauses_in_functions.rs b/src/test/compile-fail/nll/where_clauses_in_functions.rs new file mode 100644 index 0000000000000000000000000000000000000000..a13360aeca7f505a475028705477d1b5b5e34a14 --- /dev/null +++ b/src/test/compile-fail/nll/where_clauses_in_functions.rs @@ -0,0 +1,28 @@ +// 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. + +// compile-flags: -Z borrowck=mir -Z nll + +#![allow(dead_code)] + +fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) +where + 'a: 'b, +{ + (x, y) +} + +fn bar<'a, 'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) { + foo(x, y) + //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r` + //~| WARNING not reporting region error due to -Znll +} + +fn main() {}