Skip to content

Commit 6cbbee1

Browse files
committed
apply the new placeholder errors even with just one placeholder
1 parent 0a61d68 commit 6cbbee1

File tree

8 files changed

+90
-47
lines changed

8 files changed

+90
-47
lines changed

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
2828
_,
2929
ty::RePlaceholder(sup_placeholder),
3030
)) => if expected.def_id == found.def_id {
31-
return Some(self.try_report_two_placeholders_trait(
31+
return Some(self.try_report_placeholders_trait(
3232
Some(*vid),
3333
cause,
3434
Some(*sub_placeholder),
@@ -41,6 +41,54 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
4141
// I actually can't see why this would be the case ever.
4242
},
4343

44+
Some(RegionResolutionError::SubSupConflict(
45+
vid,
46+
_,
47+
SubregionOrigin::Subtype(TypeTrace {
48+
cause,
49+
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
50+
}),
51+
ty::RePlaceholder(sub_placeholder),
52+
_,
53+
_,
54+
)) => if expected.def_id == found.def_id {
55+
return Some(self.try_report_placeholders_trait(
56+
Some(*vid),
57+
cause,
58+
Some(*sub_placeholder),
59+
None,
60+
expected.def_id,
61+
expected.substs,
62+
found.substs,
63+
));
64+
} else {
65+
// I actually can't see why this would be the case ever.
66+
},
67+
68+
Some(RegionResolutionError::SubSupConflict(
69+
vid,
70+
_,
71+
SubregionOrigin::Subtype(TypeTrace {
72+
cause,
73+
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
74+
}),
75+
_,
76+
_,
77+
ty::RePlaceholder(sup_placeholder),
78+
)) => if expected.def_id == found.def_id {
79+
return Some(self.try_report_placeholders_trait(
80+
Some(*vid),
81+
cause,
82+
None,
83+
Some(*sup_placeholder),
84+
expected.def_id,
85+
expected.substs,
86+
found.substs,
87+
));
88+
} else {
89+
// I actually can't see why this would be the case ever.
90+
},
91+
4492
_ => {}
4593
}
4694

@@ -56,7 +104,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
56104
// = note: Due to a where-clause on the function `all`,
57105
// = note: `T` must implement `...` for any two lifetimes `'1` and `'2`.
58106
// = note: However, the type `T` only implements `...` for some specific lifetime `'2`.
59-
fn try_report_two_placeholders_trait(
107+
fn try_report_placeholders_trait(
60108
&self,
61109
vid: Option<ty::RegionVid>,
62110
cause: &ObligationCause<'tcx>,
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements
1+
error: implementation of `Deserialize` is not general enough
22
--> $DIR/hrtb-cache-issue-54302.rs:19:5
33
|
44
LL | assert_deserialize_owned::<&'static str>(); //~ ERROR
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:12), 'de) })...
8-
= note: ...but the lifetime must also be valid for the static lifetime...
9-
= note: ...so that the types are compatible:
10-
expected Deserialize<'de>
11-
found Deserialize<'_>
7+
= note: `&'static str` must implement `Deserialize<'0>` for any lifetime `'0`
8+
= note: but `&str` only implements `Deserialize<'1>` for some lifetime `'1`
129

1310
error: aborting due to previous error
1411

15-
For more information about this error, try `rustc --explain E0495`.

src/test/ui/hrtb/hrtb-just-for-static.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ fn give_static() {
2424
want_hrtb::<StaticInt>() //~ ERROR
2525
}
2626

27+
// AnyInt implements Foo<&'a isize> for any 'a, so it is a match.
28+
impl<'a> Foo<&'a isize> for &'a u32 { }
29+
fn give_some<'a>() {
30+
want_hrtb::<&'a u32>() //~ ERROR
31+
}
32+
2733
fn main() { }

src/test/ui/hrtb/hrtb-just-for-static.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ LL | want_hrtb::<StaticInt>() //~ ERROR
99
= note: lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:11), 'a) })...
1010
= note: ...does not necessarily outlive the static lifetime
1111

12-
error: aborting due to previous error
12+
error: implementation of `Foo` is not general enough
13+
--> $DIR/hrtb-just-for-static.rs:30:5
14+
|
15+
LL | want_hrtb::<&'a u32>() //~ ERROR
16+
| ^^^^^^^^^^^^^^^^^^^^
17+
|
18+
= note: Due to a where-clause on `want_hrtb`,
19+
= note: `&'a u32` must implement `Foo<&'0 isize>` for any lifetime `'0`
20+
= note: but `&'1 u32` only implements `Foo<&'1 isize>` for some lifetime `'1`
21+
22+
error: aborting due to 2 previous errors
1323

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

src/test/ui/issues/issue-54302-cases.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@ impl<T> RefFoo<T> for T where for<'a> &'a T: Foo<'static, T> {
6161
fn coerce_lifetime1(a: &u32) -> &'static u32
6262
{
6363
<u32 as RefFoo<u32>>::ref_foo(a)
64-
//~^ ERROR cannot infer
64+
//~^ ERROR not general enough
6565
}
6666

6767
fn coerce_lifetime2(a: &i32) -> &'static i32
6868
{
6969
<i32 as RefFoo<i32>>::ref_foo(a)
70-
//~^ ERROR cannot infer
70+
//~^ ERROR not general enough
7171
}
7272

7373
fn coerce_lifetime3(a: &u64) -> &'static u64
7474
{
7575
<u64 as RefFoo<u64>>::ref_foo(a)
76-
//~^ ERROR cannot infer
76+
//~^ ERROR not general enough
7777
}
7878

7979
fn coerce_lifetime4(a: &i64) -> &'static i64
8080
{
8181
<i64 as RefFoo<i64>>::ref_foo(a)
82-
//~^ ERROR cannot infer
82+
//~^ ERROR not general enough
8383
}
8484

8585
fn main() {}
Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,38 @@
1-
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements
1+
error: implementation of `Foo` is not general enough
22
--> $DIR/issue-54302-cases.rs:63:5
33
|
44
LL | <u32 as RefFoo<u32>>::ref_foo(a)
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:27), 'a) })...
8-
= note: ...but the lifetime must also be valid for the static lifetime...
9-
= note: ...so that the types are compatible:
10-
expected Foo<'static, u32>
11-
found Foo<'_, u32>
7+
= note: `&'0 u32` must implement `Foo<'static, u32>` for any lifetime `'0`
8+
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
129

13-
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements
10+
error: implementation of `Foo` is not general enough
1411
--> $DIR/issue-54302-cases.rs:69:5
1512
|
1613
LL | <i32 as RefFoo<i32>>::ref_foo(a)
1714
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1815
|
19-
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:27), 'a) })...
20-
= note: ...but the lifetime must also be valid for the static lifetime...
21-
= note: ...so that the types are compatible:
22-
expected Foo<'static, i32>
23-
found Foo<'_, i32>
16+
= note: `&'0 i32` must implement `Foo<'static, i32>` for any lifetime `'0`
17+
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
2418

25-
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements
19+
error: implementation of `Foo` is not general enough
2620
--> $DIR/issue-54302-cases.rs:75:5
2721
|
2822
LL | <u64 as RefFoo<u64>>::ref_foo(a)
2923
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3024
|
31-
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:27), 'a) })...
32-
= note: ...but the lifetime must also be valid for the static lifetime...
33-
= note: ...so that the types are compatible:
34-
expected Foo<'static, u64>
35-
found Foo<'_, u64>
25+
= note: `&'0 u64` must implement `Foo<'static, u64>` for any lifetime `'0`
26+
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
3627

37-
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements
28+
error: implementation of `Foo` is not general enough
3829
--> $DIR/issue-54302-cases.rs:81:5
3930
|
4031
LL | <i64 as RefFoo<i64>>::ref_foo(a)
4132
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4233
|
43-
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:27), 'a) })...
44-
= note: ...but the lifetime must also be valid for the static lifetime...
45-
= note: ...so that the types are compatible:
46-
expected Foo<'static, i64>
47-
found Foo<'_, i64>
34+
= note: `&'0 i64` must implement `Foo<'static, i64>` for any lifetime `'0`
35+
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
4836

4937
error: aborting due to 4 previous errors
5038

51-
For more information about this error, try `rustc --explain E0495`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
// Then why does it implement DeserializeOwned? This compiles.
1212
fn assert_deserialize_owned<T: DeserializeOwned>() {}
1313
assert_deserialize_owned::<&'static str>();
14-
//~^ ERROR E0495
14+
//~^ ERROR not general enough
1515

1616
// It correctly does not implement for<'de> Deserialize<'de>.
1717
//fn assert_hrtb<T: for<'de> Deserialize<'de>>() {}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements
1+
error: implementation of `Deserialize` is not general enough
22
--> $DIR/issue-54302.rs:13:5
33
|
44
LL | assert_deserialize_owned::<&'static str>();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:12), 'de) })...
8-
= note: ...but the lifetime must also be valid for the static lifetime...
9-
= note: ...so that the types are compatible:
10-
expected Deserialize<'de>
11-
found Deserialize<'_>
7+
= note: `&'static str` must implement `Deserialize<'0>` for any lifetime `'0`
8+
= note: but `&str` only implements `Deserialize<'1>` for some lifetime `'1`
129

1310
error: aborting due to previous error
1411

15-
For more information about this error, try `rustc --explain E0495`.

0 commit comments

Comments
 (0)