提交 688ab5af 编写于 作者: S Santiago Pastorino 提交者: Niko Matsakis

Check functions predicates

上级 50104966
......@@ -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)
......
// 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.
// 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() {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册