Skip to content

Commit 1371cd2

Browse files
committed
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.
1 parent 64b5599 commit 1371cd2

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10331033
assert!(!impl_self_ty.has_infer_types());
10341034

10351035
self.eq_types(self_ty, impl_self_ty, locations, category)?;
1036+
1037+
self.prove_predicate(ty::Predicate::WellFormed(impl_self_ty), locations, category);
10361038
}
10371039

10381040
// Prove the predicates coming along with `def_id`.

src/test/ui/issues/issue-28848.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-compare-mode-nll
12-
1311
struct Foo<'a, 'b: 'a>(&'a &'b ());
1412

1513
impl<'a, 'b> Foo<'a, 'b> {

src/test/ui/issues/issue-28848.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error[E0478]: lifetime bound not satisfied
2-
--> $DIR/issue-28848.rs:22:5
2+
--> $DIR/issue-28848.rs:20:5
33
|
44
LL | Foo::<'a, 'b>::xmute(u) //~ ERROR lifetime bound not satisfied
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: lifetime parameter instantiated with the lifetime 'b as defined on the function body at 21:16
8-
--> $DIR/issue-28848.rs:21:16
7+
note: lifetime parameter instantiated with the lifetime 'b as defined on the function body at 19:16
8+
--> $DIR/issue-28848.rs:19:16
99
|
1010
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
1111
| ^^
12-
note: but lifetime parameter must outlive the lifetime 'a as defined on the function body at 21:12
13-
--> $DIR/issue-28848.rs:21:12
12+
note: but lifetime parameter must outlive the lifetime 'a as defined on the function body at 19:12
13+
--> $DIR/issue-28848.rs:19:12
1414
|
1515
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
1616
| ^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(nll)]
12+
13+
struct Foo<'a, 'b: 'a>(&'a &'b ());
14+
15+
impl<'a, 'b> Foo<'a, 'b> {
16+
fn xmute(a: &'b ()) -> &'a () {
17+
unreachable!()
18+
}
19+
}
20+
21+
pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
22+
Foo::xmute(u) //~ ERROR unsatisfied lifetime constraints
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: unsatisfied lifetime constraints
2+
--> $DIR/wf-self-type.rs:22:5
3+
|
4+
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
5+
| -- -- lifetime `'b` defined here
6+
| |
7+
| lifetime `'a` defined here
8+
LL | Foo::xmute(u) //~ ERROR unsatisfied lifetime constraints
9+
| ^^^^^^^^^^^^^ returning this value requires that `'b` must outlive `'a`
10+
11+
error: aborting due to previous error
12+

0 commit comments

Comments
 (0)