Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #118046

Merged
merged 19 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address review comment
  • Loading branch information
estebank committed Nov 16, 2023
commit 6a2d9b45c4c24ed431f07bc35c58e277cf864fa2
25 changes: 7 additions & 18 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2418,11 +2418,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
field_ident: Ident,
base: &'tcx hir::Expr<'tcx>,
ty: Ty<'tcx>,
) -> bool {
) {
let Some(output_ty) = self.get_impl_future_output_ty(ty) else {
return false;
return;
};
let mut add_label = true;
if let ty::Adt(def, _) = output_ty.kind() {
// no field access on enum type
if !def.is_enum() {
Expand All @@ -2432,7 +2431,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.iter()
.any(|field| field.ident(self.tcx) == field_ident)
{
add_label = false;
err.span_label(
field_ident.span,
"field not available in `impl Future`, but it is available in its `Output`",
Expand All @@ -2446,10 +2444,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
if add_label {
err.span_label(field_ident.span, format!("field not found in `{ty}`"));
}
true
}

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

let has_label = match *base_ty.peel_refs().kind() {
match *base_ty.peel_refs().kind() {
ty::Array(_, len) => {
self.maybe_suggest_array_indexing(&mut err, expr, base, ident, len);
false
}
ty::RawPtr(..) => {
self.suggest_first_deref_field(&mut err, expr, base, ident);
false
}
ty::Param(param_ty) => {
self.point_at_param_definition(&mut err, param_ty);
false
}
ty::Alias(ty::Opaque, _) => {
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs())
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
}
_ => false,
};

if !has_label {
err.span_label(ident.span, "unknown field");
_ => {}
}

err.span_label(ident.span, "unknown field");

self.suggest_fn_call(&mut err, base, base_ty, |output_ty| {
if let ty::Adt(def, _) = output_ty.kind()
&& !def.is_enum()
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/async-await/issue-61076.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ async fn baz() -> Result<(), ()> {
let _: i32 = tuple().0; //~ ERROR no field `0`
//~^ HELP consider `await`ing on the `Future`
//~| NOTE field not available in `impl Future`
//~| NOTE unknown field

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

struct_().method(); //~ ERROR no method named
//~^ NOTE method not found in `impl Future<Output = Struct>`
Expand Down
16 changes: 11 additions & 5 deletions tests/ui/async-await/issue-61076.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,32 @@ error[E0609]: no field `0` on type `impl Future<Output = Tuple>`
--> $DIR/issue-61076.rs:71:26
|
LL | let _: i32 = tuple().0;
| ^ field not available in `impl Future`, but it is available in its `Output`
| ^
| |
| field not available in `impl Future`, but it is available in its `Output`
| unknown field
|
help: consider `await`ing on the `Future` and access the field of its `Output`
|
LL | let _: i32 = tuple().await.0;
| ++++++

error[E0609]: no field `a` on type `impl Future<Output = Struct>`
--> $DIR/issue-61076.rs:75:28
--> $DIR/issue-61076.rs:76:28
|
LL | let _: i32 = struct_().a;
| ^ field not available in `impl Future`, but it is available in its `Output`
| ^
| |
| field not available in `impl Future`, but it is available in its `Output`
| unknown field
|
help: consider `await`ing on the `Future` and access the field of its `Output`
|
LL | let _: i32 = struct_().await.a;
| ++++++

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

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