diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index 3aa00d14d39b1..2a2765a436bb5 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; use std::fmt::{self, Write}; -use std::ops::{Bound, Deref}; +use std::ops::Deref; use std::{cmp, iter}; use rustc_hashes::Hash64; @@ -348,7 +348,6 @@ impl LayoutCalculator { variants: &IndexSlice>, is_enum: bool, is_special_no_niche: bool, - scalar_valid_range: (Bound, Bound), discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool), discriminants: impl Iterator, always_sized: bool, @@ -380,7 +379,6 @@ impl LayoutCalculator { variants, is_enum, is_special_no_niche, - scalar_valid_range, always_sized, present_first, ) @@ -530,7 +528,6 @@ impl LayoutCalculator { variants: &IndexSlice>, is_enum: bool, is_special_no_niche: bool, - scalar_valid_range: (Bound, Bound), always_sized: bool, present_first: VariantIdx, ) -> LayoutCalculatorResult { @@ -570,52 +567,6 @@ impl LayoutCalculator { return Ok(st); } - let (start, end) = scalar_valid_range; - match st.backend_repr { - BackendRepr::Scalar(ref mut scalar) | BackendRepr::ScalarPair(ref mut scalar, _) => { - // Enlarging validity ranges would result in missed - // optimizations, *not* wrongly assuming the inner - // value is valid. e.g. unions already enlarge validity ranges, - // because the values may be uninitialized. - // - // Because of that we only check that the start and end - // of the range is representable with this scalar type. - - let max_value = scalar.size(dl).unsigned_int_max(); - if let Bound::Included(start) = start { - // FIXME(eddyb) this might be incorrect - it doesn't - // account for wrap-around (end < start) ranges. - assert!(start <= max_value, "{start} > {max_value}"); - scalar.valid_range_mut().start = start; - } - if let Bound::Included(end) = end { - // FIXME(eddyb) this might be incorrect - it doesn't - // account for wrap-around (end < start) ranges. - assert!(end <= max_value, "{end} > {max_value}"); - scalar.valid_range_mut().end = end; - } - - // Update `largest_niche` if we have introduced a larger niche. - let niche = Niche::from_scalar(dl, Size::ZERO, *scalar); - if let Some(niche) = niche { - match st.largest_niche { - Some(largest_niche) => { - // Replace the existing niche even if they're equal, - // because this one is at a lower offset. - if largest_niche.available(dl) <= niche.available(dl) { - st.largest_niche = Some(niche); - } - } - None => st.largest_niche = Some(niche), - } - } - } - _ => assert!( - start == Bound::Unbounded && end == Bound::Unbounded, - "nonscalar layout for layout_scalar_valid_range type: {st:#?}", - ), - } - Ok(st) } diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index 835af97358ac4..18f3bfd62e3ff 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -92,32 +92,6 @@ impl NoArgsAttributeParser for RustcNoImplicitAutorefsParser { const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitAutorefs; } -pub(crate) struct RustcLayoutScalarValidRangeStartParser; - -impl SingleAttributeParser for RustcLayoutScalarValidRangeStartParser { - const PATH: &[Symbol] = &[sym::rustc_layout_scalar_valid_range_start]; - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct)]); - const TEMPLATE: AttributeTemplate = template!(List: &["start"]); - - fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option { - parse_single_integer(cx, args) - .map(|n| AttributeKind::RustcLayoutScalarValidRangeStart(Box::new(n), cx.attr_span)) - } -} - -pub(crate) struct RustcLayoutScalarValidRangeEndParser; - -impl SingleAttributeParser for RustcLayoutScalarValidRangeEndParser { - const PATH: &[Symbol] = &[sym::rustc_layout_scalar_valid_range_end]; - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct)]); - const TEMPLATE: AttributeTemplate = template!(List: &["end"]); - - fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option { - parse_single_integer(cx, args) - .map(|n| AttributeKind::RustcLayoutScalarValidRangeEnd(Box::new(n), cx.attr_span)) - } -} - pub(crate) struct RustcLegacyConstGenericsParser; impl SingleAttributeParser for RustcLegacyConstGenericsParser { diff --git a/compiler/rustc_attr_parsing/src/attributes/util.rs b/compiler/rustc_attr_parsing/src/attributes/util.rs index 95185f1ae8692..438c6ba435056 100644 --- a/compiler/rustc_attr_parsing/src/attributes/util.rs +++ b/compiler/rustc_attr_parsing/src/attributes/util.rs @@ -33,7 +33,7 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool { /// Parse a single integer. /// /// Used by attributes that take a single integer as argument, such as -/// `#[link_ordinal]` and `#[rustc_layout_scalar_valid_range_start]`. +/// `#[link_ordinal]`. /// `cx` is the context given to the attribute. /// `args` is the parser for the attribute arguments. pub(crate) fn parse_single_integer( diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 02a7aac9659f2..d89e81bf6cc7c 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -208,8 +208,6 @@ attribute_parsers!( Single, Single, Single, - Single, - Single, Single, Single, Single, diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index c1b72369dfadf..6e7d8354dc9b4 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -1442,7 +1442,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, // First check that the base type is valid self.visit_value(&val.transmute(self.ecx.layout_of(*base)?, self.ecx)?)?; // When you extend this match, make sure to also add tests to - // tests/ui/type/pattern_types/validity.rs(( + // tests/ui/type/pattern_types/validity.rs match **pat { // Range and non-null patterns are precisely reflected into `valid_range` and thus // handled fully by `visit_scalar` (called below). @@ -1457,6 +1457,34 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, // we won't see optimizations actually breaking such programs. ty::PatternKind::Or(_patterns) => {} } + // FIXME(pattern_types): handle everything based on the pattern, not on the layout. + // it's ok to run scalar validation even if the pattern type is `u8 is 0..=255` and thus + // allows uninit values, because that's rare and so not a perf issue. + match val.layout.backend_repr { + BackendRepr::Scalar(scalar_layout) => { + if !scalar_layout.is_uninit_valid() { + // There is something to check here. + // We read directly via `ecx` since the read cannot fail -- we already read + // this field above when recursing into the field. + let scalar = self.ecx.read_scalar(val)?; + self.visit_scalar(scalar, scalar_layout)?; + } + } + BackendRepr::ScalarPair(a_layout, b_layout) => { + // We can only proceed if *both* scalars need to be initialized. + // FIXME: find a way to also check ScalarPair when one side can be uninit but + // the other must be init. + if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() { + // We read directly via `ecx` since the read cannot fail -- we already read + // this field above when recursing into the field. + let (a, b) = self.ecx.read_immediate(val)?.to_scalar_pair(); + self.visit_scalar(a, a_layout)?; + self.visit_scalar(b, b_layout)?; + } + } + BackendRepr::SimdVector { .. } | BackendRepr::SimdScalableVector { .. } => unreachable!(), + BackendRepr::Memory { .. } => unreachable!() + } } ty::Adt(adt, _) if adt.is_maybe_dangling() => { let old_may_dangle = mem::replace(&mut self.may_dangle, true); @@ -1479,15 +1507,14 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, } } - // *After* all of this, check further information stored in the layout. We need to check - // this to handle types like `NonNull` where the `Scalar` info is more restrictive than what - // the fields say (`rustc_layout_scalar_valid_range_start`). But in most cases, this will - // just propagate what the fields say, and then we want the error to point at the field -- - // so, we first recurse, then we do this check. + // *After* all of this, check further information stored in the layout. + // On leaf types like `!` or empty enums, this will raise the error. + // This means that for types wrapping such a type, we won't ever get here, but it's + // just the simplest way to check for this case. // // FIXME: We could avoid some redundant checks here. For newtypes wrapping // scalars, we do the same check on every "level" (e.g., first we check - // MyNewtype and then the scalar in there). + // the fields of MyNewtype, and then we check MyNewType again). if val.layout.is_uninhabited() { let ty = val.layout.ty; throw_validation_failure!( @@ -1495,35 +1522,40 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, format!("encountered a value of uninhabited type `{ty}`") ); } - match val.layout.backend_repr { - BackendRepr::Scalar(scalar_layout) => { - if !scalar_layout.is_uninit_valid() { - // There is something to check here. - // We read directly via `ecx` since the read cannot fail -- we already read - // this field above when recursing into the field. - let scalar = self.ecx.read_scalar(val)?; - self.visit_scalar(scalar, scalar_layout)?; + if cfg!(debug_assertions) { + // Check that we don't miss any new changes to layout computation in our checks above. + match val.layout.backend_repr { + BackendRepr::Scalar(scalar_layout) => { + if !scalar_layout.is_uninit_valid() { + // There is something to check here. + // We read directly via `ecx` since the read cannot fail -- we already read + // this field above when recursing into the field. + let scalar = self + .ecx + .read_scalar(val) + .expect("the above checks should have fully handled this situation"); + self.visit_scalar(scalar, scalar_layout) + .expect("the above checks should have fully handled this situation"); + } } - } - BackendRepr::ScalarPair(a_layout, b_layout) => { - // We can only proceed if *both* scalars need to be initialized. - // FIXME: find a way to also check ScalarPair when one side can be uninit but - // the other must be init. - if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() { - // We read directly via `ecx` since the read cannot fail -- we already read - // this field above when recursing into the field. - let (a, b) = self.ecx.read_immediate(val)?.to_scalar_pair(); - self.visit_scalar(a, a_layout)?; - self.visit_scalar(b, b_layout)?; + BackendRepr::ScalarPair(a_layout, b_layout) => { + // We can only proceed if *both* scalars need to be initialized. + // FIXME: find a way to also check ScalarPair when one side can be uninit but + // the other must be init. + if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() { + let (a, b) = self + .ecx + .read_immediate(val) + .expect("the above checks should have fully handled this situation") + .to_scalar_pair(); + self.visit_scalar(a, a_layout) + .expect("the above checks should have fully handled this situation"); + self.visit_scalar(b, b_layout) + .expect("the above checks should have fully handled this situation"); + } } - } - BackendRepr::SimdVector { .. } | BackendRepr::SimdScalableVector { .. } => { - // No checks here, we assume layout computation gets this right. - // (This is harder to check since Miri does not represent these as `Immediate`. We - // also cannot use field projections since this might be a newtype around a vector.) - } - BackendRepr::Memory { .. } => { - // Nothing to do. + BackendRepr::SimdVector { .. } | BackendRepr::SimdScalableVector { .. } => {} + BackendRepr::Memory { .. } => {} } } diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 053caee258f7b..58bf12855ad6e 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -573,16 +573,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Internal attributes, Layout related: // ========================================================================== - rustc_attr!( - rustc_layout_scalar_valid_range_start, - "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \ - niche optimizations in the standard library", - ), - rustc_attr!( - rustc_layout_scalar_valid_range_end, - "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \ - niche optimizations in the standard library", - ), rustc_attr!( rustc_simd_monomorphize_lane_limit, "the `#[rustc_simd_monomorphize_lane_limit]` attribute is just used by std::simd \ diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 556eb428a1b87..bd2a91bb21abf 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1435,12 +1435,6 @@ pub enum AttributeKind { /// Represents `#[rustc_intrinsic_const_stable_indirect]` RustcIntrinsicConstStableIndirect, - /// Represents `#[rustc_layout_scalar_valid_range_end]`. - RustcLayoutScalarValidRangeEnd(Box, Span), - - /// Represents `#[rustc_layout_scalar_valid_range_start]`. - RustcLayoutScalarValidRangeStart(Box, Span), - /// Represents `#[rustc_legacy_const_generics]` RustcLegacyConstGenerics { fn_indexes: ThinVec<(usize, Span)>, diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index 41e466a9d16b7..dd92440c7680d 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -147,8 +147,6 @@ impl AttributeKind { RustcInsignificantDtor => Yes, RustcIntrinsic => Yes, RustcIntrinsicConstStableIndirect => No, - RustcLayoutScalarValidRangeEnd(..) => Yes, - RustcLayoutScalarValidRangeStart(..) => Yes, RustcLegacyConstGenerics { .. } => Yes, RustcLintOptDenyFieldAccess { .. } => Yes, RustcLintOptTy => Yes, diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 2a09962789a52..73aefeca73192 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -15,7 +15,7 @@ //! crate as a kind of pass. This should eventually be factored away. use std::cell::Cell; -use std::ops::{Bound, ControlFlow}; +use std::ops::ControlFlow; use std::{assert_matches, iter}; use rustc_abi::{ExternAbi, Size}; @@ -1039,12 +1039,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn .fields() .iter() .map(|f| tcx.type_of(f.def_id).instantiate_identity().skip_norm_wip()); - // constructors for structs with `layout_scalar_valid_range` are unsafe to call - let safety = match tcx.layout_scalar_valid_range(adt_def_id) { - (Bound::Unbounded, Bound::Unbounded) => hir::Safety::Safe, - _ => hir::Safety::Unsafe, - }; - ty::Binder::dummy(tcx.mk_fn_sig_rust_abi(inputs, ty, safety)) + ty::Binder::dummy(tcx.mk_fn_sig_rust_abi(inputs, ty, hir::Safety::Safe)) } Expr(&hir::Expr { kind: hir::ExprKind::Closure { .. }, .. }) => { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 2e9708483a85b..806eb0cffff07 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -11,7 +11,7 @@ use std::env::VarError; use std::ffi::OsStr; use std::hash::{Hash, Hasher}; use std::marker::{PhantomData, PointeeSized}; -use std::ops::{Bound, Deref}; +use std::ops::Deref; use std::sync::{Arc, OnceLock}; use std::{fmt, iter, mem}; @@ -947,17 +947,6 @@ impl<'tcx> TyCtxt<'tcx> { matches!(self.as_lang_item(def_id), Some(LangItem::Sized | LangItem::MetaSized)) } - /// Returns a range of the start/end indices specified with the - /// `rustc_layout_scalar_valid_range` attribute. - // FIXME(eddyb) this is an awkward spot for this method, maybe move it? - pub fn layout_scalar_valid_range(self, def_id: DefId) -> (Bound, Bound) { - let start = find_attr!(self, def_id, RustcLayoutScalarValidRangeStart(n, _) => Bound::Included(**n)).unwrap_or(Bound::Unbounded); - let end = - find_attr!(self, def_id, RustcLayoutScalarValidRangeEnd(n, _) => Bound::Included(**n)) - .unwrap_or(Bound::Unbounded); - (start, end) - } - pub fn lift>>(self, value: T) -> Option { value.lift_to_interner(self) } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 53706cc8202b4..13d864e3dace4 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1,4 +1,3 @@ -use std::ops::Bound; use std::{cmp, fmt}; use rustc_abi as abi; @@ -465,17 +464,7 @@ impl<'tcx> SizeSkeleton<'tcx> { // Newtype. if def.variants().len() == 1 { if let Some(SizeSkeleton::Pointer { non_zero, tail }) = v0 { - return Ok(SizeSkeleton::Pointer { - non_zero: non_zero - || match tcx.layout_scalar_valid_range(def.did()) { - (Bound::Included(start), Bound::Unbounded) => start > 0, - (Bound::Included(start), Bound::Included(end)) => { - 0 < start && start < end - } - _ => false, - }, - tail, - }); + return Ok(SizeSkeleton::Pointer { non_zero, tail }); } else { return Err(err); } diff --git a/compiler/rustc_mir_build/src/builder/mod.rs b/compiler/rustc_mir_build/src/builder/mod.rs index 8e51ab7d4edb1..e585fb85e4c8f 100644 --- a/compiler/rustc_mir_build/src/builder/mod.rs +++ b/compiler/rustc_mir_build/src/builder/mod.rs @@ -1276,5 +1276,3 @@ mod expr; mod matches; mod misc; mod scope; - -pub(crate) use expr::category::Category as ExprCategory; diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index aed0c6e6085d3..aceddcc54de95 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -1,6 +1,5 @@ use std::borrow::Cow; use std::mem; -use std::ops::Bound; use rustc_ast::AsmMacro; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -8,7 +7,6 @@ use rustc_errors::DiagArgValue; use rustc_hir::def::DefKind; use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability, find_attr}; use rustc_middle::middle::codegen_fn_attrs::{TargetFeature, TargetFeatureKind}; -use rustc_middle::mir::BorrowKind; use rustc_middle::span_bug; use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::*; @@ -19,7 +17,6 @@ use rustc_session::lint::builtin::{DEPRECATED_SAFE_2024, UNSAFE_OP_IN_UNSAFE_FN, use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::{Span, Symbol}; -use crate::builder::ExprCategory; use crate::errors::*; struct UnsafetyVisitor<'a, 'tcx> { @@ -221,50 +218,6 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> { } } -// Searches for accesses to layout constrained fields. -struct LayoutConstrainedPlaceVisitor<'a, 'tcx> { - found: bool, - thir: &'a Thir<'tcx>, - tcx: TyCtxt<'tcx>, -} - -impl<'a, 'tcx> LayoutConstrainedPlaceVisitor<'a, 'tcx> { - fn new(thir: &'a Thir<'tcx>, tcx: TyCtxt<'tcx>) -> Self { - Self { found: false, thir, tcx } - } -} - -impl<'a, 'tcx> Visitor<'a, 'tcx> for LayoutConstrainedPlaceVisitor<'a, 'tcx> { - fn thir(&self) -> &'a Thir<'tcx> { - self.thir - } - - fn visit_expr(&mut self, expr: &'a Expr<'tcx>) { - match expr.kind { - ExprKind::Field { lhs, .. } => { - if let ty::Adt(adt_def, _) = self.thir[lhs].ty.kind() { - if (Bound::Unbounded, Bound::Unbounded) - != self.tcx.layout_scalar_valid_range(adt_def.did()) - { - self.found = true; - } - } - visit::walk_expr(self, expr); - } - - // Keep walking through the expression as long as we stay in the same - // place, i.e. the expression is a place expression and not a dereference - // (since dereferencing something leads us to a different place). - ExprKind::Deref { .. } => {} - ref kind if ExprCategory::of(kind).is_none_or(|cat| cat == ExprCategory::Place) => { - visit::walk_expr(self, expr); - } - - _ => {} - } - } -} - impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { fn thir(&self) -> &'a Thir<'tcx> { self.thir @@ -342,12 +295,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { std::mem::replace(&mut self.in_union_destructure, true); visit::walk_pat(self, pat); self.in_union_destructure = old_in_union_destructure; - } else if (Bound::Unbounded, Bound::Unbounded) - != self.tcx.layout_scalar_valid_range(adt_def.did()) - { - let old_inside_adt = std::mem::replace(&mut self.inside_adt, true); - visit::walk_pat(self, pat); - self.inside_adt = old_inside_adt; } else { visit::walk_pat(self, pat); } @@ -612,10 +559,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { if adt_def.variant(variant_index).has_unsafe_fields() { self.requires_unsafe(expr.span, InitializingTypeWithUnsafeField) } - match self.tcx.layout_scalar_valid_range(adt_def.did()) { - (Bound::Unbounded, Bound::Unbounded) => {} - _ => self.requires_unsafe(expr.span, InitializingTypeWith), - } } ExprKind::Closure(box ClosureExpr { closure_id, @@ -653,14 +596,8 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { } ExprKind::Assign { lhs, rhs } | ExprKind::AssignOp { lhs, rhs, .. } => { let lhs = &self.thir[lhs]; - // First, check whether we are mutating a layout constrained field - let mut visitor = LayoutConstrainedPlaceVisitor::new(self.thir, self.tcx); - visit::walk_expr(&mut visitor, lhs); - if visitor.found { - self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField); - } - // Second, check for accesses to union fields. Don't have any + // Check for accesses to union fields. Don't have any // special handling for AssignOp since it causes a read *and* // write to lhs. if matches!(expr.kind, ExprKind::Assign { .. }) { @@ -671,23 +608,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { return; // We have already visited everything by now. } } - ExprKind::Borrow { borrow_kind, arg } => { - let mut visitor = LayoutConstrainedPlaceVisitor::new(self.thir, self.tcx); - visit::walk_expr(&mut visitor, expr); - if visitor.found { - match borrow_kind { - BorrowKind::Fake(_) | BorrowKind::Shared - if !self.thir[arg].ty.is_freeze(self.tcx, self.typing_env) => - { - self.requires_unsafe(expr.span, BorrowOfLayoutConstrainedField) - } - BorrowKind::Mut { .. } => { - self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField) - } - BorrowKind::Fake(_) | BorrowKind::Shared => {} - } - } - } ExprKind::PlaceUnwrapUnsafeBinder { .. } | ExprKind::ValueUnwrapUnsafeBinder { .. } | ExprKind::WrapUnsafeBinder { .. } => { @@ -723,7 +643,6 @@ struct UnusedUnsafeWarning { enum UnsafeOpKind { CallToUnsafeFunction(Option), UseOfInlineAssembly, - InitializingTypeWith, InitializingTypeWithUnsafeField, UseOfMutableStatic, UseOfExternStatic, @@ -807,15 +726,6 @@ impl UnsafeOpKind { unsafe_not_inherited_note, }, ), - InitializingTypeWith => tcx.emit_node_span_lint( - UNSAFE_OP_IN_UNSAFE_FN, - hir_id, - span, - UnsafeOpInUnsafeFnInitializingTypeWithRequiresUnsafe { - span, - unsafe_not_inherited_note, - }, - ), InitializingTypeWithUnsafeField => tcx.emit_node_span_lint( UNSAFE_OP_IN_UNSAFE_FN, hir_id, @@ -988,18 +898,6 @@ impl UnsafeOpKind { UseOfInlineAssembly => { dcx.emit_err(UseOfInlineAssemblyRequiresUnsafe { span, unsafe_not_inherited_note }); } - InitializingTypeWith if unsafe_op_in_unsafe_fn_allowed => { - dcx.emit_err(InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { - span, - unsafe_not_inherited_note, - }); - } - InitializingTypeWith => { - dcx.emit_err(InitializingTypeWithRequiresUnsafe { - span, - unsafe_not_inherited_note, - }); - } InitializingTypeWithUnsafeField if unsafe_op_in_unsafe_fn_allowed => { dcx.emit_err( InitializingTypeWithUnsafeFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed { diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 6199e3766604d..dbdb51d56e8c1 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -66,18 +66,6 @@ pub(crate) struct UnsafeOpInUnsafeFnUseOfInlineAssemblyRequiresUnsafe { pub(crate) unsafe_not_inherited_note: Option, } -#[derive(Diagnostic)] -#[diag("initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe block", code = E0133)] -#[note( - "initializing a layout restricted type's field with a value outside the valid range is undefined behavior" -)] -pub(crate) struct UnsafeOpInUnsafeFnInitializingTypeWithRequiresUnsafe { - #[label("initializing type with `rustc_layout_scalar_valid_range` attr")] - pub(crate) span: Span, - #[subdiagnostic] - pub(crate) unsafe_not_inherited_note: Option, -} - #[derive(Diagnostic)] #[diag("initializing type with an unsafe field is unsafe and requires unsafe block", code = E0133)] #[note("unsafe fields may carry library invariants")] @@ -282,19 +270,6 @@ pub(crate) struct UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed { pub(crate) unsafe_not_inherited_note: Option, } -#[derive(Diagnostic)] -#[diag("initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe block", code = E0133)] -#[note( - "initializing a layout restricted type's field with a value outside the valid range is undefined behavior" -)] -pub(crate) struct InitializingTypeWithRequiresUnsafe { - #[primary_span] - #[label("initializing type with `rustc_layout_scalar_valid_range` attr")] - pub(crate) span: Span, - #[subdiagnostic] - pub(crate) unsafe_not_inherited_note: Option, -} - #[derive(Diagnostic)] #[diag("initializing type with an unsafe field is unsafe and requires unsafe block", code = E0133)] #[note("unsafe fields may carry library invariants")] @@ -306,22 +281,6 @@ pub(crate) struct InitializingTypeWithUnsafeFieldRequiresUnsafe { pub(crate) unsafe_not_inherited_note: Option, } -#[derive(Diagnostic)] -#[diag( - "initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block", - code = E0133 -)] -#[note( - "initializing a layout restricted type's field with a value outside the valid range is undefined behavior" -)] -pub(crate) struct InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed { - #[primary_span] - #[label("initializing type with `rustc_layout_scalar_valid_range` attr")] - pub(crate) span: Span, - #[subdiagnostic] - pub(crate) unsafe_not_inherited_note: Option, -} - #[derive(Diagnostic)] #[diag( "initializing type with an unsafe field is unsafe and requires unsafe block", diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 831199a59a432..c7ebafa30162d 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -314,8 +314,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | AttributeKind::RustcInsignificantDtor | AttributeKind::RustcIntrinsic | AttributeKind::RustcIntrinsicConstStableIndirect - | AttributeKind::RustcLayoutScalarValidRangeEnd(..) - | AttributeKind::RustcLayoutScalarValidRangeStart(..) | AttributeKind::RustcLintOptDenyFieldAccess { .. } | AttributeKind::RustcLintOptTy | AttributeKind::RustcLintQueryInstability diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index caeb923c18f78..3bdbd43009c6b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1755,8 +1755,6 @@ symbols! { rustc_insignificant_dtor, rustc_intrinsic, rustc_intrinsic_const_stable_indirect, - rustc_layout_scalar_valid_range_end, - rustc_layout_scalar_valid_range_start, rustc_legacy_const_generics, rustc_lint_opt_deny_field_access, rustc_lint_opt_ty, diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index 1bfe6e94cc3b6..41ee6255a8fdd 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -329,33 +329,11 @@ pub(crate) mod rustc { .fold(Tree::unit(), |tree, elt| tree.then(elt))) } - ty::Adt(adt_def, _args_ref) if !ty.is_box() => { - let (lo, hi) = cx.tcx().layout_scalar_valid_range(adt_def.did()); - - use core::ops::Bound::*; - let is_transparent = adt_def.repr().transparent(); - match (adt_def.adt_kind(), lo, hi) { - (AdtKind::Struct, Unbounded, Unbounded) => { - Self::from_struct((ty, layout), *adt_def, cx) - } - (AdtKind::Struct, Included(1), Included(_hi)) if is_transparent => { - // FIXME(@joshlf): Support `NonZero` types: - // - Check to make sure that the first field is - // numerical - // - Check to make sure that the upper bound is the - // maximum value for the field's type - // - Construct `Self::nonzero` - Err(Err::NotYetSupported) - } - (AdtKind::Enum, Unbounded, Unbounded) => { - Self::from_enum((ty, layout), *adt_def, cx) - } - (AdtKind::Union, Unbounded, Unbounded) => { - Self::from_union((ty, layout), *adt_def, cx) - } - _ => Err(Err::NotYetSupported), - } - } + ty::Adt(adt_def, _args_ref) if !ty.is_box() => match adt_def.adt_kind() { + AdtKind::Struct => Self::from_struct((ty, layout), *adt_def, cx), + AdtKind::Enum => Self::from_enum((ty, layout), *adt_def, cx), + AdtKind::Union => Self::from_union((ty, layout), *adt_def, cx), + }, ty::Ref(region, ty, mutability) => { let layout = layout_of(cx, *ty)?; diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 716ecf5723839..2ee27ed0914f7 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -700,7 +700,6 @@ fn layout_of_uncached<'tcx>( &variants, def.is_enum(), is_special_no_niche, - tcx.layout_scalar_valid_range(def.did()), discr_range_of_repr, discriminants_iter(), !maybe_unsized, @@ -725,7 +724,6 @@ fn layout_of_uncached<'tcx>( &variants, def.is_enum(), is_special_no_niche, - tcx.layout_scalar_valid_range(def.did()), discr_range_of_repr, discriminants_iter(), !maybe_unsized, diff --git a/src/doc/rustc-dev-guide/src/unsafety-checking.md b/src/doc/rustc-dev-guide/src/unsafety-checking.md index ed05f8a4c865a..e4547634280e6 100644 --- a/src/doc/rustc-dev-guide/src/unsafety-checking.md +++ b/src/doc/rustc-dev-guide/src/unsafety-checking.md @@ -30,14 +30,8 @@ side of an assignment expression and allows union fields to directly appear there, while erroring in all other cases. Union field accesses can also occur in patterns, so those have to be walked as well. -The other complicated safety check is for writes to fields of layout constrained -structs (such as [`NonNull`]). These are found by looking for the borrow or -assignment expression and then visiting the subexpression being borrowed or -assigned with a separate visitor. - [THIR]: ./thir.md [`check_unsafety`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/check_unsafety/index.html -[`NonNull`]: https://doc.rust-lang.org/std/ptr/struct.NonNull.html ## The unused_unsafe lint diff --git a/src/tools/clippy/tests/ui/eager_transmute.fixed b/src/tools/clippy/tests/ui/eager_transmute.fixed index 47a32ec836cc9..dbb3fdee43ad1 100644 --- a/src/tools/clippy/tests/ui/eager_transmute.fixed +++ b/src/tools/clippy/tests/ui/eager_transmute.fixed @@ -1,8 +1,9 @@ -#![feature(rustc_attrs)] +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] #![warn(clippy::eager_transmute)] #![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)] use std::num::NonZero; +use std::pat::pattern_type; #[repr(u8)] enum Opcode { @@ -77,23 +78,25 @@ unsafe fn f2(op: u8) { } } -#[rustc_layout_scalar_valid_range_end(254)] -struct NonMaxU8(u8); -#[rustc_layout_scalar_valid_range_end(254)] -#[rustc_layout_scalar_valid_range_start(1)] -struct NonZeroNonMaxU8(u8); +struct NonMaxU8(pattern_type!(u8 is 0..=254)); +struct NonZeroNonMaxU8(pattern_type!(u8 is 1..=254)); macro_rules! impls { ($($t:ty),*) => { $( + impl $t { + fn get(&self) -> u8 { + unsafe { std::mem::transmute(self.0) } + } + } impl PartialEq for $t { fn eq(&self, other: &u8) -> bool { - self.0 == *other + self.get() == *other } } impl PartialOrd for $t { fn partial_cmp(&self, other: &u8) -> Option { - self.0.partial_cmp(other) + self.get().partial_cmp(other) } } )* diff --git a/src/tools/clippy/tests/ui/eager_transmute.rs b/src/tools/clippy/tests/ui/eager_transmute.rs index 906cd7bccc86f..d44c501467cd7 100644 --- a/src/tools/clippy/tests/ui/eager_transmute.rs +++ b/src/tools/clippy/tests/ui/eager_transmute.rs @@ -1,8 +1,9 @@ -#![feature(rustc_attrs)] +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] #![warn(clippy::eager_transmute)] #![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)] use std::num::NonZero; +use std::pat::pattern_type; #[repr(u8)] enum Opcode { @@ -77,23 +78,25 @@ unsafe fn f2(op: u8) { } } -#[rustc_layout_scalar_valid_range_end(254)] -struct NonMaxU8(u8); -#[rustc_layout_scalar_valid_range_end(254)] -#[rustc_layout_scalar_valid_range_start(1)] -struct NonZeroNonMaxU8(u8); +struct NonMaxU8(pattern_type!(u8 is 0..=254)); +struct NonZeroNonMaxU8(pattern_type!(u8 is 1..=254)); macro_rules! impls { ($($t:ty),*) => { $( + impl $t { + fn get(&self) -> u8 { + unsafe { std::mem::transmute(self.0) } + } + } impl PartialEq for $t { fn eq(&self, other: &u8) -> bool { - self.0 == *other + self.get() == *other } } impl PartialOrd for $t { fn partial_cmp(&self, other: &u8) -> Option { - self.0.partial_cmp(other) + self.get().partial_cmp(other) } } )* diff --git a/src/tools/clippy/tests/ui/eager_transmute.stderr b/src/tools/clippy/tests/ui/eager_transmute.stderr index c719ca8adc12e..847d05cc5432f 100644 --- a/src/tools/clippy/tests/ui/eager_transmute.stderr +++ b/src/tools/clippy/tests/ui/eager_transmute.stderr @@ -1,5 +1,5 @@ error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:21:33 + --> tests/ui/eager_transmute.rs:22:33 | LL | (op < 4).then_some(unsafe { std::mem::transmute(op) }) | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + (op < 4).then(|| unsafe { std::mem::transmute(op) }) | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:28:33 + --> tests/ui/eager_transmute.rs:29:33 | LL | (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:30:33 + --> tests/ui/eager_transmute.rs:31:33 | LL | (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:32:34 + --> tests/ui/eager_transmute.rs:33:34 | LL | (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) }); | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:35:68 + --> tests/ui/eager_transmute.rs:36:68 | LL | let _: Option = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + let _: Option = (op > 0 && op < 10).then(|| unsafe { std::mem:: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:37:86 + --> tests/ui/eager_transmute.rs:38:86 | LL | let _: Option = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + let _: Option = (op > 0 && op < 10 && unrelated == 0).then(|| u | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:41:84 + --> tests/ui/eager_transmute.rs:42:84 | LL | let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + let _: Option = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| uns | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:54:70 + --> tests/ui/eager_transmute.rs:55:70 | LL | let _: Option = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + let _: Option = (1..=3).contains(&op).then(|| unsafe { std::mem | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:56:83 + --> tests/ui/eager_transmute.rs:57:83 | LL | let _: Option = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + let _: Option = ((1..=3).contains(&op) || op == 4).then(|| unsa | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:58:69 + --> tests/ui/eager_transmute.rs:59:69 | LL | let _: Option = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + let _: Option = (1..3).contains(&op).then(|| unsafe { std::mem: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:60:68 + --> tests/ui/eager_transmute.rs:61:68 | LL | let _: Option = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + let _: Option = (1..).contains(&op).then(|| unsafe { std::mem:: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:62:68 + --> tests/ui/eager_transmute.rs:63:68 | LL | let _: Option = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL + let _: Option = (..3).contains(&op).then(|| unsafe { std::mem:: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:64:69 + --> tests/ui/eager_transmute.rs:65:69 | LL | let _: Option = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + let _: Option = (..=3).contains(&op).then(|| unsafe { std::mem: | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:75:28 + --> tests/ui/eager_transmute.rs:76:28 | LL | (op < 4).then_some(std::mem::transmute::<_, Opcode>(op)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + (op < 4).then(|| std::mem::transmute::<_, Opcode>(op)); | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:106:62 + --> tests/ui/eager_transmute.rs:109:62 | LL | let _: Option> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + let _: Option> = (v1 > 0).then(|| unsafe { std::mem::transm | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:113:86 + --> tests/ui/eager_transmute.rs:116:86 | LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + let _: Option = (v2 < NonZero::new(255u8).unwrap()).then(|| u | error: this transmute is always evaluated eagerly, even if the condition is false - --> tests/ui/eager_transmute.rs:120:93 + --> tests/ui/eager_transmute.rs:123:93 | LL | let _: Option = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) }); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/miri/tests/fail/validity/nonzero.rs b/src/tools/miri/tests/fail/validity/nonzero.rs index 7cba90bc15d13..fba37ee170e3a 100644 --- a/src/tools/miri/tests/fail/validity/nonzero.rs +++ b/src/tools/miri/tests/fail/validity/nonzero.rs @@ -1,11 +1,10 @@ -#![feature(rustc_attrs)] +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] #![allow(unused_attributes)] -#[rustc_layout_scalar_valid_range_start(1)] #[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); +struct NonZero(std::pat::pattern_type!(u32 is 1..=u32::MAX)); fn main() { // Make sure that we detect this even when no function call is happening along the way - let _x = Some(unsafe { NonZero(0) }); //~ ERROR: encountered 0, but expected something greater or equal to 1 + let _x = Some(unsafe { NonZero(std::mem::transmute(0_u32)) }); //~ ERROR: encountered 0, but expected something greater or equal to 1 } diff --git a/src/tools/miri/tests/fail/validity/nonzero.stderr b/src/tools/miri/tests/fail/validity/nonzero.stderr index 2b352400b6e81..08647f18fb422 100644 --- a/src/tools/miri/tests/fail/validity/nonzero.stderr +++ b/src/tools/miri/tests/fail/validity/nonzero.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: constructing invalid value of type NonZero: encountered 0, but expected something greater or equal to 1 +error: Undefined Behavior: constructing invalid value of type (u32) is 1..: encountered 0, but expected something greater or equal to 1 --> tests/fail/validity/nonzero.rs:LL:CC | -LL | let _x = Some(unsafe { NonZero(0) }); - | ^^^^^^^^^^ Undefined Behavior occurred here +LL | let _x = Some(unsafe { NonZero(std::mem::transmute(0_u32)) }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/codegen-llvm/function-arguments.rs b/tests/codegen-llvm/function-arguments.rs index 87be219a2b2e0..6eab9a58b47ad 100644 --- a/tests/codegen-llvm/function-arguments.rs +++ b/tests/codegen-llvm/function-arguments.rs @@ -151,21 +151,6 @@ pub fn option_borrow(_x: Option<&i32>) {} #[no_mangle] pub fn option_borrow_mut(_x: Option<&mut i32>) {} -// Function that must NOT have `dereferenceable` or `align`. -#[rustc_layout_scalar_valid_range_start(16)] -pub struct RestrictedAddress(&'static i16); -enum E { - A(RestrictedAddress), - B, - C, -} -// If the `nonnull` ever goes missing, you might have to tweak the -// scalar_valid_range on `RestrictedAddress` to get it back. You -// might even have to add a `rustc_layout_scalar_valid_range_end`. -// CHECK: @nonnull_and_nondereferenceable(ptr noundef nonnull %_x) -#[no_mangle] -pub fn nonnull_and_nondereferenceable(_x: E) {} - // CHECK: @raw_struct(ptr noundef %_1) #[no_mangle] pub fn raw_struct(_: *const S) {} diff --git a/tests/crashes/122681.rs b/tests/crashes/122681.rs deleted file mode 100644 index 7dae276950e1d..0000000000000 --- a/tests/crashes/122681.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ known-bug: #122681 -#[rustc_layout_scalar_valid_range_start(1)] -struct UnitStruct; - -#[derive(Default)] -enum SomeEnum { - #[default] - Unit, - Tuple(UnitStruct), -} diff --git a/tests/debuginfo/msvc-pretty-enums.rs b/tests/debuginfo/msvc-pretty-enums.rs index de5dfef004a6e..197aa4546c770 100644 --- a/tests/debuginfo/msvc-pretty-enums.rs +++ b/tests/debuginfo/msvc-pretty-enums.rs @@ -232,7 +232,7 @@ //@ cdb-command: dx c_style_i128_d //@ cdb-check: c_style_i128_d : D [Type: enum2$] -#![feature(rustc_attrs)] +#![feature(pattern_types, pattern_type_macro)] use std::num::NonZero; @@ -270,10 +270,10 @@ enum NicheLayoutWithFields3 { F, } -#[rustc_layout_scalar_valid_range_start(340282366920938463463374607431768211454)] -#[rustc_layout_scalar_valid_range_end(1)] #[repr(transparent)] -struct Wrapping128(u128); +struct Wrapping128( + std::pat::pattern_type!(u128 is 340282366920938463463374607431768211454..=u128::MAX | 0..=1), +); enum Wrapping128Niche { X(Wrapping128), @@ -325,8 +325,9 @@ fn main() { let niche128_some = NonZero::new(123456i128); let niche128_none: Option> = None; - let wrapping_niche128_untagged = - unsafe { Wrapping128Niche::X(Wrapping128(340282366920938463463374607431768211454)) }; + let wrapping_niche128_untagged = Wrapping128Niche::X(Wrapping128(unsafe { + std::mem::transmute(340282366920938463463374607431768211454_u128) + })); let wrapping_niche128_none1 = Wrapping128Niche::Y; let wrapping_niche128_none2 = Wrapping128Niche::Z; diff --git a/tests/incremental/issue-59524-layout-scalar-valid-range-is-not-unused.rs b/tests/incremental/issue-59524-layout-scalar-valid-range-is-not-unused.rs deleted file mode 100644 index 3a2e6cf9f02aa..0000000000000 --- a/tests/incremental/issue-59524-layout-scalar-valid-range-is-not-unused.rs +++ /dev/null @@ -1,20 +0,0 @@ -// We should not see the unused_attributes lint fire for -// rustc_layout_scalar_valid_range_start, but with this bug we are -// seeing it fire (on subsequent runs) if incremental compilation is -// enabled. - -//@ revisions: bpass1 bpass2 -//@ ignore-backends: gcc -// FIXME(#62277): could be check-pass? - -#![feature(rustc_attrs)] -#![deny(unused_attributes)] - -#[rustc_layout_scalar_valid_range_start(10)] -#[rustc_layout_scalar_valid_range_end(30)] -struct RestrictedRange(u32); -const OKAY_RANGE: RestrictedRange = unsafe { RestrictedRange(20) }; - -fn main() { - OKAY_RANGE.0; -} diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff index e2cd73404bec3..f1aae54c12d60 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.32bit.diff @@ -4,13 +4,17 @@ fn mutate_discriminant() -> u8 { let mut _0: u8; let mut _1: std::option::Option; - let mut _2: isize; + let mut _2: (usize) is 1..; + let mut _3: isize; bb0: { discriminant(_1) = 1; - (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; - _2 = discriminant(_1); - switchInt(copy _2) -> [0: bb1, otherwise: bb2]; +- _2 = const 0_usize as (usize) is 1.. (Transmute); +- (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = copy _2; ++ _2 = const {transmute(0x00000000): (usize) is 1..}; ++ (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = const {transmute(0x00000000): (usize) is 1..=usize::MAX}; + _3 = discriminant(_1); + switchInt(copy _3) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff index e2cd73404bec3..382f81722cd91 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff +++ b/tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.64bit.diff @@ -4,13 +4,17 @@ fn mutate_discriminant() -> u8 { let mut _0: u8; let mut _1: std::option::Option; - let mut _2: isize; + let mut _2: (usize) is 1..; + let mut _3: isize; bb0: { discriminant(_1) = 1; - (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; - _2 = discriminant(_1); - switchInt(copy _2) -> [0: bb1, otherwise: bb2]; +- _2 = const 0_usize as (usize) is 1.. (Transmute); +- (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = copy _2; ++ _2 = const {transmute(0x0000000000000000): (usize) is 1..}; ++ (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = const {transmute(0x0000000000000000): (usize) is 1..=usize::MAX}; + _3 = discriminant(_1); + switchInt(copy _3) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/dataflow-const-prop/enum.rs b/tests/mir-opt/dataflow-const-prop/enum.rs index 207e29e63df9e..80553a3974881 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.rs +++ b/tests/mir-opt/dataflow-const-prop/enum.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_BIT_WIDTH -#![feature(custom_mir, core_intrinsics, rustc_attrs)] +#![feature(custom_mir, core_intrinsics, rustc_attrs, pattern_types, pattern_type_macro)] use std::intrinsics::mir::*; @@ -72,7 +72,7 @@ fn statics() { static RC: &E = &E::V2(4); - // CHECK: [[t:_.*]] = const {alloc5: &&E}; + // CHECK: [[t:_.*]] = const {alloc7: &&E}; // CHECK: [[e2]] = copy (*[[t]]); let e2 = RC; @@ -88,9 +88,8 @@ fn statics() { }; } -#[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] -struct NonZeroUsize(usize); +struct NonZeroUsize(std::pat::pattern_type!(usize is 1..=usize::MAX)); // EMIT_MIR enum.mutate_discriminant.DataflowConstProp.diff @@ -101,8 +100,9 @@ fn mutate_discriminant() -> u8 { let x: Option; { SetDiscriminant(x, 1); + let y = CastTransmute::<_, std::pat::pattern_type!(usize is 1..=usize::MAX)>(0_usize); // This assignment overwrites the niche in which the discriminant is stored. - place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize; + place!(Field(Field(Variant(x, 1), 0), 0)) = y; // So we cannot know the value of this discriminant. // CHECK: [[a:_.*]] = discriminant({{_.*}}); diff --git a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff index 9f8a839eee9a0..c525a94342598 100644 --- a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff @@ -6,79 +6,81 @@ debug thin => _2; let mut _0: (); let _3: MyId; - let mut _4: u16; - let _5: (); - let mut _6: u16; - let mut _7: MyId; - let mut _9: u16; - let mut _10: std::marker::PhantomData; - let _11: (); - let mut _12: u16; - let mut _13: TypedId; - let mut _15: u16; - let _16: (); - let mut _17: u16; - let mut _18: std::result::Result; - let mut _20: u16; - let _21: (); - let mut _22: u32; - let mut _23: std::option::Option; - let mut _25: u16; - let _26: (); - let mut _27: i16; - let mut _28: MyId; - let mut _30: u16; - let mut _31: u16; - let _32: (); - let mut _33: u32; - let mut _34: aggregate_struct_then_transmute::Pair; - let mut _36: u16; - let mut _37: u16; - let _38: (); + let mut _4: (u16) is 0..=55554; + let mut _5: u16; + let _6: (); + let mut _7: u16; + let mut _8: MyId; + let mut _10: u16; + let mut _11: std::marker::PhantomData; + let _12: (); + let mut _13: u16; + let mut _14: TypedId; + let mut _16: u16; + let _17: (); + let mut _18: u16; + let mut _19: std::result::Result; + let mut _21: u16; + let _22: (); + let mut _23: u32; + let mut _24: std::option::Option; + let mut _26: (u16) is 0..=55554; + let mut _27: u16; + let _28: (); + let mut _29: i16; + let mut _30: MyId; + let mut _32: u16; + let mut _33: u16; + let _34: (); + let mut _35: u32; + let mut _36: aggregate_struct_then_transmute::Pair; + let mut _38: u16; let mut _39: u16; - let mut _40: aggregate_struct_then_transmute::Pair; - let mut _42: u16; - let _43: (); + let _40: (); + let mut _41: u16; + let mut _42: aggregate_struct_then_transmute::Pair; let mut _44: u16; - let mut _45: (u16,); - let mut _47: u16; - let _48: (); + let _45: (); + let mut _46: u16; + let mut _47: (u16,); let mut _49: u16; - let mut _50: [u16; 1]; - let mut _52: *const u8; - let mut _53: (); - let _54: (); - let mut _55: *const u8; - let mut _56: *const i32; + let _50: (); + let mut _51: u16; + let mut _52: [u16; 1]; + let mut _54: *const u8; + let mut _55: (); + let _56: (); + let mut _57: *const u8; + let mut _58: *const i32; scope 1 { debug a => _3; - let _8: TypedId; + let _9: TypedId; scope 2 { - debug b => _8; - let _14: std::result::Result; + debug b => _9; + let _15: std::result::Result; scope 3 { - debug c => _14; - let _19: std::option::Option; + debug c => _15; + let _20: std::option::Option; scope 4 { - debug d => _19; - let _24: MyId; + debug d => _20; + let _25: MyId; scope 5 { - debug e => _24; - let _29: aggregate_struct_then_transmute::Pair; + debug e => _25; + let _31: aggregate_struct_then_transmute::Pair; scope 6 { - debug f => _29; - let _35: aggregate_struct_then_transmute::Pair; + debug f => _31; + let _37: aggregate_struct_then_transmute::Pair; scope 7 { - debug g => _35; - let _41: (u16,); + debug g => _37; + let _43: (u16,); scope 8 { - debug h => _41; - let _46: [u16; 1]; + debug h => _43; + let _48: [u16; 1]; scope 9 { - debug i => _46; - let _51: *const i32; + debug i => _48; + let _53: *const i32; scope 10 { - debug j => _51; + debug j => _53; } } } @@ -92,231 +94,240 @@ bb0: { StorageLive(_3); - StorageLive(_4); - _4 = copy _1; -- _3 = MyId(move _4); -+ _3 = MyId(copy _1); - StorageDead(_4); +- StorageLive(_4); ++ nop; StorageLive(_5); + _5 = copy _1; +- _4 = move _5 as (u16) is 0..=55554 (Transmute); ++ _4 = copy _1 as (u16) is 0..=55554 (Transmute); + StorageDead(_5); +- _3 = MyId(move _4); +- StorageDead(_4); ++ _3 = MyId(copy _4); ++ nop; StorageLive(_6); StorageLive(_7); -- _7 = move _3; -- _6 = move _7 as u16 (Transmute); -+ _7 = copy _3; -+ _6 = copy _1; - StorageDead(_7); -- _5 = opaque::(move _6) -> [return: bb1, unwind unreachable]; -+ _5 = opaque::(copy _1) -> [return: bb1, unwind unreachable]; + StorageLive(_8); +- _8 = move _3; +- _7 = move _8 as u16 (Transmute); ++ _8 = copy _3; ++ _7 = copy _4 as u16 (Transmute); + StorageDead(_8); + _6 = opaque::(move _7) -> [return: bb1, unwind unreachable]; } bb1: { + StorageDead(_7); StorageDead(_6); - StorageDead(_5); - StorageLive(_8); StorageLive(_9); - _9 = copy _1; StorageLive(_10); -- _10 = PhantomData::; -- _8 = TypedId::(move _9, move _10); -+ _10 = const PhantomData::; -+ _8 = TypedId::(copy _1, const PhantomData::); - StorageDead(_10); - StorageDead(_9); + _10 = copy _1; StorageLive(_11); +- _11 = PhantomData::; +- _9 = TypedId::(move _10, move _11); ++ _11 = const PhantomData::; ++ _9 = TypedId::(copy _1, const PhantomData::); + StorageDead(_11); + StorageDead(_10); StorageLive(_12); StorageLive(_13); -- _13 = move _8; -- _12 = move _13 as u16 (Transmute); -+ _13 = copy _8; -+ _12 = copy _1; - StorageDead(_13); -- _11 = opaque::(move _12) -> [return: bb2, unwind unreachable]; -+ _11 = opaque::(copy _1) -> [return: bb2, unwind unreachable]; + StorageLive(_14); +- _14 = move _9; +- _13 = move _14 as u16 (Transmute); ++ _14 = copy _9; ++ _13 = copy _1; + StorageDead(_14); +- _12 = opaque::(move _13) -> [return: bb2, unwind unreachable]; ++ _12 = opaque::(copy _1) -> [return: bb2, unwind unreachable]; } bb2: { + StorageDead(_13); StorageDead(_12); - StorageDead(_11); - StorageLive(_14); StorageLive(_15); - _15 = copy _1; -- _14 = Result::::Err(move _15); -+ _14 = Result::::Err(copy _1); - StorageDead(_15); StorageLive(_16); + _16 = copy _1; +- _15 = Result::::Err(move _16); ++ _15 = Result::::Err(copy _1); + StorageDead(_16); StorageLive(_17); StorageLive(_18); -- _18 = move _14; -- _17 = move _18 as u16 (Transmute); -+ _18 = copy _14; -+ _17 = copy _1; - StorageDead(_18); -- _16 = opaque::(move _17) -> [return: bb3, unwind unreachable]; -+ _16 = opaque::(copy _1) -> [return: bb3, unwind unreachable]; + StorageLive(_19); +- _19 = move _15; +- _18 = move _19 as u16 (Transmute); ++ _19 = copy _15; ++ _18 = copy _1; + StorageDead(_19); +- _17 = opaque::(move _18) -> [return: bb3, unwind unreachable]; ++ _17 = opaque::(copy _1) -> [return: bb3, unwind unreachable]; } bb3: { + StorageDead(_18); StorageDead(_17); - StorageDead(_16); - StorageLive(_19); StorageLive(_20); - _20 = copy _1; -- _19 = Option::::Some(move _20); -+ _19 = Option::::Some(copy _1); - StorageDead(_20); StorageLive(_21); + _21 = copy _1; +- _20 = Option::::Some(move _21); ++ _20 = Option::::Some(copy _1); + StorageDead(_21); StorageLive(_22); StorageLive(_23); - _23 = copy _19; -- _22 = move _23 as u32 (Transmute); -+ _22 = copy _19 as u32 (Transmute); - StorageDead(_23); - _21 = opaque::(move _22) -> [return: bb4, unwind unreachable]; + StorageLive(_24); + _24 = copy _20; +- _23 = move _24 as u32 (Transmute); ++ _23 = copy _20 as u32 (Transmute); + StorageDead(_24); + _22 = opaque::(move _23) -> [return: bb4, unwind unreachable]; } bb4: { + StorageDead(_23); StorageDead(_22); - StorageDead(_21); - StorageLive(_24); StorageLive(_25); - _25 = copy _1; -- _24 = MyId(move _25); -+ _24 = copy _3; - StorageDead(_25); StorageLive(_26); StorageLive(_27); - StorageLive(_28); -- _28 = move _24; -- _27 = move _28 as i16 (Transmute); -+ _28 = copy _3; -+ _27 = copy _1 as i16 (Transmute); - StorageDead(_28); - _26 = opaque::(move _27) -> [return: bb5, unwind unreachable]; - } - - bb5: { + _27 = copy _1; +- _26 = move _27 as (u16) is 0..=55554 (Transmute); ++ _26 = copy _4; StorageDead(_27); +- _25 = MyId(move _26); ++ _25 = copy _3; StorageDead(_26); + StorageLive(_28); StorageLive(_29); StorageLive(_30); - _30 = copy _1; - StorageLive(_31); - _31 = copy _1; -- _29 = Pair(move _30, move _31); -+ _29 = Pair(copy _1, copy _1); - StorageDead(_31); +- _30 = move _25; +- _29 = move _30 as i16 (Transmute); ++ _30 = copy _3; ++ _29 = copy _4 as i16 (Transmute); StorageDead(_30); - StorageLive(_32); - StorageLive(_33); - StorageLive(_34); -- _34 = move _29; -- _33 = move _34 as u32 (Transmute); -+ _34 = copy _29; -+ _33 = copy _29 as u32 (Transmute); - StorageDead(_34); - _32 = opaque::(move _33) -> [return: bb6, unwind unreachable]; + _28 = opaque::(move _29) -> [return: bb5, unwind unreachable]; } - bb6: { + bb5: { + StorageDead(_29); + StorageDead(_28); + StorageLive(_31); + StorageLive(_32); + _32 = copy _1; + StorageLive(_33); + _33 = copy _1; +- _31 = Pair(move _32, move _33); ++ _31 = Pair(copy _1, copy _1); StorageDead(_33); StorageDead(_32); + StorageLive(_34); StorageLive(_35); StorageLive(_36); - _36 = copy _1; - StorageLive(_37); - _37 = copy _1; -- _35 = Pair(move _36, move _37); -+ _35 = copy _29; - StorageDead(_37); +- _36 = move _31; +- _35 = move _36 as u32 (Transmute); ++ _36 = copy _31; ++ _35 = copy _31 as u32 (Transmute); StorageDead(_36); - StorageLive(_38); - StorageLive(_39); - StorageLive(_40); -- _40 = move _35; -- _39 = move _40 as u16 (Transmute); -+ _40 = copy _29; -+ _39 = copy _29 as u16 (Transmute); - StorageDead(_40); - _38 = opaque::(move _39) -> [return: bb7, unwind unreachable]; + _34 = opaque::(move _35) -> [return: bb6, unwind unreachable]; } - bb7: { + bb6: { + StorageDead(_35); + StorageDead(_34); + StorageLive(_37); + StorageLive(_38); + _38 = copy _1; + StorageLive(_39); + _39 = copy _1; +- _37 = Pair(move _38, move _39); ++ _37 = copy _31; StorageDead(_39); StorageDead(_38); + StorageLive(_40); StorageLive(_41); StorageLive(_42); - _42 = copy _1; -- _41 = (move _42,); -+ _41 = (copy _1,); +- _42 = move _37; +- _41 = move _42 as u16 (Transmute); ++ _42 = copy _31; ++ _41 = copy _31 as u16 (Transmute); StorageDead(_42); - StorageLive(_43); - StorageLive(_44); - StorageLive(_45); - _45 = copy _41; -- _44 = move _45 as u16 (Transmute); -+ _44 = copy _1; - StorageDead(_45); -- _43 = opaque::(move _44) -> [return: bb8, unwind unreachable]; -+ _43 = opaque::(copy _1) -> [return: bb8, unwind unreachable]; + _40 = opaque::(move _41) -> [return: bb7, unwind unreachable]; } - bb8: { + bb7: { + StorageDead(_41); + StorageDead(_40); + StorageLive(_43); + StorageLive(_44); + _44 = copy _1; +- _43 = (move _44,); ++ _43 = (copy _1,); StorageDead(_44); - StorageDead(_43); + StorageLive(_45); StorageLive(_46); StorageLive(_47); - _47 = copy _1; -- _46 = [move _47]; -+ _46 = [copy _1]; + _47 = copy _43; +- _46 = move _47 as u16 (Transmute); ++ _46 = copy _1; StorageDead(_47); +- _45 = opaque::(move _46) -> [return: bb8, unwind unreachable]; ++ _45 = opaque::(copy _1) -> [return: bb8, unwind unreachable]; + } + + bb8: { + StorageDead(_46); + StorageDead(_45); StorageLive(_48); StorageLive(_49); + _49 = copy _1; +- _48 = [move _49]; ++ _48 = [copy _1]; + StorageDead(_49); StorageLive(_50); - _50 = copy _46; -- _49 = move _50 as u16 (Transmute); -+ _49 = copy _1; - StorageDead(_50); -- _48 = opaque::(move _49) -> [return: bb9, unwind unreachable]; -+ _48 = opaque::(copy _1) -> [return: bb9, unwind unreachable]; + StorageLive(_51); + StorageLive(_52); + _52 = copy _48; +- _51 = move _52 as u16 (Transmute); ++ _51 = copy _1; + StorageDead(_52); +- _50 = opaque::(move _51) -> [return: bb9, unwind unreachable]; ++ _50 = opaque::(copy _1) -> [return: bb9, unwind unreachable]; } bb9: { - StorageDead(_49); - StorageDead(_48); - StorageLive(_51); - StorageLive(_52); - _52 = copy _2; + StorageDead(_51); + StorageDead(_50); StorageLive(_53); -- _53 = (); -- _51 = *const i32 from (move _52, move _53); -+ _53 = const (); -+ _51 = *const i32 from (copy _2, const ()); - StorageDead(_53); - StorageDead(_52); StorageLive(_54); + _54 = copy _2; StorageLive(_55); +- _55 = (); +- _53 = *const i32 from (move _54, move _55); ++ _55 = const (); ++ _53 = *const i32 from (copy _2, const ()); + StorageDead(_55); + StorageDead(_54); StorageLive(_56); - _56 = copy _51; -- _55 = move _56 as *const u8 (Transmute); -+ _55 = copy _2; - StorageDead(_56); -- _54 = opaque::<*const u8>(move _55) -> [return: bb10, unwind unreachable]; -+ _54 = opaque::<*const u8>(copy _2) -> [return: bb10, unwind unreachable]; + StorageLive(_57); + StorageLive(_58); + _58 = copy _53; +- _57 = move _58 as *const u8 (Transmute); ++ _57 = copy _2; + StorageDead(_58); +- _56 = opaque::<*const u8>(move _57) -> [return: bb10, unwind unreachable]; ++ _56 = opaque::<*const u8>(copy _2) -> [return: bb10, unwind unreachable]; } bb10: { - StorageDead(_55); - StorageDead(_54); + StorageDead(_57); + StorageDead(_56); _0 = const (); - StorageDead(_51); - StorageDead(_46); - StorageDead(_41); - StorageDead(_35); - StorageDead(_29); - StorageDead(_24); - StorageDead(_19); - StorageDead(_14); - StorageDead(_8); + StorageDead(_53); + StorageDead(_48); + StorageDead(_43); + StorageDead(_37); + StorageDead(_31); + StorageDead(_25); + StorageDead(_20); + StorageDead(_15); + StorageDead(_9); StorageDead(_3); return; } diff --git a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff index f04f778349dba..b617b3ba1eebf 100644 --- a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff @@ -6,79 +6,81 @@ debug thin => _2; let mut _0: (); let _3: MyId; - let mut _4: u16; - let _5: (); - let mut _6: u16; - let mut _7: MyId; - let mut _9: u16; - let mut _10: std::marker::PhantomData; - let _11: (); - let mut _12: u16; - let mut _13: TypedId; - let mut _15: u16; - let _16: (); - let mut _17: u16; - let mut _18: std::result::Result; - let mut _20: u16; - let _21: (); - let mut _22: u32; - let mut _23: std::option::Option; - let mut _25: u16; - let _26: (); - let mut _27: i16; - let mut _28: MyId; - let mut _30: u16; - let mut _31: u16; - let _32: (); - let mut _33: u32; - let mut _34: aggregate_struct_then_transmute::Pair; - let mut _36: u16; - let mut _37: u16; - let _38: (); + let mut _4: (u16) is 0..=55554; + let mut _5: u16; + let _6: (); + let mut _7: u16; + let mut _8: MyId; + let mut _10: u16; + let mut _11: std::marker::PhantomData; + let _12: (); + let mut _13: u16; + let mut _14: TypedId; + let mut _16: u16; + let _17: (); + let mut _18: u16; + let mut _19: std::result::Result; + let mut _21: u16; + let _22: (); + let mut _23: u32; + let mut _24: std::option::Option; + let mut _26: (u16) is 0..=55554; + let mut _27: u16; + let _28: (); + let mut _29: i16; + let mut _30: MyId; + let mut _32: u16; + let mut _33: u16; + let _34: (); + let mut _35: u32; + let mut _36: aggregate_struct_then_transmute::Pair; + let mut _38: u16; let mut _39: u16; - let mut _40: aggregate_struct_then_transmute::Pair; - let mut _42: u16; - let _43: (); + let _40: (); + let mut _41: u16; + let mut _42: aggregate_struct_then_transmute::Pair; let mut _44: u16; - let mut _45: (u16,); - let mut _47: u16; - let _48: (); + let _45: (); + let mut _46: u16; + let mut _47: (u16,); let mut _49: u16; - let mut _50: [u16; 1]; - let mut _52: *const u8; - let mut _53: (); - let _54: (); - let mut _55: *const u8; - let mut _56: *const i32; + let _50: (); + let mut _51: u16; + let mut _52: [u16; 1]; + let mut _54: *const u8; + let mut _55: (); + let _56: (); + let mut _57: *const u8; + let mut _58: *const i32; scope 1 { debug a => _3; - let _8: TypedId; + let _9: TypedId; scope 2 { - debug b => _8; - let _14: std::result::Result; + debug b => _9; + let _15: std::result::Result; scope 3 { - debug c => _14; - let _19: std::option::Option; + debug c => _15; + let _20: std::option::Option; scope 4 { - debug d => _19; - let _24: MyId; + debug d => _20; + let _25: MyId; scope 5 { - debug e => _24; - let _29: aggregate_struct_then_transmute::Pair; + debug e => _25; + let _31: aggregate_struct_then_transmute::Pair; scope 6 { - debug f => _29; - let _35: aggregate_struct_then_transmute::Pair; + debug f => _31; + let _37: aggregate_struct_then_transmute::Pair; scope 7 { - debug g => _35; - let _41: (u16,); + debug g => _37; + let _43: (u16,); scope 8 { - debug h => _41; - let _46: [u16; 1]; + debug h => _43; + let _48: [u16; 1]; scope 9 { - debug i => _46; - let _51: *const i32; + debug i => _48; + let _53: *const i32; scope 10 { - debug j => _51; + debug j => _53; } } } @@ -92,231 +94,240 @@ bb0: { StorageLive(_3); - StorageLive(_4); - _4 = copy _1; -- _3 = MyId(move _4); -+ _3 = MyId(copy _1); - StorageDead(_4); +- StorageLive(_4); ++ nop; StorageLive(_5); + _5 = copy _1; +- _4 = move _5 as (u16) is 0..=55554 (Transmute); ++ _4 = copy _1 as (u16) is 0..=55554 (Transmute); + StorageDead(_5); +- _3 = MyId(move _4); +- StorageDead(_4); ++ _3 = MyId(copy _4); ++ nop; StorageLive(_6); StorageLive(_7); -- _7 = move _3; -- _6 = move _7 as u16 (Transmute); -+ _7 = copy _3; -+ _6 = copy _1; - StorageDead(_7); -- _5 = opaque::(move _6) -> [return: bb1, unwind continue]; -+ _5 = opaque::(copy _1) -> [return: bb1, unwind continue]; + StorageLive(_8); +- _8 = move _3; +- _7 = move _8 as u16 (Transmute); ++ _8 = copy _3; ++ _7 = copy _4 as u16 (Transmute); + StorageDead(_8); + _6 = opaque::(move _7) -> [return: bb1, unwind continue]; } bb1: { + StorageDead(_7); StorageDead(_6); - StorageDead(_5); - StorageLive(_8); StorageLive(_9); - _9 = copy _1; StorageLive(_10); -- _10 = PhantomData::; -- _8 = TypedId::(move _9, move _10); -+ _10 = const PhantomData::; -+ _8 = TypedId::(copy _1, const PhantomData::); - StorageDead(_10); - StorageDead(_9); + _10 = copy _1; StorageLive(_11); +- _11 = PhantomData::; +- _9 = TypedId::(move _10, move _11); ++ _11 = const PhantomData::; ++ _9 = TypedId::(copy _1, const PhantomData::); + StorageDead(_11); + StorageDead(_10); StorageLive(_12); StorageLive(_13); -- _13 = move _8; -- _12 = move _13 as u16 (Transmute); -+ _13 = copy _8; -+ _12 = copy _1; - StorageDead(_13); -- _11 = opaque::(move _12) -> [return: bb2, unwind continue]; -+ _11 = opaque::(copy _1) -> [return: bb2, unwind continue]; + StorageLive(_14); +- _14 = move _9; +- _13 = move _14 as u16 (Transmute); ++ _14 = copy _9; ++ _13 = copy _1; + StorageDead(_14); +- _12 = opaque::(move _13) -> [return: bb2, unwind continue]; ++ _12 = opaque::(copy _1) -> [return: bb2, unwind continue]; } bb2: { + StorageDead(_13); StorageDead(_12); - StorageDead(_11); - StorageLive(_14); StorageLive(_15); - _15 = copy _1; -- _14 = Result::::Err(move _15); -+ _14 = Result::::Err(copy _1); - StorageDead(_15); StorageLive(_16); + _16 = copy _1; +- _15 = Result::::Err(move _16); ++ _15 = Result::::Err(copy _1); + StorageDead(_16); StorageLive(_17); StorageLive(_18); -- _18 = move _14; -- _17 = move _18 as u16 (Transmute); -+ _18 = copy _14; -+ _17 = copy _1; - StorageDead(_18); -- _16 = opaque::(move _17) -> [return: bb3, unwind continue]; -+ _16 = opaque::(copy _1) -> [return: bb3, unwind continue]; + StorageLive(_19); +- _19 = move _15; +- _18 = move _19 as u16 (Transmute); ++ _19 = copy _15; ++ _18 = copy _1; + StorageDead(_19); +- _17 = opaque::(move _18) -> [return: bb3, unwind continue]; ++ _17 = opaque::(copy _1) -> [return: bb3, unwind continue]; } bb3: { + StorageDead(_18); StorageDead(_17); - StorageDead(_16); - StorageLive(_19); StorageLive(_20); - _20 = copy _1; -- _19 = Option::::Some(move _20); -+ _19 = Option::::Some(copy _1); - StorageDead(_20); StorageLive(_21); + _21 = copy _1; +- _20 = Option::::Some(move _21); ++ _20 = Option::::Some(copy _1); + StorageDead(_21); StorageLive(_22); StorageLive(_23); - _23 = copy _19; -- _22 = move _23 as u32 (Transmute); -+ _22 = copy _19 as u32 (Transmute); - StorageDead(_23); - _21 = opaque::(move _22) -> [return: bb4, unwind continue]; + StorageLive(_24); + _24 = copy _20; +- _23 = move _24 as u32 (Transmute); ++ _23 = copy _20 as u32 (Transmute); + StorageDead(_24); + _22 = opaque::(move _23) -> [return: bb4, unwind continue]; } bb4: { + StorageDead(_23); StorageDead(_22); - StorageDead(_21); - StorageLive(_24); StorageLive(_25); - _25 = copy _1; -- _24 = MyId(move _25); -+ _24 = copy _3; - StorageDead(_25); StorageLive(_26); StorageLive(_27); - StorageLive(_28); -- _28 = move _24; -- _27 = move _28 as i16 (Transmute); -+ _28 = copy _3; -+ _27 = copy _1 as i16 (Transmute); - StorageDead(_28); - _26 = opaque::(move _27) -> [return: bb5, unwind continue]; - } - - bb5: { + _27 = copy _1; +- _26 = move _27 as (u16) is 0..=55554 (Transmute); ++ _26 = copy _4; StorageDead(_27); +- _25 = MyId(move _26); ++ _25 = copy _3; StorageDead(_26); + StorageLive(_28); StorageLive(_29); StorageLive(_30); - _30 = copy _1; - StorageLive(_31); - _31 = copy _1; -- _29 = Pair(move _30, move _31); -+ _29 = Pair(copy _1, copy _1); - StorageDead(_31); +- _30 = move _25; +- _29 = move _30 as i16 (Transmute); ++ _30 = copy _3; ++ _29 = copy _4 as i16 (Transmute); StorageDead(_30); - StorageLive(_32); - StorageLive(_33); - StorageLive(_34); -- _34 = move _29; -- _33 = move _34 as u32 (Transmute); -+ _34 = copy _29; -+ _33 = copy _29 as u32 (Transmute); - StorageDead(_34); - _32 = opaque::(move _33) -> [return: bb6, unwind continue]; + _28 = opaque::(move _29) -> [return: bb5, unwind continue]; } - bb6: { + bb5: { + StorageDead(_29); + StorageDead(_28); + StorageLive(_31); + StorageLive(_32); + _32 = copy _1; + StorageLive(_33); + _33 = copy _1; +- _31 = Pair(move _32, move _33); ++ _31 = Pair(copy _1, copy _1); StorageDead(_33); StorageDead(_32); + StorageLive(_34); StorageLive(_35); StorageLive(_36); - _36 = copy _1; - StorageLive(_37); - _37 = copy _1; -- _35 = Pair(move _36, move _37); -+ _35 = copy _29; - StorageDead(_37); +- _36 = move _31; +- _35 = move _36 as u32 (Transmute); ++ _36 = copy _31; ++ _35 = copy _31 as u32 (Transmute); StorageDead(_36); - StorageLive(_38); - StorageLive(_39); - StorageLive(_40); -- _40 = move _35; -- _39 = move _40 as u16 (Transmute); -+ _40 = copy _29; -+ _39 = copy _29 as u16 (Transmute); - StorageDead(_40); - _38 = opaque::(move _39) -> [return: bb7, unwind continue]; + _34 = opaque::(move _35) -> [return: bb6, unwind continue]; } - bb7: { + bb6: { + StorageDead(_35); + StorageDead(_34); + StorageLive(_37); + StorageLive(_38); + _38 = copy _1; + StorageLive(_39); + _39 = copy _1; +- _37 = Pair(move _38, move _39); ++ _37 = copy _31; StorageDead(_39); StorageDead(_38); + StorageLive(_40); StorageLive(_41); StorageLive(_42); - _42 = copy _1; -- _41 = (move _42,); -+ _41 = (copy _1,); +- _42 = move _37; +- _41 = move _42 as u16 (Transmute); ++ _42 = copy _31; ++ _41 = copy _31 as u16 (Transmute); StorageDead(_42); - StorageLive(_43); - StorageLive(_44); - StorageLive(_45); - _45 = copy _41; -- _44 = move _45 as u16 (Transmute); -+ _44 = copy _1; - StorageDead(_45); -- _43 = opaque::(move _44) -> [return: bb8, unwind continue]; -+ _43 = opaque::(copy _1) -> [return: bb8, unwind continue]; + _40 = opaque::(move _41) -> [return: bb7, unwind continue]; } - bb8: { + bb7: { + StorageDead(_41); + StorageDead(_40); + StorageLive(_43); + StorageLive(_44); + _44 = copy _1; +- _43 = (move _44,); ++ _43 = (copy _1,); StorageDead(_44); - StorageDead(_43); + StorageLive(_45); StorageLive(_46); StorageLive(_47); - _47 = copy _1; -- _46 = [move _47]; -+ _46 = [copy _1]; + _47 = copy _43; +- _46 = move _47 as u16 (Transmute); ++ _46 = copy _1; StorageDead(_47); +- _45 = opaque::(move _46) -> [return: bb8, unwind continue]; ++ _45 = opaque::(copy _1) -> [return: bb8, unwind continue]; + } + + bb8: { + StorageDead(_46); + StorageDead(_45); StorageLive(_48); StorageLive(_49); + _49 = copy _1; +- _48 = [move _49]; ++ _48 = [copy _1]; + StorageDead(_49); StorageLive(_50); - _50 = copy _46; -- _49 = move _50 as u16 (Transmute); -+ _49 = copy _1; - StorageDead(_50); -- _48 = opaque::(move _49) -> [return: bb9, unwind continue]; -+ _48 = opaque::(copy _1) -> [return: bb9, unwind continue]; + StorageLive(_51); + StorageLive(_52); + _52 = copy _48; +- _51 = move _52 as u16 (Transmute); ++ _51 = copy _1; + StorageDead(_52); +- _50 = opaque::(move _51) -> [return: bb9, unwind continue]; ++ _50 = opaque::(copy _1) -> [return: bb9, unwind continue]; } bb9: { - StorageDead(_49); - StorageDead(_48); - StorageLive(_51); - StorageLive(_52); - _52 = copy _2; + StorageDead(_51); + StorageDead(_50); StorageLive(_53); -- _53 = (); -- _51 = *const i32 from (move _52, move _53); -+ _53 = const (); -+ _51 = *const i32 from (copy _2, const ()); - StorageDead(_53); - StorageDead(_52); StorageLive(_54); + _54 = copy _2; StorageLive(_55); +- _55 = (); +- _53 = *const i32 from (move _54, move _55); ++ _55 = const (); ++ _53 = *const i32 from (copy _2, const ()); + StorageDead(_55); + StorageDead(_54); StorageLive(_56); - _56 = copy _51; -- _55 = move _56 as *const u8 (Transmute); -+ _55 = copy _2; - StorageDead(_56); -- _54 = opaque::<*const u8>(move _55) -> [return: bb10, unwind continue]; -+ _54 = opaque::<*const u8>(copy _2) -> [return: bb10, unwind continue]; + StorageLive(_57); + StorageLive(_58); + _58 = copy _53; +- _57 = move _58 as *const u8 (Transmute); ++ _57 = copy _2; + StorageDead(_58); +- _56 = opaque::<*const u8>(move _57) -> [return: bb10, unwind continue]; ++ _56 = opaque::<*const u8>(copy _2) -> [return: bb10, unwind continue]; } bb10: { - StorageDead(_55); - StorageDead(_54); + StorageDead(_57); + StorageDead(_56); _0 = const (); - StorageDead(_51); - StorageDead(_46); - StorageDead(_41); - StorageDead(_35); - StorageDead(_29); - StorageDead(_24); - StorageDead(_19); - StorageDead(_14); - StorageDead(_8); + StorageDead(_53); + StorageDead(_48); + StorageDead(_43); + StorageDead(_37); + StorageDead(_31); + StorageDead(_25); + StorageDead(_20); + StorageDead(_15); + StorageDead(_9); StorageDead(_3); return; } diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index 07309c1569cd8..26ad012fa330b 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -6,7 +6,7 @@ #![feature(rustc_attrs)] #![feature(custom_mir)] #![feature(core_intrinsics)] -#![feature(freeze)] +#![feature(freeze, pattern_type_range_trait, const_trait_impl, pattern_types, pattern_type_macro)] #![allow(ambiguous_wide_pointer_comparisons)] #![allow(unconditional_panic)] #![allow(unnecessary_transmutes)] @@ -947,9 +947,12 @@ fn cast_pointer_eq(p1: *mut u8, p2: *mut u32, p3: *mut u32, p4: *mut [u32]) { // CHECK: _0 = const (); } +// CHECK: fn aggregate_struct_then_transmute unsafe fn aggregate_struct_then_transmute(id: u16, thin: *const u8) { - // CHECK: opaque::(copy _1) - let a = MyId(id); + // CHECK: [[PAT:_[0-9]+]] = copy _1 as (u16) is 0..=55554 (Transmute); + // CHECK: [[TEMP:_[0-9]+]] = copy [[PAT]] as u16 (Transmute); + // CHECK: opaque::(move [[TEMP]]) + let a = MyId(std::intrinsics::transmute(id)); opaque(std::intrinsics::transmute::<_, u16>(a)); // CHECK: opaque::(copy _1) @@ -967,9 +970,9 @@ unsafe fn aggregate_struct_then_transmute(id: u16, thin: *const u8) { opaque(std::intrinsics::transmute::<_, u32>(d)); // Still need the transmute, but the aggregate can be skipped - // CHECK: [[TEMP:_[0-9]+]] = copy _1 as i16 (Transmute); + // CHECK: [[TEMP:_[0-9]+]] = copy [[PAT]] as i16 (Transmute); // CHECK: opaque::(move [[TEMP]]) - let e = MyId(id); + let e = MyId(std::intrinsics::transmute(id)); opaque(std::intrinsics::transmute::<_, i16>(e)); // CHECK: [[PAIR:_[0-9]+]] = Pair(copy _1, copy _1); @@ -1193,8 +1196,7 @@ fn identity(x: T) -> T { fn takes_const_ptr(_: *const T) {} #[repr(transparent)] -#[rustc_layout_scalar_valid_range_end(55555)] -struct MyId(u16); +struct MyId(std::pat::pattern_type!(u16 is 0..55555)); #[repr(transparent)] struct TypedId(u16, PhantomData); diff --git a/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-abort.diff b/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-abort.diff index 7014146cb8624..9940e32982871 100644 --- a/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-abort.diff +++ b/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-abort.diff @@ -4,13 +4,15 @@ fn mutate_discriminant() -> u8 { let mut _0: u8; let mut _1: std::option::Option; - let mut _2: isize; + let mut _2: (usize) is 1..; + let mut _3: isize; bb0: { discriminant(_1) = 1; - (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; - _2 = discriminant(_1); - switchInt(copy _2) -> [0: bb1, otherwise: bb2]; + _2 = const 0_usize as (usize) is 1.. (Transmute); + (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = copy _2; + _3 = discriminant(_1); + switchInt(copy _3) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-unwind.diff b/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-unwind.diff index 7014146cb8624..9940e32982871 100644 --- a/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-unwind.diff +++ b/tests/mir-opt/jump_threading.mutate_discriminant.JumpThreading.panic-unwind.diff @@ -4,13 +4,15 @@ fn mutate_discriminant() -> u8 { let mut _0: u8; let mut _1: std::option::Option; - let mut _2: isize; + let mut _2: (usize) is 1..; + let mut _3: isize; bb0: { discriminant(_1) = 1; - (((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; - _2 = discriminant(_1); - switchInt(copy _2) -> [0: bb1, otherwise: bb2]; + _2 = const 0_usize as (usize) is 1.. (Transmute); + (((_1 as variant#1).0: NonZeroUsize).0: (usize) is 1..=usize::MAX) = copy _2; + _3 = discriminant(_1); + switchInt(copy _3) -> [0: bb1, otherwise: bb2]; } bb1: { diff --git a/tests/mir-opt/jump_threading.rs b/tests/mir-opt/jump_threading.rs index 39a2f16c5ad6f..e4942a5c173fd 100644 --- a/tests/mir-opt/jump_threading.rs +++ b/tests/mir-opt/jump_threading.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Zmir-enable-passes=+Inline // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -#![feature(try_trait_v2)] +#![feature(try_trait_v2, pattern_type_macro, pattern_types)] #![feature(custom_mir, core_intrinsics, rustc_attrs)] use std::intrinsics::mir::*; @@ -311,9 +311,8 @@ fn duplicate_chain(x: bool) -> u8 { } } -#[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] -struct NonZeroUsize(usize); +struct NonZeroUsize(std::pat::pattern_type!(usize is 1..=usize::MAX)); /// Verify that we correctly discard threads that may mutate a discriminant by aliasing. #[custom_mir(dialect = "runtime", phase = "post-cleanup")] @@ -326,8 +325,9 @@ fn mutate_discriminant() -> u8 { let x: Option; { SetDiscriminant(x, 1); + let y = CastTransmute::<_, std::pat::pattern_type!(usize is 1..=usize::MAX)>(0_usize); // This assignment overwrites the niche in which the discriminant is stored. - place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize; + place!(Field(Field(Variant(x, 1), 0), 0)) = y; // So we cannot know the value of this discriminant. let a = Discriminant(x); match a { diff --git a/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.rs b/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.rs deleted file mode 100644 index 8ea4eac1a6173..0000000000000 --- a/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(u32::MAX)] //~ ERROR -pub struct A(u32); - -#[rustc_layout_scalar_valid_range_end(1, 2)] //~ ERROR -pub struct B(u8); - -#[rustc_layout_scalar_valid_range_end(a = "a")] //~ ERROR -pub struct C(i32); - -#[rustc_layout_scalar_valid_range_end(1)] //~ ERROR -enum E { - X = 1, - Y = 14, -} - -#[rustc_layout_scalar_valid_range_start(rustc_layout_scalar_valid_range_start)] //~ ERROR -struct NonZero(T); - -fn not_field() -> impl Send { - NonZero(false) -} - -fn main() { - let _ = A(0); - let _ = B(0); - let _ = C(0); - unsafe { - let _ = E::X; - } -} diff --git a/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.stderr b/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.stderr deleted file mode 100644 index 457affe4950ee..0000000000000 --- a/tests/ui/attributes/invalid_rustc_layout_scalar_valid_range.stderr +++ /dev/null @@ -1,68 +0,0 @@ -error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:3:1 - | -LL | #[rustc_layout_scalar_valid_range_start(u32::MAX)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------^^ - | | - | expected an integer literal here - | -help: must be of the form - | -LL - #[rustc_layout_scalar_valid_range_start(u32::MAX)] -LL + #[rustc_layout_scalar_valid_range_start(start)] - | - -error[E0805]: malformed `rustc_layout_scalar_valid_range_end` attribute input - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:6:1 - | -LL | #[rustc_layout_scalar_valid_range_end(1, 2)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^ - | | - | expected a single argument here - | -help: must be of the form - | -LL - #[rustc_layout_scalar_valid_range_end(1, 2)] -LL + #[rustc_layout_scalar_valid_range_end(end)] - | - -error[E0539]: malformed `rustc_layout_scalar_valid_range_end` attribute input - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:9:1 - | -LL | #[rustc_layout_scalar_valid_range_end(a = "a")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^ - | | - | expected an integer literal here - | -help: must be of the form - | -LL - #[rustc_layout_scalar_valid_range_end(a = "a")] -LL + #[rustc_layout_scalar_valid_range_end(end)] - | - -error: `#[rustc_layout_scalar_valid_range_end]` attribute cannot be used on enums - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:12:1 - | -LL | #[rustc_layout_scalar_valid_range_end(1)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: `#[rustc_layout_scalar_valid_range_end]` can only be applied to structs - -error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input - --> $DIR/invalid_rustc_layout_scalar_valid_range.rs:18:1 - | -LL | #[rustc_layout_scalar_valid_range_start(rustc_layout_scalar_valid_range_start)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^ - | | - | expected an integer literal here - | -help: must be of the form - | -LL - #[rustc_layout_scalar_valid_range_start(rustc_layout_scalar_valid_range_start)] -LL + #[rustc_layout_scalar_valid_range_start(start)] - | - -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0539, E0805. -For more information about an error, try `rustc --explain E0539`. diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index 9dcdb9a69272b..c73feb9110f11 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -129,10 +129,6 @@ fn test2() { } //~| ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type pub fn test3() {} -#[rustc_layout_scalar_valid_range_start] -//~^ ERROR malformed -#[rustc_layout_scalar_valid_range_end] -//~^ ERROR malformed #[must_not_suspend()] //~^ ERROR malformed #[cfi_encoding = ""] diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index bc539438613b0..784cbb38aaedd 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -23,13 +23,13 @@ LL | #[cfg_attr(predicate, attr1, attr2, ...)] | ++++++++++++++++++++++++++++++ error[E0463]: can't find crate for `wloop` - --> $DIR/malformed-attrs.rs:214:1 + --> $DIR/malformed-attrs.rs:210:1 | LL | extern crate wloop; | ^^^^^^^^^^^^^^^^^^^ can't find crate error: malformed `allow` attribute input - --> $DIR/malformed-attrs.rs:180:1 + --> $DIR/malformed-attrs.rs:176:1 | LL | #[allow] | ^^^^^^^^ @@ -45,7 +45,7 @@ LL | #[allow(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `expect` attribute input - --> $DIR/malformed-attrs.rs:182:1 + --> $DIR/malformed-attrs.rs:178:1 | LL | #[expect] | ^^^^^^^^^ @@ -61,7 +61,7 @@ LL | #[expect(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `warn` attribute input - --> $DIR/malformed-attrs.rs:184:1 + --> $DIR/malformed-attrs.rs:180:1 | LL | #[warn] | ^^^^^^^ @@ -77,7 +77,7 @@ LL | #[warn(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `deny` attribute input - --> $DIR/malformed-attrs.rs:186:1 + --> $DIR/malformed-attrs.rs:182:1 | LL | #[deny] | ^^^^^^^ @@ -93,7 +93,7 @@ LL | #[deny(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `forbid` attribute input - --> $DIR/malformed-attrs.rs:188:1 + --> $DIR/malformed-attrs.rs:184:1 | LL | #[forbid] | ^^^^^^^^^ @@ -127,7 +127,7 @@ LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ error[E0658]: allow_internal_unsafe side-steps the unsafe_code lint - --> $DIR/malformed-attrs.rs:219:1 + --> $DIR/malformed-attrs.rs:215:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -583,30 +583,8 @@ LL | #[proc_macro_derive(TraitName)] LL | #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] | ++++++++++++++++++++++++++++++++++++++++++ -error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input - --> $DIR/malformed-attrs.rs:132:1 - | -LL | #[rustc_layout_scalar_valid_range_start] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list - | -help: must be of the form - | -LL | #[rustc_layout_scalar_valid_range_start(start)] - | +++++++ - -error[E0539]: malformed `rustc_layout_scalar_valid_range_end` attribute input - --> $DIR/malformed-attrs.rs:134:1 - | -LL | #[rustc_layout_scalar_valid_range_end] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list - | -help: must be of the form - | -LL | #[rustc_layout_scalar_valid_range_end(end)] - | +++++ - error[E0539]: malformed `must_not_suspend` attribute input - --> $DIR/malformed-attrs.rs:136:1 + --> $DIR/malformed-attrs.rs:132:1 | LL | #[must_not_suspend()] | ^^^^^^^^^^^^^^^^^^--^ @@ -622,7 +600,7 @@ LL + #[must_not_suspend] | error[E0539]: malformed `cfi_encoding` attribute input - --> $DIR/malformed-attrs.rs:138:1 + --> $DIR/malformed-attrs.rs:134:1 | LL | #[cfi_encoding = ""] | ^^^^^^^^^^^^^^^^^--^ @@ -635,7 +613,7 @@ LL | #[cfi_encoding = "encoding"] | ++++++++ error[E0565]: malformed `marker` attribute input - --> $DIR/malformed-attrs.rs:157:1 + --> $DIR/malformed-attrs.rs:153:1 | LL | #[marker = 3] | ^^^^^^^^^---^ @@ -649,7 +627,7 @@ LL + #[marker] | error[E0565]: malformed `fundamental` attribute input - --> $DIR/malformed-attrs.rs:159:1 + --> $DIR/malformed-attrs.rs:155:1 | LL | #[fundamental()] | ^^^^^^^^^^^^^--^ @@ -663,7 +641,7 @@ LL + #[fundamental] | error[E0565]: malformed `ffi_pure` attribute input - --> $DIR/malformed-attrs.rs:167:5 + --> $DIR/malformed-attrs.rs:163:5 | LL | #[unsafe(ffi_pure = 1)] | ^^^^^^^^^^^^^^^^^^---^^ @@ -677,7 +655,7 @@ LL + #[ffi_pure] | error[E0539]: malformed `link_ordinal` attribute input - --> $DIR/malformed-attrs.rs:169:5 + --> $DIR/malformed-attrs.rs:165:5 | LL | #[link_ordinal] | ^^^^^^^^^^^^^^^ expected this to be a list @@ -689,7 +667,7 @@ LL | #[link_ordinal(ordinal)] | +++++++++ error[E0565]: malformed `ffi_const` attribute input - --> $DIR/malformed-attrs.rs:173:5 + --> $DIR/malformed-attrs.rs:169:5 | LL | #[unsafe(ffi_const = 1)] | ^^^^^^^^^^^^^^^^^^^---^^ @@ -703,13 +681,13 @@ LL + #[ffi_const] | error[E0539]: malformed `linkage` attribute input - --> $DIR/malformed-attrs.rs:175:5 + --> $DIR/malformed-attrs.rs:171:5 | LL | #[linkage] | ^^^^^^^^^^ expected this to be of the form `linkage = "..."` error[E0539]: malformed `debugger_visualizer` attribute input - --> $DIR/malformed-attrs.rs:190:1 + --> $DIR/malformed-attrs.rs:186:1 | LL | #[debugger_visualizer] | ^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -721,7 +699,7 @@ LL | #[debugger_visualizer(natvis_file = "...", gdb_script_file = "...")] | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0565]: malformed `automatically_derived` attribute input - --> $DIR/malformed-attrs.rs:192:1 + --> $DIR/malformed-attrs.rs:188:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^----^ @@ -735,7 +713,7 @@ LL + #[automatically_derived] | error[E0565]: malformed `non_exhaustive` attribute input - --> $DIR/malformed-attrs.rs:200:1 + --> $DIR/malformed-attrs.rs:196:1 | LL | #[non_exhaustive = 1] | ^^^^^^^^^^^^^^^^^---^ @@ -749,7 +727,7 @@ LL + #[non_exhaustive] | error[E0565]: malformed `thread_local` attribute input - --> $DIR/malformed-attrs.rs:206:1 + --> $DIR/malformed-attrs.rs:202:1 | LL | #[thread_local()] | ^^^^^^^^^^^^^^--^ @@ -763,7 +741,7 @@ LL + #[thread_local] | error[E0565]: malformed `no_link` attribute input - --> $DIR/malformed-attrs.rs:210:1 + --> $DIR/malformed-attrs.rs:206:1 | LL | #[no_link()] | ^^^^^^^^^--^ @@ -777,7 +755,7 @@ LL + #[no_link] | error[E0539]: malformed `macro_use` attribute input - --> $DIR/malformed-attrs.rs:212:1 + --> $DIR/malformed-attrs.rs:208:1 | LL | #[macro_use = 1] | ^^^^^^^^^^^^---^ @@ -795,7 +773,7 @@ LL + #[macro_use] | error[E0539]: malformed `macro_export` attribute input - --> $DIR/malformed-attrs.rs:217:1 + --> $DIR/malformed-attrs.rs:213:1 | LL | #[macro_export = 18] | ^^^^^^^^^^^^^^^----^ @@ -812,7 +790,7 @@ LL + #[macro_export] | error[E0565]: malformed `allow_internal_unsafe` attribute input - --> $DIR/malformed-attrs.rs:219:1 + --> $DIR/malformed-attrs.rs:215:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^---^ @@ -935,7 +913,7 @@ LL | #[no_implicit_prelude = 23] = help: `#[no_implicit_prelude]` can be applied to crates and modules warning: missing options for `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:142:1 + --> $DIR/malformed-attrs.rs:138:1 | LL | #[diagnostic::on_unimplemented] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -944,7 +922,7 @@ LL | #[diagnostic::on_unimplemented] = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default warning: malformed `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:144:1 + --> $DIR/malformed-attrs.rs:140:1 | LL | #[diagnostic::on_unimplemented = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here @@ -952,13 +930,13 @@ LL | #[diagnostic::on_unimplemented = 1] = help: only `message`, `note` and `label` are allowed as options warning: `#[diagnostic::do_not_recommend]` does not expect any arguments - --> $DIR/malformed-attrs.rs:151:1 + --> $DIR/malformed-attrs.rs:147:1 | LL | #[diagnostic::do_not_recommend()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: `#[automatically_derived]` attribute cannot be used on modules - --> $DIR/malformed-attrs.rs:192:1 + --> $DIR/malformed-attrs.rs:188:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -967,7 +945,7 @@ LL | #[automatically_derived = 18] = help: `#[automatically_derived]` can only be applied to trait impl blocks error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:226:1 + --> $DIR/malformed-attrs.rs:222:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ @@ -986,7 +964,7 @@ LL | #[coroutine = 63] || {} = note: expected unit type `()` found coroutine `{coroutine@$DIR/malformed-attrs.rs:115:23: 115:25}` -error: aborting due to 75 previous errors; 8 warnings emitted +error: aborting due to 73 previous errors; 8 warnings emitted Some errors have detailed explanations: E0308, E0463, E0539, E0565, E0658, E0805. For more information about an error, try `rustc --explain E0308`. @@ -1014,7 +992,7 @@ LL | #[ignore()] Future breakage diagnostic: error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:226:1 + --> $DIR/malformed-attrs.rs:222:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ diff --git a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr index 6ae23c6b24b1d..4493067e9a8bb 100644 --- a/tests/ui/consts/const-eval/raw-bytes.32bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.32bit.stderr @@ -1,5 +1,5 @@ error[E0080]: constructing invalid value of type Enum: at ., encountered 0x00000001, but expected a valid enum tag - --> $DIR/raw-bytes.rs:23:1 + --> $DIR/raw-bytes.rs:24:1 | LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -10,7 +10,7 @@ LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; } error[E0080]: constructing invalid value of type Enum2: at ., encountered 0x00000000, but expected a valid enum tag - --> $DIR/raw-bytes.rs:31:1 + --> $DIR/raw-bytes.rs:32:1 | LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -21,7 +21,7 @@ LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type UninhDiscriminant: at ., encountered an uninhabited enum variant - --> $DIR/raw-bytes.rs:45:1 + --> $DIR/raw-bytes.rs:46:1 | LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -32,7 +32,7 @@ LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute } error[E0080]: constructing invalid value of type UninhDiscriminant: at ., encountered 0x03, but expected a valid enum tag - --> $DIR/raw-bytes.rs:47:1 + --> $DIR/raw-bytes.rs:48:1 | LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -43,7 +43,7 @@ LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute } error[E0080]: constructing invalid value of type Option<(char, char)>: at ..0.1, encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`) - --> $DIR/raw-bytes.rs:53:1 + --> $DIR/raw-bytes.rs:54:1 | LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -54,7 +54,7 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran } error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:58:1 + --> $DIR/raw-bytes.rs:59:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -65,7 +65,7 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type NonZero: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:61:1 + --> $DIR/raw-bytes.rs:62:1 | LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -76,7 +76,7 @@ LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; } error[E0080]: constructing invalid value of type NonZero: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:63:1 + --> $DIR/raw-bytes.rs:64:1 | LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -86,10 +86,10 @@ LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; 00 00 00 00 │ .... } -error[E0080]: constructing invalid value of type RestrictedRange1: encountered 42, but expected something in the range 10..=30 - --> $DIR/raw-bytes.rs:69:1 +error[E0080]: constructing invalid value of type RestrictedRange1: at .0, encountered 42, but expected something in the range 10..=30 + --> $DIR/raw-bytes.rs:68:1 | -LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; +LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(mem::transmute(42_u32)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -97,10 +97,10 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; 2a 00 00 00 │ *... } -error[E0080]: constructing invalid value of type RestrictedRange2: encountered 20, but expected something less or equal to 10, or greater or equal to 30 - --> $DIR/raw-bytes.rs:75:1 +error[E0080]: constructing invalid value of type RestrictedRange2: at .0, encountered 20, but expected something less or equal to 10, or greater or equal to 30 + --> $DIR/raw-bytes.rs:72:1 | -LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; +LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(mem::transmute(20_i32)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -109,7 +109,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; } error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:78:1 + --> $DIR/raw-bytes.rs:75:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -120,7 +120,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { } error[E0080]: constructing invalid value of type &u16: encountered an unaligned reference (required 2 byte alignment but found 1) - --> $DIR/raw-bytes.rs:85:1 + --> $DIR/raw-bytes.rs:82:1 | LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -131,7 +131,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: constructing invalid value of type Box: encountered an unaligned box (required 2 byte alignment but found 1) - --> $DIR/raw-bytes.rs:88:1 + --> $DIR/raw-bytes.rs:85:1 | LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -142,7 +142,7 @@ LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: constructing invalid value of type &u16: encountered a null reference - --> $DIR/raw-bytes.rs:91:1 + --> $DIR/raw-bytes.rs:88:1 | LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -153,7 +153,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type Box: encountered a null box - --> $DIR/raw-bytes.rs:94:1 + --> $DIR/raw-bytes.rs:91:1 | LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -164,7 +164,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type &u8: encountered a dangling reference (0x539[noalloc] has no provenance) - --> $DIR/raw-bytes.rs:97:1 + --> $DIR/raw-bytes.rs:94:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -175,7 +175,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; } error[E0080]: constructing invalid value of type Box: encountered a dangling box (0x539[noalloc] has no provenance) - --> $DIR/raw-bytes.rs:100:1 + --> $DIR/raw-bytes.rs:97:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -186,7 +186,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; } error[E0080]: constructing invalid value of type fn(): encountered null pointer, but expected a function pointer - --> $DIR/raw-bytes.rs:103:1 + --> $DIR/raw-bytes.rs:100:1 | LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -197,7 +197,7 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type fn(): encountered 0xd[noalloc], but expected a function pointer - --> $DIR/raw-bytes.rs:105:1 + --> $DIR/raw-bytes.rs:102:1 | LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -208,7 +208,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; } error[E0080]: constructing invalid value of type fn(): encountered ALLOC3, but expected a function pointer - --> $DIR/raw-bytes.rs:107:1 + --> $DIR/raw-bytes.rs:104:1 | LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -219,7 +219,7 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; } error[E0080]: constructing invalid value of type &Bar: encountered a reference pointing to uninhabited type Bar - --> $DIR/raw-bytes.rs:113:1 + --> $DIR/raw-bytes.rs:110:1 | LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -230,7 +230,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; } error[E0080]: constructing invalid value of type &str: encountered a dangling reference (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:137:1 + --> $DIR/raw-bytes.rs:134:1 | LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -241,7 +241,7 @@ LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; } error[E0080]: constructing invalid value of type (&str,): at .0, encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:139:1 + --> $DIR/raw-bytes.rs:136:1 | LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -252,7 +252,7 @@ LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, us } error[E0080]: constructing invalid value of type &MyStr: encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:141:1 + --> $DIR/raw-bytes.rs:138:1 | LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -263,7 +263,7 @@ LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize: } error[E0080]: constructing invalid value of type &str: at ., encountered uninitialized memory, but expected a string - --> $DIR/raw-bytes.rs:144:1 + --> $DIR/raw-bytes.rs:141:1 | LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -274,7 +274,7 @@ LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit: } error[E0080]: constructing invalid value of type &MyStr: at ..0, encountered uninitialized memory, but expected a string - --> $DIR/raw-bytes.rs:146:1 + --> $DIR/raw-bytes.rs:143:1 | LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -285,7 +285,7 @@ LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUni } error[E0080]: constructing invalid value of type &MyStr: at ..0, encountered a pointer, but expected a string - --> $DIR/raw-bytes.rs:148:1 + --> $DIR/raw-bytes.rs:145:1 | LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -298,7 +298,7 @@ LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _> } error[E0080]: constructing invalid value of type &[u8]: encountered a dangling reference (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:152:1 + --> $DIR/raw-bytes.rs:149:1 | LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -309,7 +309,7 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; } error[E0080]: constructing invalid value of type &[u32]: encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:154:1 + --> $DIR/raw-bytes.rs:151:1 | LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -320,7 +320,7 @@ LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, is } error[E0080]: constructing invalid value of type Box<[u8]>: encountered a dangling box (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:157:1 + --> $DIR/raw-bytes.rs:154:1 | LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -331,7 +331,7 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us } error[E0080]: constructing invalid value of type &[bool; 1]: at .[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:160:1 + --> $DIR/raw-bytes.rs:157:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -342,13 +342,13 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:160:40 + --> $DIR/raw-bytes.rs:157:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..0, encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:164:1 + --> $DIR/raw-bytes.rs:161:1 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -359,13 +359,13 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3 } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:164:42 + --> $DIR/raw-bytes.rs:161:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..1[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:167:1 + --> $DIR/raw-bytes.rs:164:1 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -376,13 +376,13 @@ LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::tran } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:167:42 + --> $DIR/raw-bytes.rs:164:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC17, but expected a vtable pointer - --> $DIR/raw-bytes.rs:171:1 + --> $DIR/raw-bytes.rs:168:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -393,7 +393,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC19, but expected a vtable pointer - --> $DIR/raw-bytes.rs:174:1 + --> $DIR/raw-bytes.rs:171:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -404,7 +404,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered 0x4[noalloc], but expected a vtable pointer - --> $DIR/raw-bytes.rs:177:1 + --> $DIR/raw-bytes.rs:174:1 | LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -415,7 +415,7 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC22, but expected a vtable pointer - --> $DIR/raw-bytes.rs:179:1 + --> $DIR/raw-bytes.rs:176:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -426,7 +426,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans } error[E0080]: constructing invalid value of type &dyn Trait: at .., encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:182:1 + --> $DIR/raw-bytes.rs:179:1 | LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -437,7 +437,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, } error[E0080]: constructing invalid value of type *const dyn Trait: encountered null pointer, but expected a vtable pointer - --> $DIR/raw-bytes.rs:185:1 + --> $DIR/raw-bytes.rs:182:1 | LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -448,7 +448,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute } error[E0080]: constructing invalid value of type *const dyn Trait: encountered ALLOC27, but expected a vtable pointer - --> $DIR/raw-bytes.rs:187:1 + --> $DIR/raw-bytes.rs:184:1 | LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -459,7 +459,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm } error[E0080]: constructing invalid value of type &[!; 1]: encountered a reference pointing to uninhabited type [!; 1] - --> $DIR/raw-bytes.rs:191:1 + --> $DIR/raw-bytes.rs:188:1 | LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -470,7 +470,7 @@ LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; } error[E0080]: constructing invalid value of type &[!]: at .[0], encountered a value of the never type `!` - --> $DIR/raw-bytes.rs:192:1 + --> $DIR/raw-bytes.rs:189:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -481,7 +481,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; } error[E0080]: constructing invalid value of type &[!]: at .[0], encountered a value of the never type `!` - --> $DIR/raw-bytes.rs:193:1 + --> $DIR/raw-bytes.rs:190:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; | ^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -492,7 +492,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:196:1 + --> $DIR/raw-bytes.rs:193:1 | LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -503,7 +503,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) } } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered a pointer, but expected an integer - --> $DIR/raw-bytes.rs:199:1 + --> $DIR/raw-bytes.rs:196:1 | LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem::size_of::<&u32>()) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -516,7 +516,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem: } error[E0080]: constructing invalid value of type &[bool]: at .[0], encountered 0x11, but expected a boolean - --> $DIR/raw-bytes.rs:202:1 + --> $DIR/raw-bytes.rs:199:1 | LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -527,7 +527,7 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) } error[E0080]: constructing invalid value of type &[u16]: at .[1], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:206:1 + --> $DIR/raw-bytes.rs:203:1 | LL | pub static S7: &[u16] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -538,7 +538,7 @@ LL | pub static S7: &[u16] = unsafe { } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:213:1 + --> $DIR/raw-bytes.rs:210:1 | LL | pub static R4: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -549,7 +549,7 @@ LL | pub static R4: &[u8] = unsafe { } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered a pointer, but expected an integer - --> $DIR/raw-bytes.rs:218:1 + --> $DIR/raw-bytes.rs:215:1 | LL | pub static R5: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -562,7 +562,7 @@ LL | pub static R5: &[u8] = unsafe { } error[E0080]: constructing invalid value of type &[bool]: at .[0], encountered 0x11, but expected a boolean - --> $DIR/raw-bytes.rs:223:1 + --> $DIR/raw-bytes.rs:220:1 | LL | pub static R6: &[bool] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value diff --git a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr index 0f1e095719f54..07deb955d24e7 100644 --- a/tests/ui/consts/const-eval/raw-bytes.64bit.stderr +++ b/tests/ui/consts/const-eval/raw-bytes.64bit.stderr @@ -1,5 +1,5 @@ error[E0080]: constructing invalid value of type Enum: at ., encountered 0x0000000000000001, but expected a valid enum tag - --> $DIR/raw-bytes.rs:23:1 + --> $DIR/raw-bytes.rs:24:1 | LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -10,7 +10,7 @@ LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) }; } error[E0080]: constructing invalid value of type Enum2: at ., encountered 0x0000000000000000, but expected a valid enum tag - --> $DIR/raw-bytes.rs:31:1 + --> $DIR/raw-bytes.rs:32:1 | LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -21,7 +21,7 @@ LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type UninhDiscriminant: at ., encountered an uninhabited enum variant - --> $DIR/raw-bytes.rs:45:1 + --> $DIR/raw-bytes.rs:46:1 | LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -32,7 +32,7 @@ LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute } error[E0080]: constructing invalid value of type UninhDiscriminant: at ., encountered 0x03, but expected a valid enum tag - --> $DIR/raw-bytes.rs:47:1 + --> $DIR/raw-bytes.rs:48:1 | LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -43,7 +43,7 @@ LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute } error[E0080]: constructing invalid value of type Option<(char, char)>: at ..0.1, encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`) - --> $DIR/raw-bytes.rs:53:1 + --> $DIR/raw-bytes.rs:54:1 | LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) })); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -54,7 +54,7 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran } error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:58:1 + --> $DIR/raw-bytes.rs:59:1 | LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -65,7 +65,7 @@ LL | const NULL_PTR: NonNull = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type NonZero: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:61:1 + --> $DIR/raw-bytes.rs:62:1 | LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -76,7 +76,7 @@ LL | const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; } error[E0080]: constructing invalid value of type NonZero: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:63:1 + --> $DIR/raw-bytes.rs:64:1 | LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -86,10 +86,10 @@ LL | const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; 00 00 00 00 00 00 00 00 │ ........ } -error[E0080]: constructing invalid value of type RestrictedRange1: encountered 42, but expected something in the range 10..=30 - --> $DIR/raw-bytes.rs:69:1 +error[E0080]: constructing invalid value of type RestrictedRange1: at .0, encountered 42, but expected something in the range 10..=30 + --> $DIR/raw-bytes.rs:68:1 | -LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; +LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(mem::transmute(42_u32)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -97,10 +97,10 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; 2a 00 00 00 │ *... } -error[E0080]: constructing invalid value of type RestrictedRange2: encountered 20, but expected something less or equal to 10, or greater or equal to 30 - --> $DIR/raw-bytes.rs:75:1 +error[E0080]: constructing invalid value of type RestrictedRange2: at .0, encountered 20, but expected something less or equal to 10, or greater or equal to 30 + --> $DIR/raw-bytes.rs:72:1 | -LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; +LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(mem::transmute(20_i32)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value | = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -109,7 +109,7 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; } error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/raw-bytes.rs:78:1 + --> $DIR/raw-bytes.rs:75:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -120,7 +120,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { } error[E0080]: constructing invalid value of type &u16: encountered an unaligned reference (required 2 byte alignment but found 1) - --> $DIR/raw-bytes.rs:85:1 + --> $DIR/raw-bytes.rs:82:1 | LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -131,7 +131,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: constructing invalid value of type Box: encountered an unaligned box (required 2 byte alignment but found 1) - --> $DIR/raw-bytes.rs:88:1 + --> $DIR/raw-bytes.rs:85:1 | LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -142,7 +142,7 @@ LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; } error[E0080]: constructing invalid value of type &u16: encountered a null reference - --> $DIR/raw-bytes.rs:91:1 + --> $DIR/raw-bytes.rs:88:1 | LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -153,7 +153,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type Box: encountered a null box - --> $DIR/raw-bytes.rs:94:1 + --> $DIR/raw-bytes.rs:91:1 | LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -164,7 +164,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type &u8: encountered a dangling reference (0x539[noalloc] has no provenance) - --> $DIR/raw-bytes.rs:97:1 + --> $DIR/raw-bytes.rs:94:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -175,7 +175,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; } error[E0080]: constructing invalid value of type Box: encountered a dangling box (0x539[noalloc] has no provenance) - --> $DIR/raw-bytes.rs:100:1 + --> $DIR/raw-bytes.rs:97:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -186,7 +186,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; } error[E0080]: constructing invalid value of type fn(): encountered null pointer, but expected a function pointer - --> $DIR/raw-bytes.rs:103:1 + --> $DIR/raw-bytes.rs:100:1 | LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -197,7 +197,7 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; } error[E0080]: constructing invalid value of type fn(): encountered 0xd[noalloc], but expected a function pointer - --> $DIR/raw-bytes.rs:105:1 + --> $DIR/raw-bytes.rs:102:1 | LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -208,7 +208,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; } error[E0080]: constructing invalid value of type fn(): encountered ALLOC3, but expected a function pointer - --> $DIR/raw-bytes.rs:107:1 + --> $DIR/raw-bytes.rs:104:1 | LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -219,7 +219,7 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; } error[E0080]: constructing invalid value of type &Bar: encountered a reference pointing to uninhabited type Bar - --> $DIR/raw-bytes.rs:113:1 + --> $DIR/raw-bytes.rs:110:1 | LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -230,7 +230,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) }; } error[E0080]: constructing invalid value of type &str: encountered a dangling reference (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:137:1 + --> $DIR/raw-bytes.rs:134:1 | LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -241,7 +241,7 @@ LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) }; } error[E0080]: constructing invalid value of type (&str,): at .0, encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:139:1 + --> $DIR/raw-bytes.rs:136:1 | LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -252,7 +252,7 @@ LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, us } error[E0080]: constructing invalid value of type &MyStr: encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:141:1 + --> $DIR/raw-bytes.rs:138:1 | LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -263,7 +263,7 @@ LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize: } error[E0080]: constructing invalid value of type &str: at ., encountered uninitialized memory, but expected a string - --> $DIR/raw-bytes.rs:144:1 + --> $DIR/raw-bytes.rs:141:1 | LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -274,7 +274,7 @@ LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit: } error[E0080]: constructing invalid value of type &MyStr: at ..0, encountered uninitialized memory, but expected a string - --> $DIR/raw-bytes.rs:146:1 + --> $DIR/raw-bytes.rs:143:1 | LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:: { uninit: () }]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -285,7 +285,7 @@ LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUni } error[E0080]: constructing invalid value of type &MyStr: at ..0, encountered a pointer, but expected a string - --> $DIR/raw-bytes.rs:148:1 + --> $DIR/raw-bytes.rs:145:1 | LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -298,7 +298,7 @@ LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _> } error[E0080]: constructing invalid value of type &[u8]: encountered a dangling reference (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:152:1 + --> $DIR/raw-bytes.rs:149:1 | LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -309,7 +309,7 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; } error[E0080]: constructing invalid value of type &[u32]: encountered invalid reference metadata: slice is bigger than largest supported object - --> $DIR/raw-bytes.rs:154:1 + --> $DIR/raw-bytes.rs:151:1 | LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -320,7 +320,7 @@ LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, is } error[E0080]: constructing invalid value of type Box<[u8]>: encountered a dangling box (going beyond the bounds of its allocation) - --> $DIR/raw-bytes.rs:157:1 + --> $DIR/raw-bytes.rs:154:1 | LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -331,7 +331,7 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us } error[E0080]: constructing invalid value of type &[bool; 1]: at .[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:160:1 + --> $DIR/raw-bytes.rs:157:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -342,13 +342,13 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:160:40 + --> $DIR/raw-bytes.rs:157:40 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..0, encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:164:1 + --> $DIR/raw-bytes.rs:161:1 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -359,13 +359,13 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3 } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:164:42 + --> $DIR/raw-bytes.rs:161:42 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type &MySlice<[bool; 1]>: at ..1[0], encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:167:1 + --> $DIR/raw-bytes.rs:164:1 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -376,13 +376,13 @@ LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::tran } note: erroneous constant encountered - --> $DIR/raw-bytes.rs:167:42 + --> $DIR/raw-bytes.rs:164:42 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC17, but expected a vtable pointer - --> $DIR/raw-bytes.rs:171:1 + --> $DIR/raw-bytes.rs:168:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -393,7 +393,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC19, but expected a vtable pointer - --> $DIR/raw-bytes.rs:174:1 + --> $DIR/raw-bytes.rs:171:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -404,7 +404,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered 0x4[noalloc], but expected a vtable pointer - --> $DIR/raw-bytes.rs:177:1 + --> $DIR/raw-bytes.rs:174:1 | LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -415,7 +415,7 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u } error[E0080]: constructing invalid value of type W<&dyn Trait>: at .0, encountered ALLOC22, but expected a vtable pointer - --> $DIR/raw-bytes.rs:179:1 + --> $DIR/raw-bytes.rs:176:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -426,7 +426,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans } error[E0080]: constructing invalid value of type &dyn Trait: at .., encountered 0x03, but expected a boolean - --> $DIR/raw-bytes.rs:182:1 + --> $DIR/raw-bytes.rs:179:1 | LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -437,7 +437,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, } error[E0080]: constructing invalid value of type *const dyn Trait: encountered null pointer, but expected a vtable pointer - --> $DIR/raw-bytes.rs:185:1 + --> $DIR/raw-bytes.rs:182:1 | LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -448,7 +448,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute } error[E0080]: constructing invalid value of type *const dyn Trait: encountered ALLOC27, but expected a vtable pointer - --> $DIR/raw-bytes.rs:187:1 + --> $DIR/raw-bytes.rs:184:1 | LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -459,7 +459,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm } error[E0080]: constructing invalid value of type &[!; 1]: encountered a reference pointing to uninhabited type [!; 1] - --> $DIR/raw-bytes.rs:191:1 + --> $DIR/raw-bytes.rs:188:1 | LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -470,7 +470,7 @@ LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; } error[E0080]: constructing invalid value of type &[!]: at .[0], encountered a value of the never type `!` - --> $DIR/raw-bytes.rs:192:1 + --> $DIR/raw-bytes.rs:189:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; | ^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -481,7 +481,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; } error[E0080]: constructing invalid value of type &[!]: at .[0], encountered a value of the never type `!` - --> $DIR/raw-bytes.rs:193:1 + --> $DIR/raw-bytes.rs:190:1 | LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; | ^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -492,7 +492,7 @@ LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:196:1 + --> $DIR/raw-bytes.rs:193:1 | LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -503,7 +503,7 @@ LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) } } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered a pointer, but expected an integer - --> $DIR/raw-bytes.rs:199:1 + --> $DIR/raw-bytes.rs:196:1 | LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem::size_of::<&u32>()) }; | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -516,7 +516,7 @@ LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, mem: } error[E0080]: constructing invalid value of type &[bool]: at .[0], encountered 0x11, but expected a boolean - --> $DIR/raw-bytes.rs:202:1 + --> $DIR/raw-bytes.rs:199:1 | LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -527,7 +527,7 @@ LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) } error[E0080]: constructing invalid value of type &[u16]: at .[1], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:206:1 + --> $DIR/raw-bytes.rs:203:1 | LL | pub static S7: &[u16] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -538,7 +538,7 @@ LL | pub static S7: &[u16] = unsafe { } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered uninitialized memory, but expected an integer - --> $DIR/raw-bytes.rs:213:1 + --> $DIR/raw-bytes.rs:210:1 | LL | pub static R4: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -549,7 +549,7 @@ LL | pub static R4: &[u8] = unsafe { } error[E0080]: constructing invalid value of type &[u8]: at .[0], encountered a pointer, but expected an integer - --> $DIR/raw-bytes.rs:218:1 + --> $DIR/raw-bytes.rs:215:1 | LL | pub static R5: &[u8] = unsafe { | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -562,7 +562,7 @@ LL | pub static R5: &[u8] = unsafe { } error[E0080]: constructing invalid value of type &[bool]: at .[0], encountered 0x11, but expected a boolean - --> $DIR/raw-bytes.rs:223:1 + --> $DIR/raw-bytes.rs:220:1 | LL | pub static R6: &[bool] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value diff --git a/tests/ui/consts/const-eval/raw-bytes.rs b/tests/ui/consts/const-eval/raw-bytes.rs index d63e1d5b062cf..acaf8c8310aab 100644 --- a/tests/ui/consts/const-eval/raw-bytes.rs +++ b/tests/ui/consts/const-eval/raw-bytes.rs @@ -6,6 +6,7 @@ //@ ignore-parallel-frontend different alloc ids #![allow(invalid_value, unnecessary_transmutes)] #![feature(never_type, rustc_attrs, ptr_metadata, slice_from_ptr_range, const_slice_from_ptr_range)] +#![feature(pattern_types, pattern_type_macro)] use std::mem; use std::alloc::Layout; @@ -63,16 +64,12 @@ const NULL_U8: NonZero = unsafe { mem::transmute(0u8) }; const NULL_USIZE: NonZero = unsafe { mem::transmute(0usize) }; //~^ ERROR constructing invalid value -#[rustc_layout_scalar_valid_range_start(10)] -#[rustc_layout_scalar_valid_range_end(30)] -struct RestrictedRange1(u32); -const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; +struct RestrictedRange1(std::pat::pattern_type!(u32 is 10..=30)); +const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(mem::transmute(42_u32)) }; //~^ ERROR constructing invalid value -#[rustc_layout_scalar_valid_range_start(30)] -#[rustc_layout_scalar_valid_range_end(10)] -struct RestrictedRange2(u32); -const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; +struct RestrictedRange2(std::pat::pattern_type!(i32 is 30.. | ..=10)); +const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(mem::transmute(20_i32)) }; //~^ ERROR constructing invalid value const NULL_FAT_PTR: NonNull = unsafe { diff --git a/tests/ui/consts/const-eval/ub-nonnull.rs b/tests/ui/consts/const-eval/ub-nonnull.rs index daa4c40f98a96..b6aca0684b84d 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.rs +++ b/tests/ui/consts/const-eval/ub-nonnull.rs @@ -36,20 +36,6 @@ union MaybeUninit { const UNINIT: NonZero = unsafe { MaybeUninit { uninit: () }.init }; //~^ ERROR uninitialized -// Also test other uses of rustc_layout_scalar_valid_range_start - -#[rustc_layout_scalar_valid_range_start(10)] -#[rustc_layout_scalar_valid_range_end(30)] -struct RestrictedRange1(u32); -const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; -//~^ ERROR invalid value - -#[rustc_layout_scalar_valid_range_start(30)] -#[rustc_layout_scalar_valid_range_end(10)] -struct RestrictedRange2(u32); -const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; -//~^ ERROR invalid value - const NULL_FAT_PTR: NonNull = unsafe { //~^ ERROR invalid value let x: &dyn Send = &42; diff --git a/tests/ui/consts/const-eval/ub-nonnull.stderr b/tests/ui/consts/const-eval/ub-nonnull.stderr index 9c88f149b32e9..5bd23944ed5be 100644 --- a/tests/ui/consts/const-eval/ub-nonnull.stderr +++ b/tests/ui/consts/const-eval/ub-nonnull.stderr @@ -47,30 +47,8 @@ LL | const UNINIT: NonZero = unsafe { MaybeUninit { uninit: () }.init }; __ │ ░ } -error[E0080]: constructing invalid value of type RestrictedRange1: encountered 42, but expected something in the range 10..=30 - --> $DIR/ub-nonnull.rs:44:1 - | -LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value - | - = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { - HEX_DUMP - } - -error[E0080]: constructing invalid value of type RestrictedRange2: encountered 20, but expected something less or equal to 10, or greater or equal to 30 - --> $DIR/ub-nonnull.rs:50:1 - | -LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value - | - = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { - HEX_DUMP - } - error[E0080]: constructing invalid value of type NonNull: at .pointer, encountered 0, but expected something greater or equal to 1 - --> $DIR/ub-nonnull.rs:53:1 + --> $DIR/ub-nonnull.rs:39:1 | LL | const NULL_FAT_PTR: NonNull = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -81,7 +59,7 @@ LL | const NULL_FAT_PTR: NonNull = unsafe { } error[E0080]: constructing invalid value of type NonNull<()>: at .pointer, encountered a maybe-null pointer, but expected something that is definitely non-zero - --> $DIR/ub-nonnull.rs:61:1 + --> $DIR/ub-nonnull.rs:47:1 | LL | const MAYBE_NULL_PTR: NonNull<()> = unsafe { mem::transmute((&raw const S).wrapping_add(4)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -91,6 +69,6 @@ LL | const MAYBE_NULL_PTR: NonNull<()> = unsafe { mem::transmute((&raw const S). HEX_DUMP } -error: aborting due to 9 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-eval/ub-ref-ptr.rs b/tests/ui/consts/const-eval/ub-ref-ptr.rs index 5cc327797a139..1f92e8edec2ca 100644 --- a/tests/ui/consts/const-eval/ub-ref-ptr.rs +++ b/tests/ui/consts/const-eval/ub-ref-ptr.rs @@ -4,10 +4,10 @@ //@ normalize-stderr: "([0-9a-f][0-9a-f] |__ |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?()?─*╼ )+ *│.*" -> "HEX_DUMP" //@ dont-require-annotations: NOTE //@ normalize-stderr: "0x[0-9](\.\.|\])" -> "0x%$1" -#![feature(rustc_attrs)] +#![feature(pattern_types, pattern_type_macro)] #![allow(invalid_value)] //@ ignore-parallel-frontend different alloc ids -use std::mem; +use std::{mem, pat::pattern_type}; #[repr(C)] union MaybeUninit { @@ -75,14 +75,15 @@ const UNALIGNED_READ: () = unsafe { ptr.read(); //~ ERROR accessing memory }; -// Check the general case of a pointer value not falling into the scalar valid range. -#[rustc_layout_scalar_valid_range_start(1000)] +/* +FIXME(pattern_types): allow for other integer range restricitons on raw pointers? pub struct High { - pointer: *const (), + pointer: pattern_type!(*const () is 1000..), } static S: u32 = 0; // just a static to construct a pointer with unknown absolute address const INVALID_VALUE_PTR: High = unsafe { mem::transmute(&S) }; -//~^ ERROR invalid value +//^ ERROR invalid value +*/ fn main() {} diff --git a/tests/ui/consts/const-eval/ub-ref-ptr.stderr b/tests/ui/consts/const-eval/ub-ref-ptr.stderr index 17ddea05e93f7..1087d89f6389d 100644 --- a/tests/ui/consts/const-eval/ub-ref-ptr.stderr +++ b/tests/ui/consts/const-eval/ub-ref-ptr.stderr @@ -114,7 +114,7 @@ LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; HEX_DUMP } -error[E0080]: reading memory at ALLOC6[0x%..0x%], but memory is uninitialized at [0x%..0x%], and this operation requires initialized memory +error[E0080]: reading memory at ALLOC5[0x%..0x%], but memory is uninitialized at [0x%..0x%], and this operation requires initialized memory --> $DIR/ub-ref-ptr.rs:54:41 | LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; @@ -135,7 +135,7 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; HEX_DUMP } -error[E0080]: reading memory at ALLOC7[0x%..0x%], but memory is uninitialized at [0x%..0x%], and this operation requires initialized memory +error[E0080]: reading memory at ALLOC6[0x%..0x%], but memory is uninitialized at [0x%..0x%], and this operation requires initialized memory --> $DIR/ub-ref-ptr.rs:59:38 | LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; @@ -184,17 +184,6 @@ error[E0080]: accessing memory based on pointer with alignment 1, but alignment LL | ptr.read(); | ^^^^^^^^^^ evaluation of `UNALIGNED_READ` failed here -error[E0080]: constructing invalid value of type High: encountered a pointer with unknown absolute address, but expected something that is definitely greater or equal to 1000 - --> $DIR/ub-ref-ptr.rs:84:1 - | -LL | const INVALID_VALUE_PTR: High = unsafe { mem::transmute(&S) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value - | - = note: the rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { - HEX_DUMP - } - -error: aborting due to 18 previous errors +error: aborting due to 17 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/enum-discriminant/ptr_niche.rs b/tests/ui/enum-discriminant/ptr_niche.rs index 32df08bce6345..45dbe50248217 100644 --- a/tests/ui/enum-discriminant/ptr_niche.rs +++ b/tests/ui/enum-discriminant/ptr_niche.rs @@ -2,37 +2,41 @@ //! Check that we can codegen setting and getting discriminants, including non-null niches, //! for enums with a pointer-like ABI. This used to crash llvm. -#![feature(rustc_attrs)] -use std::{ptr, mem}; +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] +use std::{ptr, mem, pat::pattern_type}; - -#[rustc_layout_scalar_valid_range_start(1)] -#[rustc_layout_scalar_valid_range_end(100)] #[derive(Copy, Clone)] -struct PointerWithRange(#[allow(dead_code)] *const u8); +struct PointerWithRange(#[allow(dead_code)] pattern_type!(*const u8 is !null)); fn main() { - let val = unsafe { PointerWithRange(ptr::without_provenance(90)) }; + let val = + unsafe { PointerWithRange(mem::transmute::<*const u8, _>(ptr::without_provenance(90))) }; let ptr = Some(val); assert!(ptr.is_some()); let raw = unsafe { mem::transmute::<_, usize>(ptr) }; assert_eq!(raw, 90); + /* + FIXME(pattern_types): allow restricting raw pointers to smaller integer ranges? let ptr = Some(Some(val)); assert!(ptr.is_some()); assert!(ptr.unwrap().is_some()); let raw = unsafe { mem::transmute::<_, usize>(ptr) }; assert_eq!(raw, 90); + */ let ptr: Option = None; assert!(ptr.is_none()); let raw = unsafe { mem::transmute::<_, usize>(ptr) }; assert!(!(1..=100).contains(&raw)); + /* + FIXME(pattern_types): allow restricting raw pointers to smaller integer ranges? let ptr: Option> = None; assert!(ptr.is_none()); let raw = unsafe { mem::transmute::<_, usize>(ptr) }; assert!(!(1..=100).contains(&raw)); + */ } diff --git a/tests/ui/impl-trait/unsafety-checking-cycle.rs b/tests/ui/impl-trait/unsafety-checking-cycle.rs deleted file mode 100644 index 2306f079e5da8..0000000000000 --- a/tests/ui/impl-trait/unsafety-checking-cycle.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Ensure that we don't get a cycle error from trying to determine whether an -// opaque type implements `Freeze` in safety checking, when it doesn't matter. - -//@ check-pass - -#![feature(rustc_attrs)] - -struct AnyValue(T); - -// No need to check for `Freeze` here, there's no -// `rustc_layout_scalar_valid_range_start` involved. -fn not_restricted(c: bool) -> impl Sized { - if c { - let x = AnyValue(not_restricted(false)); - &x.0; - } - 2u32 -} - -#[rustc_layout_scalar_valid_range_start(1)] -struct NonZero(T); - -// No need to check for `Freeze` here, we're not borrowing the field. -fn not_field(c: bool) -> impl Sized { - if c { - let x = unsafe { NonZero(not_field(false)) }; - &x; - } - 5u32 -} - -fn main() {} diff --git a/tests/ui/layout/valid_range_oob.rs b/tests/ui/layout/valid_range_oob.rs deleted file mode 100644 index 8ae9f6e97260c..0000000000000 --- a/tests/ui/layout/valid_range_oob.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ failure-status: 101 -//@ normalize-stderr: "note: .*\n\n" -> "" -//@ normalize-stderr: "thread 'rustc'.*panicked.*\n" -> "" -//@ rustc-env:RUST_BACKTRACE=0 - -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_end(257)] -struct Foo(i8); - -// Need to do in a constant, as runtime codegen -// does not compute the layout of `Foo` in check builds. -const FOO: Foo = unsafe { Foo(1) }; - -fn main() {} diff --git a/tests/ui/layout/valid_range_oob.stderr b/tests/ui/layout/valid_range_oob.stderr deleted file mode 100644 index fc6ebcf1692fe..0000000000000 --- a/tests/ui/layout/valid_range_oob.stderr +++ /dev/null @@ -1,8 +0,0 @@ - -257 > 255 -error: the compiler unexpectedly panicked. This is a bug - -query stack during panic: -#0 [layout_of] computing layout of `Foo` -#1 [eval_to_allocation_raw] const-evaluating + checking `FOO` -... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack diff --git a/tests/ui/lint/invalid_value.rs b/tests/ui/lint/invalid_value.rs index 29e8e6cfef6dd..54435583b1341 100644 --- a/tests/ui/lint/invalid_value.rs +++ b/tests/ui/lint/invalid_value.rs @@ -2,11 +2,12 @@ // in a lint. #![allow(deprecated)] #![deny(invalid_value)] -#![feature(never_type, rustc_attrs)] +#![feature(never_type, rustc_attrs, pattern_types, pattern_type_macro)] use std::mem::{self, MaybeUninit}; use std::ptr::NonNull; use std::num::NonZero; +use std::pat::pattern_type; enum Void {} @@ -16,10 +17,8 @@ struct RefPair((&'static i32, i32)); struct Wrap { wrapped: T } enum WrapEnum { Wrapped(T) } -#[rustc_layout_scalar_valid_range_start(0)] -#[rustc_layout_scalar_valid_range_end(128)] #[repr(transparent)] -pub(crate) struct NonBig(u64); +pub(crate) struct NonBig(pattern_type!(u64 is 0..=128)); /// A two-variant enum, thus needs a tag and may not remain uninitialized. enum Fruit { @@ -43,9 +42,7 @@ enum TwoUninhabited { B(Void), } -#[rustc_layout_scalar_valid_range_start(254)] -#[rustc_layout_scalar_valid_range_end(1)] -pub(crate) struct WrapAroundRange(u8); +pub(crate) struct WrapAroundRange(pattern_type!(i8 is -1..=1)); #[allow(unused)] fn generic() { diff --git a/tests/ui/lint/invalid_value.stderr b/tests/ui/lint/invalid_value.stderr index 63df1e5d11d68..8500d3732e1a4 100644 --- a/tests/ui/lint/invalid_value.stderr +++ b/tests/ui/lint/invalid_value.stderr @@ -1,5 +1,5 @@ error: the type `&T` does not permit zero-initialization - --> $DIR/invalid_value.rs:53:32 + --> $DIR/invalid_value.rs:50:32 | LL | let _val: &'static T = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -15,7 +15,7 @@ LL | #![deny(invalid_value)] | ^^^^^^^^^^^^^ error: the type `&T` does not permit being left uninitialized - --> $DIR/invalid_value.rs:54:32 + --> $DIR/invalid_value.rs:51:32 | LL | let _val: &'static T = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +26,7 @@ LL | let _val: &'static T = mem::uninitialized(); = note: references must be non-null error: the type `Wrap<&T>` does not permit zero-initialization - --> $DIR/invalid_value.rs:56:38 + --> $DIR/invalid_value.rs:53:38 | LL | let _val: Wrap<&'static T> = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -36,13 +36,13 @@ LL | let _val: Wrap<&'static T> = mem::zeroed(); | = note: `Wrap<&T>` must be non-null note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `Wrap<&T>` does not permit being left uninitialized - --> $DIR/invalid_value.rs:57:38 + --> $DIR/invalid_value.rs:54:38 | LL | let _val: Wrap<&'static T> = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -52,13 +52,13 @@ LL | let _val: Wrap<&'static T> = mem::uninitialized(); | = note: `Wrap<&T>` must be non-null note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `!` does not permit zero-initialization - --> $DIR/invalid_value.rs:64:23 + --> $DIR/invalid_value.rs:61:23 | LL | let _val: ! = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -66,7 +66,7 @@ LL | let _val: ! = mem::zeroed(); = note: the `!` type has no valid value error: the type `!` does not permit being left uninitialized - --> $DIR/invalid_value.rs:65:23 + --> $DIR/invalid_value.rs:62:23 | LL | let _val: ! = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -74,7 +74,7 @@ LL | let _val: ! = mem::uninitialized(); = note: the `!` type has no valid value error: the type `(i32, !)` does not permit zero-initialization - --> $DIR/invalid_value.rs:67:30 + --> $DIR/invalid_value.rs:64:30 | LL | let _val: (i32, !) = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -82,7 +82,7 @@ LL | let _val: (i32, !) = mem::zeroed(); = note: the `!` type has no valid value error: the type `(i32, !)` does not permit being left uninitialized - --> $DIR/invalid_value.rs:68:30 + --> $DIR/invalid_value.rs:65:30 | LL | let _val: (i32, !) = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -90,31 +90,31 @@ LL | let _val: (i32, !) = mem::uninitialized(); = note: integers must be initialized error: the type `Void` does not permit zero-initialization - --> $DIR/invalid_value.rs:70:26 + --> $DIR/invalid_value.rs:67:26 | LL | let _val: Void = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | note: enums with no inhabited variants have no valid value - --> $DIR/invalid_value.rs:11:1 + --> $DIR/invalid_value.rs:12:1 | LL | enum Void {} | ^^^^^^^^^ error: the type `Void` does not permit being left uninitialized - --> $DIR/invalid_value.rs:71:26 + --> $DIR/invalid_value.rs:68:26 | LL | let _val: Void = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | note: enums with no inhabited variants have no valid value - --> $DIR/invalid_value.rs:11:1 + --> $DIR/invalid_value.rs:12:1 | LL | enum Void {} | ^^^^^^^^^ error: the type `&i32` does not permit zero-initialization - --> $DIR/invalid_value.rs:73:34 + --> $DIR/invalid_value.rs:70:34 | LL | let _val: &'static i32 = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -125,7 +125,7 @@ LL | let _val: &'static i32 = mem::zeroed(); = note: references must be non-null error: the type `&i32` does not permit being left uninitialized - --> $DIR/invalid_value.rs:74:34 + --> $DIR/invalid_value.rs:71:34 | LL | let _val: &'static i32 = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | let _val: &'static i32 = mem::uninitialized(); = note: references must be non-null error: the type `Ref` does not permit zero-initialization - --> $DIR/invalid_value.rs:76:25 + --> $DIR/invalid_value.rs:73:25 | LL | let _val: Ref = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -146,13 +146,13 @@ LL | let _val: Ref = mem::zeroed(); | = note: `Ref` must be non-null note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:13:12 + --> $DIR/invalid_value.rs:14:12 | LL | struct Ref(&'static i32); | ^^^^^^^^^^^^ error: the type `Ref` does not permit being left uninitialized - --> $DIR/invalid_value.rs:77:25 + --> $DIR/invalid_value.rs:74:25 | LL | let _val: Ref = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -162,13 +162,13 @@ LL | let _val: Ref = mem::uninitialized(); | = note: `Ref` must be non-null note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:13:12 + --> $DIR/invalid_value.rs:14:12 | LL | struct Ref(&'static i32); | ^^^^^^^^^^^^ error: the type `fn()` does not permit zero-initialization - --> $DIR/invalid_value.rs:79:26 + --> $DIR/invalid_value.rs:76:26 | LL | let _val: fn() = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL | let _val: fn() = mem::zeroed(); = note: function pointers must be non-null error: the type `fn()` does not permit being left uninitialized - --> $DIR/invalid_value.rs:80:26 + --> $DIR/invalid_value.rs:77:26 | LL | let _val: fn() = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -190,7 +190,7 @@ LL | let _val: fn() = mem::uninitialized(); = note: function pointers must be non-null error: the type `Wrap` does not permit zero-initialization - --> $DIR/invalid_value.rs:82:32 + --> $DIR/invalid_value.rs:79:32 | LL | let _val: Wrap = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -200,13 +200,13 @@ LL | let _val: Wrap = mem::zeroed(); | = note: `Wrap` must be non-null note: because function pointers must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `Wrap` does not permit being left uninitialized - --> $DIR/invalid_value.rs:83:32 + --> $DIR/invalid_value.rs:80:32 | LL | let _val: Wrap = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -216,13 +216,13 @@ LL | let _val: Wrap = mem::uninitialized(); | = note: `Wrap` must be non-null note: because function pointers must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `WrapEnum` does not permit zero-initialization - --> $DIR/invalid_value.rs:85:36 + --> $DIR/invalid_value.rs:82:36 | LL | let _val: WrapEnum = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -232,13 +232,13 @@ LL | let _val: WrapEnum = mem::zeroed(); | = note: `WrapEnum` must be non-null note: because function pointers must be non-null (in this field of the only potentially inhabited enum variant) - --> $DIR/invalid_value.rs:17:28 + --> $DIR/invalid_value.rs:18:28 | LL | enum WrapEnum { Wrapped(T) } | ^ error: the type `WrapEnum` does not permit being left uninitialized - --> $DIR/invalid_value.rs:86:36 + --> $DIR/invalid_value.rs:83:36 | LL | let _val: WrapEnum = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -248,13 +248,13 @@ LL | let _val: WrapEnum = mem::uninitialized(); | = note: `WrapEnum` must be non-null note: because function pointers must be non-null (in this field of the only potentially inhabited enum variant) - --> $DIR/invalid_value.rs:17:28 + --> $DIR/invalid_value.rs:18:28 | LL | enum WrapEnum { Wrapped(T) } | ^ error: the type `Wrap<(RefPair, i32)>` does not permit zero-initialization - --> $DIR/invalid_value.rs:88:42 + --> $DIR/invalid_value.rs:85:42 | LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -263,18 +263,18 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | note: `RefPair` must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:14:16 + --> $DIR/invalid_value.rs:15:16 | LL | struct RefPair((&'static i32, i32)); | ^^^^^^^^^^^^^^^^^^^ error: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized - --> $DIR/invalid_value.rs:89:42 + --> $DIR/invalid_value.rs:86:42 | LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -283,18 +283,18 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | note: `RefPair` must be non-null (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ note: because references must be non-null (in this struct field) - --> $DIR/invalid_value.rs:14:16 + --> $DIR/invalid_value.rs:15:16 | LL | struct RefPair((&'static i32, i32)); | ^^^^^^^^^^^^^^^^^^^ error: the type `NonNull` does not permit zero-initialization - --> $DIR/invalid_value.rs:91:34 + --> $DIR/invalid_value.rs:88:34 | LL | let _val: NonNull = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -305,7 +305,7 @@ LL | let _val: NonNull = mem::zeroed(); = note: `std::ptr::NonNull` must be non-null error: the type `NonNull` does not permit being left uninitialized - --> $DIR/invalid_value.rs:92:34 + --> $DIR/invalid_value.rs:89:34 | LL | let _val: NonNull = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -316,7 +316,7 @@ LL | let _val: NonNull = mem::uninitialized(); = note: `std::ptr::NonNull` must be non-null error: the type `(NonZero, i32)` does not permit zero-initialization - --> $DIR/invalid_value.rs:94:41 + --> $DIR/invalid_value.rs:91:41 | LL | let _val: (NonZero, i32) = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -325,7 +325,7 @@ LL | let _val: (NonZero, i32) = mem::zeroed(); = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `(NonZero, i32)` does not permit being left uninitialized - --> $DIR/invalid_value.rs:95:41 + --> $DIR/invalid_value.rs:92:41 | LL | let _val: (NonZero, i32) = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -334,7 +334,7 @@ LL | let _val: (NonZero, i32) = mem::uninitialized(); = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `*const dyn Send` does not permit zero-initialization - --> $DIR/invalid_value.rs:97:37 + --> $DIR/invalid_value.rs:94:37 | LL | let _val: *const dyn Send = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -345,7 +345,7 @@ LL | let _val: *const dyn Send = mem::zeroed(); = note: the vtable of a wide raw pointer must be non-null error: the type `*const dyn Send` does not permit being left uninitialized - --> $DIR/invalid_value.rs:98:37 + --> $DIR/invalid_value.rs:95:37 | LL | let _val: *const dyn Send = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -356,7 +356,7 @@ LL | let _val: *const dyn Send = mem::uninitialized(); = note: the vtable of a wide raw pointer must be non-null error: the type `[fn(); 2]` does not permit zero-initialization - --> $DIR/invalid_value.rs:100:31 + --> $DIR/invalid_value.rs:97:31 | LL | let _val: [fn(); 2] = mem::zeroed(); | ^^^^^^^^^^^^^ @@ -367,7 +367,7 @@ LL | let _val: [fn(); 2] = mem::zeroed(); = note: function pointers must be non-null error: the type `[fn(); 2]` does not permit being left uninitialized - --> $DIR/invalid_value.rs:101:31 + --> $DIR/invalid_value.rs:98:31 | LL | let _val: [fn(); 2] = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -378,59 +378,59 @@ LL | let _val: [fn(); 2] = mem::uninitialized(); = note: function pointers must be non-null error: the type `TwoUninhabited` does not permit zero-initialization - --> $DIR/invalid_value.rs:103:36 + --> $DIR/invalid_value.rs:100:36 | LL | let _val: TwoUninhabited = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | note: enums with no inhabited variants have no valid value - --> $DIR/invalid_value.rs:41:1 + --> $DIR/invalid_value.rs:40:1 | LL | enum TwoUninhabited { | ^^^^^^^^^^^^^^^^^^^ error: the type `TwoUninhabited` does not permit being left uninitialized - --> $DIR/invalid_value.rs:104:36 + --> $DIR/invalid_value.rs:101:36 | LL | let _val: TwoUninhabited = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | note: enums with no inhabited variants have no valid value - --> $DIR/invalid_value.rs:41:1 + --> $DIR/invalid_value.rs:40:1 | LL | enum TwoUninhabited { | ^^^^^^^^^^^^^^^^^^^ error: the type `OneFruitNonZero` does not permit zero-initialization - --> $DIR/invalid_value.rs:106:37 + --> $DIR/invalid_value.rs:103:37 | LL | let _val: OneFruitNonZero = mem::zeroed(); | ^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `OneFruitNonZero` must be non-null note: because `std::num::NonZero` must be non-null (in this field of the only potentially inhabited enum variant) - --> $DIR/invalid_value.rs:38:12 + --> $DIR/invalid_value.rs:37:12 | LL | Banana(NonZero), | ^^^^^^^^^^^^ = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `OneFruitNonZero` does not permit being left uninitialized - --> $DIR/invalid_value.rs:107:37 + --> $DIR/invalid_value.rs:104:37 | LL | let _val: OneFruitNonZero = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed | = note: `OneFruitNonZero` must be non-null note: because `std::num::NonZero` must be non-null (in this field of the only potentially inhabited enum variant) - --> $DIR/invalid_value.rs:38:12 + --> $DIR/invalid_value.rs:37:12 | LL | Banana(NonZero), | ^^^^^^^^^^^^ = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `bool` does not permit being left uninitialized - --> $DIR/invalid_value.rs:111:26 + --> $DIR/invalid_value.rs:108:26 | LL | let _val: bool = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -441,7 +441,7 @@ LL | let _val: bool = mem::uninitialized(); = note: booleans must be either `true` or `false` error: the type `Wrap` does not permit being left uninitialized - --> $DIR/invalid_value.rs:114:32 + --> $DIR/invalid_value.rs:111:32 | LL | let _val: Wrap = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -451,13 +451,13 @@ LL | let _val: Wrap = mem::uninitialized(); | = note: `Wrap` must be initialized inside its custom valid range note: characters must be a valid Unicode codepoint (in this struct field) - --> $DIR/invalid_value.rs:16:18 + --> $DIR/invalid_value.rs:17:18 | LL | struct Wrap { wrapped: T } | ^^^^^^^^^^ error: the type `NonBig` does not permit being left uninitialized - --> $DIR/invalid_value.rs:117:28 + --> $DIR/invalid_value.rs:114:28 | LL | let _val: NonBig = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -466,14 +466,9 @@ LL | let _val: NonBig = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `NonBig` must be initialized inside its custom valid range -note: integers must be initialized (in this struct field) - --> $DIR/invalid_value.rs:22:26 - | -LL | pub(crate) struct NonBig(u64); - | ^^^ error: the type `Fruit` does not permit being left uninitialized - --> $DIR/invalid_value.rs:120:27 + --> $DIR/invalid_value.rs:117:27 | LL | let _val: Fruit = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -482,13 +477,13 @@ LL | let _val: Fruit = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | note: enums with multiple inhabited variants have to be initialized to a variant - --> $DIR/invalid_value.rs:25:1 + --> $DIR/invalid_value.rs:24:1 | LL | enum Fruit { | ^^^^^^^^^^ error: the type `[bool; 2]` does not permit being left uninitialized - --> $DIR/invalid_value.rs:123:31 + --> $DIR/invalid_value.rs:120:31 | LL | let _val: [bool; 2] = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -499,7 +494,7 @@ LL | let _val: [bool; 2] = mem::uninitialized(); = note: booleans must be either `true` or `false` error: the type `i32` does not permit being left uninitialized - --> $DIR/invalid_value.rs:126:25 + --> $DIR/invalid_value.rs:123:25 | LL | let _val: i32 = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -510,7 +505,7 @@ LL | let _val: i32 = mem::uninitialized(); = note: integers must be initialized error: the type `f32` does not permit being left uninitialized - --> $DIR/invalid_value.rs:129:25 + --> $DIR/invalid_value.rs:126:25 | LL | let _val: f32 = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -521,7 +516,7 @@ LL | let _val: f32 = mem::uninitialized(); = note: floats must be initialized error: the type `*const ()` does not permit being left uninitialized - --> $DIR/invalid_value.rs:132:31 + --> $DIR/invalid_value.rs:129:31 | LL | let _val: *const () = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -532,7 +527,7 @@ LL | let _val: *const () = mem::uninitialized(); = note: raw pointers must be initialized error: the type `*const [()]` does not permit being left uninitialized - --> $DIR/invalid_value.rs:135:33 + --> $DIR/invalid_value.rs:132:33 | LL | let _val: *const [()] = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -543,7 +538,7 @@ LL | let _val: *const [()] = mem::uninitialized(); = note: raw pointers must be initialized error: the type `WrapAroundRange` does not permit being left uninitialized - --> $DIR/invalid_value.rs:138:37 + --> $DIR/invalid_value.rs:135:37 | LL | let _val: WrapAroundRange = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -552,14 +547,9 @@ LL | let _val: WrapAroundRange = mem::uninitialized(); | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | = note: `WrapAroundRange` must be initialized inside its custom valid range -note: integers must be initialized (in this struct field) - --> $DIR/invalid_value.rs:48:35 - | -LL | pub(crate) struct WrapAroundRange(u8); - | ^^ error: the type `Result` does not permit being left uninitialized - --> $DIR/invalid_value.rs:143:38 + --> $DIR/invalid_value.rs:140:38 | LL | let _val: Result = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -571,7 +561,7 @@ note: enums with multiple inhabited variants have to be initialized to a variant --> $SRC_DIR/core/src/result.rs:LL:COL error: the type `&i32` does not permit zero-initialization - --> $DIR/invalid_value.rs:151:34 + --> $DIR/invalid_value.rs:148:34 | LL | let _val: &'static i32 = mem::transmute(0usize); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -582,7 +572,7 @@ LL | let _val: &'static i32 = mem::transmute(0usize); = note: references must be non-null error: the type `&[i32]` does not permit zero-initialization - --> $DIR/invalid_value.rs:152:36 + --> $DIR/invalid_value.rs:149:36 | LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -593,7 +583,7 @@ LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize)); = note: references must be non-null error: the type `NonZero` does not permit zero-initialization - --> $DIR/invalid_value.rs:153:34 + --> $DIR/invalid_value.rs:150:34 | LL | let _val: NonZero = mem::transmute(0); | ^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed @@ -602,7 +592,7 @@ LL | let _val: NonZero = mem::transmute(0); = note: because `core::num::niche_types::NonZeroU32Inner` must be non-null error: the type `NonNull` does not permit zero-initialization - --> $DIR/invalid_value.rs:156:34 + --> $DIR/invalid_value.rs:153:34 | LL | let _val: NonNull = MaybeUninit::zeroed().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -613,7 +603,7 @@ LL | let _val: NonNull = MaybeUninit::zeroed().assume_init(); = note: `std::ptr::NonNull` must be non-null error: the type `NonNull` does not permit being left uninitialized - --> $DIR/invalid_value.rs:157:34 + --> $DIR/invalid_value.rs:154:34 | LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -624,7 +614,7 @@ LL | let _val: NonNull = MaybeUninit::uninit().assume_init(); = note: `std::ptr::NonNull` must be non-null error: the type `bool` does not permit being left uninitialized - --> $DIR/invalid_value.rs:158:26 + --> $DIR/invalid_value.rs:155:26 | LL | let _val: bool = MaybeUninit::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/parser/bad-lit-suffixes.rs b/tests/ui/parser/bad-lit-suffixes.rs index 0a1ee12073023..70e3f7aa6c3b2 100644 --- a/tests/ui/parser/bad-lit-suffixes.rs +++ b/tests/ui/parser/bad-lit-suffixes.rs @@ -40,8 +40,6 @@ fn g() {} //~^ ERROR suffixes on string literals are invalid extern "C" {} -#[rustc_layout_scalar_valid_range_start(0suffix)] -//~^ ERROR invalid suffix `suffix` for number literal struct S; impl S { diff --git a/tests/ui/parser/bad-lit-suffixes.stderr b/tests/ui/parser/bad-lit-suffixes.stderr index 6c3dbbcec6453..f93db6ab29a23 100644 --- a/tests/ui/parser/bad-lit-suffixes.stderr +++ b/tests/ui/parser/bad-lit-suffixes.stderr @@ -160,20 +160,12 @@ error: suffixes on string literals are invalid LL | #[link(name = "string"suffix)] | ^^^^^^^^^^^^^^ invalid suffix `suffix` -error: invalid suffix `suffix` for number literal - --> $DIR/bad-lit-suffixes.rs:43:41 - | -LL | #[rustc_layout_scalar_valid_range_start(0suffix)] - | ^^^^^^^ invalid suffix `suffix` - | - = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) - error: suffixes on string literals are invalid - --> $DIR/bad-lit-suffixes.rs:48:25 + --> $DIR/bad-lit-suffixes.rs:46:25 | LL | #[rustc_confusables("blah"suffix)] | ^^^^^^^^^^^^ invalid suffix `suffix` -error: aborting due to 22 previous errors; 2 warnings emitted +error: aborting due to 21 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0539`. diff --git a/tests/ui/print_type_sizes/niche-filling.rs b/tests/ui/print_type_sizes/niche-filling.rs index 719bc2a07dc91..4a8d3b81b9d37 100644 --- a/tests/ui/print_type_sizes/niche-filling.rs +++ b/tests/ui/print_type_sizes/niche-filling.rs @@ -15,16 +15,14 @@ // ^-- needed because `--pass check` does not emit the output needed. // FIXME: consider using an attribute instead of side-effects. #![allow(dead_code)] -#![feature(rustc_attrs)] +#![feature(rustc_attrs, pattern_types, pattern_type_macro)] use std::num::NonZero; pub enum MyOption { None, Some(T) } -#[rustc_layout_scalar_valid_range_start(0)] -#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)] pub struct MyNotNegativeOne { - _i: i32, + _i: std::pat::pattern_type!(i32 is 0..=i32::MAX | i32::MIN..=-2), } impl Default for MyOption { diff --git a/tests/ui/structs-enums/type-sizes.rs b/tests/ui/structs-enums/type-sizes.rs index a8fadcc1d1ec6..af87b4cd92b72 100644 --- a/tests/ui/structs-enums/type-sizes.rs +++ b/tests/ui/structs-enums/type-sizes.rs @@ -238,10 +238,6 @@ struct VecDummy { len: usize, } -#[rustc_layout_scalar_valid_range_start(1)] -#[rustc_layout_scalar_valid_range_end(100)] -struct PointerWithRange(#[allow(dead_code)] *const u8); - pub fn main() { assert_eq!(size_of::(), 1 as usize); assert_eq!(size_of::(), 4 as usize); @@ -357,8 +353,4 @@ pub fn main() { // the end which means the 8-sized field shouldn't be alignment-promoted before the 4-sized one. let v = ReorderEndNiche { a: EndNiche8([0; 7], false), b: MiddleNiche4(0, 0, false, 0) }; assert!(ptr::from_ref(&v.a).addr() > ptr::from_ref(&v.b).addr()); - - - assert_eq!(size_of::>(), size_of::()); - assert_eq!(size_of::>>(), size_of::()); } diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.rs deleted file mode 100644 index ca44fa7e4e756..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(rustc_attrs)] -#![allow(internal_features)] - -#[derive(Debug)] -#[rustc_layout_scalar_valid_range_start(2)] -struct NonZeroAndOneU8(u8); - -fn main() { - println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); - //~^ ERROR found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.stderr deleted file mode 100644 index 040c1d5bcbee4..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/initializing-ranged-via-ctor.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0277]: expected a `FnOnce({integer})` closure, found `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` - --> $DIR/initializing-ranged-via-ctor.rs:9:34 - | -LL | println!("{:?}", Some(1).map(NonZeroAndOneU8).unwrap()); - | --- ^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` - | | - | required by a bound introduced by this call - | - = help: the trait `FnOnce({integer})` is not implemented for fn item `unsafe fn(u8) -> NonZeroAndOneU8 {NonZeroAndOneU8}` - = note: unsafe function cannot be called generically without an unsafe block -note: required by a bound in `Option::::map` - --> $SRC_DIR/core/src/option.rs:LL:COL - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.rs deleted file mode 100644 index a91e579510d4d..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(rustc_attrs)] - -#[derive(Debug)] -#[rustc_layout_scalar_valid_range_start(2)] -struct NonZeroAndOneU8(u8); - -fn main() { - let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; - //~^ ERROR mismatched types -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.stderr deleted file mode 100644 index abd59bdbc75bf..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged-ctor-as-fn-ptr.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/ranged-ctor-as-fn-ptr.rs:8:40 - | -LL | let x: fn(u8) -> NonZeroAndOneU8 = NonZeroAndOneU8; - | ------------------------- ^^^^^^^^^^^^^^^ expected safe fn, found unsafe fn - | | - | expected due to this - | - = note: expected fn pointer `fn(_) -> NonZeroAndOneU8` - found struct constructor `unsafe fn(_) -> NonZeroAndOneU8 {NonZeroAndOneU8}` - = note: unsafe functions cannot be coerced into safe function pointers - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.rs deleted file mode 100644 index 0fa2da917e9f8..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let _x = NonZero(0); //~ ERROR initializing type with `rustc_layout_scalar_valid_range` attr -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.stderr deleted file mode 100644 index b6875e1581514..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block - --> $DIR/ranged_ints.rs:7:14 - | -LL | let _x = NonZero(0); - | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr - | - = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.rs deleted file mode 100644 index a3d9f54efe20c..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let mut x = unsafe { NonZero(1) }; - let y = &mut x.0; //~ ERROR mutation of layout constrained field is unsafe - if let Some(NonZero(ref mut y)) = Some(x) {} //~ ERROR mutation of layout constrained field is unsafe -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.stderr deleted file mode 100644 index 1885e77af7e0b..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints2.rs:8:13 - | -LL | let y = &mut x.0; - | ^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints2.rs:9:25 - | -LL | if let Some(NonZero(ref mut y)) = Some(x) {} - | ^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.rs deleted file mode 100644 index a9f5b2089c4d8..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { -} - -const fn foo() -> NonZero { - let mut x = unsafe { NonZero(1) }; - let y = &mut x.0; - //~^ ERROR mutation of layout constrained field is unsafe - unsafe { NonZero(1) } -} - -const fn bar() -> NonZero { - let mut x = unsafe { NonZero(1) }; - let y = unsafe { &mut x.0 }; - unsafe { NonZero(1) } -} - -const fn boo() -> NonZero { - let mut x = unsafe { NonZero(1) }; - unsafe { let y = &mut x.0; } - unsafe { NonZero(1) } -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.stderr deleted file mode 100644 index 3373d627b5e12..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints2_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints2_const.rs:11:13 - | -LL | let y = &mut x.0; - | ^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.rs deleted file mode 100644 index 47d67fac6785c..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(rustc_attrs)] - -use std::cell::Cell; - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let mut x = unsafe { NonZero(Cell::new(1)) }; - let y = &x.0; //~ ERROR borrow of layout constrained field with interior mutability -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.stderr deleted file mode 100644 index 8dcb99fc16dbf..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block - --> $DIR/ranged_ints3.rs:10:13 - | -LL | let y = &x.0; - | ^^^^ borrow of layout constrained field with interior mutability - | - = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.rs deleted file mode 100644 index 91e84f7ffbd1b..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![feature(rustc_attrs)] - -use std::cell::Cell; - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() {} - -const fn foo() -> NonZero> { - let mut x = unsafe { NonZero(Cell::new(1)) }; - let y = &x.0; - //~^ ERROR borrow of layout constrained field with interior mutability - unsafe { NonZero(Cell::new(1)) } -} - -const fn bar() -> NonZero> { - let mut x = unsafe { NonZero(Cell::new(1)) }; - let y = unsafe { &x.0 }; - unsafe { NonZero(Cell::new(1)) } -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.stderr deleted file mode 100644 index a72ab1a3b7449..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block - --> $DIR/ranged_ints3_const.rs:12:13 - | -LL | let y = &x.0; - | ^^^^ borrow of layout constrained field with interior mutability - | - = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.rs deleted file mode 100644 index de6be506d5611..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(rustc_attrs)] - -use std::cell::Cell; - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let mut x = unsafe { NonZero(Cell::new(1)) }; - match x { - NonZero(ref x) => { x } - //~^ ERROR borrow of layout constrained field with interior mutability - }; - - let mut y = unsafe { NonZero(42) }; - match y { NonZero(ref y) => { y } }; // OK, type of `y` is freeze - match y { NonZero(ref mut y) => { y } }; - //~^ ERROR mutation of layout constrained field -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.stderr deleted file mode 100644 index 1bdc29d077c0f..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints3_match.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block - --> $DIR/ranged_ints3_match.rs:11:17 - | -LL | NonZero(ref x) => { x } - | ^^^^^ borrow of layout constrained field with interior mutability - | - = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values - -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints3_match.rs:17:23 - | -LL | match y { NonZero(ref mut y) => { y } }; - | ^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.rs deleted file mode 100644 index d8632c48434f2..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() { - let mut x = unsafe { NonZero(1) }; - x.0 = 0; //~ ERROR mutation of layout constrained field is unsafe -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.stderr deleted file mode 100644 index 4a703696b8847..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints4.rs:8:5 - | -LL | x.0 = 0; - | ^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.rs deleted file mode 100644 index f09168c3d3f9c..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() {} - -const fn foo() -> NonZero { - let mut x = unsafe { NonZero(1) }; - x.0 = 0; - //~^ ERROR mutation of layout constrained field is unsafe - x -} - -const fn bar() -> NonZero { - let mut x = unsafe { NonZero(1) }; - unsafe { x.0 = 0 }; // this is UB - x -} diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.stderr deleted file mode 100644 index 604ec1167e49f..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints4_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/ranged_ints4_const.rs:10:5 - | -LL | x.0 = 0; - | ^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.rs deleted file mode 100644 index 8477772867e91..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(rustc_attrs)] - -#[rustc_layout_scalar_valid_range_start(1)] -#[repr(transparent)] -pub(crate) struct NonZero(pub(crate) T); -fn main() {} - -const fn foo() -> NonZero { NonZero(0) } -//~^ ERROR initializing type with `rustc_layout_scalar_valid_range` attr is unsafe - -const fn bar() -> NonZero { unsafe { NonZero(0) } } diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.stderr b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.stderr deleted file mode 100644 index 2b8be290d3adb..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block - --> $DIR/ranged_ints_const.rs:8:34 - | -LL | const fn foo() -> NonZero { NonZero(0) } - | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr - | - = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_macro.rs b/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_macro.rs deleted file mode 100644 index 44a12bbd0a6bd..0000000000000 --- a/tests/ui/unsafe/rustc_layout_scalar_valid_range/ranged_ints_macro.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ build-pass - -#![feature(rustc_attrs)] - -macro_rules! apply { - ($val:expr) => { - #[rustc_layout_scalar_valid_range_start($val)] - #[repr(transparent)] - pub(crate) struct NonZero(pub(crate) T); - } -} - -apply!(1); - -fn main() { - let _x = unsafe { NonZero(1) }; -} diff --git a/tests/ui/unsafe/unsafe-assign.rs b/tests/ui/unsafe/unsafe-assign.rs deleted file mode 100644 index 02ce238854d87..0000000000000 --- a/tests/ui/unsafe/unsafe-assign.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![feature(rustc_attrs)] -#![allow(unused,dead_code)] - -fn nested_field() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let mut foo = unsafe { NonZero((1,)) }; - foo.0.0 = 0; - //~^ ERROR: mutation of layout constrained field is unsafe -} - -fn block() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let mut foo = unsafe { NonZero((1,)) }; - { foo.0 }.0 = 0; - // ^ not unsafe because the result of the block expression is a new place -} - -fn main() {} diff --git a/tests/ui/unsafe/unsafe-assign.stderr b/tests/ui/unsafe/unsafe-assign.stderr deleted file mode 100644 index 1fa5d715c2e1a..0000000000000 --- a/tests/ui/unsafe/unsafe-assign.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/unsafe-assign.rs:9:5 - | -LL | foo.0.0 = 0; - | ^^^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/unsafe-borrow.rs b/tests/ui/unsafe/unsafe-borrow.rs deleted file mode 100644 index ab0e59489a96a..0000000000000 --- a/tests/ui/unsafe/unsafe-borrow.rs +++ /dev/null @@ -1,53 +0,0 @@ -#![feature(rustc_attrs)] -#![allow(unused,dead_code)] - -fn tuple_struct() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let mut foo = unsafe { NonZero((1,)) }; - let a = &mut foo.0.0; - //~^ ERROR: mutation of layout constrained field is unsafe -} - -fn slice() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero<'a, T>(&'a mut [T]); - - let mut nums = [1, 2, 3, 4]; - let mut foo = unsafe { NonZero(&mut nums[..]) }; - let a = &mut foo.0[2]; - // ^ not unsafe because there is an implicit dereference here -} - -fn array() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero([T; 4]); - - let nums = [1, 2, 3, 4]; - let mut foo = unsafe { NonZero(nums) }; - let a = &mut foo.0[2]; - //~^ ERROR: mutation of layout constrained field is unsafe -} - -fn block() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let foo = unsafe { NonZero((1,)) }; - &mut { foo.0 }.0; - // ^ not unsafe because the result of the block expression is a new place -} - -fn mtch() { - #[rustc_layout_scalar_valid_range_start(1)] - struct NonZero(T); - - let mut foo = unsafe { NonZero((1,)) }; - match &mut foo { - NonZero((a,)) => *a = 0, - //~^ ERROR: mutation of layout constrained field is unsafe - } -} - -fn main() {} diff --git a/tests/ui/unsafe/unsafe-borrow.stderr b/tests/ui/unsafe/unsafe-borrow.stderr deleted file mode 100644 index a53b50583ca40..0000000000000 --- a/tests/ui/unsafe/unsafe-borrow.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/unsafe-borrow.rs:9:13 - | -LL | let a = &mut foo.0.0; - | ^^^^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/unsafe-borrow.rs:29:13 - | -LL | let a = &mut foo.0[2]; - | ^^^^^^^^^^^^^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block - --> $DIR/unsafe-borrow.rs:48:18 - | -LL | NonZero((a,)) => *a = 0, - | ^ mutation of layout constrained field - | - = note: mutating layout constrained fields cannot statically be checked for valid values - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0133`.