From 08e5a77b069dc55481fef6a415c5bb8f056c00c9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 7 Mar 2023 22:03:12 +0000 Subject: [PATCH] Don't report E0740 for type error --- compiler/rustc_hir_analysis/src/check/check.rs | 4 +++- tests/ui/union/unresolved-field-isnt-copy.rs | 8 ++++++++ tests/ui/union/unresolved-field-isnt-copy.stderr | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/ui/union/unresolved-field-isnt-copy.rs create mode 100644 tests/ui/union/unresolved-field-isnt-copy.stderr 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`.