summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_trait_selection/src/traits/coherence.rs11
-rw-r--r--tests/ui/coherence/negative-coherence-considering-regions.any_lt.stderr12
-rw-r--r--tests/ui/coherence/negative-coherence-considering-regions.rs23
3 files changed, 44 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs
index 0a476540d51..a4f600560ae 100644
--- a/compiler/rustc_trait_selection/src/traits/coherence.rs
+++ b/compiler/rustc_trait_selection/src/traits/coherence.rs
@@ -434,12 +434,19 @@ fn impl_intersection_has_negative_obligation(
             param_env,
             negative_predicate,
         ));
-
         if !ocx.select_all_or_error().is_empty() {
             continue;
         }
 
-        // FIXME: regions here too...
+        // FIXME: We could use the assumed_wf_types from both impls, I think,
+        // if that wasn't implemented just for LocalDefId, and we'd need to do
+        //the normalization ourselves since this is totally fallible...
+        let outlives_env = OutlivesEnvironment::new(param_env);
+
+        let errors = infcx.resolve_regions(&outlives_env);
+        if !errors.is_empty() {
+            continue;
+        }
 
         return true;
     }
diff --git a/tests/ui/coherence/negative-coherence-considering-regions.any_lt.stderr b/tests/ui/coherence/negative-coherence-considering-regions.any_lt.stderr
new file mode 100644
index 00000000000..4cf50b4f208
--- /dev/null
+++ b/tests/ui/coherence/negative-coherence-considering-regions.any_lt.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `Bar` for type `&_`
+  --> $DIR/negative-coherence-considering-regions.rs:22:1
+   |
+LL | impl<T> Bar for T where T: Foo {}
+   | ------------------------------ first implementation here
+...
+LL | impl<T> Bar for &T {}
+   | ^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/tests/ui/coherence/negative-coherence-considering-regions.rs b/tests/ui/coherence/negative-coherence-considering-regions.rs
new file mode 100644
index 00000000000..a43ad19eca7
--- /dev/null
+++ b/tests/ui/coherence/negative-coherence-considering-regions.rs
@@ -0,0 +1,23 @@
+// revisions: any_lt static_lt
+//[static_lt] check-pass
+
+#![feature(negative_impls)]
+#![feature(with_negative_coherence)]
+
+trait Foo {}
+
+impl<T> !Foo for &'static T {}
+
+trait Bar {}
+
+impl<T> Bar for T where T: Foo {}
+
+#[cfg(any_lt)]
+impl<T> Bar for &T {}
+//[any_lt]~^ ERROR conflicting implementations of trait `Bar` for type `&_`
+
+#[cfg(static_lt)]
+impl<T> Bar for &'static T {}
+
+
+fn main() {}