From 10672f8bfe77f3f33619780c7a5a91673aee7984 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Tue, 9 Aug 2022 19:37:37 +0100 Subject: [PATCH 1/6] Add mem_uninitialized lint to FCW on most usages --- compiler/rustc_lint/src/builtin.rs | 198 +++++++++ compiler/rustc_lint/src/lib.rs | 1 + library/core/src/mem/maybe_uninit.rs | 2 + .../ui/const-generics/issues/issue-61422.rs | 2 +- .../mem-uninitialized-future-compat.rs | 60 +++ .../mem-uninitialized-future-compat.stderr | 375 +++++++++++++++++ .../panic-uninitialized-zeroed.mir.stderr | 338 +++++++++++++++ .../intrinsics/panic-uninitialized-zeroed.rs | 2 +- .../panic-uninitialized-zeroed.strict.stderr | 338 +++++++++++++++ .../panic-uninitialized-zeroed.thir.stderr | 338 +++++++++++++++ src/test/ui/lint/uninitialized-zeroed.rs | 2 +- src/test/ui/lint/uninitialized-zeroed.stderr | 392 ++++++++++++++++++ src/test/ui/uninit-empty-types.rs | 2 +- 13 files changed, 2046 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/intrinsics/mem-uninitialized-future-compat.rs create mode 100644 src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr create mode 100644 src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr create mode 100644 src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr create mode 100644 src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index f06bfa912ca5..6aeabdccf0bc 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2591,6 +2591,204 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { } } +declare_lint! { + /// The `mem_uninitialized` lint detects all uses of `std::mem::uninitialized` that are not + /// known to be safe. + /// + /// This function is extremely dangerous, and nearly all uses of it cause immediate Undefined + /// Behavior. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(mem_uninitialized)] + /// fn main() { + /// let x: [char; 16] = unsafe { std::mem::uninitialized() }; + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Creating an invalid value is undefined behavior, and nearly all types are invalid when left + /// uninitialized. + /// + /// To avoid churn, however, this will not lint for types made up entirely of integers, floats, + /// or raw pointers. This is not saying that leaving these types uninitialized is okay, + /// however. + pub MEM_UNINITIALIZED, + Warn, + "use of mem::uninitialized", + @future_incompatible = FutureIncompatibleInfo { + reference: "FIXME: fill this in", + reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow, + explain_reason: false, + }; +} + +declare_lint_pass!(MemUninitialized => [MEM_UNINITIALIZED]); + +impl<'tcx> LateLintPass<'tcx> for MemUninitialized { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) { + /// Information about why a type cannot be initialized this way. + /// Contains an error message and optionally a span to point at. + type InitError = (String, Option); + + /// Determine if this expression is a "dangerous initialization". + fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { + if let hir::ExprKind::Call(ref path_expr, _) = expr.kind { + // Find calls to `mem::{uninitialized,zeroed}` methods. + if let hir::ExprKind::Path(ref qpath) = path_expr.kind { + if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id() { + if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) { + return true; + } + } + } + } + + false + } + + /// Return `None` only if we are sure this type does + /// allow being left uninitialized. + fn ty_find_init_error<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { + use rustc_type_ir::sty::TyKind::*; + match ty.kind() { + // Primitive types that don't like 0 as a value. + Ref(..) => Some(("references must be non-null".to_string(), None)), + Adt(..) if ty.is_box() => Some(("`Box` must be non-null".to_string(), None)), + FnPtr(..) => Some(("function pointers must be non-null".to_string(), None)), + Never => Some(("the `!` type has no valid value".to_string(), None)), + RawPtr(tm) if matches!(tm.ty.kind(), Dynamic(..)) => + // raw ptr to dyn Trait + { + Some(("the vtable of a wide raw pointer must be non-null".to_string(), None)) + } + // Primitive types with other constraints. + Bool => Some(("booleans must be either `true` or `false`".to_string(), None)), + Char => Some(("characters must be a valid Unicode codepoint".to_string(), None)), + Adt(adt_def, _) if adt_def.is_union() => None, + // Recurse and checks for some compound types. + Adt(adt_def, substs) => { + // First check if this ADT has a layout attribute (like `NonNull` and friends). + use std::ops::Bound; + match cx.tcx.layout_scalar_valid_range(adt_def.did()) { + // We exploit here that `layout_scalar_valid_range` will never + // return `Bound::Excluded`. (And we have tests checking that we + // handle the attribute correctly.) + (Bound::Included(lo), _) if lo > 0 => { + return Some((format!("`{}` must be non-null", ty), None)); + } + (Bound::Included(_), _) | (_, Bound::Included(_)) => { + return Some(( + format!( + "`{}` must be initialized inside its custom valid range", + ty, + ), + None, + )); + } + _ => {} + } + // Now, recurse. + match adt_def.variants().len() { + 0 => Some(("enums with no variants have no valid value".to_string(), None)), + 1 => { + // Struct, or enum with exactly one variant. + // Proceed recursively, check all fields. + let variant = &adt_def.variant(VariantIdx::from_u32(0)); + variant.fields.iter().find_map(|field| { + ty_find_init_error(cx, field.ty(cx.tcx, substs)).map( + |(mut msg, span)| { + if span.is_none() { + // Point to this field, should be helpful for figuring + // out where the source of the error is. + let span = cx.tcx.def_span(field.did); + write!( + &mut msg, + " (in this {} field)", + adt_def.descr() + ) + .unwrap(); + (msg, Some(span)) + } else { + // Just forward. + (msg, span) + } + }, + ) + }) + } + // Multi-variant enum. + _ => { + // This will warn on something like Result, !> which + // is not UB under the current enum layout, even ignoring the 0x01 + // filling. + // + // That's probably fine though. + let span = cx.tcx.def_span(adt_def.did()); + Some(( + "enums have to be initialized to a variant".to_string(), + Some(span), + )) + } + } + } + Tuple(..) => { + // Proceed recursively, check all fields. + ty.tuple_fields().iter().find_map(|field| ty_find_init_error(cx, field)) + } + Array(ty, len) => { + match len.try_eval_usize(cx.tcx, cx.param_env) { + // Array known to be zero sized, we can't warn. + Some(0) => None, + + Some(_) | None => ty_find_init_error(cx, *ty), + } + } + Int(_) | Uint(_) | Float(_) | RawPtr(_) => { + // These are Plain Old Data types that people expect to work if they leave them + // uninitialized. + None + } + // Pessimistic fallback. + _ => Some(("type might not be allowed to be left uninitialized".to_string(), None)), + } + } + + if is_dangerous_init(cx, expr) { + // This conjures an instance of a type out of nothing, + // 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)) = with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty)) { + // FIXME(davidtwco): make translatable + cx.struct_span_lint(MEM_UNINITIALIZED, expr.span, |lint| { + let mut err = with_no_trimmed_paths!(lint.build(&format!( + "the type `{}` does not definitely permit being left uninitialized", + conjured_ty, + ))); + + err.span_label(expr.span, "this code causes undefined behavior when executed"); + err.span_label( + expr.span, + "help: use `MaybeUninit` instead, \ + and only call `assume_init` after initialization is done", + ); + if let Some(span) = span { + err.span_note(span, &msg); + } else { + err.note(&msg); + } + err.emit(); + }); + } + } + } +} + declare_lint! { /// The `clashing_extern_declarations` lint detects when an `extern fn` /// has been declared with the same name but different types. diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 370a75cf7006..b5cc970a4bd0 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -211,6 +211,7 @@ macro_rules! late_lint_mod_passes { UnreachablePub: UnreachablePub, ExplicitOutlivesRequirements: ExplicitOutlivesRequirements, InvalidValue: InvalidValue, + MemUninitialized: MemUninitialized, DerefNullPtr: DerefNullPtr, // May Depend on constants elsewhere UnusedBrokenConst: UnusedBrokenConst, diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 2490c07679dd..8efb3e4eff9f 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -33,6 +33,7 @@ use crate::slice; /// /// ```rust,no_run /// # #![allow(invalid_value)] +/// # #![cfg_attr(not(bootstrap), allow(mem_uninitialized))] /// use std::mem::{self, MaybeUninit}; /// /// let b: bool = unsafe { mem::uninitialized() }; // undefined behavior! ⚠️ @@ -48,6 +49,7 @@ use crate::slice; /// /// ```rust,no_run /// # #![allow(invalid_value)] +/// # #![cfg_attr(not(bootstrap), allow(mem_uninitialized))] /// use std::mem::{self, MaybeUninit}; /// /// let x: i32 = unsafe { mem::uninitialized() }; // undefined behavior! ⚠️ diff --git a/src/test/ui/const-generics/issues/issue-61422.rs b/src/test/ui/const-generics/issues/issue-61422.rs index 0b9cf40d8555..a48d0b9bfa25 100644 --- a/src/test/ui/const-generics/issues/issue-61422.rs +++ b/src/test/ui/const-generics/issues/issue-61422.rs @@ -7,7 +7,7 @@ use std::mem; fn foo() { let arr: [u8; SIZE] = unsafe { - #[allow(deprecated)] + #[allow(deprecated, mem_uninitialized)] let array: [u8; SIZE] = mem::uninitialized(); array }; diff --git a/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs b/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs new file mode 100644 index 000000000000..d20b63f8ffd4 --- /dev/null +++ b/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs @@ -0,0 +1,60 @@ +#![feature(never_type)] +#![deny(mem_uninitialized)] +#![allow(deprecated, invalid_value, dead_code)] + +use std::mem::MaybeUninit; + +struct UninitStruct { + a: u32, + b: char, +} + +unsafe fn unknown_type() { + std::mem::uninitialized::(); + //~^ ERROR the type `T` does not definitely permit being left uninitialized + + std::mem::uninitialized::<[T; N]>(); + //~^ ERROR the type `[T; N]` does not definitely permit being left uninitialized + + std::mem::uninitialized::<[char; N]>(); + //~^ ERROR the type `[char; N]` does not definitely permit being left uninitialized + + std::mem::uninitialized::<[T; 0]>(); + std::mem::uninitialized::<[char; 0]>(); +} + +fn main() { + unsafe { + std::mem::uninitialized::<&'static u32>(); + //~^ ERROR the type `&u32` does not definitely permit being left uninitialized + + std::mem::uninitialized::>(); + //~^ ERROR the type `std::boxed::Box` does not definitely permit being left uninitialized + + std::mem::uninitialized::(); + //~^ ERROR the type `fn()` does not definitely permit being left uninitialized + + std::mem::uninitialized::(); + //~^ ERROR the type `!` does not definitely permit being left uninitialized + + std::mem::uninitialized::<*mut dyn std::io::Write>(); + //~^ ERROR the type `*mut dyn std::io::Write` does not definitely permit being left uninitialized + + std::mem::uninitialized::(); + //~^ ERROR the type `bool` does not definitely permit being left uninitialized + + std::mem::uninitialized::(); + //~^ ERROR the type `char` does not definitely permit being left uninitialized + + std::mem::uninitialized::(); + //~^ ERROR the type `UninitStruct` does not definitely permit being left uninitialized + + std::mem::uninitialized::<(u32, char)>(); + //~^ ERROR the type `(u32, char)` does not definitely permit being left uninitialized + + std::mem::uninitialized::>>(); + std::mem::uninitialized::(); + std::mem::uninitialized::(); + std::mem::uninitialized::<*const u8>(); + } +} diff --git a/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr b/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr new file mode 100644 index 000000000000..1aa497046d8d --- /dev/null +++ b/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr @@ -0,0 +1,375 @@ +error: the type `T` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:13:5 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: type might not be allowed to be left uninitialized + +error: the type `[T; N]` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:16:5 + | +LL | std::mem::uninitialized::<[T; N]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: type might not be allowed to be left uninitialized + +error: the type `[char; N]` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:19:5 + | +LL | std::mem::uninitialized::<[char; N]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: characters must be a valid Unicode codepoint + +error: the type `&u32` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:28:9 + | +LL | std::mem::uninitialized::<&'static u32>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: references must be non-null + +error: the type `std::boxed::Box` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:31:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: `Box` must be non-null + +error: the type `fn()` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:34:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: function pointers must be non-null + +error: the type `!` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:37:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: the `!` type has no valid value + +error: the type `*mut dyn std::io::Write` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:40:9 + | +LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: the vtable of a wide raw pointer must be non-null + +error: the type `bool` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:43:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: booleans must be either `true` or `false` + +error: the type `char` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:46:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: characters must be a valid Unicode codepoint + +error: the type `UninitStruct` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:49:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this struct field) + --> $DIR/mem-uninitialized-future-compat.rs:9:5 + | +LL | b: char, + | ^^^^^^^ + +error: the type `(u32, char)` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:52:9 + | +LL | std::mem::uninitialized::<(u32, char)>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in + = note: characters must be a valid Unicode codepoint + +error: aborting due to 12 previous errors + +Future incompatibility report: Future breakage diagnostic: +error: the type `T` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:13:5 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: type might not be allowed to be left uninitialized + +Future breakage diagnostic: +error: the type `[T; N]` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:16:5 + | +LL | std::mem::uninitialized::<[T; N]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: type might not be allowed to be left uninitialized + +Future breakage diagnostic: +error: the type `[char; N]` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:19:5 + | +LL | std::mem::uninitialized::<[char; N]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: characters must be a valid Unicode codepoint + +Future breakage diagnostic: +error: the type `&u32` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:28:9 + | +LL | std::mem::uninitialized::<&'static u32>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: references must be non-null + +Future breakage diagnostic: +error: the type `std::boxed::Box` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:31:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `Box` must be non-null + +Future breakage diagnostic: +error: the type `fn()` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:34:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: function pointers must be non-null + +Future breakage diagnostic: +error: the type `!` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:37:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the `!` type has no valid value + +Future breakage diagnostic: +error: the type `*mut dyn std::io::Write` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:40:9 + | +LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the vtable of a wide raw pointer must be non-null + +Future breakage diagnostic: +error: the type `bool` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:43:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: booleans must be either `true` or `false` + +Future breakage diagnostic: +error: the type `char` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:46:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: characters must be a valid Unicode codepoint + +Future breakage diagnostic: +error: the type `UninitStruct` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:49:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this struct field) + --> $DIR/mem-uninitialized-future-compat.rs:9:5 + | +LL | b: char, + | ^^^^^^^ + +Future breakage diagnostic: +error: the type `(u32, char)` does not definitely permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:52:9 + | +LL | std::mem::uninitialized::<(u32, char)>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: characters must be a valid Unicode codepoint + diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr new file mode 100644 index 000000000000..79fe6be09c9a --- /dev/null +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr @@ -0,0 +1,338 @@ +Future incompatibility report: Future breakage diagnostic: +warning: the type `!` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:79:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the `!` type has no valid value + +Future breakage diagnostic: +warning: the type `Foo` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:92:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: the `!` type has no valid value (in this struct field) + --> $DIR/panic-uninitialized-zeroed.rs:24:5 + | +LL | y: !, + | ^^^^ + +Future breakage diagnostic: +warning: the type `Bar` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:105:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: enums with no variants have no valid value + +Future breakage diagnostic: +warning: the type `[Foo; 2]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:118:16 + | +LL | || mem::uninitialized::<[Foo; 2]>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: the `!` type has no valid value (in this struct field) + --> $DIR/panic-uninitialized-zeroed.rs:24:5 + | +LL | y: !, + | ^^^^ + +Future breakage diagnostic: +warning: the type `[Bar; 2]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:131:16 + | +LL | || mem::uninitialized::<[Bar; 2]>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: enums with no variants have no valid value + +Future breakage diagnostic: +warning: the type `fn()` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:145:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: function pointers must be non-null + +Future breakage diagnostic: +warning: the type `*const dyn std::marker::Send` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:154:16 + | +LL | || mem::uninitialized::<*const dyn Send>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the vtable of a wide raw pointer must be non-null + +Future breakage diagnostic: +warning: the type `(std::ptr::NonNull, u32, u32)` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:163:16 + | +LL | || mem::uninitialized::<(NonNull, u32, u32)>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `std::ptr::NonNull` must be non-null + +Future breakage diagnostic: +warning: the type `OneVariant_NonZero` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:175:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:33:1 + | +LL | enum OneVariant_NonZero { + | ^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `LR_NonZero` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:186:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:53:1 + | +LL | enum LR_NonZero { + | ^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:191:16 + | +LL | || mem::uninitialized::>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:53:1 + | +LL | enum LR_NonZero { + | ^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `NoNullVariant` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:197:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:41:1 + | +LL | enum NoNullVariant { + | ^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `bool` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:210:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: booleans must be either `true` or `false` + +Future breakage diagnostic: +warning: the type `LR` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:215:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:48:1 + | +LL | enum LR { + | ^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:220:16 + | +LL | || mem::uninitialized::>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:48:1 + | +LL | enum LR { + | ^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::MaybeUninit` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:233:20 + | +LL | let _val = mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: type might not be allowed to be left uninitialized + +Future breakage diagnostic: +warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:289:24 + | +LL | let _val = mem::uninitialized::<[NonNull<()>; 1]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `std::ptr::NonNull<()>` must be non-null + diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs index 255151a96032..d54a5b3de611 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs @@ -9,7 +9,7 @@ // This test checks panic emitted from `mem::{uninitialized,zeroed}`. #![feature(never_type, arbitrary_enum_discriminant)] -#![allow(deprecated, invalid_value)] +#![allow(deprecated, invalid_value, mem_uninitialized)] use std::{ mem::{self, MaybeUninit, ManuallyDrop}, diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr new file mode 100644 index 000000000000..79fe6be09c9a --- /dev/null +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr @@ -0,0 +1,338 @@ +Future incompatibility report: Future breakage diagnostic: +warning: the type `!` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:79:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the `!` type has no valid value + +Future breakage diagnostic: +warning: the type `Foo` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:92:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: the `!` type has no valid value (in this struct field) + --> $DIR/panic-uninitialized-zeroed.rs:24:5 + | +LL | y: !, + | ^^^^ + +Future breakage diagnostic: +warning: the type `Bar` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:105:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: enums with no variants have no valid value + +Future breakage diagnostic: +warning: the type `[Foo; 2]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:118:16 + | +LL | || mem::uninitialized::<[Foo; 2]>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: the `!` type has no valid value (in this struct field) + --> $DIR/panic-uninitialized-zeroed.rs:24:5 + | +LL | y: !, + | ^^^^ + +Future breakage diagnostic: +warning: the type `[Bar; 2]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:131:16 + | +LL | || mem::uninitialized::<[Bar; 2]>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: enums with no variants have no valid value + +Future breakage diagnostic: +warning: the type `fn()` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:145:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: function pointers must be non-null + +Future breakage diagnostic: +warning: the type `*const dyn std::marker::Send` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:154:16 + | +LL | || mem::uninitialized::<*const dyn Send>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the vtable of a wide raw pointer must be non-null + +Future breakage diagnostic: +warning: the type `(std::ptr::NonNull, u32, u32)` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:163:16 + | +LL | || mem::uninitialized::<(NonNull, u32, u32)>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `std::ptr::NonNull` must be non-null + +Future breakage diagnostic: +warning: the type `OneVariant_NonZero` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:175:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:33:1 + | +LL | enum OneVariant_NonZero { + | ^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `LR_NonZero` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:186:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:53:1 + | +LL | enum LR_NonZero { + | ^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:191:16 + | +LL | || mem::uninitialized::>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:53:1 + | +LL | enum LR_NonZero { + | ^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `NoNullVariant` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:197:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:41:1 + | +LL | enum NoNullVariant { + | ^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `bool` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:210:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: booleans must be either `true` or `false` + +Future breakage diagnostic: +warning: the type `LR` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:215:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:48:1 + | +LL | enum LR { + | ^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:220:16 + | +LL | || mem::uninitialized::>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:48:1 + | +LL | enum LR { + | ^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::MaybeUninit` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:233:20 + | +LL | let _val = mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: type might not be allowed to be left uninitialized + +Future breakage diagnostic: +warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:289:24 + | +LL | let _val = mem::uninitialized::<[NonNull<()>; 1]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `std::ptr::NonNull<()>` must be non-null + diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr new file mode 100644 index 000000000000..79fe6be09c9a --- /dev/null +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr @@ -0,0 +1,338 @@ +Future incompatibility report: Future breakage diagnostic: +warning: the type `!` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:79:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the `!` type has no valid value + +Future breakage diagnostic: +warning: the type `Foo` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:92:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: the `!` type has no valid value (in this struct field) + --> $DIR/panic-uninitialized-zeroed.rs:24:5 + | +LL | y: !, + | ^^^^ + +Future breakage diagnostic: +warning: the type `Bar` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:105:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: enums with no variants have no valid value + +Future breakage diagnostic: +warning: the type `[Foo; 2]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:118:16 + | +LL | || mem::uninitialized::<[Foo; 2]>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: the `!` type has no valid value (in this struct field) + --> $DIR/panic-uninitialized-zeroed.rs:24:5 + | +LL | y: !, + | ^^^^ + +Future breakage diagnostic: +warning: the type `[Bar; 2]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:131:16 + | +LL | || mem::uninitialized::<[Bar; 2]>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: enums with no variants have no valid value + +Future breakage diagnostic: +warning: the type `fn()` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:145:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: function pointers must be non-null + +Future breakage diagnostic: +warning: the type `*const dyn std::marker::Send` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:154:16 + | +LL | || mem::uninitialized::<*const dyn Send>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the vtable of a wide raw pointer must be non-null + +Future breakage diagnostic: +warning: the type `(std::ptr::NonNull, u32, u32)` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:163:16 + | +LL | || mem::uninitialized::<(NonNull, u32, u32)>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `std::ptr::NonNull` must be non-null + +Future breakage diagnostic: +warning: the type `OneVariant_NonZero` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:175:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:33:1 + | +LL | enum OneVariant_NonZero { + | ^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `LR_NonZero` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:186:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:53:1 + | +LL | enum LR_NonZero { + | ^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:191:16 + | +LL | || mem::uninitialized::>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:53:1 + | +LL | enum LR_NonZero { + | ^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `NoNullVariant` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:197:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:41:1 + | +LL | enum NoNullVariant { + | ^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `bool` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:210:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: booleans must be either `true` or `false` + +Future breakage diagnostic: +warning: the type `LR` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:215:16 + | +LL | || mem::uninitialized::(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:48:1 + | +LL | enum LR { + | ^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:220:16 + | +LL | || mem::uninitialized::>(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/panic-uninitialized-zeroed.rs:48:1 + | +LL | enum LR { + | ^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::mem::MaybeUninit` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:233:20 + | +LL | let _val = mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: type might not be allowed to be left uninitialized + +Future breakage diagnostic: +warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized + --> $DIR/panic-uninitialized-zeroed.rs:289:24 + | +LL | let _val = mem::uninitialized::<[NonNull<()>; 1]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/panic-uninitialized-zeroed.rs:12:37 + | +LL | #![allow(deprecated, invalid_value, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `std::ptr::NonNull<()>` must be non-null + diff --git a/src/test/ui/lint/uninitialized-zeroed.rs b/src/test/ui/lint/uninitialized-zeroed.rs index dae258407ebb..a00c7881fb91 100644 --- a/src/test/ui/lint/uninitialized-zeroed.rs +++ b/src/test/ui/lint/uninitialized-zeroed.rs @@ -2,7 +2,7 @@ // in a lint. #![feature(never_type, rustc_attrs)] -#![allow(deprecated)] +#![allow(deprecated, mem_uninitialized)] #![deny(invalid_value)] use std::mem::{self, MaybeUninit}; diff --git a/src/test/ui/lint/uninitialized-zeroed.stderr b/src/test/ui/lint/uninitialized-zeroed.stderr index b46042e7be43..b788c804c870 100644 --- a/src/test/ui/lint/uninitialized-zeroed.stderr +++ b/src/test/ui/lint/uninitialized-zeroed.stderr @@ -526,3 +526,395 @@ LL | let _val: bool = MaybeUninit::uninit().assume_init(); error: aborting due to 43 previous errors +Future incompatibility report: Future breakage diagnostic: +warning: the type `&T` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:41:32 + | +LL | let _val: &'static T = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: references must be non-null + +Future breakage diagnostic: +warning: the type `Wrap<&T>` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:44:38 + | +LL | let _val: Wrap<&'static T> = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: references must be non-null (in this struct field) + --> $DIR/uninitialized-zeroed.rs:17:18 + | +LL | struct Wrap { wrapped: T } + | ^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `!` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:52:23 + | +LL | let _val: ! = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the `!` type has no valid value + +Future breakage diagnostic: +warning: the type `(i32, !)` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:55:30 + | +LL | let _val: (i32, !) = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the `!` type has no valid value + +Future breakage diagnostic: +warning: the type `Void` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:58:26 + | +LL | let _val: Void = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: enums with no variants have no valid value + +Future breakage diagnostic: +warning: the type `&i32` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:61:34 + | +LL | let _val: &'static i32 = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: references must be non-null + +Future breakage diagnostic: +warning: the type `Ref` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:64:25 + | +LL | let _val: Ref = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: references must be non-null (in this struct field) + --> $DIR/uninitialized-zeroed.rs:14:12 + | +LL | struct Ref(&'static i32); + | ^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `fn()` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:67:26 + | +LL | let _val: fn() = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: function pointers must be non-null + +Future breakage diagnostic: +warning: the type `Wrap` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:70:32 + | +LL | let _val: Wrap = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: function pointers must be non-null (in this struct field) + --> $DIR/uninitialized-zeroed.rs:17:18 + | +LL | struct Wrap { wrapped: T } + | ^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `WrapEnum` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:73:36 + | +LL | let _val: WrapEnum = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: function pointers must be non-null (in this enum field) + --> $DIR/uninitialized-zeroed.rs:18:28 + | +LL | enum WrapEnum { Wrapped(T) } + | ^ + +Future breakage diagnostic: +warning: the type `Wrap<(RefPair, i32)>` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:76:42 + | +LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: references must be non-null (in this struct field) + --> $DIR/uninitialized-zeroed.rs:15:16 + | +LL | struct RefPair((&'static i32, i32)); + | ^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `std::ptr::NonNull` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:79:34 + | +LL | let _val: NonNull = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `std::ptr::NonNull` must be non-null + +Future breakage diagnostic: +warning: the type `*const dyn std::marker::Send` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:82:37 + | +LL | let _val: *const dyn Send = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: the vtable of a wide raw pointer must be non-null + +Future breakage diagnostic: +warning: the type `[fn(); 2]` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:85:31 + | +LL | let _val: [fn(); 2] = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: function pointers must be non-null + +Future breakage diagnostic: +warning: the type `bool` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:89:26 + | +LL | let _val: bool = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: booleans must be either `true` or `false` + +Future breakage diagnostic: +warning: the type `Wrap` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:92:32 + | +LL | let _val: Wrap = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this struct field) + --> $DIR/uninitialized-zeroed.rs:17:18 + | +LL | struct Wrap { wrapped: T } + | ^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `NonBig` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:95:28 + | +LL | let _val: NonBig = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: `NonBig` must be initialized inside its custom valid range + +Future breakage diagnostic: +warning: the type `Fruit` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:98:27 + | +LL | let _val: Fruit = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/uninitialized-zeroed.rs:26:1 + | +LL | enum Fruit { + | ^^^^^^^^^^ + +Future breakage diagnostic: +warning: the type `[bool; 2]` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:101:31 + | +LL | let _val: [bool; 2] = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in + = note: booleans must be either `true` or `false` + +Future breakage diagnostic: +warning: the type `OneFruit` does not definitely permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:124:30 + | +LL | let _val: OneFruit = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/uninitialized-zeroed.rs:5:22 + | +LL | #![allow(deprecated, mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/uninitialized-zeroed.rs:32:1 + | +LL | enum OneFruit { + | ^^^^^^^^^^^^^ + diff --git a/src/test/ui/uninit-empty-types.rs b/src/test/ui/uninit-empty-types.rs index b21de882b2ce..dff974f132fa 100644 --- a/src/test/ui/uninit-empty-types.rs +++ b/src/test/ui/uninit-empty-types.rs @@ -7,7 +7,7 @@ use std::mem::MaybeUninit; struct Foo; -#[allow(deprecated)] +#[allow(deprecated, mem_uninitialized)] pub fn main() { unsafe { // `Foo` and `[Foo; 2]` are both zero sized and inhabited, so this is safe. From ad8bc896722701b4848b3173689791cb68261a92 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Sat, 27 Aug 2022 21:31:37 +0100 Subject: [PATCH 2/6] Bless tests --- .../panic-uninitialized-zeroed.mir.stderr | 18 ------------------ .../panic-uninitialized-zeroed.strict.stderr | 18 ------------------ .../panic-uninitialized-zeroed.thir.stderr | 18 ------------------ 3 files changed, 54 deletions(-) diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr index 79fe6be09c9a..50bb02306fc5 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr @@ -300,24 +300,6 @@ note: enums have to be initialized to a variant LL | enum LR { | ^^^^^^^ -Future breakage diagnostic: -warning: the type `std::mem::MaybeUninit` does not definitely permit being left uninitialized - --> $DIR/panic-uninitialized-zeroed.rs:233:20 - | -LL | let _val = mem::uninitialized::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/panic-uninitialized-zeroed.rs:12:37 - | -LL | #![allow(deprecated, invalid_value, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: type might not be allowed to be left uninitialized - Future breakage diagnostic: warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:289:24 diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr index 79fe6be09c9a..50bb02306fc5 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr @@ -300,24 +300,6 @@ note: enums have to be initialized to a variant LL | enum LR { | ^^^^^^^ -Future breakage diagnostic: -warning: the type `std::mem::MaybeUninit` does not definitely permit being left uninitialized - --> $DIR/panic-uninitialized-zeroed.rs:233:20 - | -LL | let _val = mem::uninitialized::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/panic-uninitialized-zeroed.rs:12:37 - | -LL | #![allow(deprecated, invalid_value, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: type might not be allowed to be left uninitialized - Future breakage diagnostic: warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:289:24 diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr index 79fe6be09c9a..50bb02306fc5 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr @@ -300,24 +300,6 @@ note: enums have to be initialized to a variant LL | enum LR { | ^^^^^^^ -Future breakage diagnostic: -warning: the type `std::mem::MaybeUninit` does not definitely permit being left uninitialized - --> $DIR/panic-uninitialized-zeroed.rs:233:20 - | -LL | let _val = mem::uninitialized::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/panic-uninitialized-zeroed.rs:12:37 - | -LL | #![allow(deprecated, invalid_value, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: type might not be allowed to be left uninitialized - Future breakage diagnostic: warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:289:24 From 86a98df3df088c15b3c205ce6b020e4b9c762303 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Sun, 28 Aug 2022 11:39:15 +0100 Subject: [PATCH 3/6] Indicate when a type is generic or not generic --- compiler/rustc_lint/src/builtin.rs | 97 +++++++---- .../mem-uninitialized-future-compat.rs | 31 ++-- .../mem-uninitialized-future-compat.stderr | 162 +++++++++++++----- .../panic-uninitialized-zeroed.mir.stderr | 32 ++-- .../panic-uninitialized-zeroed.strict.stderr | 32 ++-- .../panic-uninitialized-zeroed.thir.stderr | 32 ++-- src/test/ui/lint/uninitialized-zeroed.stderr | 40 ++--- 7 files changed, 270 insertions(+), 156 deletions(-) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 6aeabdccf0bc..3b9684b5536f 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2633,7 +2633,29 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) { /// Information about why a type cannot be initialized this way. /// Contains an error message and optionally a span to point at. - type InitError = (String, Option); + struct InitError { + msg: String, + span: Option, + generic: bool, + } + + impl InitError { + fn new(msg: impl Into) -> Self { + Self { msg: msg.into(), span: None, generic: false } + } + + fn with_span(msg: impl Into, span: Span) -> Self { + Self { msg: msg.into(), span: Some(span), generic: false } + } + + fn generic() -> Self { + Self { + msg: "type might not be allowed to be left uninitialized".to_string(), + span: None, + generic: true, + } + } + } /// Determine if this expression is a "dangerous initialization". fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { @@ -2657,18 +2679,18 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { use rustc_type_ir::sty::TyKind::*; match ty.kind() { // Primitive types that don't like 0 as a value. - Ref(..) => Some(("references must be non-null".to_string(), None)), - Adt(..) if ty.is_box() => Some(("`Box` must be non-null".to_string(), None)), - FnPtr(..) => Some(("function pointers must be non-null".to_string(), None)), - Never => Some(("the `!` type has no valid value".to_string(), None)), + Ref(..) => Some(InitError::new("references must be non-null")), + Adt(..) if ty.is_box() => Some(InitError::new("`Box` must be non-null")), + FnPtr(..) => Some(InitError::new("function pointers must be non-null")), + Never => Some(InitError::new("the `!` type has no valid value")), RawPtr(tm) if matches!(tm.ty.kind(), Dynamic(..)) => // raw ptr to dyn Trait { - Some(("the vtable of a wide raw pointer must be non-null".to_string(), None)) + Some(InitError::new("the vtable of a wide raw pointer must be non-null")) } // Primitive types with other constraints. - Bool => Some(("booleans must be either `true` or `false`".to_string(), None)), - Char => Some(("characters must be a valid Unicode codepoint".to_string(), None)), + Bool => Some(InitError::new("booleans must be either `true` or `false`")), + Char => Some(InitError::new("characters must be a valid Unicode codepoint")), Adt(adt_def, _) if adt_def.is_union() => None, // Recurse and checks for some compound types. Adt(adt_def, substs) => { @@ -2679,29 +2701,25 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { // return `Bound::Excluded`. (And we have tests checking that we // handle the attribute correctly.) (Bound::Included(lo), _) if lo > 0 => { - return Some((format!("`{}` must be non-null", ty), None)); + return Some(InitError::new(format!("`{ty}` must be non-null"))); } (Bound::Included(_), _) | (_, Bound::Included(_)) => { - return Some(( - format!( - "`{}` must be initialized inside its custom valid range", - ty, - ), - None, - )); + return Some(InitError::new(format!( + "`{ty}` must be initialized inside its custom valid range" + ))); } _ => {} } // Now, recurse. match adt_def.variants().len() { - 0 => Some(("enums with no variants have no valid value".to_string(), None)), + 0 => Some(InitError::new("enums with no variants have no valid value")), 1 => { // Struct, or enum with exactly one variant. // Proceed recursively, check all fields. let variant = &adt_def.variant(VariantIdx::from_u32(0)); variant.fields.iter().find_map(|field| { ty_find_init_error(cx, field.ty(cx.tcx, substs)).map( - |(mut msg, span)| { + |InitError { mut msg, span, generic }| { if span.is_none() { // Point to this field, should be helpful for figuring // out where the source of the error is. @@ -2712,10 +2730,11 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { adt_def.descr() ) .unwrap(); - (msg, Some(span)) + + InitError { msg, span: Some(span), generic } } else { // Just forward. - (msg, span) + InitError { msg, span, generic } } }, ) @@ -2729,9 +2748,9 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { // // That's probably fine though. let span = cx.tcx.def_span(adt_def.did()); - Some(( - "enums have to be initialized to a variant".to_string(), - Some(span), + Some(InitError::with_span( + "enums have to be initialized to a variant", + span, )) } } @@ -2745,7 +2764,14 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { // Array known to be zero sized, we can't warn. Some(0) => None, - Some(_) | None => ty_find_init_error(cx, *ty), + // Array length known to be nonzero, warn. + Some(1..) => ty_find_init_error(cx, *ty), + + // Array length unknown, use the "might not permit" wording. + None => ty_find_init_error(cx, *ty).map(|mut e| { + e.generic = true; + e + }), } } Int(_) | Uint(_) | Float(_) | RawPtr(_) => { @@ -2754,7 +2780,7 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { None } // Pessimistic fallback. - _ => Some(("type might not be allowed to be left uninitialized".to_string(), None)), + _ => Some(InitError::generic()), } } @@ -2763,13 +2789,18 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { // 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)) = with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty)) { + if let Some(init_error) = with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty)) { + let main_msg = with_no_trimmed_paths!(if init_error.generic { + format!( + "the type `{conjured_ty}` is generic, and might not permit being left uninitialized" + ) + } else { + format!("the type `{conjured_ty}` does not permit being left uninitialized") + }); + // FIXME(davidtwco): make translatable cx.struct_span_lint(MEM_UNINITIALIZED, expr.span, |lint| { - let mut err = with_no_trimmed_paths!(lint.build(&format!( - "the type `{}` does not definitely permit being left uninitialized", - conjured_ty, - ))); + let mut err = lint.build(&main_msg); err.span_label(expr.span, "this code causes undefined behavior when executed"); err.span_label( @@ -2777,10 +2808,10 @@ impl<'tcx> LateLintPass<'tcx> for MemUninitialized { "help: use `MaybeUninit` instead, \ and only call `assume_init` after initialization is done", ); - if let Some(span) = span { - err.span_note(span, &msg); + if let Some(span) = init_error.span { + err.span_note(span, &init_error.msg); } else { - err.note(&msg); + err.note(&init_error.msg); } err.emit(); }); diff --git a/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs b/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs index d20b63f8ffd4..abfc2271ac15 100644 --- a/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs +++ b/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs @@ -11,13 +11,16 @@ struct UninitStruct { unsafe fn unknown_type() { std::mem::uninitialized::(); - //~^ ERROR the type `T` does not definitely permit being left uninitialized + //~^ ERROR the type `T` is generic, and might not permit being left uninitialized std::mem::uninitialized::<[T; N]>(); - //~^ ERROR the type `[T; N]` does not definitely permit being left uninitialized + //~^ ERROR the type `[T; N]` is generic, and might not permit being left uninitialized std::mem::uninitialized::<[char; N]>(); - //~^ ERROR the type `[char; N]` does not definitely permit being left uninitialized + //~^ ERROR the type `[char; N]` is generic, and might not permit being left uninitialized + + std::mem::uninitialized::<[UninitStruct; N]>(); + //~^ ERROR the type `[UninitStruct; N]` is generic, and might not permit being left uninitialized std::mem::uninitialized::<[T; 0]>(); std::mem::uninitialized::<[char; 0]>(); @@ -26,35 +29,39 @@ unsafe fn unknown_type() { fn main() { unsafe { std::mem::uninitialized::<&'static u32>(); - //~^ ERROR the type `&u32` does not definitely permit being left uninitialized + //~^ ERROR the type `&u32` does not permit being left uninitialized std::mem::uninitialized::>(); - //~^ ERROR the type `std::boxed::Box` does not definitely permit being left uninitialized + //~^ ERROR the type `std::boxed::Box` does not permit being left uninitialized std::mem::uninitialized::(); - //~^ ERROR the type `fn()` does not definitely permit being left uninitialized + //~^ ERROR the type `fn()` does not permit being left uninitialized std::mem::uninitialized::(); - //~^ ERROR the type `!` does not definitely permit being left uninitialized + //~^ ERROR the type `!` does not permit being left uninitialized std::mem::uninitialized::<*mut dyn std::io::Write>(); - //~^ ERROR the type `*mut dyn std::io::Write` does not definitely permit being left uninitialized + //~^ ERROR the type `*mut dyn std::io::Write` does not permit being left uninitialized std::mem::uninitialized::(); - //~^ ERROR the type `bool` does not definitely permit being left uninitialized + //~^ ERROR the type `bool` does not permit being left uninitialized std::mem::uninitialized::(); - //~^ ERROR the type `char` does not definitely permit being left uninitialized + //~^ ERROR the type `char` does not permit being left uninitialized std::mem::uninitialized::(); - //~^ ERROR the type `UninitStruct` does not definitely permit being left uninitialized + //~^ ERROR the type `UninitStruct` does not permit being left uninitialized + + std::mem::uninitialized::<[UninitStruct; 16]>(); + //~^ ERROR the type `[UninitStruct; 16]` does not permit being left uninitialized std::mem::uninitialized::<(u32, char)>(); - //~^ ERROR the type `(u32, char)` does not definitely permit being left uninitialized + //~^ ERROR the type `(u32, char)` does not permit being left uninitialized std::mem::uninitialized::>>(); std::mem::uninitialized::(); std::mem::uninitialized::(); std::mem::uninitialized::<*const u8>(); + std::mem::uninitialized::<[u8; 64]>(); } } diff --git a/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr b/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr index 1aa497046d8d..8111b24a4669 100644 --- a/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr +++ b/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr @@ -1,4 +1,4 @@ -error: the type `T` does not definitely permit being left uninitialized +error: the type `T` is generic, and might not permit being left uninitialized --> $DIR/mem-uninitialized-future-compat.rs:13:5 | LL | std::mem::uninitialized::(); @@ -15,7 +15,7 @@ LL | #![deny(mem_uninitialized)] = note: for more information, see FIXME: fill this in = note: type might not be allowed to be left uninitialized -error: the type `[T; N]` does not definitely permit being left uninitialized +error: the type `[T; N]` is generic, and might not permit being left uninitialized --> $DIR/mem-uninitialized-future-compat.rs:16:5 | LL | std::mem::uninitialized::<[T; N]>(); @@ -27,7 +27,7 @@ LL | std::mem::uninitialized::<[T; N]>(); = note: for more information, see FIXME: fill this in = note: type might not be allowed to be left uninitialized -error: the type `[char; N]` does not definitely permit being left uninitialized +error: the type `[char; N]` is generic, and might not permit being left uninitialized --> $DIR/mem-uninitialized-future-compat.rs:19:5 | LL | std::mem::uninitialized::<[char; N]>(); @@ -39,8 +39,24 @@ LL | std::mem::uninitialized::<[char; N]>(); = note: for more information, see FIXME: fill this in = note: characters must be a valid Unicode codepoint -error: the type `&u32` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:28:9 +error: the type `[UninitStruct; N]` is generic, and might not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:22:5 + | +LL | std::mem::uninitialized::<[UninitStruct; N]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this struct field) + --> $DIR/mem-uninitialized-future-compat.rs:9:5 + | +LL | b: char, + | ^^^^^^^ + +error: the type `&u32` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:31:9 | LL | std::mem::uninitialized::<&'static u32>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,8 +67,8 @@ LL | std::mem::uninitialized::<&'static u32>(); = note: for more information, see FIXME: fill this in = note: references must be non-null -error: the type `std::boxed::Box` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:31:9 +error: the type `std::boxed::Box` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:34:9 | LL | std::mem::uninitialized::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,8 +79,8 @@ LL | std::mem::uninitialized::>(); = note: for more information, see FIXME: fill this in = note: `Box` must be non-null -error: the type `fn()` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:34:9 +error: the type `fn()` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:37:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,8 +91,8 @@ LL | std::mem::uninitialized::(); = note: for more information, see FIXME: fill this in = note: function pointers must be non-null -error: the type `!` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:37:9 +error: the type `!` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:40:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -87,8 +103,8 @@ LL | std::mem::uninitialized::(); = note: for more information, see FIXME: fill this in = note: the `!` type has no valid value -error: the type `*mut dyn std::io::Write` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:40:9 +error: the type `*mut dyn std::io::Write` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:43:9 | LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -99,8 +115,8 @@ LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); = note: for more information, see FIXME: fill this in = note: the vtable of a wide raw pointer must be non-null -error: the type `bool` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:43:9 +error: the type `bool` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:46:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,8 +127,8 @@ LL | std::mem::uninitialized::(); = note: for more information, see FIXME: fill this in = note: booleans must be either `true` or `false` -error: the type `char` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:46:9 +error: the type `char` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:49:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,8 +139,8 @@ LL | std::mem::uninitialized::(); = note: for more information, see FIXME: fill this in = note: characters must be a valid Unicode codepoint -error: the type `UninitStruct` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:49:9 +error: the type `UninitStruct` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:52:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,8 +155,24 @@ note: characters must be a valid Unicode codepoint (in this struct field) LL | b: char, | ^^^^^^^ -error: the type `(u32, char)` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:52:9 +error: the type `[UninitStruct; 16]` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:55:9 + | +LL | std::mem::uninitialized::<[UninitStruct; 16]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this struct field) + --> $DIR/mem-uninitialized-future-compat.rs:9:5 + | +LL | b: char, + | ^^^^^^^ + +error: the type `(u32, char)` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:58:9 | LL | std::mem::uninitialized::<(u32, char)>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -151,10 +183,10 @@ LL | std::mem::uninitialized::<(u32, char)>(); = note: for more information, see FIXME: fill this in = note: characters must be a valid Unicode codepoint -error: aborting due to 12 previous errors +error: aborting due to 14 previous errors Future incompatibility report: Future breakage diagnostic: -error: the type `T` does not definitely permit being left uninitialized +error: the type `T` is generic, and might not permit being left uninitialized --> $DIR/mem-uninitialized-future-compat.rs:13:5 | LL | std::mem::uninitialized::(); @@ -172,7 +204,7 @@ LL | #![deny(mem_uninitialized)] = note: type might not be allowed to be left uninitialized Future breakage diagnostic: -error: the type `[T; N]` does not definitely permit being left uninitialized +error: the type `[T; N]` is generic, and might not permit being left uninitialized --> $DIR/mem-uninitialized-future-compat.rs:16:5 | LL | std::mem::uninitialized::<[T; N]>(); @@ -190,7 +222,7 @@ LL | #![deny(mem_uninitialized)] = note: type might not be allowed to be left uninitialized Future breakage diagnostic: -error: the type `[char; N]` does not definitely permit being left uninitialized +error: the type `[char; N]` is generic, and might not permit being left uninitialized --> $DIR/mem-uninitialized-future-compat.rs:19:5 | LL | std::mem::uninitialized::<[char; N]>(); @@ -208,8 +240,30 @@ LL | #![deny(mem_uninitialized)] = note: characters must be a valid Unicode codepoint Future breakage diagnostic: -error: the type `&u32` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:28:9 +error: the type `[UninitStruct; N]` is generic, and might not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:22:5 + | +LL | std::mem::uninitialized::<[UninitStruct; N]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this struct field) + --> $DIR/mem-uninitialized-future-compat.rs:9:5 + | +LL | b: char, + | ^^^^^^^ + +Future breakage diagnostic: +error: the type `&u32` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:31:9 | LL | std::mem::uninitialized::<&'static u32>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -226,8 +280,8 @@ LL | #![deny(mem_uninitialized)] = note: references must be non-null Future breakage diagnostic: -error: the type `std::boxed::Box` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:31:9 +error: the type `std::boxed::Box` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:34:9 | LL | std::mem::uninitialized::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -244,8 +298,8 @@ LL | #![deny(mem_uninitialized)] = note: `Box` must be non-null Future breakage diagnostic: -error: the type `fn()` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:34:9 +error: the type `fn()` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:37:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -262,8 +316,8 @@ LL | #![deny(mem_uninitialized)] = note: function pointers must be non-null Future breakage diagnostic: -error: the type `!` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:37:9 +error: the type `!` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:40:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -280,8 +334,8 @@ LL | #![deny(mem_uninitialized)] = note: the `!` type has no valid value Future breakage diagnostic: -error: the type `*mut dyn std::io::Write` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:40:9 +error: the type `*mut dyn std::io::Write` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:43:9 | LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -298,8 +352,8 @@ LL | #![deny(mem_uninitialized)] = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: -error: the type `bool` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:43:9 +error: the type `bool` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:46:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -316,8 +370,8 @@ LL | #![deny(mem_uninitialized)] = note: booleans must be either `true` or `false` Future breakage diagnostic: -error: the type `char` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:46:9 +error: the type `char` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:49:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -334,8 +388,8 @@ LL | #![deny(mem_uninitialized)] = note: characters must be a valid Unicode codepoint Future breakage diagnostic: -error: the type `UninitStruct` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:49:9 +error: the type `UninitStruct` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:52:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -356,8 +410,30 @@ LL | b: char, | ^^^^^^^ Future breakage diagnostic: -error: the type `(u32, char)` does not definitely permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:52:9 +error: the type `[UninitStruct; 16]` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:55:9 + | +LL | std::mem::uninitialized::<[UninitStruct; 16]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this struct field) + --> $DIR/mem-uninitialized-future-compat.rs:9:5 + | +LL | b: char, + | ^^^^^^^ + +Future breakage diagnostic: +error: the type `(u32, char)` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:58:9 | LL | std::mem::uninitialized::<(u32, char)>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr index 50bb02306fc5..6d571c38845c 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr @@ -1,5 +1,5 @@ Future incompatibility report: Future breakage diagnostic: -warning: the type `!` does not definitely permit being left uninitialized +warning: the type `!` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:79:16 | LL | || mem::uninitialized::(), @@ -17,7 +17,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: the `!` type has no valid value Future breakage diagnostic: -warning: the type `Foo` does not definitely permit being left uninitialized +warning: the type `Foo` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:92:16 | LL | || mem::uninitialized::(), @@ -39,7 +39,7 @@ LL | y: !, | ^^^^ Future breakage diagnostic: -warning: the type `Bar` does not definitely permit being left uninitialized +warning: the type `Bar` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:105:16 | LL | || mem::uninitialized::(), @@ -57,7 +57,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: enums with no variants have no valid value Future breakage diagnostic: -warning: the type `[Foo; 2]` does not definitely permit being left uninitialized +warning: the type `[Foo; 2]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:118:16 | LL | || mem::uninitialized::<[Foo; 2]>(), @@ -79,7 +79,7 @@ LL | y: !, | ^^^^ Future breakage diagnostic: -warning: the type `[Bar; 2]` does not definitely permit being left uninitialized +warning: the type `[Bar; 2]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:131:16 | LL | || mem::uninitialized::<[Bar; 2]>(), @@ -97,7 +97,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: enums with no variants have no valid value Future breakage diagnostic: -warning: the type `fn()` does not definitely permit being left uninitialized +warning: the type `fn()` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:145:16 | LL | || mem::uninitialized::(), @@ -115,7 +115,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: function pointers must be non-null Future breakage diagnostic: -warning: the type `*const dyn std::marker::Send` does not definitely permit being left uninitialized +warning: the type `*const dyn std::marker::Send` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:154:16 | LL | || mem::uninitialized::<*const dyn Send>(), @@ -133,7 +133,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: -warning: the type `(std::ptr::NonNull, u32, u32)` does not definitely permit being left uninitialized +warning: the type `(std::ptr::NonNull, u32, u32)` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:163:16 | LL | || mem::uninitialized::<(NonNull, u32, u32)>(), @@ -151,7 +151,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: `std::ptr::NonNull` must be non-null Future breakage diagnostic: -warning: the type `OneVariant_NonZero` does not definitely permit being left uninitialized +warning: the type `OneVariant_NonZero` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:175:16 | LL | || mem::uninitialized::(), @@ -173,7 +173,7 @@ LL | enum OneVariant_NonZero { | ^^^^^^^^^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `LR_NonZero` does not definitely permit being left uninitialized +warning: the type `LR_NonZero` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:186:16 | LL | || mem::uninitialized::(), @@ -195,7 +195,7 @@ LL | enum LR_NonZero { | ^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized +warning: the type `std::mem::ManuallyDrop` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:191:16 | LL | || mem::uninitialized::>(), @@ -217,7 +217,7 @@ LL | enum LR_NonZero { | ^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `NoNullVariant` does not definitely permit being left uninitialized +warning: the type `NoNullVariant` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:197:16 | LL | || mem::uninitialized::(), @@ -239,7 +239,7 @@ LL | enum NoNullVariant { | ^^^^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `bool` does not definitely permit being left uninitialized +warning: the type `bool` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:210:16 | LL | || mem::uninitialized::(), @@ -257,7 +257,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: booleans must be either `true` or `false` Future breakage diagnostic: -warning: the type `LR` does not definitely permit being left uninitialized +warning: the type `LR` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:215:16 | LL | || mem::uninitialized::(), @@ -279,7 +279,7 @@ LL | enum LR { | ^^^^^^^ Future breakage diagnostic: -warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized +warning: the type `std::mem::ManuallyDrop` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:220:16 | LL | || mem::uninitialized::>(), @@ -301,7 +301,7 @@ LL | enum LR { | ^^^^^^^ Future breakage diagnostic: -warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized +warning: the type `[std::ptr::NonNull<()>; 1]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:289:24 | LL | let _val = mem::uninitialized::<[NonNull<()>; 1]>(); diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr index 50bb02306fc5..6d571c38845c 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr @@ -1,5 +1,5 @@ Future incompatibility report: Future breakage diagnostic: -warning: the type `!` does not definitely permit being left uninitialized +warning: the type `!` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:79:16 | LL | || mem::uninitialized::(), @@ -17,7 +17,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: the `!` type has no valid value Future breakage diagnostic: -warning: the type `Foo` does not definitely permit being left uninitialized +warning: the type `Foo` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:92:16 | LL | || mem::uninitialized::(), @@ -39,7 +39,7 @@ LL | y: !, | ^^^^ Future breakage diagnostic: -warning: the type `Bar` does not definitely permit being left uninitialized +warning: the type `Bar` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:105:16 | LL | || mem::uninitialized::(), @@ -57,7 +57,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: enums with no variants have no valid value Future breakage diagnostic: -warning: the type `[Foo; 2]` does not definitely permit being left uninitialized +warning: the type `[Foo; 2]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:118:16 | LL | || mem::uninitialized::<[Foo; 2]>(), @@ -79,7 +79,7 @@ LL | y: !, | ^^^^ Future breakage diagnostic: -warning: the type `[Bar; 2]` does not definitely permit being left uninitialized +warning: the type `[Bar; 2]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:131:16 | LL | || mem::uninitialized::<[Bar; 2]>(), @@ -97,7 +97,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: enums with no variants have no valid value Future breakage diagnostic: -warning: the type `fn()` does not definitely permit being left uninitialized +warning: the type `fn()` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:145:16 | LL | || mem::uninitialized::(), @@ -115,7 +115,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: function pointers must be non-null Future breakage diagnostic: -warning: the type `*const dyn std::marker::Send` does not definitely permit being left uninitialized +warning: the type `*const dyn std::marker::Send` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:154:16 | LL | || mem::uninitialized::<*const dyn Send>(), @@ -133,7 +133,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: -warning: the type `(std::ptr::NonNull, u32, u32)` does not definitely permit being left uninitialized +warning: the type `(std::ptr::NonNull, u32, u32)` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:163:16 | LL | || mem::uninitialized::<(NonNull, u32, u32)>(), @@ -151,7 +151,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: `std::ptr::NonNull` must be non-null Future breakage diagnostic: -warning: the type `OneVariant_NonZero` does not definitely permit being left uninitialized +warning: the type `OneVariant_NonZero` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:175:16 | LL | || mem::uninitialized::(), @@ -173,7 +173,7 @@ LL | enum OneVariant_NonZero { | ^^^^^^^^^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `LR_NonZero` does not definitely permit being left uninitialized +warning: the type `LR_NonZero` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:186:16 | LL | || mem::uninitialized::(), @@ -195,7 +195,7 @@ LL | enum LR_NonZero { | ^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized +warning: the type `std::mem::ManuallyDrop` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:191:16 | LL | || mem::uninitialized::>(), @@ -217,7 +217,7 @@ LL | enum LR_NonZero { | ^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `NoNullVariant` does not definitely permit being left uninitialized +warning: the type `NoNullVariant` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:197:16 | LL | || mem::uninitialized::(), @@ -239,7 +239,7 @@ LL | enum NoNullVariant { | ^^^^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `bool` does not definitely permit being left uninitialized +warning: the type `bool` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:210:16 | LL | || mem::uninitialized::(), @@ -257,7 +257,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: booleans must be either `true` or `false` Future breakage diagnostic: -warning: the type `LR` does not definitely permit being left uninitialized +warning: the type `LR` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:215:16 | LL | || mem::uninitialized::(), @@ -279,7 +279,7 @@ LL | enum LR { | ^^^^^^^ Future breakage diagnostic: -warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized +warning: the type `std::mem::ManuallyDrop` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:220:16 | LL | || mem::uninitialized::>(), @@ -301,7 +301,7 @@ LL | enum LR { | ^^^^^^^ Future breakage diagnostic: -warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized +warning: the type `[std::ptr::NonNull<()>; 1]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:289:24 | LL | let _val = mem::uninitialized::<[NonNull<()>; 1]>(); diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr index 50bb02306fc5..6d571c38845c 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr @@ -1,5 +1,5 @@ Future incompatibility report: Future breakage diagnostic: -warning: the type `!` does not definitely permit being left uninitialized +warning: the type `!` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:79:16 | LL | || mem::uninitialized::(), @@ -17,7 +17,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: the `!` type has no valid value Future breakage diagnostic: -warning: the type `Foo` does not definitely permit being left uninitialized +warning: the type `Foo` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:92:16 | LL | || mem::uninitialized::(), @@ -39,7 +39,7 @@ LL | y: !, | ^^^^ Future breakage diagnostic: -warning: the type `Bar` does not definitely permit being left uninitialized +warning: the type `Bar` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:105:16 | LL | || mem::uninitialized::(), @@ -57,7 +57,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: enums with no variants have no valid value Future breakage diagnostic: -warning: the type `[Foo; 2]` does not definitely permit being left uninitialized +warning: the type `[Foo; 2]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:118:16 | LL | || mem::uninitialized::<[Foo; 2]>(), @@ -79,7 +79,7 @@ LL | y: !, | ^^^^ Future breakage diagnostic: -warning: the type `[Bar; 2]` does not definitely permit being left uninitialized +warning: the type `[Bar; 2]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:131:16 | LL | || mem::uninitialized::<[Bar; 2]>(), @@ -97,7 +97,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: enums with no variants have no valid value Future breakage diagnostic: -warning: the type `fn()` does not definitely permit being left uninitialized +warning: the type `fn()` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:145:16 | LL | || mem::uninitialized::(), @@ -115,7 +115,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: function pointers must be non-null Future breakage diagnostic: -warning: the type `*const dyn std::marker::Send` does not definitely permit being left uninitialized +warning: the type `*const dyn std::marker::Send` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:154:16 | LL | || mem::uninitialized::<*const dyn Send>(), @@ -133,7 +133,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: -warning: the type `(std::ptr::NonNull, u32, u32)` does not definitely permit being left uninitialized +warning: the type `(std::ptr::NonNull, u32, u32)` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:163:16 | LL | || mem::uninitialized::<(NonNull, u32, u32)>(), @@ -151,7 +151,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: `std::ptr::NonNull` must be non-null Future breakage diagnostic: -warning: the type `OneVariant_NonZero` does not definitely permit being left uninitialized +warning: the type `OneVariant_NonZero` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:175:16 | LL | || mem::uninitialized::(), @@ -173,7 +173,7 @@ LL | enum OneVariant_NonZero { | ^^^^^^^^^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `LR_NonZero` does not definitely permit being left uninitialized +warning: the type `LR_NonZero` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:186:16 | LL | || mem::uninitialized::(), @@ -195,7 +195,7 @@ LL | enum LR_NonZero { | ^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized +warning: the type `std::mem::ManuallyDrop` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:191:16 | LL | || mem::uninitialized::>(), @@ -217,7 +217,7 @@ LL | enum LR_NonZero { | ^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `NoNullVariant` does not definitely permit being left uninitialized +warning: the type `NoNullVariant` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:197:16 | LL | || mem::uninitialized::(), @@ -239,7 +239,7 @@ LL | enum NoNullVariant { | ^^^^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `bool` does not definitely permit being left uninitialized +warning: the type `bool` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:210:16 | LL | || mem::uninitialized::(), @@ -257,7 +257,7 @@ LL | #![allow(deprecated, invalid_value, mem_uninitialized)] = note: booleans must be either `true` or `false` Future breakage diagnostic: -warning: the type `LR` does not definitely permit being left uninitialized +warning: the type `LR` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:215:16 | LL | || mem::uninitialized::(), @@ -279,7 +279,7 @@ LL | enum LR { | ^^^^^^^ Future breakage diagnostic: -warning: the type `std::mem::ManuallyDrop` does not definitely permit being left uninitialized +warning: the type `std::mem::ManuallyDrop` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:220:16 | LL | || mem::uninitialized::>(), @@ -301,7 +301,7 @@ LL | enum LR { | ^^^^^^^ Future breakage diagnostic: -warning: the type `[std::ptr::NonNull<()>; 1]` does not definitely permit being left uninitialized +warning: the type `[std::ptr::NonNull<()>; 1]` does not permit being left uninitialized --> $DIR/panic-uninitialized-zeroed.rs:289:24 | LL | let _val = mem::uninitialized::<[NonNull<()>; 1]>(); diff --git a/src/test/ui/lint/uninitialized-zeroed.stderr b/src/test/ui/lint/uninitialized-zeroed.stderr index b788c804c870..0c79f2ac1cb7 100644 --- a/src/test/ui/lint/uninitialized-zeroed.stderr +++ b/src/test/ui/lint/uninitialized-zeroed.stderr @@ -527,7 +527,7 @@ LL | let _val: bool = MaybeUninit::uninit().assume_init(); error: aborting due to 43 previous errors Future incompatibility report: Future breakage diagnostic: -warning: the type `&T` does not definitely permit being left uninitialized +warning: the type `&T` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:41:32 | LL | let _val: &'static T = mem::uninitialized(); @@ -545,7 +545,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: references must be non-null Future breakage diagnostic: -warning: the type `Wrap<&T>` does not definitely permit being left uninitialized +warning: the type `Wrap<&T>` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:44:38 | LL | let _val: Wrap<&'static T> = mem::uninitialized(); @@ -567,7 +567,7 @@ LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ Future breakage diagnostic: -warning: the type `!` does not definitely permit being left uninitialized +warning: the type `!` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:52:23 | LL | let _val: ! = mem::uninitialized(); @@ -585,7 +585,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: the `!` type has no valid value Future breakage diagnostic: -warning: the type `(i32, !)` does not definitely permit being left uninitialized +warning: the type `(i32, !)` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:55:30 | LL | let _val: (i32, !) = mem::uninitialized(); @@ -603,7 +603,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: the `!` type has no valid value Future breakage diagnostic: -warning: the type `Void` does not definitely permit being left uninitialized +warning: the type `Void` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:58:26 | LL | let _val: Void = mem::uninitialized(); @@ -621,7 +621,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: enums with no variants have no valid value Future breakage diagnostic: -warning: the type `&i32` does not definitely permit being left uninitialized +warning: the type `&i32` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:61:34 | LL | let _val: &'static i32 = mem::uninitialized(); @@ -639,7 +639,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: references must be non-null Future breakage diagnostic: -warning: the type `Ref` does not definitely permit being left uninitialized +warning: the type `Ref` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:64:25 | LL | let _val: Ref = mem::uninitialized(); @@ -661,7 +661,7 @@ LL | struct Ref(&'static i32); | ^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `fn()` does not definitely permit being left uninitialized +warning: the type `fn()` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:67:26 | LL | let _val: fn() = mem::uninitialized(); @@ -679,7 +679,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: function pointers must be non-null Future breakage diagnostic: -warning: the type `Wrap` does not definitely permit being left uninitialized +warning: the type `Wrap` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:70:32 | LL | let _val: Wrap = mem::uninitialized(); @@ -701,7 +701,7 @@ LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ Future breakage diagnostic: -warning: the type `WrapEnum` does not definitely permit being left uninitialized +warning: the type `WrapEnum` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:73:36 | LL | let _val: WrapEnum = mem::uninitialized(); @@ -723,7 +723,7 @@ LL | enum WrapEnum { Wrapped(T) } | ^ Future breakage diagnostic: -warning: the type `Wrap<(RefPair, i32)>` does not definitely permit being left uninitialized +warning: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:76:42 | LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); @@ -745,7 +745,7 @@ LL | struct RefPair((&'static i32, i32)); | ^^^^^^^^^^^^^^^^^^^ Future breakage diagnostic: -warning: the type `std::ptr::NonNull` does not definitely permit being left uninitialized +warning: the type `std::ptr::NonNull` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:79:34 | LL | let _val: NonNull = mem::uninitialized(); @@ -763,7 +763,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: `std::ptr::NonNull` must be non-null Future breakage diagnostic: -warning: the type `*const dyn std::marker::Send` does not definitely permit being left uninitialized +warning: the type `*const dyn std::marker::Send` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:82:37 | LL | let _val: *const dyn Send = mem::uninitialized(); @@ -781,7 +781,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: -warning: the type `[fn(); 2]` does not definitely permit being left uninitialized +warning: the type `[fn(); 2]` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:85:31 | LL | let _val: [fn(); 2] = mem::uninitialized(); @@ -799,7 +799,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: function pointers must be non-null Future breakage diagnostic: -warning: the type `bool` does not definitely permit being left uninitialized +warning: the type `bool` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:89:26 | LL | let _val: bool = mem::uninitialized(); @@ -817,7 +817,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: booleans must be either `true` or `false` Future breakage diagnostic: -warning: the type `Wrap` does not definitely permit being left uninitialized +warning: the type `Wrap` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:92:32 | LL | let _val: Wrap = mem::uninitialized(); @@ -839,7 +839,7 @@ LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ Future breakage diagnostic: -warning: the type `NonBig` does not definitely permit being left uninitialized +warning: the type `NonBig` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:95:28 | LL | let _val: NonBig = mem::uninitialized(); @@ -857,7 +857,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: `NonBig` must be initialized inside its custom valid range Future breakage diagnostic: -warning: the type `Fruit` does not definitely permit being left uninitialized +warning: the type `Fruit` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:98:27 | LL | let _val: Fruit = mem::uninitialized(); @@ -879,7 +879,7 @@ LL | enum Fruit { | ^^^^^^^^^^ Future breakage diagnostic: -warning: the type `[bool; 2]` does not definitely permit being left uninitialized +warning: the type `[bool; 2]` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:101:31 | LL | let _val: [bool; 2] = mem::uninitialized(); @@ -897,7 +897,7 @@ LL | #![allow(deprecated, mem_uninitialized)] = note: booleans must be either `true` or `false` Future breakage diagnostic: -warning: the type `OneFruit` does not definitely permit being left uninitialized +warning: the type `OneFruit` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:124:30 | LL | let _val: OneFruit = mem::uninitialized(); From dc4b6a94e8b0eb492e5858abdb75b15c82b91d7d Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Sun, 28 Aug 2022 23:24:27 +0100 Subject: [PATCH 4/6] Ignore invalid_value lint if mem_uninitialized would lint --- compiler/rustc_lint/src/builtin.rs | 273 ++--------- compiler/rustc_lint/src/lib.rs | 3 + compiler/rustc_lint/src/mem_uninitialized.rs | 233 +++++++++ src/test/ui/lint/uninitialized-zeroed.rs | 40 +- src/test/ui/lint/uninitialized-zeroed.stderr | 468 ++----------------- 5 files changed, 325 insertions(+), 692 deletions(-) create mode 100644 compiler/rustc_lint/src/mem_uninitialized.rs diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 3b9684b5536f..a4261048d8d0 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2366,7 +2366,13 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { #[derive(Debug, Copy, Clone, PartialEq)] enum InitKind { Zeroed, - Uninit, + Uninit { is_mem_uninit: bool }, + } + + impl InitKind { + fn is_uninit(self) -> bool { + matches!(self, InitKind::Uninit { .. }) + } } /// Information about why a type cannot be initialized this way. @@ -2398,7 +2404,9 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { let def_id = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()?; match cx.tcx.get_diagnostic_name(def_id) { Some(sym::mem_zeroed) => return Some(InitKind::Zeroed), - Some(sym::mem_uninitialized) => return Some(InitKind::Uninit), + Some(sym::mem_uninitialized) => { + return Some(InitKind::Uninit { is_mem_uninit: true }); + } Some(sym::transmute) if is_zero(&args[0]) => return Some(InitKind::Zeroed), _ => {} } @@ -2414,7 +2422,9 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { let def_id = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()?; match cx.tcx.get_diagnostic_name(def_id) { Some(sym::maybe_uninit_zeroed) => return Some(InitKind::Zeroed), - Some(sym::maybe_uninit_uninit) => return Some(InitKind::Uninit), + Some(sym::maybe_uninit_uninit) => { + return Some(InitKind::Uninit { is_mem_uninit: false }); + } _ => {} } } @@ -2453,19 +2463,19 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { Some(("the vtable of a wide raw pointer must be non-null".to_string(), None)) } // Primitive types with other constraints. - Bool if init == InitKind::Uninit => { + Bool if init.is_uninit() => { Some(("booleans must be either `true` or `false`".to_string(), None)) } - Char if init == InitKind::Uninit => { + Char if init.is_uninit() => { Some(("characters must be a valid Unicode codepoint".to_string(), None)) } - Int(_) | Uint(_) if init == InitKind::Uninit => { + Int(_) | Uint(_) if init.is_uninit() => { Some(("integers must not be uninitialized".to_string(), None)) } - Float(_) if init == InitKind::Uninit => { + Float(_) if init.is_uninit() => { Some(("floats must not be uninitialized".to_string(), None)) } - RawPtr(_) if init == InitKind::Uninit => { + RawPtr(_) if init.is_uninit() => { Some(("raw pointers must not be uninitialized".to_string(), None)) } // Recurse and checks for some compound types. @@ -2479,9 +2489,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { (Bound::Included(lo), _) if lo > 0 => { return Some((format!("`{}` must be non-null", ty), None)); } - (Bound::Included(_), _) | (_, Bound::Included(_)) - if init == InitKind::Uninit => - { + (Bound::Included(_), _) | (_, Bound::Included(_)) if init.is_uninit() => { return Some(( format!( "`{}` must be initialized inside its custom valid range", @@ -2523,7 +2531,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { } // Multi-variant enum. _ => { - if init == InitKind::Uninit && is_multi_variant(*adt_def) { + if init.is_uninit() && is_multi_variant(*adt_def) { let span = cx.tcx.def_span(adt_def.did()); Some(( "enums have to be initialized to a variant".to_string(), @@ -2560,6 +2568,16 @@ 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 init == (InitKind::Uninit { is_mem_uninit: true }) { + // We don't want to warn here for things that mem_uninitialized will warn about + if with_no_trimmed_paths!( + crate::mem_uninitialized::ty_find_init_error(cx, conjured_ty).is_some() + ) { + return; + } + } + if let Some((msg, span)) = with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty, init)) { @@ -2570,7 +2588,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { conjured_ty, match init { InitKind::Zeroed => "zero-initialization", - InitKind::Uninit => "being left uninitialized", + InitKind::Uninit { .. } => "being left uninitialized", }, )); err.span_label(expr.span, "this code causes undefined behavior when executed"); @@ -2591,235 +2609,6 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { } } -declare_lint! { - /// The `mem_uninitialized` lint detects all uses of `std::mem::uninitialized` that are not - /// known to be safe. - /// - /// This function is extremely dangerous, and nearly all uses of it cause immediate Undefined - /// Behavior. - /// - /// ### Example - /// - /// ```rust,compile_fail - /// #![deny(mem_uninitialized)] - /// fn main() { - /// let x: [char; 16] = unsafe { std::mem::uninitialized() }; - /// } - /// ``` - /// - /// {{produces}} - /// - /// ### Explanation - /// - /// Creating an invalid value is undefined behavior, and nearly all types are invalid when left - /// uninitialized. - /// - /// To avoid churn, however, this will not lint for types made up entirely of integers, floats, - /// or raw pointers. This is not saying that leaving these types uninitialized is okay, - /// however. - pub MEM_UNINITIALIZED, - Warn, - "use of mem::uninitialized", - @future_incompatible = FutureIncompatibleInfo { - reference: "FIXME: fill this in", - reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow, - explain_reason: false, - }; -} - -declare_lint_pass!(MemUninitialized => [MEM_UNINITIALIZED]); - -impl<'tcx> LateLintPass<'tcx> for MemUninitialized { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) { - /// Information about why a type cannot be initialized this way. - /// Contains an error message and optionally a span to point at. - struct InitError { - msg: String, - span: Option, - generic: bool, - } - - impl InitError { - fn new(msg: impl Into) -> Self { - Self { msg: msg.into(), span: None, generic: false } - } - - fn with_span(msg: impl Into, span: Span) -> Self { - Self { msg: msg.into(), span: Some(span), generic: false } - } - - fn generic() -> Self { - Self { - msg: "type might not be allowed to be left uninitialized".to_string(), - span: None, - generic: true, - } - } - } - - /// Determine if this expression is a "dangerous initialization". - fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { - if let hir::ExprKind::Call(ref path_expr, _) = expr.kind { - // Find calls to `mem::{uninitialized,zeroed}` methods. - if let hir::ExprKind::Path(ref qpath) = path_expr.kind { - if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id() { - if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) { - return true; - } - } - } - } - - false - } - - /// Return `None` only if we are sure this type does - /// allow being left uninitialized. - fn ty_find_init_error<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { - use rustc_type_ir::sty::TyKind::*; - match ty.kind() { - // Primitive types that don't like 0 as a value. - Ref(..) => Some(InitError::new("references must be non-null")), - Adt(..) if ty.is_box() => Some(InitError::new("`Box` must be non-null")), - FnPtr(..) => Some(InitError::new("function pointers must be non-null")), - Never => Some(InitError::new("the `!` type has no valid value")), - RawPtr(tm) if matches!(tm.ty.kind(), Dynamic(..)) => - // raw ptr to dyn Trait - { - Some(InitError::new("the vtable of a wide raw pointer must be non-null")) - } - // Primitive types with other constraints. - Bool => Some(InitError::new("booleans must be either `true` or `false`")), - Char => Some(InitError::new("characters must be a valid Unicode codepoint")), - Adt(adt_def, _) if adt_def.is_union() => None, - // Recurse and checks for some compound types. - Adt(adt_def, substs) => { - // First check if this ADT has a layout attribute (like `NonNull` and friends). - use std::ops::Bound; - match cx.tcx.layout_scalar_valid_range(adt_def.did()) { - // We exploit here that `layout_scalar_valid_range` will never - // return `Bound::Excluded`. (And we have tests checking that we - // handle the attribute correctly.) - (Bound::Included(lo), _) if lo > 0 => { - return Some(InitError::new(format!("`{ty}` must be non-null"))); - } - (Bound::Included(_), _) | (_, Bound::Included(_)) => { - return Some(InitError::new(format!( - "`{ty}` must be initialized inside its custom valid range" - ))); - } - _ => {} - } - // Now, recurse. - match adt_def.variants().len() { - 0 => Some(InitError::new("enums with no variants have no valid value")), - 1 => { - // Struct, or enum with exactly one variant. - // Proceed recursively, check all fields. - let variant = &adt_def.variant(VariantIdx::from_u32(0)); - variant.fields.iter().find_map(|field| { - ty_find_init_error(cx, field.ty(cx.tcx, substs)).map( - |InitError { mut msg, span, generic }| { - if span.is_none() { - // Point to this field, should be helpful for figuring - // out where the source of the error is. - let span = cx.tcx.def_span(field.did); - write!( - &mut msg, - " (in this {} field)", - adt_def.descr() - ) - .unwrap(); - - InitError { msg, span: Some(span), generic } - } else { - // Just forward. - InitError { msg, span, generic } - } - }, - ) - }) - } - // Multi-variant enum. - _ => { - // This will warn on something like Result, !> which - // is not UB under the current enum layout, even ignoring the 0x01 - // filling. - // - // That's probably fine though. - let span = cx.tcx.def_span(adt_def.did()); - Some(InitError::with_span( - "enums have to be initialized to a variant", - span, - )) - } - } - } - Tuple(..) => { - // Proceed recursively, check all fields. - ty.tuple_fields().iter().find_map(|field| ty_find_init_error(cx, field)) - } - Array(ty, len) => { - match len.try_eval_usize(cx.tcx, cx.param_env) { - // Array known to be zero sized, we can't warn. - Some(0) => None, - - // Array length known to be nonzero, warn. - Some(1..) => ty_find_init_error(cx, *ty), - - // Array length unknown, use the "might not permit" wording. - None => ty_find_init_error(cx, *ty).map(|mut e| { - e.generic = true; - e - }), - } - } - Int(_) | Uint(_) | Float(_) | RawPtr(_) => { - // These are Plain Old Data types that people expect to work if they leave them - // uninitialized. - None - } - // Pessimistic fallback. - _ => Some(InitError::generic()), - } - } - - if is_dangerous_init(cx, expr) { - // This conjures an instance of a type out of nothing, - // 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(init_error) = with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty)) { - let main_msg = with_no_trimmed_paths!(if init_error.generic { - format!( - "the type `{conjured_ty}` is generic, and might not permit being left uninitialized" - ) - } else { - format!("the type `{conjured_ty}` does not permit being left uninitialized") - }); - - // FIXME(davidtwco): make translatable - cx.struct_span_lint(MEM_UNINITIALIZED, expr.span, |lint| { - let mut err = lint.build(&main_msg); - - err.span_label(expr.span, "this code causes undefined behavior when executed"); - err.span_label( - expr.span, - "help: use `MaybeUninit` instead, \ - and only call `assume_init` after initialization is done", - ); - if let Some(span) = init_error.span { - err.span_note(span, &init_error.msg); - } else { - err.note(&init_error.msg); - } - err.emit(); - }); - } - } - } -} - declare_lint! { /// The `clashing_extern_declarations` lint detects when an `extern fn` /// has been declared with the same name but different types. diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index b5cc970a4bd0..54ce067d5446 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -57,6 +57,7 @@ mod internal; mod late; mod let_underscore; mod levels; +mod mem_uninitialized; mod methods; mod non_ascii_idents; mod non_fmt_panic; @@ -69,6 +70,8 @@ mod traits; mod types; mod unused; +use mem_uninitialized::MemUninitialized; + pub use array_into_iter::ARRAY_INTO_ITER; use rustc_ast as ast; diff --git a/compiler/rustc_lint/src/mem_uninitialized.rs b/compiler/rustc_lint/src/mem_uninitialized.rs new file mode 100644 index 000000000000..f14441d0ce73 --- /dev/null +++ b/compiler/rustc_lint/src/mem_uninitialized.rs @@ -0,0 +1,233 @@ +use crate::context::LintContext; +use crate::LateContext; +use crate::LateLintPass; +use rustc_hir as hir; +use rustc_middle::ty::print::with_no_trimmed_paths; +use rustc_middle::ty::Ty; +use rustc_session::lint::FutureIncompatibilityReason; +use rustc_span::symbol::sym; +use rustc_span::Span; +use rustc_target::abi::VariantIdx; +use std::fmt::Write; + +declare_lint! { + /// The `mem_uninitialized` lint detects all uses of `std::mem::uninitialized` that are not + /// known to be safe. + /// + /// This function is extremely dangerous, and nearly all uses of it cause immediate Undefined + /// Behavior. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(mem_uninitialized)] + /// fn main() { + /// let x: [char; 16] = unsafe { std::mem::uninitialized() }; + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Creating an invalid value is undefined behavior, and nearly all types are invalid when left + /// uninitialized. + /// + /// To avoid churn, however, this will not lint for types made up entirely of integers, floats, + /// or raw pointers. This is not saying that leaving these types uninitialized is okay, + /// however. + pub MEM_UNINITIALIZED, + Warn, + "use of mem::uninitialized", + @future_incompatible = FutureIncompatibleInfo { + reference: "FIXME: fill this in", + reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow, + explain_reason: false, + }; +} + +declare_lint_pass!(MemUninitialized => [MEM_UNINITIALIZED]); + +/// Information about why a type cannot be initialized this way. +/// Contains an error message and optionally a span to point at. +pub struct InitError { + msg: String, + span: Option, + generic: bool, +} + +impl InitError { + fn new(msg: impl Into) -> Self { + Self { msg: msg.into(), span: None, generic: false } + } + + fn with_span(msg: impl Into, span: Span) -> Self { + Self { msg: msg.into(), span: Some(span), generic: false } + } + + fn generic() -> Self { + Self { + msg: "type might not be allowed to be left uninitialized".to_string(), + span: None, + generic: true, + } + } +} + +/// Return `None` only if we are sure this type does +/// allow being left uninitialized. +pub fn ty_find_init_error<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { + use rustc_type_ir::sty::TyKind::*; + match ty.kind() { + // Primitive types that don't like 0 as a value. + Ref(..) => Some(InitError::new("references must be non-null")), + Adt(..) if ty.is_box() => Some(InitError::new("`Box` must be non-null")), + FnPtr(..) => Some(InitError::new("function pointers must be non-null")), + Never => Some(InitError::new("the `!` type has no valid value")), + RawPtr(tm) if matches!(tm.ty.kind(), Dynamic(..)) => + // raw ptr to dyn Trait + { + Some(InitError::new("the vtable of a wide raw pointer must be non-null")) + } + // Primitive types with other constraints. + Bool => Some(InitError::new("booleans must be either `true` or `false`")), + Char => Some(InitError::new("characters must be a valid Unicode codepoint")), + Adt(adt_def, _) if adt_def.is_union() => None, + // Recurse and checks for some compound types. + Adt(adt_def, substs) => { + // First check if this ADT has a layout attribute (like `NonNull` and friends). + use std::ops::Bound; + match cx.tcx.layout_scalar_valid_range(adt_def.did()) { + // We exploit here that `layout_scalar_valid_range` will never + // return `Bound::Excluded`. (And we have tests checking that we + // handle the attribute correctly.) + (Bound::Included(lo), _) if lo > 0 => { + return Some(InitError::new(format!("`{ty}` must be non-null"))); + } + (Bound::Included(_), _) | (_, Bound::Included(_)) => { + return Some(InitError::new(format!( + "`{ty}` must be initialized inside its custom valid range" + ))); + } + _ => {} + } + // Now, recurse. + match adt_def.variants().len() { + 0 => Some(InitError::new("enums with no variants have no valid value")), + 1 => { + // Struct, or enum with exactly one variant. + // Proceed recursively, check all fields. + let variant = &adt_def.variant(VariantIdx::from_u32(0)); + variant.fields.iter().find_map(|field| { + ty_find_init_error(cx, field.ty(cx.tcx, substs)).map( + |InitError { mut msg, span, generic }| { + if span.is_none() { + // Point to this field, should be helpful for figuring + // out where the source of the error is. + let span = cx.tcx.def_span(field.did); + write!(&mut msg, " (in this {} field)", adt_def.descr()) + .unwrap(); + + InitError { msg, span: Some(span), generic } + } else { + // Just forward. + InitError { msg, span, generic } + } + }, + ) + }) + } + // Multi-variant enum. + _ => { + // This will warn on something like Result, !> which + // is not UB under the current enum layout, even ignoring the 0x01 + // filling. + // + // That's probably fine though. + let span = cx.tcx.def_span(adt_def.did()); + Some(InitError::with_span("enums have to be initialized to a variant", span)) + } + } + } + Tuple(..) => { + // Proceed recursively, check all fields. + ty.tuple_fields().iter().find_map(|field| ty_find_init_error(cx, field)) + } + Array(ty, len) => { + match len.try_eval_usize(cx.tcx, cx.param_env) { + // Array known to be zero sized, we can't warn. + Some(0) => None, + + // Array length known to be nonzero, warn. + Some(1..) => ty_find_init_error(cx, *ty), + + // Array length unknown, use the "might not permit" wording. + None => ty_find_init_error(cx, *ty).map(|mut e| { + e.generic = true; + e + }), + } + } + Int(_) | Uint(_) | Float(_) | RawPtr(_) => { + // These are Plain Old Data types that people expect to work if they leave them + // uninitialized. + None + } + // Pessimistic fallback. + _ => Some(InitError::generic()), + } +} + +impl<'tcx> LateLintPass<'tcx> for MemUninitialized { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) { + /// Determine if this expression is a "dangerous initialization". + fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { + if let hir::ExprKind::Call(ref path_expr, _) = expr.kind { + // Find calls to `mem::{uninitialized,zeroed}` methods. + if let hir::ExprKind::Path(ref qpath) = path_expr.kind { + if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id() { + if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) { + return true; + } + } + } + } + + false + } + + if is_dangerous_init(cx, expr) { + // This conjures an instance of a type out of nothing, + // 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(init_error) = with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty)) { + let main_msg = with_no_trimmed_paths!(if init_error.generic { + format!( + "the type `{conjured_ty}` is generic, and might not permit being left uninitialized" + ) + } else { + format!("the type `{conjured_ty}` does not permit being left uninitialized") + }); + + // FIXME(davidtwco): make translatable + cx.struct_span_lint(MEM_UNINITIALIZED, expr.span, |lint| { + let mut err = lint.build(&main_msg); + + err.span_label(expr.span, "this code causes undefined behavior when executed"); + err.span_label( + expr.span, + "help: use `MaybeUninit` instead, \ + and only call `assume_init` after initialization is done", + ); + if let Some(span) = init_error.span { + err.span_note(span, &init_error.msg); + } else { + err.note(&init_error.msg); + } + err.emit(); + }); + } + } + } +} diff --git a/src/test/ui/lint/uninitialized-zeroed.rs b/src/test/ui/lint/uninitialized-zeroed.rs index a00c7881fb91..d4c3cbdb57ff 100644 --- a/src/test/ui/lint/uninitialized-zeroed.rs +++ b/src/test/ui/lint/uninitialized-zeroed.rs @@ -38,10 +38,10 @@ enum OneFruit { fn generic() { unsafe { let _val: &'static T = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: &'static T = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: &'static T = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: Wrap<&'static T> = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: Wrap<&'static T> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: Wrap<&'static T> = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized } } @@ -49,56 +49,56 @@ fn main() { unsafe { // Things that cannot even be zero. let _val: ! = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: ! = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: ! = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: (i32, !) = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: (i32, !) = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: (i32, !) = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: Void = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: Void = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: Void = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: &'static i32 = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: &'static i32 = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: &'static i32 = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: Ref = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: Ref = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: Ref = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: fn() = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: fn() = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: fn() = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: Wrap = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: Wrap = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: Wrap = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: WrapEnum = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: WrapEnum = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: WrapEnum = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: Wrap<(RefPair, i32)> = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: Wrap<(RefPair, i32)> = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: NonNull = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: NonNull = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: NonNull = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: *const dyn Send = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: *const dyn Send = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: *const dyn Send = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: [fn(); 2] = mem::zeroed(); //~ ERROR: does not permit zero-initialization - let _val: [fn(); 2] = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: [fn(); 2] = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized // Things that can be zero, but not uninit. let _val: bool = mem::zeroed(); - let _val: bool = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: bool = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: Wrap = mem::zeroed(); - let _val: Wrap = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: Wrap = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: NonBig = mem::zeroed(); - let _val: NonBig = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: NonBig = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: Fruit = mem::zeroed(); - let _val: Fruit = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: Fruit = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: [bool; 2] = mem::zeroed(); - let _val: [bool; 2] = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: [bool; 2] = MaybeUninit::uninit().assume_init(); //~ ERROR: does not permit being left uninitialized let _val: i32 = mem::zeroed(); let _val: i32 = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized @@ -132,6 +132,6 @@ fn main() { // Some things that happen to work due to rustc implementation details, // but are not guaranteed to keep working. - let _val: OneFruit = mem::uninitialized(); + let _val: OneFruit = MaybeUninit::uninit().assume_init(); } } diff --git a/src/test/ui/lint/uninitialized-zeroed.stderr b/src/test/ui/lint/uninitialized-zeroed.stderr index 0c79f2ac1cb7..b6bf46e14fe2 100644 --- a/src/test/ui/lint/uninitialized-zeroed.stderr +++ b/src/test/ui/lint/uninitialized-zeroed.stderr @@ -17,8 +17,8 @@ LL | #![deny(invalid_value)] error: the type `&T` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:41:32 | -LL | let _val: &'static T = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: &'static T = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -43,8 +43,8 @@ LL | struct Wrap { wrapped: T } error: the type `Wrap<&T>` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:44:38 | -LL | let _val: Wrap<&'static T> = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: Wrap<&'static T> = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -69,8 +69,8 @@ LL | let _val: ! = mem::zeroed(); error: the type `!` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:52:23 | -LL | let _val: ! = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: ! = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -91,8 +91,8 @@ LL | let _val: (i32, !) = mem::zeroed(); error: the type `(i32, !)` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:55:30 | -LL | let _val: (i32, !) = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: (i32, !) = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -113,8 +113,8 @@ LL | let _val: Void = mem::zeroed(); error: the type `Void` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:58:26 | -LL | let _val: Void = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: Void = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -135,8 +135,8 @@ LL | let _val: &'static i32 = mem::zeroed(); error: the type `&i32` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:61:34 | -LL | let _val: &'static i32 = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: &'static i32 = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -161,8 +161,8 @@ LL | struct Ref(&'static i32); error: the type `Ref` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:64:25 | -LL | let _val: Ref = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: Ref = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -187,8 +187,8 @@ LL | let _val: fn() = mem::zeroed(); error: the type `fn()` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:67:26 | -LL | let _val: fn() = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: fn() = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -213,8 +213,8 @@ LL | struct Wrap { wrapped: T } error: the type `Wrap` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:70:32 | -LL | let _val: Wrap = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: Wrap = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -243,8 +243,8 @@ LL | enum WrapEnum { Wrapped(T) } error: the type `WrapEnum` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:73:36 | -LL | let _val: WrapEnum = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: WrapEnum = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -273,8 +273,8 @@ LL | struct RefPair((&'static i32, i32)); error: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:76:42 | -LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: Wrap<(RefPair, i32)> = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -299,8 +299,8 @@ LL | let _val: NonNull = mem::zeroed(); error: the type `NonNull` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:79:34 | -LL | let _val: NonNull = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -321,8 +321,8 @@ LL | let _val: *const dyn Send = mem::zeroed(); error: the type `*const dyn Send` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:82:37 | -LL | let _val: *const dyn Send = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: *const dyn Send = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -343,8 +343,8 @@ LL | let _val: [fn(); 2] = mem::zeroed(); error: the type `[fn(); 2]` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:85:31 | -LL | let _val: [fn(); 2] = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: [fn(); 2] = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -354,8 +354,8 @@ LL | let _val: [fn(); 2] = mem::uninitialized(); error: the type `bool` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:89:26 | -LL | let _val: bool = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: bool = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -365,8 +365,8 @@ LL | let _val: bool = mem::uninitialized(); error: the type `Wrap` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:92:32 | -LL | let _val: Wrap = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: Wrap = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -380,8 +380,8 @@ LL | struct Wrap { wrapped: T } error: the type `NonBig` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:95:28 | -LL | let _val: NonBig = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: NonBig = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -391,8 +391,8 @@ LL | let _val: NonBig = mem::uninitialized(); error: the type `Fruit` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:98:27 | -LL | let _val: Fruit = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: Fruit = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -406,8 +406,8 @@ LL | enum Fruit { error: the type `[bool; 2]` does not permit being left uninitialized --> $DIR/uninitialized-zeroed.rs:101:31 | -LL | let _val: [bool; 2] = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ +LL | let _val: [bool; 2] = MaybeUninit::uninit().assume_init(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done @@ -526,395 +526,3 @@ LL | let _val: bool = MaybeUninit::uninit().assume_init(); error: aborting due to 43 previous errors -Future incompatibility report: Future breakage diagnostic: -warning: the type `&T` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:41:32 - | -LL | let _val: &'static T = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: references must be non-null - -Future breakage diagnostic: -warning: the type `Wrap<&T>` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:44:38 - | -LL | let _val: Wrap<&'static T> = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in -note: references must be non-null (in this struct field) - --> $DIR/uninitialized-zeroed.rs:17:18 - | -LL | struct Wrap { wrapped: T } - | ^^^^^^^^^^ - -Future breakage diagnostic: -warning: the type `!` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:52:23 - | -LL | let _val: ! = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: the `!` type has no valid value - -Future breakage diagnostic: -warning: the type `(i32, !)` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:55:30 - | -LL | let _val: (i32, !) = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: the `!` type has no valid value - -Future breakage diagnostic: -warning: the type `Void` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:58:26 - | -LL | let _val: Void = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: enums with no variants have no valid value - -Future breakage diagnostic: -warning: the type `&i32` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:61:34 - | -LL | let _val: &'static i32 = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: references must be non-null - -Future breakage diagnostic: -warning: the type `Ref` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:64:25 - | -LL | let _val: Ref = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in -note: references must be non-null (in this struct field) - --> $DIR/uninitialized-zeroed.rs:14:12 - | -LL | struct Ref(&'static i32); - | ^^^^^^^^^^^^ - -Future breakage diagnostic: -warning: the type `fn()` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:67:26 - | -LL | let _val: fn() = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: function pointers must be non-null - -Future breakage diagnostic: -warning: the type `Wrap` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:70:32 - | -LL | let _val: Wrap = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in -note: function pointers must be non-null (in this struct field) - --> $DIR/uninitialized-zeroed.rs:17:18 - | -LL | struct Wrap { wrapped: T } - | ^^^^^^^^^^ - -Future breakage diagnostic: -warning: the type `WrapEnum` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:73:36 - | -LL | let _val: WrapEnum = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in -note: function pointers must be non-null (in this enum field) - --> $DIR/uninitialized-zeroed.rs:18:28 - | -LL | enum WrapEnum { Wrapped(T) } - | ^ - -Future breakage diagnostic: -warning: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:76:42 - | -LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in -note: references must be non-null (in this struct field) - --> $DIR/uninitialized-zeroed.rs:15:16 - | -LL | struct RefPair((&'static i32, i32)); - | ^^^^^^^^^^^^^^^^^^^ - -Future breakage diagnostic: -warning: the type `std::ptr::NonNull` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:79:34 - | -LL | let _val: NonNull = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: `std::ptr::NonNull` must be non-null - -Future breakage diagnostic: -warning: the type `*const dyn std::marker::Send` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:82:37 - | -LL | let _val: *const dyn Send = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: the vtable of a wide raw pointer must be non-null - -Future breakage diagnostic: -warning: the type `[fn(); 2]` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:85:31 - | -LL | let _val: [fn(); 2] = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: function pointers must be non-null - -Future breakage diagnostic: -warning: the type `bool` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:89:26 - | -LL | let _val: bool = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: booleans must be either `true` or `false` - -Future breakage diagnostic: -warning: the type `Wrap` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:92:32 - | -LL | let _val: Wrap = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in -note: characters must be a valid Unicode codepoint (in this struct field) - --> $DIR/uninitialized-zeroed.rs:17:18 - | -LL | struct Wrap { wrapped: T } - | ^^^^^^^^^^ - -Future breakage diagnostic: -warning: the type `NonBig` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:95:28 - | -LL | let _val: NonBig = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: `NonBig` must be initialized inside its custom valid range - -Future breakage diagnostic: -warning: the type `Fruit` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:98:27 - | -LL | let _val: Fruit = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in -note: enums have to be initialized to a variant - --> $DIR/uninitialized-zeroed.rs:26:1 - | -LL | enum Fruit { - | ^^^^^^^^^^ - -Future breakage diagnostic: -warning: the type `[bool; 2]` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:101:31 - | -LL | let _val: [bool; 2] = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in - = note: booleans must be either `true` or `false` - -Future breakage diagnostic: -warning: the type `OneFruit` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:124:30 - | -LL | let _val: OneFruit = mem::uninitialized(); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | this code causes undefined behavior when executed - | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done - | -note: the lint level is defined here - --> $DIR/uninitialized-zeroed.rs:5:22 - | -LL | #![allow(deprecated, mem_uninitialized)] - | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in -note: enums have to be initialized to a variant - --> $DIR/uninitialized-zeroed.rs:32:1 - | -LL | enum OneFruit { - | ^^^^^^^^^^^^^ - From 96a2e65449eebd797cf44b1c89a4936ae7063749 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Thu, 8 Sep 2022 10:24:44 +0100 Subject: [PATCH 5/6] Add more tests, add docs for is_mem_uninit field --- compiler/rustc_lint/src/builtin.rs | 9 +- .../mem-uninitialized-future-compat.rs | 39 ++ .../mem-uninitialized-future-compat.stderr | 362 ++++++++++++++++-- 3 files changed, 380 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index a4261048d8d0..aaaa90ab7bf7 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2366,7 +2366,14 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { #[derive(Debug, Copy, Clone, PartialEq)] enum InitKind { Zeroed, - Uninit { is_mem_uninit: bool }, + /// `is_mem_uninit` is true *only* if this is a call to `mem::uninitialized()`, not if + /// this is a `MaybeUninit::uninit().assume_init()`. + /// + /// This lets us avoid duplicate errors being shown, for code that matches the + /// mem_uninitialized FCW. + Uninit { + is_mem_uninit: bool, + }, } impl InitKind { diff --git a/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs b/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs index abfc2271ac15..bd0ac6c3ee06 100644 --- a/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs +++ b/src/test/ui/intrinsics/mem-uninitialized-future-compat.rs @@ -9,6 +9,19 @@ struct UninitStruct { b: char, } +enum OneVariant { + Hello, +} + +enum TwoVariant { + Hello, + Goodbye, +} + +enum OneVariantWith { + Hello(T), +} + unsafe fn unknown_type() { std::mem::uninitialized::(); //~^ ERROR the type `T` is generic, and might not permit being left uninitialized @@ -22,6 +35,12 @@ unsafe fn unknown_type() { std::mem::uninitialized::<[UninitStruct; N]>(); //~^ ERROR the type `[UninitStruct; N]` is generic, and might not permit being left uninitialized + std::mem::uninitialized::>(); + //~^ ERROR the type `std::result::Result` does not permit being left uninitialized + + std::mem::uninitialized::>(); + //~^ ERROR the type `OneVariantWith` is generic, and might not permit being left uninitialized + std::mem::uninitialized::<[T; 0]>(); std::mem::uninitialized::<[char; 0]>(); } @@ -58,10 +77,30 @@ fn main() { std::mem::uninitialized::<(u32, char)>(); //~^ ERROR the type `(u32, char)` does not permit being left uninitialized + std::mem::uninitialized::(); + //~^ ERROR the type `TwoVariant` does not permit being left uninitialized + + std::mem::uninitialized::>(); + //~^ ERROR the type `std::result::Result` does not permit being left uninitialized + + std::mem::uninitialized::>(); + //~^ ERROR the type `std::result::Result` does not permit being left uninitialized + + std::mem::uninitialized::>(); + //~^ ERROR the type `std::option::Option` does not permit being left uninitialized + + std::mem::uninitialized::>(); + //~^ ERROR the type `OneVariantWith` does not permit being left uninitialized + + std::mem::uninitialized::>(); + //~^ ERROR the type `OneVariantWith` does not permit being left uninitialized + std::mem::uninitialized::>>(); std::mem::uninitialized::(); std::mem::uninitialized::(); std::mem::uninitialized::<*const u8>(); std::mem::uninitialized::<[u8; 64]>(); + std::mem::uninitialized::(); + std::mem::uninitialized::>(); } } diff --git a/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr b/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr index 8111b24a4669..11f9cd44de58 100644 --- a/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr +++ b/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr @@ -1,5 +1,5 @@ error: the type `T` is generic, and might not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:13:5 + --> $DIR/mem-uninitialized-future-compat.rs:26:5 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | #![deny(mem_uninitialized)] = note: type might not be allowed to be left uninitialized error: the type `[T; N]` is generic, and might not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:16:5 + --> $DIR/mem-uninitialized-future-compat.rs:29:5 | LL | std::mem::uninitialized::<[T; N]>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | std::mem::uninitialized::<[T; N]>(); = note: type might not be allowed to be left uninitialized error: the type `[char; N]` is generic, and might not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:19:5 + --> $DIR/mem-uninitialized-future-compat.rs:32:5 | LL | std::mem::uninitialized::<[char; N]>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | std::mem::uninitialized::<[char; N]>(); = note: characters must be a valid Unicode codepoint error: the type `[UninitStruct; N]` is generic, and might not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:22:5 + --> $DIR/mem-uninitialized-future-compat.rs:35:5 | LL | std::mem::uninitialized::<[UninitStruct; N]>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,8 +55,40 @@ note: characters must be a valid Unicode codepoint (in this struct field) LL | b: char, | ^^^^^^^ +error: the type `std::result::Result` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:38:5 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $SRC_DIR/core/src/result.rs:LL:COL + | +LL | pub enum Result { + | ^^^^^^^^^^^^^^^^^^^^^ + +error: the type `OneVariantWith` is generic, and might not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:41:5 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: type might not be allowed to be left uninitialized (in this enum field) + --> $DIR/mem-uninitialized-future-compat.rs:22:11 + | +LL | Hello(T), + | ^ + error: the type `&u32` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:31:9 + --> $DIR/mem-uninitialized-future-compat.rs:50:9 | LL | std::mem::uninitialized::<&'static u32>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -68,7 +100,7 @@ LL | std::mem::uninitialized::<&'static u32>(); = note: references must be non-null error: the type `std::boxed::Box` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:34:9 + --> $DIR/mem-uninitialized-future-compat.rs:53:9 | LL | std::mem::uninitialized::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +112,7 @@ LL | std::mem::uninitialized::>(); = note: `Box` must be non-null error: the type `fn()` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:37:9 + --> $DIR/mem-uninitialized-future-compat.rs:56:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +124,7 @@ LL | std::mem::uninitialized::(); = note: function pointers must be non-null error: the type `!` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:40:9 + --> $DIR/mem-uninitialized-future-compat.rs:59:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +136,7 @@ LL | std::mem::uninitialized::(); = note: the `!` type has no valid value error: the type `*mut dyn std::io::Write` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:43:9 + --> $DIR/mem-uninitialized-future-compat.rs:62:9 | LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -116,7 +148,7 @@ LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); = note: the vtable of a wide raw pointer must be non-null error: the type `bool` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:46:9 + --> $DIR/mem-uninitialized-future-compat.rs:65:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -128,7 +160,7 @@ LL | std::mem::uninitialized::(); = note: booleans must be either `true` or `false` error: the type `char` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:49:9 + --> $DIR/mem-uninitialized-future-compat.rs:68:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -140,7 +172,7 @@ LL | std::mem::uninitialized::(); = note: characters must be a valid Unicode codepoint error: the type `UninitStruct` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:52:9 + --> $DIR/mem-uninitialized-future-compat.rs:71:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,7 +188,7 @@ LL | b: char, | ^^^^^^^ error: the type `[UninitStruct; 16]` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:55:9 + --> $DIR/mem-uninitialized-future-compat.rs:74:9 | LL | std::mem::uninitialized::<[UninitStruct; 16]>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -172,7 +204,7 @@ LL | b: char, | ^^^^^^^ error: the type `(u32, char)` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:58:9 + --> $DIR/mem-uninitialized-future-compat.rs:77:9 | LL | std::mem::uninitialized::<(u32, char)>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -183,11 +215,107 @@ LL | std::mem::uninitialized::<(u32, char)>(); = note: for more information, see FIXME: fill this in = note: characters must be a valid Unicode codepoint -error: aborting due to 14 previous errors +error: the type `TwoVariant` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:80:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/mem-uninitialized-future-compat.rs:16:1 + | +LL | enum TwoVariant { + | ^^^^^^^^^^^^^^^ + +error: the type `std::result::Result` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:83:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $SRC_DIR/core/src/result.rs:LL:COL + | +LL | pub enum Result { + | ^^^^^^^^^^^^^^^^^^^^^ + +error: the type `std::result::Result` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:86:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $SRC_DIR/core/src/result.rs:LL:COL + | +LL | pub enum Result { + | ^^^^^^^^^^^^^^^^^^^^^ + +error: the type `std::option::Option` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:89:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $SRC_DIR/core/src/option.rs:LL:COL + | +LL | pub enum Option { + | ^^^^^^^^^^^^^^^^^^ + +error: the type `OneVariantWith` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:92:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this enum field) + --> $DIR/mem-uninitialized-future-compat.rs:22:11 + | +LL | Hello(T), + | ^ + +error: the type `OneVariantWith` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:95:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | + = note: for more information, see FIXME: fill this in +note: the `!` type has no valid value (in this enum field) + --> $DIR/mem-uninitialized-future-compat.rs:22:11 + | +LL | Hello(T), + | ^ + +error: aborting due to 22 previous errors Future incompatibility report: Future breakage diagnostic: error: the type `T` is generic, and might not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:13:5 + --> $DIR/mem-uninitialized-future-compat.rs:26:5 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +333,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `[T; N]` is generic, and might not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:16:5 + --> $DIR/mem-uninitialized-future-compat.rs:29:5 | LL | std::mem::uninitialized::<[T; N]>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -223,7 +351,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `[char; N]` is generic, and might not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:19:5 + --> $DIR/mem-uninitialized-future-compat.rs:32:5 | LL | std::mem::uninitialized::<[char; N]>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +369,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `[UninitStruct; N]` is generic, and might not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:22:5 + --> $DIR/mem-uninitialized-future-compat.rs:35:5 | LL | std::mem::uninitialized::<[UninitStruct; N]>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -261,9 +389,53 @@ note: characters must be a valid Unicode codepoint (in this struct field) LL | b: char, | ^^^^^^^ +Future breakage diagnostic: +error: the type `std::result::Result` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:38:5 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $SRC_DIR/core/src/result.rs:LL:COL + | +LL | pub enum Result { + | ^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +error: the type `OneVariantWith` is generic, and might not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:41:5 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: type might not be allowed to be left uninitialized (in this enum field) + --> $DIR/mem-uninitialized-future-compat.rs:22:11 + | +LL | Hello(T), + | ^ + Future breakage diagnostic: error: the type `&u32` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:31:9 + --> $DIR/mem-uninitialized-future-compat.rs:50:9 | LL | std::mem::uninitialized::<&'static u32>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -281,7 +453,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `std::boxed::Box` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:34:9 + --> $DIR/mem-uninitialized-future-compat.rs:53:9 | LL | std::mem::uninitialized::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -299,7 +471,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `fn()` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:37:9 + --> $DIR/mem-uninitialized-future-compat.rs:56:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -317,7 +489,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `!` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:40:9 + --> $DIR/mem-uninitialized-future-compat.rs:59:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -335,7 +507,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `*mut dyn std::io::Write` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:43:9 + --> $DIR/mem-uninitialized-future-compat.rs:62:9 | LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -353,7 +525,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `bool` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:46:9 + --> $DIR/mem-uninitialized-future-compat.rs:65:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -371,7 +543,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `char` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:49:9 + --> $DIR/mem-uninitialized-future-compat.rs:68:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -389,7 +561,7 @@ LL | #![deny(mem_uninitialized)] Future breakage diagnostic: error: the type `UninitStruct` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:52:9 + --> $DIR/mem-uninitialized-future-compat.rs:71:9 | LL | std::mem::uninitialized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -411,7 +583,7 @@ LL | b: char, Future breakage diagnostic: error: the type `[UninitStruct; 16]` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:55:9 + --> $DIR/mem-uninitialized-future-compat.rs:74:9 | LL | std::mem::uninitialized::<[UninitStruct; 16]>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -433,7 +605,7 @@ LL | b: char, Future breakage diagnostic: error: the type `(u32, char)` does not permit being left uninitialized - --> $DIR/mem-uninitialized-future-compat.rs:58:9 + --> $DIR/mem-uninitialized-future-compat.rs:77:9 | LL | std::mem::uninitialized::<(u32, char)>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -449,3 +621,135 @@ LL | #![deny(mem_uninitialized)] = note: for more information, see FIXME: fill this in = note: characters must be a valid Unicode codepoint +Future breakage diagnostic: +error: the type `TwoVariant` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:80:9 + | +LL | std::mem::uninitialized::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $DIR/mem-uninitialized-future-compat.rs:16:1 + | +LL | enum TwoVariant { + | ^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +error: the type `std::result::Result` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:83:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $SRC_DIR/core/src/result.rs:LL:COL + | +LL | pub enum Result { + | ^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +error: the type `std::result::Result` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:86:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $SRC_DIR/core/src/result.rs:LL:COL + | +LL | pub enum Result { + | ^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +error: the type `std::option::Option` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:89:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: enums have to be initialized to a variant + --> $SRC_DIR/core/src/option.rs:LL:COL + | +LL | pub enum Option { + | ^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +error: the type `OneVariantWith` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:92:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: characters must be a valid Unicode codepoint (in this enum field) + --> $DIR/mem-uninitialized-future-compat.rs:22:11 + | +LL | Hello(T), + | ^ + +Future breakage diagnostic: +error: the type `OneVariantWith` does not permit being left uninitialized + --> $DIR/mem-uninitialized-future-compat.rs:95:9 + | +LL | std::mem::uninitialized::>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done + | +note: the lint level is defined here + --> $DIR/mem-uninitialized-future-compat.rs:2:9 + | +LL | #![deny(mem_uninitialized)] + | ^^^^^^^^^^^^^^^^^ + = note: for more information, see FIXME: fill this in +note: the `!` type has no valid value (in this enum field) + --> $DIR/mem-uninitialized-future-compat.rs:22:11 + | +LL | Hello(T), + | ^ + From 76eb1c704d68b5dad604c4b8695906cc0f18338a Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Thu, 8 Sep 2022 13:01:09 +0100 Subject: [PATCH 6/6] Add tracking issue link to error --- compiler/rustc_lint/src/mem_uninitialized.rs | 2 +- .../mem-uninitialized-future-compat.stderr | 88 +++++++++---------- .../panic-uninitialized-zeroed.mir.stderr | 32 +++---- .../panic-uninitialized-zeroed.strict.stderr | 32 +++---- .../panic-uninitialized-zeroed.thir.stderr | 32 +++---- 5 files changed, 93 insertions(+), 93 deletions(-) diff --git a/compiler/rustc_lint/src/mem_uninitialized.rs b/compiler/rustc_lint/src/mem_uninitialized.rs index f14441d0ce73..fadf985dff32 100644 --- a/compiler/rustc_lint/src/mem_uninitialized.rs +++ b/compiler/rustc_lint/src/mem_uninitialized.rs @@ -40,7 +40,7 @@ declare_lint! { Warn, "use of mem::uninitialized", @future_incompatible = FutureIncompatibleInfo { - reference: "FIXME: fill this in", + reference: "issue #101570 ", reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow, explain_reason: false, }; diff --git a/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr b/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr index 11f9cd44de58..8b2a5144ddcc 100644 --- a/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr +++ b/src/test/ui/intrinsics/mem-uninitialized-future-compat.stderr @@ -12,7 +12,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: type might not be allowed to be left uninitialized error: the type `[T; N]` is generic, and might not permit being left uninitialized @@ -24,7 +24,7 @@ LL | std::mem::uninitialized::<[T; N]>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: type might not be allowed to be left uninitialized error: the type `[char; N]` is generic, and might not permit being left uninitialized @@ -36,7 +36,7 @@ LL | std::mem::uninitialized::<[char; N]>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: characters must be a valid Unicode codepoint error: the type `[UninitStruct; N]` is generic, and might not permit being left uninitialized @@ -48,7 +48,7 @@ LL | std::mem::uninitialized::<[UninitStruct; N]>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: characters must be a valid Unicode codepoint (in this struct field) --> $DIR/mem-uninitialized-future-compat.rs:9:5 | @@ -64,7 +64,7 @@ LL | std::mem::uninitialized::>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $SRC_DIR/core/src/result.rs:LL:COL | @@ -80,7 +80,7 @@ LL | std::mem::uninitialized::>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: type might not be allowed to be left uninitialized (in this enum field) --> $DIR/mem-uninitialized-future-compat.rs:22:11 | @@ -96,7 +96,7 @@ LL | std::mem::uninitialized::<&'static u32>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: references must be non-null error: the type `std::boxed::Box` does not permit being left uninitialized @@ -108,7 +108,7 @@ LL | std::mem::uninitialized::>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: `Box` must be non-null error: the type `fn()` does not permit being left uninitialized @@ -120,7 +120,7 @@ LL | std::mem::uninitialized::(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: function pointers must be non-null error: the type `!` does not permit being left uninitialized @@ -132,7 +132,7 @@ LL | std::mem::uninitialized::(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the `!` type has no valid value error: the type `*mut dyn std::io::Write` does not permit being left uninitialized @@ -144,7 +144,7 @@ LL | std::mem::uninitialized::<*mut dyn std::io::Write>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the vtable of a wide raw pointer must be non-null error: the type `bool` does not permit being left uninitialized @@ -156,7 +156,7 @@ LL | std::mem::uninitialized::(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: booleans must be either `true` or `false` error: the type `char` does not permit being left uninitialized @@ -168,7 +168,7 @@ LL | std::mem::uninitialized::(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: characters must be a valid Unicode codepoint error: the type `UninitStruct` does not permit being left uninitialized @@ -180,7 +180,7 @@ LL | std::mem::uninitialized::(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: characters must be a valid Unicode codepoint (in this struct field) --> $DIR/mem-uninitialized-future-compat.rs:9:5 | @@ -196,7 +196,7 @@ LL | std::mem::uninitialized::<[UninitStruct; 16]>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: characters must be a valid Unicode codepoint (in this struct field) --> $DIR/mem-uninitialized-future-compat.rs:9:5 | @@ -212,7 +212,7 @@ LL | std::mem::uninitialized::<(u32, char)>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: characters must be a valid Unicode codepoint error: the type `TwoVariant` does not permit being left uninitialized @@ -224,7 +224,7 @@ LL | std::mem::uninitialized::(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/mem-uninitialized-future-compat.rs:16:1 | @@ -240,7 +240,7 @@ LL | std::mem::uninitialized::>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $SRC_DIR/core/src/result.rs:LL:COL | @@ -256,7 +256,7 @@ LL | std::mem::uninitialized::>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $SRC_DIR/core/src/result.rs:LL:COL | @@ -272,7 +272,7 @@ LL | std::mem::uninitialized::>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $SRC_DIR/core/src/option.rs:LL:COL | @@ -288,7 +288,7 @@ LL | std::mem::uninitialized::>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: characters must be a valid Unicode codepoint (in this enum field) --> $DIR/mem-uninitialized-future-compat.rs:22:11 | @@ -304,7 +304,7 @@ LL | std::mem::uninitialized::>(); | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: the `!` type has no valid value (in this enum field) --> $DIR/mem-uninitialized-future-compat.rs:22:11 | @@ -328,7 +328,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: type might not be allowed to be left uninitialized Future breakage diagnostic: @@ -346,7 +346,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: type might not be allowed to be left uninitialized Future breakage diagnostic: @@ -364,7 +364,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: characters must be a valid Unicode codepoint Future breakage diagnostic: @@ -382,7 +382,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: characters must be a valid Unicode codepoint (in this struct field) --> $DIR/mem-uninitialized-future-compat.rs:9:5 | @@ -404,7 +404,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $SRC_DIR/core/src/result.rs:LL:COL | @@ -426,7 +426,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: type might not be allowed to be left uninitialized (in this enum field) --> $DIR/mem-uninitialized-future-compat.rs:22:11 | @@ -448,7 +448,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: references must be non-null Future breakage diagnostic: @@ -466,7 +466,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: `Box` must be non-null Future breakage diagnostic: @@ -484,7 +484,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: function pointers must be non-null Future breakage diagnostic: @@ -502,7 +502,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the `!` type has no valid value Future breakage diagnostic: @@ -520,7 +520,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: @@ -538,7 +538,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: booleans must be either `true` or `false` Future breakage diagnostic: @@ -556,7 +556,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: characters must be a valid Unicode codepoint Future breakage diagnostic: @@ -574,7 +574,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: characters must be a valid Unicode codepoint (in this struct field) --> $DIR/mem-uninitialized-future-compat.rs:9:5 | @@ -596,7 +596,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: characters must be a valid Unicode codepoint (in this struct field) --> $DIR/mem-uninitialized-future-compat.rs:9:5 | @@ -618,7 +618,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: characters must be a valid Unicode codepoint Future breakage diagnostic: @@ -636,7 +636,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/mem-uninitialized-future-compat.rs:16:1 | @@ -658,7 +658,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $SRC_DIR/core/src/result.rs:LL:COL | @@ -680,7 +680,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $SRC_DIR/core/src/result.rs:LL:COL | @@ -702,7 +702,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $SRC_DIR/core/src/option.rs:LL:COL | @@ -724,7 +724,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: characters must be a valid Unicode codepoint (in this enum field) --> $DIR/mem-uninitialized-future-compat.rs:22:11 | @@ -746,7 +746,7 @@ note: the lint level is defined here | LL | #![deny(mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: the `!` type has no valid value (in this enum field) --> $DIR/mem-uninitialized-future-compat.rs:22:11 | diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr index 6d571c38845c..d26215e3063e 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.mir.stderr @@ -13,7 +13,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the `!` type has no valid value Future breakage diagnostic: @@ -31,7 +31,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: the `!` type has no valid value (in this struct field) --> $DIR/panic-uninitialized-zeroed.rs:24:5 | @@ -53,7 +53,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: enums with no variants have no valid value Future breakage diagnostic: @@ -71,7 +71,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: the `!` type has no valid value (in this struct field) --> $DIR/panic-uninitialized-zeroed.rs:24:5 | @@ -93,7 +93,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: enums with no variants have no valid value Future breakage diagnostic: @@ -111,7 +111,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: function pointers must be non-null Future breakage diagnostic: @@ -129,7 +129,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: @@ -147,7 +147,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: `std::ptr::NonNull` must be non-null Future breakage diagnostic: @@ -165,7 +165,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:33:1 | @@ -187,7 +187,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:53:1 | @@ -209,7 +209,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:53:1 | @@ -231,7 +231,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:41:1 | @@ -253,7 +253,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: booleans must be either `true` or `false` Future breakage diagnostic: @@ -271,7 +271,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:48:1 | @@ -293,7 +293,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:48:1 | @@ -315,6 +315,6 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: `std::ptr::NonNull<()>` must be non-null diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr index 6d571c38845c..d26215e3063e 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.strict.stderr @@ -13,7 +13,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the `!` type has no valid value Future breakage diagnostic: @@ -31,7 +31,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: the `!` type has no valid value (in this struct field) --> $DIR/panic-uninitialized-zeroed.rs:24:5 | @@ -53,7 +53,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: enums with no variants have no valid value Future breakage diagnostic: @@ -71,7 +71,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: the `!` type has no valid value (in this struct field) --> $DIR/panic-uninitialized-zeroed.rs:24:5 | @@ -93,7 +93,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: enums with no variants have no valid value Future breakage diagnostic: @@ -111,7 +111,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: function pointers must be non-null Future breakage diagnostic: @@ -129,7 +129,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: @@ -147,7 +147,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: `std::ptr::NonNull` must be non-null Future breakage diagnostic: @@ -165,7 +165,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:33:1 | @@ -187,7 +187,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:53:1 | @@ -209,7 +209,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:53:1 | @@ -231,7 +231,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:41:1 | @@ -253,7 +253,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: booleans must be either `true` or `false` Future breakage diagnostic: @@ -271,7 +271,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:48:1 | @@ -293,7 +293,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:48:1 | @@ -315,6 +315,6 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: `std::ptr::NonNull<()>` must be non-null diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr b/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr index 6d571c38845c..d26215e3063e 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.thir.stderr @@ -13,7 +13,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the `!` type has no valid value Future breakage diagnostic: @@ -31,7 +31,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: the `!` type has no valid value (in this struct field) --> $DIR/panic-uninitialized-zeroed.rs:24:5 | @@ -53,7 +53,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: enums with no variants have no valid value Future breakage diagnostic: @@ -71,7 +71,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: the `!` type has no valid value (in this struct field) --> $DIR/panic-uninitialized-zeroed.rs:24:5 | @@ -93,7 +93,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: enums with no variants have no valid value Future breakage diagnostic: @@ -111,7 +111,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: function pointers must be non-null Future breakage diagnostic: @@ -129,7 +129,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: the vtable of a wide raw pointer must be non-null Future breakage diagnostic: @@ -147,7 +147,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: `std::ptr::NonNull` must be non-null Future breakage diagnostic: @@ -165,7 +165,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:33:1 | @@ -187,7 +187,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:53:1 | @@ -209,7 +209,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:53:1 | @@ -231,7 +231,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:41:1 | @@ -253,7 +253,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: booleans must be either `true` or `false` Future breakage diagnostic: @@ -271,7 +271,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:48:1 | @@ -293,7 +293,7 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 note: enums have to be initialized to a variant --> $DIR/panic-uninitialized-zeroed.rs:48:1 | @@ -315,6 +315,6 @@ note: the lint level is defined here | LL | #![allow(deprecated, invalid_value, mem_uninitialized)] | ^^^^^^^^^^^^^^^^^ - = note: for more information, see FIXME: fill this in + = note: for more information, see issue #101570 = note: `std::ptr::NonNull<()>` must be non-null