Skip to content

Commit

Permalink
Auto merge of #64474 - Mark-Simulacrum:permit-err-overlap, r=matthewj…
Browse files Browse the repository at this point in the history
…asper

Permit impls referencing errors to overlap

Fixes #43400; previously this would emit an overlapping impls error, but no longer does.
  • Loading branch information
bors committed Sep 15, 2019
2 parents 60895fd + 959c710 commit 96d07e0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/coherence/conflicting-impl-with-err.rs
Original file line number Diff line number Diff line change
@@ -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() {}
15 changes: 15 additions & 0 deletions src/test/ui/coherence/conflicting-impl-with-err.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 96d07e0

Please sign in to comment.