diff options
| author | bors <bors@rust-lang.org> | 2019-09-15 16:21:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-09-15 16:21:34 +0000 |
| commit | 96d07e0ac9f0c56b95a2561c6cedac0b23a5d2a3 (patch) | |
| tree | 552afbd527cd65a3ea1767ea3094b0b821824e67 | |
| parent | 60895fd1f9ad24ee41bb3dac67fc2c5f127ecdb4 (diff) | |
| parent | 959c710e8599f3c5d5c8ec1eddd4f536ffda654f (diff) | |
| download | rust-96d07e0ac9f0c56b95a2561c6cedac0b23a5d2a3.tar.gz rust-96d07e0ac9f0c56b95a2561c6cedac0b23a5d2a3.zip | |
Auto merge of #64474 - Mark-Simulacrum:permit-err-overlap, r=matthewjasper
Permit impls referencing errors to overlap Fixes #43400; previously this would emit an overlapping impls error, but no longer does.
| -rw-r--r-- | src/librustc/ty/mod.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/coherence/conflicting-impl-with-err.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/coherence/conflicting-impl-with-err.stderr | 15 |
3 files changed, 38 insertions, 0 deletions
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 41e4295caec..17eb4a8957f 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2894,6 +2894,13 @@ impl<'tcx> TyCtxt<'tcx> { pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId) -> Option<ImplOverlapKind> { + // If either trait impl references an error, they're allowed to overlap, + // as one of them essentially doesn't exist. + if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.references_error()) || + self.impl_trait_ref(def_id2).map_or(false, |tr| tr.references_error()) { + return Some(ImplOverlapKind::Permitted); + } + let is_legit = if self.features().overlapping_marker_traits { let trait1_is_empty = self.impl_trait_ref(def_id1) .map_or(false, |trait_ref| { diff --git a/src/test/ui/coherence/conflicting-impl-with-err.rs b/src/test/ui/coherence/conflicting-impl-with-err.rs new file mode 100644 index 00000000000..3e0234b874d --- /dev/null +++ b/src/test/ui/coherence/conflicting-impl-with-err.rs @@ -0,0 +1,16 @@ +struct ErrorKind; +struct Error(ErrorKind); + +impl From<nope::Thing> for Error { //~ ERROR failed to resolve + fn from(_: nope::Thing) -> Self { //~ ERROR failed to resolve + unimplemented!() + } +} + +impl From<ErrorKind> for Error { + fn from(_: ErrorKind) -> Self { + unimplemented!() + } +} + +fn main() {} diff --git a/src/test/ui/coherence/conflicting-impl-with-err.stderr b/src/test/ui/coherence/conflicting-impl-with-err.stderr new file mode 100644 index 00000000000..a8a5730accd --- /dev/null +++ b/src/test/ui/coherence/conflicting-impl-with-err.stderr @@ -0,0 +1,15 @@ +error[E0433]: failed to resolve: use of undeclared type or module `nope` + --> $DIR/conflicting-impl-with-err.rs:4:11 + | +LL | impl From<nope::Thing> for Error { + | ^^^^ use of undeclared type or module `nope` + +error[E0433]: failed to resolve: use of undeclared type or module `nope` + --> $DIR/conflicting-impl-with-err.rs:5:16 + | +LL | fn from(_: nope::Thing) -> Self { + | ^^^^ use of undeclared type or module `nope` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0433`. |
