Skip to content

Commit 1c22819

Browse files
authored
Unrolled build for rust-lang#139423
Rollup merge of rust-lang#139423 - compiler-errors:field-autoderef, r=oli-obk Suppress missing field error when autoderef bottoms out in infer I see this error repeatedly when doing refactorings, and it's pretty misleading b/c it's not the source of the error.
2 parents 7d7de5b + b8c4c16 commit 1c22819

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2920,8 +2920,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29202920
}
29212921
// We failed to check the expression, report an error.
29222922

2923-
// Emits an error if we deref an infer variable, like calling `.field` on a base type of &_.
2924-
self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false));
2923+
// Emits an error if we deref an infer variable, like calling `.field` on a base type
2924+
// of `&_`. We can also use this to suppress unnecessary "missing field" errors that
2925+
// will follow ambiguity errors.
2926+
let final_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false));
2927+
if let ty::Error(_) = final_ty.kind() {
2928+
return final_ty;
2929+
}
29252930

29262931
if let Some((adjustments, did)) = private_candidate {
29272932
// (#90483) apply adjustments to avoid ExprUseVisitor from

tests/ui/typeck/issue-65611.rs

-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ fn main() {
5858
let mut buffer = ArrayVec::new();
5959
let x = buffer.last().unwrap().0.clone();
6060
//~^ ERROR type annotations needed
61-
//~| ERROR no field `0` on type `&_`
6261
buffer.reverse();
6362
}

tests/ui/typeck/issue-65611.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ error[E0282]: type annotations needed
44
LL | let x = buffer.last().unwrap().0.clone();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
66

7-
error[E0609]: no field `0` on type `&_`
8-
--> $DIR/issue-65611.rs:59:36
9-
|
10-
LL | let x = buffer.last().unwrap().0.clone();
11-
| ^ unknown field
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to 1 previous error
148

15-
Some errors have detailed explanations: E0282, E0609.
16-
For more information about an error, try `rustc --explain E0282`.
9+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)