about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2021-10-22 17:54:20 -0300
committerSantiago Pastorino <spastorino@gmail.com>2021-10-22 17:54:20 -0300
commit953418685769424388fb9ea1f4b2beaceedb6857 (patch)
tree9c25a6391ff62954512b16744c54d24c7237b6b4
parent9e264137e9cececda98521bd411f3317c408a0ec (diff)
downloadrust-953418685769424388fb9ea1f4b2beaceedb6857.tar.gz
rust-953418685769424388fb9ea1f4b2beaceedb6857.zip
Hide negative coherence checks under negative_impls feature flag
-rw-r--r--compiler/rustc_trait_selection/src/traits/coherence.rs9
-rw-r--r--src/test/ui/coherence/coherence-overlap-negate-not-use-feature-gate.rs8
-rw-r--r--src/test/ui/coherence/coherence-overlap-negate-not-use-feature-gate.stderr11
-rw-r--r--src/test/ui/coherence/coherence-overlap-negate-use-feature-gate.rs11
-rw-r--r--src/test/ui/coherence/coherence-overlap-negative-trait.rs2
5 files changed, 37 insertions, 4 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs
index 35fd3153680..2d61675b856 100644
--- a/compiler/rustc_trait_selection/src/traits/coherence.rs
+++ b/compiler/rustc_trait_selection/src/traits/coherence.rs
@@ -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
diff --git a/src/test/ui/coherence/coherence-overlap-negate-not-use-feature-gate.rs b/src/test/ui/coherence/coherence-overlap-negate-not-use-feature-gate.rs
new file mode 100644
index 00000000000..a067736f63a
--- /dev/null
+++ b/src/test/ui/coherence/coherence-overlap-negate-not-use-feature-gate.rs
@@ -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() {}
diff --git a/src/test/ui/coherence/coherence-overlap-negate-not-use-feature-gate.stderr b/src/test/ui/coherence/coherence-overlap-negate-not-use-feature-gate.stderr
new file mode 100644
index 00000000000..4b55001ecc0
--- /dev/null
+++ b/src/test/ui/coherence/coherence-overlap-negate-not-use-feature-gate.stderr
@@ -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`.
diff --git a/src/test/ui/coherence/coherence-overlap-negate-use-feature-gate.rs b/src/test/ui/coherence/coherence-overlap-negate-use-feature-gate.rs
new file mode 100644
index 00000000000..e024eae9819
--- /dev/null
+++ b/src/test/ui/coherence/coherence-overlap-negate-use-feature-gate.rs
@@ -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() {}
diff --git a/src/test/ui/coherence/coherence-overlap-negative-trait.rs b/src/test/ui/coherence/coherence-overlap-negative-trait.rs
index 357c4e87c91..ab65163bea4 100644
--- a/src/test/ui/coherence/coherence-overlap-negative-trait.rs
+++ b/src/test/ui/coherence/coherence-overlap-negative-trait.rs
@@ -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;