apply the new placeholder errors even with just one placeholder

This commit is contained in:
Niko Matsakis 2018-11-18 13:25:53 -05:00
parent 0a61d682a1
commit 6cbbee1dc7
8 changed files with 90 additions and 47 deletions

View File

@ -28,7 +28,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
_,
ty::RePlaceholder(sup_placeholder),
)) => if expected.def_id == found.def_id {
return Some(self.try_report_two_placeholders_trait(
return Some(self.try_report_placeholders_trait(
Some(*vid),
cause,
Some(*sub_placeholder),
@ -41,6 +41,54 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
// I actually can't see why this would be the case ever.
},
Some(RegionResolutionError::SubSupConflict(
vid,
_,
SubregionOrigin::Subtype(TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
ty::RePlaceholder(sub_placeholder),
_,
_,
)) => if expected.def_id == found.def_id {
return Some(self.try_report_placeholders_trait(
Some(*vid),
cause,
Some(*sub_placeholder),
None,
expected.def_id,
expected.substs,
found.substs,
));
} else {
// I actually can't see why this would be the case ever.
},
Some(RegionResolutionError::SubSupConflict(
vid,
_,
SubregionOrigin::Subtype(TypeTrace {
cause,
values: ValuePairs::TraitRefs(ExpectedFound { expected, found }),
}),
_,
_,
ty::RePlaceholder(sup_placeholder),
)) => if expected.def_id == found.def_id {
return Some(self.try_report_placeholders_trait(
Some(*vid),
cause,
None,
Some(*sup_placeholder),
expected.def_id,
expected.substs,
found.substs,
));
} else {
// I actually can't see why this would be the case ever.
},
_ => {}
}
@ -56,7 +104,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
// = note: Due to a where-clause on the function `all`,
// = note: `T` must implement `...` for any two lifetimes `'1` and `'2`.
// = note: However, the type `T` only implements `...` for some specific lifetime `'2`.
fn try_report_two_placeholders_trait(
fn try_report_placeholders_trait(
&self,
vid: Option<ty::RegionVid>,
cause: &ObligationCause<'tcx>,

View File

@ -1,15 +1,11 @@
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements
error: implementation of `Deserialize` is not general enough
--> $DIR/hrtb-cache-issue-54302.rs:19:5
|
LL | assert_deserialize_owned::<&'static str>(); //~ ERROR
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:12), 'de) })...
= note: ...but the lifetime must also be valid for the static lifetime...
= note: ...so that the types are compatible:
expected Deserialize<'de>
found Deserialize<'_>
= note: `&'static str` must implement `Deserialize<'0>` for any lifetime `'0`
= note: but `&str` only implements `Deserialize<'1>` for some lifetime `'1`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.

View File

@ -24,4 +24,10 @@ fn give_static() {
want_hrtb::<StaticInt>() //~ ERROR
}
// AnyInt implements Foo<&'a isize> for any 'a, so it is a match.
impl<'a> Foo<&'a isize> for &'a u32 { }
fn give_some<'a>() {
want_hrtb::<&'a u32>() //~ ERROR
}
fn main() { }

View File

@ -9,6 +9,16 @@ LL | want_hrtb::<StaticInt>() //~ ERROR
= note: lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:11), 'a) })...
= note: ...does not necessarily outlive the static lifetime
error: aborting due to previous error
error: implementation of `Foo` is not general enough
--> $DIR/hrtb-just-for-static.rs:30:5
|
LL | want_hrtb::<&'a u32>() //~ ERROR
| ^^^^^^^^^^^^^^^^^^^^
|
= note: Due to a where-clause on `want_hrtb`,
= note: `&'a u32` must implement `Foo<&'0 isize>` for any lifetime `'0`
= note: but `&'1 u32` only implements `Foo<&'1 isize>` for some lifetime `'1`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -61,25 +61,25 @@ impl<T> RefFoo<T> for T where for<'a> &'a T: Foo<'static, T> {
fn coerce_lifetime1(a: &u32) -> &'static u32
{
<u32 as RefFoo<u32>>::ref_foo(a)
//~^ ERROR cannot infer
//~^ ERROR not general enough
}
fn coerce_lifetime2(a: &i32) -> &'static i32
{
<i32 as RefFoo<i32>>::ref_foo(a)
//~^ ERROR cannot infer
//~^ ERROR not general enough
}
fn coerce_lifetime3(a: &u64) -> &'static u64
{
<u64 as RefFoo<u64>>::ref_foo(a)
//~^ ERROR cannot infer
//~^ ERROR not general enough
}
fn coerce_lifetime4(a: &i64) -> &'static i64
{
<i64 as RefFoo<i64>>::ref_foo(a)
//~^ ERROR cannot infer
//~^ ERROR not general enough
}
fn main() {}

View File

@ -1,51 +1,38 @@
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements
error: implementation of `Foo` is not general enough
--> $DIR/issue-54302-cases.rs:63:5
|
LL | <u32 as RefFoo<u32>>::ref_foo(a)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:27), 'a) })...
= note: ...but the lifetime must also be valid for the static lifetime...
= note: ...so that the types are compatible:
expected Foo<'static, u32>
found Foo<'_, u32>
= note: `&'0 u32` must implement `Foo<'static, u32>` for any lifetime `'0`
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements
error: implementation of `Foo` is not general enough
--> $DIR/issue-54302-cases.rs:69:5
|
LL | <i32 as RefFoo<i32>>::ref_foo(a)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:27), 'a) })...
= note: ...but the lifetime must also be valid for the static lifetime...
= note: ...so that the types are compatible:
expected Foo<'static, i32>
found Foo<'_, i32>
= note: `&'0 i32` must implement `Foo<'static, i32>` for any lifetime `'0`
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements
error: implementation of `Foo` is not general enough
--> $DIR/issue-54302-cases.rs:75:5
|
LL | <u64 as RefFoo<u64>>::ref_foo(a)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:27), 'a) })...
= note: ...but the lifetime must also be valid for the static lifetime...
= note: ...so that the types are compatible:
expected Foo<'static, u64>
found Foo<'_, u64>
= note: `&'0 u64` must implement `Foo<'static, u64>` for any lifetime `'0`
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements
error: implementation of `Foo` is not general enough
--> $DIR/issue-54302-cases.rs:81:5
|
LL | <i64 as RefFoo<i64>>::ref_foo(a)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:27), 'a) })...
= note: ...but the lifetime must also be valid for the static lifetime...
= note: ...so that the types are compatible:
expected Foo<'static, i64>
found Foo<'_, i64>
= note: `&'0 i64` must implement `Foo<'static, i64>` for any lifetime `'0`
= note: but `&'1 _` only implements `Foo<'_, _>` for some lifetime `'1`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0495`.

View File

@ -11,7 +11,7 @@ fn main() {
// Then why does it implement DeserializeOwned? This compiles.
fn assert_deserialize_owned<T: DeserializeOwned>() {}
assert_deserialize_owned::<&'static str>();
//~^ ERROR E0495
//~^ ERROR not general enough
// It correctly does not implement for<'de> Deserialize<'de>.
//fn assert_hrtb<T: for<'de> Deserialize<'de>>() {}

View File

@ -1,15 +1,11 @@
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements
error: implementation of `Deserialize` is not general enough
--> $DIR/issue-54302.rs:13:5
|
LL | assert_deserialize_owned::<&'static str>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U2, name: BrNamed(crate0:DefIndex(1:12), 'de) })...
= note: ...but the lifetime must also be valid for the static lifetime...
= note: ...so that the types are compatible:
expected Deserialize<'de>
found Deserialize<'_>
= note: `&'static str` must implement `Deserialize<'0>` for any lifetime `'0`
= note: but `&str` only implements `Deserialize<'1>` for some lifetime `'1`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.