Hide negative coherence checks under negative_impls feature flag

This commit is contained in:
Santiago Pastorino 2021-10-22 17:54:20 -03:00
parent 9e264137e9
commit 9534186857
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
5 changed files with 37 additions and 4 deletions

View file

@ -233,10 +233,11 @@ fn overlap_within_probe(
.unwrap_or(false)
} else {
!selcx.predicate_may_hold_fatal(o)
|| o.flip_polarity(tcx)
.as_ref()
.map(|o| selcx.infcx().predicate_must_hold_modulo_regions(o))
.unwrap_or(false)
|| tcx.features().negative_impls
&& o.flip_polarity(tcx)
.as_ref()
.map(|o| selcx.infcx().predicate_must_hold_modulo_regions(o))
.unwrap_or(false)
}
});
// FIXME: the call to `selcx.predicate_may_hold_fatal` above should be ported

View file

@ -0,0 +1,8 @@
use std::ops::DerefMut;
trait Foo {}
impl<T: DerefMut> Foo for T {}
impl<U> Foo for &U {}
//~^ ERROR: conflicting implementations of trait `Foo` for type `&_` [E0119]
fn main() {}

View file

@ -0,0 +1,11 @@
error[E0119]: conflicting implementations of trait `Foo` for type `&_`
--> $DIR/coherence-overlap-negate-not-use-feature-gate.rs:5:1
|
LL | impl<T: DerefMut> Foo for T {}
| --------------------------- first implementation here
LL | impl<U> Foo for &U {}
| ^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0119`.

View file

@ -0,0 +1,11 @@
// check-pass
#![feature(negative_impls)]
use std::ops::DerefMut;
trait Foo {}
impl<T: DerefMut> Foo for T {}
impl<U> Foo for &U {}
fn main() {}

View file

@ -3,6 +3,8 @@
//
// Check that if we promise to not impl what would overlap it doesn't actually overlap
#![feature(negative_impls)]
extern crate error_lib as lib;
use lib::Error;