mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
address review comment
This commit is contained in:
parent
4f7dddd4a1
commit
6a2d9b45c4
@ -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() {
|
||||
@ -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`",
|
||||
@ -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(
|
||||
@ -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()
|
||||
|
@ -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>`
|
||||
|
@ -26,7 +26,10 @@ 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`
|
||||
|
|
||||
@ -34,10 +37,13 @@ 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`
|
||||
|
|
||||
@ -45,7 +51,7 @@ 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>`
|
||||
@ -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>`
|
||||
|
Loading…
Reference in New Issue
Block a user