about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-09-12 23:07:23 +0200
committerFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-09-12 23:07:23 +0200
commitab83d501a404bede933df8f33e280a7534cc71bf (patch)
tree543bc4c223aaa4454b0b1ef41a58bf2ec71a3b47 /compiler
parentc7dbe7a830100c70d59994fd940bf75bb6e39b39 (diff)
downloadrust-ab83d501a404bede933df8f33e280a7534cc71bf.tar.gz
rust-ab83d501a404bede933df8f33e280a7534cc71bf.zip
Do not issue E0071 if a type error has already been reported
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0071.md14
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/checks.rs28
2 files changed, 26 insertions, 16 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0071.md b/compiler/rustc_error_codes/src/error_codes/E0071.md
index bc2c03a0220..a6d6d19762b 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0071.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0071.md
@@ -15,13 +15,13 @@ form of initializer was used.
 For example, the code above can be fixed to:
 
 ```
-enum Foo {
-    FirstValue(i32)
-}
+type U32 = u32;
+let t: U32 = 4;
+```
 
-fn main() {
-    let u = Foo::FirstValue(0i32);
+or:
 
-    let t = 4;
-}
+```
+struct U32 { value: u32 }
+let t = U32 { value: 4 };
 ```
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
index 9efb52a08b7..e74e79fd1bf 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
@@ -494,15 +494,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
             Some((variant, ty))
         } else {
-            struct_span_err!(
-                self.tcx.sess,
-                path_span,
-                E0071,
-                "expected struct, variant or union type, found {}",
-                ty.sort_string(self.tcx)
-            )
-            .span_label(path_span, "not a struct")
-            .emit();
+            match ty.kind() {
+                ty::Error(_) => {
+                    // E0071 might be caused by a spelling error, which will have
+                    // already caused an error message and probably a suggestion
+                    // elsewhere. Refrain from emitting more unhelpful errors here
+                    // (issue #88844).
+                }
+                _ => {
+                    struct_span_err!(
+                        self.tcx.sess,
+                        path_span,
+                        E0071,
+                        "expected struct, variant or union type, found {}",
+                        ty.sort_string(self.tcx)
+                    )
+                    .span_label(path_span, "not a struct")
+                    .emit();
+                }
+            }
             None
         }
     }