about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-03-07 22:03:12 +0000
committerMichael Goulet <michael@errs.io>2023-03-08 01:55:32 +0000
commit08e5a77b069dc55481fef6a415c5bb8f056c00c9 (patch)
treee4a8899b0c5b2dfb703f8456720b3e7a8840b6d4
parent38b96553112dce3de630890701f17d86e265f6ba (diff)
Don't report E0740 for type error
-rw-r--r--compiler/rustc_hir_analysis/src/check/check.rs4
-rw-r--r--tests/ui/union/unresolved-field-isnt-copy.rs8
-rw-r--r--tests/ui/union/unresolved-field-isnt-copy.stderr9
3 files changed, 20 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs
index 3449d3d439d..ec09a12e9a1 100644
--- a/compiler/rustc_hir_analysis/src/check/check.rs
+++ b/compiler/rustc_hir_analysis/src/check/check.rs
@@ -114,9 +114,11 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
                     allowed_union_field(*elem, tcx, param_env)
                 }
                 _ => {
-                    // Fallback case: allow `ManuallyDrop` and things that are `Copy`.
+                    // Fallback case: allow `ManuallyDrop` and things that are `Copy`,
+                    // also no need to report an error if the type is unresolved.
                     ty.ty_adt_def().is_some_and(|adt_def| adt_def.is_manually_drop())
                         || ty.is_copy_modulo_regions(tcx, param_env)
+                        || ty.references_error()
                 }
             }
         }
diff --git a/tests/ui/union/unresolved-field-isnt-copy.rs b/tests/ui/union/unresolved-field-isnt-copy.rs
new file mode 100644
index 00000000000..7a6d79b2faa
--- /dev/null
+++ b/tests/ui/union/unresolved-field-isnt-copy.rs
@@ -0,0 +1,8 @@
+// Unresolved fields are not copy, but also shouldn't report an extra E0740.
+
+pub union Foo {
+    x: *const Missing,
+    //~^ ERROR cannot find type `Missing` in this scope
+}
+
+fn main() {}
diff --git a/tests/ui/union/unresolved-field-isnt-copy.stderr b/tests/ui/union/unresolved-field-isnt-copy.stderr
new file mode 100644
index 00000000000..22301582eef
--- /dev/null
+++ b/tests/ui/union/unresolved-field-isnt-copy.stderr
@@ -0,0 +1,9 @@
+error[E0412]: cannot find type `Missing` in this scope
+  --> $DIR/unresolved-field-isnt-copy.rs:4:15
+   |
+LL |     x: *const Missing,
+   |               ^^^^^^^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0412`.