Skip to content

Commit e7d7615

Browse files
committed
rustc_lint: avoid trimmed paths for ty_find_init_error
1 parent 51742be commit e7d7615

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

compiler/rustc_lint/src/builtin.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use rustc_hir::{ForeignItemKind, GenericParamKind, PatKind};
4040
use rustc_hir::{HirId, HirIdSet, Node};
4141
use rustc_index::vec::Idx;
4242
use rustc_middle::lint::LintDiagnosticBuilder;
43+
use rustc_middle::ty::print::with_no_trimmed_paths;
4344
use rustc_middle::ty::subst::{GenericArgKind, Subst};
4445
use rustc_middle::ty::{self, layout::LayoutError, Ty, TyCtxt};
4546
use rustc_session::lint::FutureIncompatibleInfo;
@@ -2040,7 +2041,9 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
20402041
// using zeroed or uninitialized memory.
20412042
// We are extremely conservative with what we warn about.
20422043
let conjured_ty = cx.typeck_results().expr_ty(expr);
2043-
if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty, init) {
2044+
if let Some((msg, span)) =
2045+
with_no_trimmed_paths(|| ty_find_init_error(cx.tcx, conjured_ty, init))
2046+
{
20442047
cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| {
20452048
let mut err = lint.build(&format!(
20462049
"the type `{}` does not permit {}",

src/test/ui/lint/uninitialized-zeroed.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ LL | let _val: NonNull<i32> = mem::zeroed();
294294
| this code causes undefined behavior when executed
295295
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
296296
|
297-
= note: `NonNull<i32>` must be non-null
297+
= note: `std::ptr::NonNull<i32>` must be non-null
298298

299299
error: the type `NonNull<i32>` does not permit being left uninitialized
300300
--> $DIR/uninitialized-zeroed.rs:80:34
@@ -305,7 +305,7 @@ LL | let _val: NonNull<i32> = mem::uninitialized();
305305
| this code causes undefined behavior when executed
306306
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
307307
|
308-
= note: `NonNull<i32>` must be non-null
308+
= note: `std::ptr::NonNull<i32>` must be non-null
309309

310310
error: the type `*const dyn Send` does not permit zero-initialization
311311
--> $DIR/uninitialized-zeroed.rs:82:37
@@ -415,7 +415,7 @@ LL | let _val: NonZeroU32 = mem::transmute(0);
415415
| this code causes undefined behavior when executed
416416
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
417417
|
418-
= note: `NonZeroU32` must be non-null
418+
= note: `std::num::NonZeroU32` must be non-null
419419

420420
error: the type `NonNull<i32>` does not permit zero-initialization
421421
--> $DIR/uninitialized-zeroed.rs:104:34
@@ -426,7 +426,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init();
426426
| this code causes undefined behavior when executed
427427
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
428428
|
429-
= note: `NonNull<i32>` must be non-null
429+
= note: `std::ptr::NonNull<i32>` must be non-null
430430

431431
error: the type `NonNull<i32>` does not permit being left uninitialized
432432
--> $DIR/uninitialized-zeroed.rs:105:34
@@ -437,7 +437,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init();
437437
| this code causes undefined behavior when executed
438438
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
439439
|
440-
= note: `NonNull<i32>` must be non-null
440+
= note: `std::ptr::NonNull<i32>` must be non-null
441441

442442
error: the type `bool` does not permit being left uninitialized
443443
--> $DIR/uninitialized-zeroed.rs:106:26

0 commit comments

Comments
 (0)