about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-11-18 13:25:53 -0500
committerNiko Matsakis <niko@alum.mit.edu>2019-01-02 17:35:06 -0500
commit6cbbee1dc7ec5c680bb5c83af0aa1b16b3a03cc0 (patch)
tree0dc929297bda1fbc9ab4585909457ab3cd16be4f
parent0a61d682a194954494df3cdefb926172c5d423c4 (diff)
downloadrust-6cbbee1dc7ec5c680bb5c83af0aa1b16b3a03cc0.tar.gz
rust-6cbbee1dc7ec5c680bb5c83af0aa1b16b3a03cc0.zip
apply the new placeholder errors even with just one placeholder
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs52
-rw-r--r--src/test/ui/hrtb/hrtb-cache-issue-54302.stderr10
-rw-r--r--src/test/ui/hrtb/hrtb-just-for-static.rs6
-rw-r--r--src/test/ui/hrtb/hrtb-just-for-static.stderr12
-rw-r--r--src/test/ui/issues/issue-54302-cases.rs8
-rw-r--r--src/test/ui/issues/issue-54302-cases.stderr37
-rw-r--r--src/test/ui/issues/issue-54302.rs2
-rw-r--r--src/test/ui/issues/issue-54302.stderr10
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 f5e9f3814b4..83fe3da7077 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<ty::RegionVid>,
         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 940a6e3f068..e82fa51524e 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 3aee241ccd2..88d5ce8e640 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::<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() { }
diff --git a/src/test/ui/hrtb/hrtb-just-for-static.stderr b/src/test/ui/hrtb/hrtb-just-for-static.stderr
index d3c2f7d059a..6ea415c1734 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::<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`.
diff --git a/src/test/ui/issues/issue-54302-cases.rs b/src/test/ui/issues/issue-54302-cases.rs
index 286d37b182e..faa116269ee 100644
--- a/src/test/ui/issues/issue-54302-cases.rs
+++ b/src/test/ui/issues/issue-54302-cases.rs
@@ -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() {}
diff --git a/src/test/ui/issues/issue-54302-cases.stderr b/src/test/ui/issues/issue-54302-cases.stderr
index 09a4e091d2b..6469829e789 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 |     <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`.
diff --git a/src/test/ui/issues/issue-54302.rs b/src/test/ui/issues/issue-54302.rs
index 35cdc73a78f..1bfaebc3895 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<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>>() {}
diff --git a/src/test/ui/issues/issue-54302.stderr b/src/test/ui/issues/issue-54302.stderr
index b456d2582ff..1b255204b6e 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`.