]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/pat.rs
Rollup merge of #87960 - hkmatsumoto:suggest-inexisting-field-for-unmentioned-field...
[rust.git] / compiler / rustc_typeck / src / check / pat.rs
index a056ab6aef2aec0398476a4b793e0cea99b40c19..829268e3cb527d7b5240a75c4cd454f5b9a95327 100644 (file)
@@ -1452,7 +1452,8 @@ fn error_inexistent_fields(
                     plural
                 ),
             );
-            if plural == "" {
+
+            if unmentioned_fields.len() == 1 {
                 let input =
                     unmentioned_fields.iter().map(|(_, field)| field.name).collect::<Vec<_>>();
                 let suggested_name = find_best_match_for_name(&input, ident.name, None);
@@ -1473,6 +1474,18 @@ fn error_inexistent_fields(
                         // We don't want to throw `E0027` in case we have thrown `E0026` for them.
                         unmentioned_fields.retain(|&(_, x)| x.name != suggested_name);
                     }
+                } else if inexistent_fields.len() == 1 {
+                    let unmentioned_field = unmentioned_fields[0].1.name;
+                    err.span_suggestion_short(
+                        ident.span,
+                        &format!(
+                            "`{}` has a field named `{}`",
+                            tcx.def_path_str(variant.def_id),
+                            unmentioned_field
+                        ),
+                        unmentioned_field.to_string(),
+                        Applicability::MaybeIncorrect,
+                    );
                 }
             }
         }