提交 1371cd27 编写于 作者: N Niko Matsakis

check the self type is well-formed

This fixes `issue-28848.rs` -- it also handles another case that the
AST region checker gets wrong (`wf-self-type.rs`).  I don't actually
think that this is the *right way* to be enforcing this constraint --
I think we should probably do it more generally, perhaps by editing
`predicates_of` for the impl itself. The chalk-style implied bounds
setup ought to fix this.
上级 64b55993
......@@ -1033,6 +1033,8 @@ fn relate_type_and_user_type(
assert!(!impl_self_ty.has_infer_types());
self.eq_types(self_ty, impl_self_ty, locations, category)?;
self.prove_predicate(ty::Predicate::WellFormed(impl_self_ty), locations, category);
}
// Prove the predicates coming along with `def_id`.
......
......@@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
struct Foo<'a, 'b: 'a>(&'a &'b ());
impl<'a, 'b> Foo<'a, 'b> {
......
error[E0478]: lifetime bound not satisfied
--> $DIR/issue-28848.rs:22:5
--> $DIR/issue-28848.rs:20:5
|
LL | Foo::<'a, 'b>::xmute(u) //~ ERROR lifetime bound not satisfied
| ^^^^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime 'b as defined on the function body at 21:16
--> $DIR/issue-28848.rs:21:16
note: lifetime parameter instantiated with the lifetime 'b as defined on the function body at 19:16
--> $DIR/issue-28848.rs:19:16
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| ^^
note: but lifetime parameter must outlive the lifetime 'a as defined on the function body at 21:12
--> $DIR/issue-28848.rs:21:12
note: but lifetime parameter must outlive the lifetime 'a as defined on the function body at 19:12
--> $DIR/issue-28848.rs:19:12
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| ^^
......
// 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.
#![feature(nll)]
struct Foo<'a, 'b: 'a>(&'a &'b ());
impl<'a, 'b> Foo<'a, 'b> {
fn xmute(a: &'b ()) -> &'a () {
unreachable!()
}
}
pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
Foo::xmute(u) //~ ERROR unsatisfied lifetime constraints
}
fn main() {}
error: unsatisfied lifetime constraints
--> $DIR/wf-self-type.rs:22:5
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | Foo::xmute(u) //~ ERROR unsatisfied lifetime constraints
| ^^^^^^^^^^^^^ returning this value requires that `'b` must outlive `'a`
error: aborting due to previous error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册