Skip to content

Commit da52563

Browse files
committed
Improve SubSupConflict case with one named, one anonymous lifetime parameter #42701
1 parent 4b6f725 commit da52563

23 files changed

+76
-115
lines changed

src/librustc/infer/error_reporting/different_lifetimes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6060
pub fn try_report_anon_anon_conflict(&self, error: &RegionResolutionError<'tcx>) -> bool {
6161
let (span, sub, sup) = match *error {
6262
ConcreteFailure(ref origin, sub, sup) => (origin.span(), sub, sup),
63+
SubSupConflict(_, ref origin, sub, _, sup) => (origin.span(), sub, sup),
6364
_ => return false, // inapplicable
6465
};
6566

src/librustc/infer/error_reporting/named_anon_conflict.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
2121
pub fn try_report_named_anon_conflict(&self, error: &RegionResolutionError<'tcx>) -> bool {
2222
let (span, sub, sup) = match *error {
2323
ConcreteFailure(ref origin, sub, sup) => (origin.span(), sub, sup),
24+
SubSupConflict(_, ref origin, sub, _, sup) => (origin.span(), sub, sup),
2425
_ => return false, // inapplicable
2526
};
2627

src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
3030
{
3131
// x and y here have two distinct lifetimes:
3232
let z: I::A = if cond { x } else { y };
33-
//~^ ERROR cannot infer
33+
//~^ ERROR lifetime mismatch
3434
}
3535

3636
pub fn main() {}

src/test/compile-fail/associated-types/cache/project-fn-ret-contravariant.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
5050

5151
#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
5252
fn transmute<'a,'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
53-
let a = bar(foo, y); //[krisskross]~ ERROR E0495
54-
let b = bar(foo, x); //[krisskross]~ ERROR E0495
55-
(a, b)
53+
let a = bar(foo, y);
54+
let b = bar(foo, x);
55+
(a, b) //[krisskross]~ ERROR 55:5: 55:6: lifetime mismatch [E0623]
56+
//[krisskross]~^ ERROR 55:8: 55:9: lifetime mismatch [E0623]
5657
}
5758

5859
#[rustc_error]

src/test/compile-fail/associated-types/cache/project-fn-ret-invariant.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ fn baz<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
4545
#[cfg(oneuse)] // one instantiation: BAD
4646
fn baz<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
4747
let f = foo; // <-- No consistent type can be inferred for `f` here.
48-
let a = bar(f, x); //[oneuse]~^ ERROR E0495
48+
let a = bar(f, x);
4949
let b = bar(f, y);
50-
(a, b)
50+
(a, b) //[oneuse]~ ERROR E0623
5151
}
5252

5353
#[cfg(transmute)] // one instantiations: BAD
@@ -60,9 +60,10 @@ fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {
6060

6161
#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
6262
fn transmute<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
63-
let a = bar(foo, y); //[krisskross]~ ERROR E0495
64-
let b = bar(foo, x); //[krisskross]~ ERROR E0495
65-
(a, b)
63+
let a = bar(foo, y);
64+
let b = bar(foo, x);
65+
(a, b) //[krisskross]~ ERROR E0623
66+
//[krisskross]~^ ERROR E0623
6667
}
6768

6869
#[rustc_error]

src/test/compile-fail/borrowck/borrowck-reborrow-from-shorter-lived-andmut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct S<'a> {
1717

1818
fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
1919
S { pointer: &mut *p.pointer }
20-
//~^ ERROR cannot infer
20+
//~^ ERROR lifetime mismatch
2121
}
2222

2323
fn main() {

src/test/compile-fail/issue-17728.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ trait TraversesWorld {
2121
fn attemptTraverse(&self, room: &Room, directionStr: &str) -> Result<&Room, &str> {
2222
let direction = str_to_direction(directionStr);
2323
let maybe_room = room.direction_to_room.get(&direction);
24-
//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
2524
match maybe_room {
2625
Some(entry) => Ok(entry),
26+
//~^ ERROR 25:28: 25:37: lifetime mismatch [E0623]
2727
_ => Err("Direction does not exist in room.")
2828
}
2929
}

src/test/compile-fail/issue-40288-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ fn prove_static<T: 'static + ?Sized>(_: &'static T) {}
1212

1313
fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
1414
let mut out = [x];
15-
//~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
1615
{
1716
let slice: &mut [_] = &mut out;
1817
slice[0] = y;
1918
}
2019
out[0]
20+
//~^ ERROR 19:5: 19:11: explicit lifetime required in the type of `y` [E0621]
2121
}
2222

2323
struct Struct<T, U: ?Sized> {
@@ -27,12 +27,12 @@ struct Struct<T, U: ?Sized> {
2727

2828
fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
2929
let mut out = Struct { head: x, _tail: [()] };
30-
//~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
3130
{
3231
let dst: &mut Struct<_, [()]> = &mut out;
3332
dst.head = y;
3433
}
3534
out.head
35+
//~^ ERROR 34:5: 34:13: explicit lifetime required in the type of `y` [E0621]
3636
}
3737

3838
fn main() {

src/test/compile-fail/object-lifetime-default-from-box-error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn store(ss: &mut SomeStruct, b: Box<SomeTrait>) {
3838
fn store1<'b>(ss: &mut SomeStruct, b: Box<SomeTrait+'b>) {
3939
// Here we override the lifetimes explicitly, and so naturally we get an error.
4040

41-
ss.r = b; //~ ERROR cannot infer an appropriate lifetime
41+
ss.r = b; //~ ERROR 41:12: 41:13: explicit lifetime required in the type of `ss` [E0621]
4242
}
4343

4444
fn main() {

src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) {
2121
fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) {
2222
// Here we try to call `foo` but do not know that `'a` and `'b` are
2323
// related as required.
24-
a(x, y); //~ ERROR cannot infer
24+
a(x, y); //~ ERROR 24:7: 24:8: lifetime mismatch [E0623]
2525
}
2626

2727
fn d() {

0 commit comments

Comments
 (0)