Skip to content

Commit 1d99ddb

Browse files
Consider regions
1 parent 8597bf1 commit 1d99ddb

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,19 @@ fn impl_intersection_has_negative_obligation(
434434
param_env,
435435
negative_predicate,
436436
));
437-
438437
if !ocx.select_all_or_error().is_empty() {
439438
continue;
440439
}
441440

442-
// FIXME: regions here too...
441+
// FIXME: We could use the assumed_wf_types from both impls, I think,
442+
// if that wasn't implemented just for LocalDefId, and we'd need to do
443+
//the normalization ourselves since this is totally fallible...
444+
let outlives_env = OutlivesEnvironment::new(param_env);
445+
446+
let errors = infcx.resolve_regions(&outlives_env);
447+
if !errors.is_empty() {
448+
continue;
449+
}
443450

444451
return true;
445452
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0119]: conflicting implementations of trait `Bar` for type `&_`
2+
--> $DIR/negative-coherence-considering-regions.rs:22:1
3+
|
4+
LL | impl<T> Bar for T where T: Foo {}
5+
| ------------------------------ first implementation here
6+
...
7+
LL | impl<T> Bar for &T {}
8+
| ^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0119`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// revisions: any_lt static_lt
2+
//[static_lt] check-pass
3+
4+
#![feature(negative_impls)]
5+
#![feature(with_negative_coherence)]
6+
7+
trait Foo {}
8+
9+
impl<T> !Foo for &'static T {}
10+
11+
trait Bar {}
12+
13+
impl<T> Bar for T where T: Foo {}
14+
15+
#[cfg(any_lt)]
16+
impl<T> Bar for &T {}
17+
//[any_lt]~^ ERROR conflicting implementations of trait `Bar` for type `&_`
18+
19+
#[cfg(static_lt)]
20+
impl<T> Bar for &'static T {}
21+
22+
23+
fn main() {}

0 commit comments

Comments
 (0)