diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2023-11-15 18:18:42 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2023-11-16 17:00:24 +0000 |
| commit | 6a2d9b45c4c24ed431f07bc35c58e277cf864fa2 (patch) | |
| tree | c53ef4f44a5e70aa5c35b6f99147586087388e9f /compiler | |
| parent | 4f7dddd4a177c761f8576e6c1fedfd73db8bfe7d (diff) | |
| download | rust-6a2d9b45c4c24ed431f07bc35c58e277cf864fa2.tar.gz rust-6a2d9b45c4c24ed431f07bc35c58e277cf864fa2.zip | |
address review comment
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_typeck/src/expr.rs | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index c5a312a6605..7e235ea7f46 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -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() |
