Skip to content

Commit 96d07e0

Browse files
committed
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.
2 parents 60895fd + 959c710 commit 96d07e0

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/librustc/ty/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2894,6 +2894,13 @@ impl<'tcx> TyCtxt<'tcx> {
28942894
pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId)
28952895
-> Option<ImplOverlapKind>
28962896
{
2897+
// If either trait impl references an error, they're allowed to overlap,
2898+
// as one of them essentially doesn't exist.
2899+
if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.references_error()) ||
2900+
self.impl_trait_ref(def_id2).map_or(false, |tr| tr.references_error()) {
2901+
return Some(ImplOverlapKind::Permitted);
2902+
}
2903+
28972904
let is_legit = if self.features().overlapping_marker_traits {
28982905
let trait1_is_empty = self.impl_trait_ref(def_id1)
28992906
.map_or(false, |trait_ref| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct ErrorKind;
2+
struct Error(ErrorKind);
3+
4+
impl From<nope::Thing> for Error { //~ ERROR failed to resolve
5+
fn from(_: nope::Thing) -> Self { //~ ERROR failed to resolve
6+
unimplemented!()
7+
}
8+
}
9+
10+
impl From<ErrorKind> for Error {
11+
fn from(_: ErrorKind) -> Self {
12+
unimplemented!()
13+
}
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0433]: failed to resolve: use of undeclared type or module `nope`
2+
--> $DIR/conflicting-impl-with-err.rs:4:11
3+
|
4+
LL | impl From<nope::Thing> for Error {
5+
| ^^^^ use of undeclared type or module `nope`
6+
7+
error[E0433]: failed to resolve: use of undeclared type or module `nope`
8+
--> $DIR/conflicting-impl-with-err.rs:5:16
9+
|
10+
LL | fn from(_: nope::Thing) -> Self {
11+
| ^^^^ use of undeclared type or module `nope`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)