Skip to content

Commit 6a2d9b4

Browse files
committed
address review comment
1 parent 4f7dddd commit 6a2d9b4

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -2418,11 +2418,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24182418
field_ident: Ident,
24192419
base: &'tcx hir::Expr<'tcx>,
24202420
ty: Ty<'tcx>,
2421-
) -> bool {
2421+
) {
24222422
let Some(output_ty) = self.get_impl_future_output_ty(ty) else {
2423-
return false;
2423+
return;
24242424
};
2425-
let mut add_label = true;
24262425
if let ty::Adt(def, _) = output_ty.kind() {
24272426
// no field access on enum type
24282427
if !def.is_enum() {
@@ -2432,7 +2431,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24322431
.iter()
24332432
.any(|field| field.ident(self.tcx) == field_ident)
24342433
{
2435-
add_label = false;
24362434
err.span_label(
24372435
field_ident.span,
24382436
"field not available in `impl Future`, but it is available in its `Output`",
@@ -2446,10 +2444,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24462444
}
24472445
}
24482446
}
2449-
if add_label {
2450-
err.span_label(field_ident.span, format!("field not found in `{ty}`"));
2451-
}
2452-
true
24532447
}
24542448

24552449
fn ban_nonexisting_field(
@@ -2465,29 +2459,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24652459
);
24662460
let mut err = self.no_such_field_err(ident, base_ty, base.hir_id);
24672461

2468-
let has_label = match *base_ty.peel_refs().kind() {
2462+
match *base_ty.peel_refs().kind() {
24692463
ty::Array(_, len) => {
24702464
self.maybe_suggest_array_indexing(&mut err, expr, base, ident, len);
2471-
false
24722465
}
24732466
ty::RawPtr(..) => {
24742467
self.suggest_first_deref_field(&mut err, expr, base, ident);
2475-
false
24762468
}
24772469
ty::Param(param_ty) => {
24782470
self.point_at_param_definition(&mut err, param_ty);
2479-
false
24802471
}
24812472
ty::Alias(ty::Opaque, _) => {
2482-
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs())
2473+
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
24832474
}
2484-
_ => false,
2485-
};
2486-
2487-
if !has_label {
2488-
err.span_label(ident.span, "unknown field");
2475+
_ => {}
24892476
}
24902477

2478+
err.span_label(ident.span, "unknown field");
2479+
24912480
self.suggest_fn_call(&mut err, base, base_ty, |output_ty| {
24922481
if let ty::Adt(def, _) = output_ty.kind()
24932482
&& !def.is_enum()

tests/ui/async-await/issue-61076.rs

+2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ async fn baz() -> Result<(), ()> {
7171
let _: i32 = tuple().0; //~ ERROR no field `0`
7272
//~^ HELP consider `await`ing on the `Future`
7373
//~| NOTE field not available in `impl Future`
74+
//~| NOTE unknown field
7475

7576
let _: i32 = struct_().a; //~ ERROR no field `a`
7677
//~^ HELP consider `await`ing on the `Future`
7778
//~| NOTE field not available in `impl Future`
79+
//~| NOTE unknown field
7880

7981
struct_().method(); //~ ERROR no method named
8082
//~^ NOTE method not found in `impl Future<Output = Struct>`

tests/ui/async-await/issue-61076.stderr

+11-5
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,32 @@ error[E0609]: no field `0` on type `impl Future<Output = Tuple>`
2626
--> $DIR/issue-61076.rs:71:26
2727
|
2828
LL | let _: i32 = tuple().0;
29-
| ^ field not available in `impl Future`, but it is available in its `Output`
29+
| ^
30+
| |
31+
| field not available in `impl Future`, but it is available in its `Output`
32+
| unknown field
3033
|
3134
help: consider `await`ing on the `Future` and access the field of its `Output`
3235
|
3336
LL | let _: i32 = tuple().await.0;
3437
| ++++++
3538

3639
error[E0609]: no field `a` on type `impl Future<Output = Struct>`
37-
--> $DIR/issue-61076.rs:75:28
40+
--> $DIR/issue-61076.rs:76:28
3841
|
3942
LL | let _: i32 = struct_().a;
40-
| ^ field not available in `impl Future`, but it is available in its `Output`
43+
| ^
44+
| |
45+
| field not available in `impl Future`, but it is available in its `Output`
46+
| unknown field
4147
|
4248
help: consider `await`ing on the `Future` and access the field of its `Output`
4349
|
4450
LL | let _: i32 = struct_().await.a;
4551
| ++++++
4652

4753
error[E0599]: no method named `method` found for opaque type `impl Future<Output = Struct>` in the current scope
48-
--> $DIR/issue-61076.rs:79:15
54+
--> $DIR/issue-61076.rs:81:15
4955
|
5056
LL | struct_().method();
5157
| ^^^^^^ method not found in `impl Future<Output = Struct>`
@@ -56,7 +62,7 @@ LL | struct_().await.method();
5662
| ++++++
5763

5864
error[E0308]: mismatched types
59-
--> $DIR/issue-61076.rs:88:9
65+
--> $DIR/issue-61076.rs:90:9
6066
|
6167
LL | match tuple() {
6268
| ------- this expression has type `impl Future<Output = Tuple>`

0 commit comments

Comments
 (0)