Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Consider regions
  • Loading branch information
compiler-errors committed Oct 23, 2023
commit 1d99ddbfe81b7d766c6e6f54dbc722c70d0b6be7
11 changes: 9 additions & 2 deletions compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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`.
23 changes: 23 additions & 0 deletions tests/ui/coherence/negative-coherence-considering-regions.rs
Original file line number Diff line number Diff line change
@@ -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() {}