Skip to content

Commit fcb1f18

Browse files
committed
Don't show fields from other crates
1 parent 2e79f5f commit fcb1f18

File tree

2 files changed

+7
-35
lines changed

2 files changed

+7
-35
lines changed

compiler/rustc_lint/src/builtin.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,9 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
24992499
) -> Option<InitError> {
25002500
let field_err = variant.fields.iter().find_map(|field| {
25012501
ty_find_init_error(cx, field.ty(cx.tcx, substs), init).map(|mut err| {
2502-
if err.span.is_none() {
2502+
if !field.did.is_local() {
2503+
err
2504+
} else if err.span.is_none() {
25032505
err.span = Some(cx.tcx.def_span(field.did));
25042506
write!(&mut err.message, " (in this {descr})").unwrap();
25052507
err

src/test/ui/lint/invalid_value.stderr

+4-34
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,7 @@ LL | let _val: NonNull<i32> = mem::uninitialized();
332332
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
333333
|
334334
= note: `std::ptr::NonNull<i32>` must be non-null
335-
note: raw pointers must not be uninitialized (in this struct field)
336-
--> $SRC_DIR/core/src/ptr/non_null.rs:LL:COL
337-
|
338-
LL | pointer: *const T,
339-
| ^^^^^^^^^^^^^^^^^
335+
= note: raw pointers must not be uninitialized
340336

341337
error: the type `(NonZeroU32, i32)` does not permit zero-initialization
342338
--> $DIR/invalid_value.rs:95:39
@@ -359,18 +355,7 @@ LL | let _val: (NonZeroU32, i32) = mem::uninitialized();
359355
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
360356
|
361357
= note: `std::num::NonZeroU32` must be non-null
362-
note: integers must not be uninitialized (in this struct field)
363-
--> $SRC_DIR/core/src/num/nonzero.rs:LL:COL
364-
|
365-
LL | / nonzero_integers! {
366-
LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
367-
LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
368-
LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
369-
... |
370-
LL | | #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIs...
371-
LL | | }
372-
| |_^
373-
= note: this error originates in the macro `nonzero_integers` (in Nightly builds, run with -Z macro-backtrace for more info)
358+
= note: integers must not be uninitialized
374359

375360
error: the type `*const dyn Send` does not permit zero-initialization
376361
--> $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
477462
|
478463
LL | Banana(NonZeroU32),
479464
| ^^^^^^^^^^
480-
note: integers must not be uninitialized (in this struct field)
481-
--> $SRC_DIR/core/src/num/nonzero.rs:LL:COL
482-
|
483-
LL | / nonzero_integers! {
484-
LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
485-
LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
486-
LL | | #[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
487-
... |
488-
LL | | #[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIs...
489-
LL | | }
490-
| |_^
491-
= note: this error originates in the macro `nonzero_integers` (in Nightly builds, run with -Z macro-backtrace for more info)
465+
= note: integers must not be uninitialized
492466

493467
error: the type `bool` does not permit being left uninitialized
494468
--> $DIR/invalid_value.rs:112:26
@@ -688,11 +662,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init();
688662
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
689663
|
690664
= note: `std::ptr::NonNull<i32>` must be non-null
691-
note: raw pointers must not be uninitialized (in this struct field)
692-
--> $SRC_DIR/core/src/ptr/non_null.rs:LL:COL
693-
|
694-
LL | pointer: *const T,
695-
| ^^^^^^^^^^^^^^^^^
665+
= note: raw pointers must not be uninitialized
696666

697667
error: the type `bool` does not permit being left uninitialized
698668
--> $DIR/invalid_value.rs:159:26

0 commit comments

Comments
 (0)