Skip to content

Commit 7bc3f55

Browse files
committed
apply the same logic to ConcreteFailure errors
1 parent 77924de commit 7bc3f55

File tree

6 files changed

+69
-38
lines changed

6 files changed

+69
-38
lines changed

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,56 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
8989
// I actually can't see why this would be the case ever.
9090
},
9191

92+
Some(RegionResolutionError::ConcreteFailure(
93+
SubregionOrigin::Subtype(TypeTrace { .. }),
94+
ty::RePlaceholder(_),
95+
ty::RePlaceholder(_),
96+
)) => {
97+
// I actually can't see why this would be the case ever.
98+
},
99+
100+
Some(RegionResolutionError::ConcreteFailure(
101+
SubregionOrigin::Subtype(TypeTrace {
102+
cause,
103+
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
104+
}),
105+
sub_region,
106+
sup_region @ ty::RePlaceholder(_),
107+
)) => if expected.def_id == found.def_id {
108+
return Some(self.try_report_placeholders_trait(
109+
Some(sub_region),
110+
cause,
111+
None,
112+
Some(*sup_region),
113+
expected.def_id,
114+
expected.substs,
115+
found.substs,
116+
));
117+
} else {
118+
// I actually can't see why this would be the case ever.
119+
},
120+
121+
Some(RegionResolutionError::ConcreteFailure(
122+
SubregionOrigin::Subtype(TypeTrace {
123+
cause,
124+
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
125+
}),
126+
sub_region @ ty::RePlaceholder(_),
127+
sup_region,
128+
)) => if expected.def_id == found.def_id {
129+
return Some(self.try_report_placeholders_trait(
130+
Some(sup_region),
131+
cause,
132+
None,
133+
Some(*sub_region),
134+
expected.def_id,
135+
expected.substs,
136+
found.substs,
137+
));
138+
} else {
139+
// I actually can't see why this would be the case ever.
140+
},
141+
92142
_ => {}
93143
}
94144

src/test/ui/generator/auto-trait-regions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ fn main() {
2828
assert_foo(x);
2929
};
3030
assert_foo(gen);
31-
//~^ ERROR mismatched types
32-
//~| ERROR mismatched types
31+
//~^ ERROR implementation of `Foo` is not general enough
3332

3433
// Allow impls which matches any lifetime
3534
let x = &OnlyFooIfRef(No);
Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/auto-trait-regions.rs:30:5
3-
|
4-
LL | assert_foo(gen);
5-
| ^^^^^^^^^^ lifetime mismatch
6-
|
7-
= note: expected type `Foo`
8-
found type `Foo`
9-
= note: lifetime RePlaceholder(Placeholder { universe: U31, name: BrAnon(1) })...
10-
= note: ...does not necessarily outlive the static lifetime
11-
12-
error[E0308]: mismatched types
1+
error: implementation of `Foo` is not general enough
132
--> $DIR/auto-trait-regions.rs:30:5
143
|
154
LL | assert_foo(gen);
16-
| ^^^^^^^^^^ lifetime mismatch
5+
| ^^^^^^^^^^
176
|
18-
= note: expected type `Foo`
19-
found type `Foo`
20-
= note: lifetime RePlaceholder(Placeholder { universe: U35, name: BrAnon(1) })...
21-
= note: ...does not necessarily outlive the static lifetime
7+
= note: `&'0 OnlyFooIfStaticRef` must implement `Foo` for any lifetime `'0`
8+
= note: but `&'1 OnlyFooIfStaticRef` only implements `Foo` for some lifetime `'1`
229

2310
error: implementation of `Foo` is not general enough
24-
--> $DIR/auto-trait-regions.rs:49:5
11+
--> $DIR/auto-trait-regions.rs:48:5
2512
|
2613
LL | assert_foo(gen);
2714
| ^^^^^^^^^^
2815
|
2916
= note: `A<'0, '1>` must implement `Foo` for any two lifetimes `'0` and `'1`
3017
= note: but `A<'_, '2>` only implements `Foo` for some lifetime `'2`
3118

32-
error: aborting due to 3 previous errors
19+
error: aborting due to 2 previous errors
3320

34-
For more information about this error, try `rustc --explain E0308`.
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
error[E0308]: mismatched types
1+
error: implementation of `Foo` is not general enough
22
--> $DIR/hrtb-just-for-static.rs:24:5
33
|
44
LL | want_hrtb::<StaticInt>() //~ ERROR
5-
| ^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
5+
| ^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: expected type `Foo<&'a isize>`
8-
found type `Foo<&'static isize>`
9-
= note: lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:11), 'a) })...
10-
= note: ...does not necessarily outlive the static lifetime
7+
= note: Due to a where-clause on `want_hrtb`,
8+
= note: `StaticInt` must implement `Foo<&'0 isize>` for any lifetime `'0`
9+
= note: but `StaticInt` only implements `Foo<&'1 isize>` for some lifetime `'1`
1110

1211
error: implementation of `Foo` is not general enough
1312
--> $DIR/hrtb-just-for-static.rs:30:5
@@ -21,4 +20,3 @@ LL | want_hrtb::<&'a u32>() //~ ERROR
2120

2221
error: aborting due to 2 previous errors
2322

24-
For more information about this error, try `rustc --explain E0308`.

src/test/ui/where-clauses/where-for-self-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ fn foo<T>(x: &T)
1818
{}
1919

2020
fn main() {
21-
foo(&X); //~ ERROR E0308
21+
foo(&X); //~ ERROR implementation of `Bar` is not general enough
2222
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
error[E0308]: mismatched types
1+
error: implementation of `Bar` is not general enough
22
--> $DIR/where-for-self-2.rs:21:5
33
|
4-
LL | foo(&X); //~ ERROR E0308
5-
| ^^^ lifetime mismatch
4+
LL | foo(&X); //~ ERROR implementation of `Bar` is not general enough
5+
| ^^^
66
|
7-
= note: expected type `Bar`
8-
found type `Bar`
9-
= note: lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:10), 'a) })...
10-
= note: ...does not necessarily outlive the static lifetime
7+
= note: Due to a where-clause on `foo`,
8+
= note: `&'0 _` must implement `Bar` for any lifetime `'0`
9+
= note: but `&'1 u32` only implements `Bar` for some lifetime `'1`
1110

1211
error: aborting due to previous error
1312

14-
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)