From 6cbbee1dc7ec5c680bb5c83af0aa1b16b3a03cc0 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 18 Nov 2018 13:25:53 -0500 Subject: [PATCH] apply the new placeholder errors even with just one placeholder --- .../nice_region_error/placeholder_error.rs | 52 ++++++++++++++++++- .../ui/hrtb/hrtb-cache-issue-54302.stderr | 10 ++-- src/test/ui/hrtb/hrtb-just-for-static.rs | 6 +++ src/test/ui/hrtb/hrtb-just-for-static.stderr | 12 ++++- src/test/ui/issues/issue-54302-cases.rs | 8 +-- src/test/ui/issues/issue-54302-cases.stderr | 37 +++++-------- src/test/ui/issues/issue-54302.rs | 2 +- src/test/ui/issues/issue-54302.stderr | 10 ++-- 8 files changed, 90 insertions(+), 47 deletions(-) diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index f5e9f3814b46..83fe3da70775 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -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, cause: &ObligationCause<'tcx>, diff --git a/src/test/ui/hrtb/hrtb-cache-issue-54302.stderr b/src/test/ui/hrtb/hrtb-cache-issue-54302.stderr index 940a6e3f0685..e82fa51524ef 100644 --- a/src/test/ui/hrtb/hrtb-cache-issue-54302.stderr +++ b/src/test/ui/hrtb/hrtb-cache-issue-54302.stderr @@ -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`. diff --git a/src/test/ui/hrtb/hrtb-just-for-static.rs b/src/test/ui/hrtb/hrtb-just-for-static.rs index 3aee241ccd2d..88d5ce8e6405 100644 --- a/src/test/ui/hrtb/hrtb-just-for-static.rs +++ b/src/test/ui/hrtb/hrtb-just-for-static.rs @@ -24,4 +24,10 @@ fn give_static() { want_hrtb::() //~ 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() { } diff --git a/src/test/ui/hrtb/hrtb-just-for-static.stderr b/src/test/ui/hrtb/hrtb-just-for-static.stderr index d3c2f7d059a6..6ea415c1734b 100644 --- a/src/test/ui/hrtb/hrtb-just-for-static.stderr +++ b/src/test/ui/hrtb/hrtb-just-for-static.stderr @@ -9,6 +9,16 @@ LL | want_hrtb::() //~ 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`. diff --git a/src/test/ui/issues/issue-54302-cases.rs b/src/test/ui/issues/issue-54302-cases.rs index 286d37b182e3..faa116269ee9 100644 --- a/src/test/ui/issues/issue-54302-cases.rs +++ b/src/test/ui/issues/issue-54302-cases.rs @@ -61,25 +61,25 @@ impl RefFoo for T where for<'a> &'a T: Foo<'static, T> { fn coerce_lifetime1(a: &u32) -> &'static u32 { >::ref_foo(a) - //~^ ERROR cannot infer + //~^ ERROR not general enough } fn coerce_lifetime2(a: &i32) -> &'static i32 { >::ref_foo(a) - //~^ ERROR cannot infer + //~^ ERROR not general enough } fn coerce_lifetime3(a: &u64) -> &'static u64 { >::ref_foo(a) - //~^ ERROR cannot infer + //~^ ERROR not general enough } fn coerce_lifetime4(a: &i64) -> &'static i64 { >::ref_foo(a) - //~^ ERROR cannot infer + //~^ ERROR not general enough } fn main() {} diff --git a/src/test/ui/issues/issue-54302-cases.stderr b/src/test/ui/issues/issue-54302-cases.stderr index 09a4e091d2bc..6469829e789b 100644 --- a/src/test/ui/issues/issue-54302-cases.stderr +++ b/src/test/ui/issues/issue-54302-cases.stderr @@ -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 | >::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 | >::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 | >::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 | >::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`. diff --git a/src/test/ui/issues/issue-54302.rs b/src/test/ui/issues/issue-54302.rs index 35cdc73a78fd..1bfaebc3895d 100644 --- a/src/test/ui/issues/issue-54302.rs +++ b/src/test/ui/issues/issue-54302.rs @@ -11,7 +11,7 @@ fn main() { // Then why does it implement DeserializeOwned? This compiles. fn assert_deserialize_owned() {} assert_deserialize_owned::<&'static str>(); - //~^ ERROR E0495 + //~^ ERROR not general enough // It correctly does not implement for<'de> Deserialize<'de>. //fn assert_hrtb Deserialize<'de>>() {} diff --git a/src/test/ui/issues/issue-54302.stderr b/src/test/ui/issues/issue-54302.stderr index b456d2582ffd..1b255204b6ef 100644 --- a/src/test/ui/issues/issue-54302.stderr +++ b/src/test/ui/issues/issue-54302.stderr @@ -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`.