mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
rustc_lint: avoid trimmed paths for ty_find_init_error
This commit is contained in:
parent
51742be6d8
commit
e7d7615105
@ -40,6 +40,7 @@ use rustc_hir::{ForeignItemKind, GenericParamKind, PatKind};
|
||||
use rustc_hir::{HirId, HirIdSet, Node};
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_middle::lint::LintDiagnosticBuilder;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, Subst};
|
||||
use rustc_middle::ty::{self, layout::LayoutError, Ty, TyCtxt};
|
||||
use rustc_session::lint::FutureIncompatibleInfo;
|
||||
@ -2040,7 +2041,9 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
|
||||
// using zeroed or uninitialized memory.
|
||||
// We are extremely conservative with what we warn about.
|
||||
let conjured_ty = cx.typeck_results().expr_ty(expr);
|
||||
if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty, init) {
|
||||
if let Some((msg, span)) =
|
||||
with_no_trimmed_paths(|| ty_find_init_error(cx.tcx, conjured_ty, init))
|
||||
{
|
||||
cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| {
|
||||
let mut err = lint.build(&format!(
|
||||
"the type `{}` does not permit {}",
|
||||
|
@ -294,7 +294,7 @@ LL | let _val: NonNull<i32> = mem::zeroed();
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
|
|
||||
= note: `NonNull<i32>` must be non-null
|
||||
= note: `std::ptr::NonNull<i32>` must be non-null
|
||||
|
||||
error: the type `NonNull<i32>` does not permit being left uninitialized
|
||||
--> $DIR/uninitialized-zeroed.rs:80:34
|
||||
@ -305,7 +305,7 @@ LL | let _val: NonNull<i32> = mem::uninitialized();
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
|
|
||||
= note: `NonNull<i32>` must be non-null
|
||||
= note: `std::ptr::NonNull<i32>` must be non-null
|
||||
|
||||
error: the type `*const dyn Send` does not permit zero-initialization
|
||||
--> $DIR/uninitialized-zeroed.rs:82:37
|
||||
@ -415,7 +415,7 @@ LL | let _val: NonZeroU32 = mem::transmute(0);
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
|
|
||||
= note: `NonZeroU32` must be non-null
|
||||
= note: `std::num::NonZeroU32` must be non-null
|
||||
|
||||
error: the type `NonNull<i32>` does not permit zero-initialization
|
||||
--> $DIR/uninitialized-zeroed.rs:104:34
|
||||
@ -426,7 +426,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init();
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
|
|
||||
= note: `NonNull<i32>` must be non-null
|
||||
= note: `std::ptr::NonNull<i32>` must be non-null
|
||||
|
||||
error: the type `NonNull<i32>` does not permit being left uninitialized
|
||||
--> $DIR/uninitialized-zeroed.rs:105:34
|
||||
@ -437,7 +437,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init();
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
|
|
||||
= note: `NonNull<i32>` must be non-null
|
||||
= note: `std::ptr::NonNull<i32>` must be non-null
|
||||
|
||||
error: the type `bool` does not permit being left uninitialized
|
||||
--> $DIR/uninitialized-zeroed.rs:106:26
|
||||
|
Loading…
Reference in New Issue
Block a user