From fcb1f1874f8c1b40b2ba5228a905c7875b21ce88 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 3 Nov 2022 15:30:52 +0000 Subject: [PATCH] Don't show fields from other crates --- compiler/rustc_lint/src/builtin.rs | 4 ++- src/test/ui/lint/invalid_value.stderr | 38 +++------------------------ 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 2f3a2dcb819..4bde57881f0 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2499,7 +2499,9 @@ fn variant_find_init_error<'tcx>( ) -> Option { let field_err = variant.fields.iter().find_map(|field| { ty_find_init_error(cx, field.ty(cx.tcx, substs), init).map(|mut err| { - if err.span.is_none() { + if !field.did.is_local() { + err + } else if err.span.is_none() { err.span = Some(cx.tcx.def_span(field.did)); write!(&mut err.message, " (in this {descr})").unwrap(); err diff --git a/src/test/ui/lint/invalid_value.stderr b/src/test/ui/lint/invalid_value.stderr index e9449605e35..9f0f51f4d97 100644 --- a/src/test/ui/lint/invalid_value.stderr +++ b/src/test/ui/lint/invalid_value.stderr @@ -332,11 +332,7 @@ LL | let _val: NonNull = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `std::ptr::NonNull` must be non-null -note: raw pointers must not be uninitialized (in this struct field) - --> $SRC_DIR/core/src/ptr/non_null.rs:LL:COL - | -LL | pointer: *const T, - | ^^^^^^^^^^^^^^^^^ + = note: raw pointers must not be uninitialized error: the type `(NonZeroU32, i32)` does not permit zero-initialization --> $DIR/invalid_value.rs:95:39 @@ -359,18 +355,7 @@ LL | let _val: (NonZeroU32, i32) = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `std::num::NonZeroU32` must be non-null -note: integers must not be uninitialized (in this struct field) - --> $SRC_DIR/core/src/num/nonzero.rs:LL:COL - | -LL | / nonzero_integers! { -LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8); -LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16); -LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32); -... | -LL | | #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIs... -LL | | } - | |_^ - = note: this error originates in the macro `nonzero_integers` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: integers must not be uninitialized error: the type `*const dyn Send` does not permit zero-initialization --> $DIR/invalid_value.rs:98:37 @@ -477,18 +462,7 @@ note: `std::num::NonZeroU32` must be non-null (in this field of the only potenti | LL | Banana(NonZeroU32), | ^^^^^^^^^^ -note: integers must not be uninitialized (in this struct field) - --> $SRC_DIR/core/src/num/nonzero.rs:LL:COL - | -LL | / nonzero_integers! { -LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8); -LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16); -LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32); -... | -LL | | #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIs... -LL | | } - | |_^ - = note: this error originates in the macro `nonzero_integers` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: integers must not be uninitialized error: the type `bool` does not permit being left uninitialized --> $DIR/invalid_value.rs:112:26 @@ -688,11 +662,7 @@ LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `std::ptr::NonNull` must be non-null -note: raw pointers must not be uninitialized (in this struct field) - --> $SRC_DIR/core/src/ptr/non_null.rs:LL:COL - | -LL | pointer: *const T, - | ^^^^^^^^^^^^^^^^^ + = note: raw pointers must not be uninitialized error: the type `bool` does not permit being left uninitialized --> $DIR/invalid_value.rs:159:26