Skip to content

Commit 2983d9c

Browse files
committed
Elide invalid method receiver error when it contains TyErr
Fix rust-lang#58712.
1 parent c1d2d83 commit 2983d9c

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/librustc_typeck/check/wfcheck.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,9 @@ fn receiver_is_valid<'fcx, 'tcx, 'gcx>(
842842
} else {
843843
debug!("receiver_is_valid: type `{:?}` does not deref to `{:?}`",
844844
receiver_ty, self_ty);
845-
return false
845+
// If he receiver already has errors reported due to it, consider it valid to avoid
846+
// unecessary errors (#58712).
847+
return receiver_ty.references_error();
846848
}
847849

848850
// without the `arbitrary_self_types` feature, `receiver_ty` must directly deref to

src/test/ui/issues/issue-58712.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
struct AddrVec<H, A> {
2+
h: H,
3+
a: A,
4+
}
5+
6+
impl<H> AddrVec<H, DeviceId> {
7+
//~^ ERROR cannot find type `DeviceId` in this scope
8+
pub fn device(&self) -> DeviceId {
9+
//~^ ERROR cannot find type `DeviceId` in this scope
10+
self.tail()
11+
}
12+
}
13+
14+
fn main() {}
15+

src/test/ui/issues/issue-58712.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0412]: cannot find type `DeviceId` in this scope
2+
--> $DIR/issue-58712.rs:6:20
3+
|
4+
LL | impl<H> AddrVec<H, DeviceId> {
5+
| ^^^^^^^^ not found in this scope
6+
7+
error[E0412]: cannot find type `DeviceId` in this scope
8+
--> $DIR/issue-58712.rs:8:29
9+
|
10+
LL | pub fn device(&self) -> DeviceId {
11+
| ^^^^^^^^ not found in this scope
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)