Skip to content

Commit 9534186

Browse files
committed
Hide negative coherence checks under negative_impls feature flag
1 parent 9e26413 commit 9534186

5 files changed

+37
-4
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/coherence.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,11 @@ fn overlap_within_probe(
233233
.unwrap_or(false)
234234
} else {
235235
!selcx.predicate_may_hold_fatal(o)
236-
|| o.flip_polarity(tcx)
237-
.as_ref()
238-
.map(|o| selcx.infcx().predicate_must_hold_modulo_regions(o))
239-
.unwrap_or(false)
236+
|| tcx.features().negative_impls
237+
&& o.flip_polarity(tcx)
238+
.as_ref()
239+
.map(|o| selcx.infcx().predicate_must_hold_modulo_regions(o))
240+
.unwrap_or(false)
240241
}
241242
});
242243
// FIXME: the call to `selcx.predicate_may_hold_fatal` above should be ported
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std::ops::DerefMut;
2+
3+
trait Foo {}
4+
impl<T: DerefMut> Foo for T {}
5+
impl<U> Foo for &U {}
6+
//~^ ERROR: conflicting implementations of trait `Foo` for type `&_` [E0119]
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0119]: conflicting implementations of trait `Foo` for type `&_`
2+
--> $DIR/coherence-overlap-negate-not-use-feature-gate.rs:5:1
3+
|
4+
LL | impl<T: DerefMut> Foo for T {}
5+
| --------------------------- first implementation here
6+
LL | impl<U> Foo for &U {}
7+
| ^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0119`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
3+
#![feature(negative_impls)]
4+
5+
use std::ops::DerefMut;
6+
7+
trait Foo {}
8+
impl<T: DerefMut> Foo for T {}
9+
impl<U> Foo for &U {}
10+
11+
fn main() {}

Diff for: src/test/ui/coherence/coherence-overlap-negative-trait.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44
// Check that if we promise to not impl what would overlap it doesn't actually overlap
55

6+
#![feature(negative_impls)]
7+
68
extern crate error_lib as lib;
79
use lib::Error;
810

0 commit comments

Comments
 (0)