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 Bar for T where T: Foo {} + | ------------------------------ first implementation here +... +LL | impl 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 !Foo for &'static T {} + +trait Bar {} + +impl Bar for T where T: Foo {} + +#[cfg(any_lt)] +impl Bar for &T {} +//[any_lt]~^ ERROR conflicting implementations of trait `Bar` for type `&_` + +#[cfg(static_lt)] +impl Bar for &'static T {} + + +fn main() {}