diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 7b4e838a1a7fb..b6e63de1a2095 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -37,6 +37,16 @@ impl CombineAttributeParser for ReprParser { }; if list.is_empty() { + cx.check_target( + "()", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); + let attr_span = cx.attr_span; cx.adcx().warn_empty_attribute(attr_span); return vec![]; @@ -53,17 +63,19 @@ impl CombineAttributeParser for ReprParser { reprs } - //FIXME Still checked fully in `check_attr.rs` - //This one is slightly more complicated because the allowed targets depend on the arguments - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::ManuallyChecked; const STABILITY: AttributeStability = AttributeStability::Stable; } fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option { use ReprAttr::*; - macro_rules! no_args { - ($constructor: expr) => {{ + macro_rules! repr_int { + ($arg: ident, $constructor: expr) => {{ + cx.check_target( + concat!("(", stringify!($arg), ")"), + &AllowedTargets::AllowList(&[Allow(Target::Enum), Warn(Target::MacroCall)]), + ); cx.expect_no_args(param.args())?; Some($constructor) }}; @@ -71,33 +83,100 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option< match param.path().word_sym() { Some(sym::align) => { + cx.check_target( + "(align(...))", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); let l = cx.expect_list(param.args(), param.span())?; parse_repr_align(cx, l, AlignKind::Align) } - Some(sym::packed) => match param.args() { - ArgParser::NoArgs => Some(ReprPacked(Align::ONE)), - ArgParser::List(l) => parse_repr_align(cx, l, AlignKind::Packed), - ArgParser::NameValue(_) => { - cx.adcx().expected_list_or_no_args(param.span()); - None + Some(sym::packed) => { + cx.check_target( + "(packed)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); + match param.args() { + ArgParser::NoArgs => Some(ReprPacked(Align::ONE)), + ArgParser::List(l) => parse_repr_align(cx, l, AlignKind::Packed), + ArgParser::NameValue(_) => { + cx.adcx().expected_list_or_no_args(param.span()); + None + } } - }, - Some(sym::Rust) => no_args!(ReprRust), - Some(sym::C) => no_args!(ReprC), - Some(sym::simd) => no_args!(ReprSimd), - Some(sym::transparent) => no_args!(ReprTransparent), - Some(sym::i8) => no_args!(ReprInt(SignedInt(IntTy::I8))), - Some(sym::u8) => no_args!(ReprInt(UnsignedInt(UintTy::U8))), - Some(sym::i16) => no_args!(ReprInt(SignedInt(IntTy::I16))), - Some(sym::u16) => no_args!(ReprInt(UnsignedInt(UintTy::U16))), - Some(sym::i32) => no_args!(ReprInt(SignedInt(IntTy::I32))), - Some(sym::u32) => no_args!(ReprInt(UnsignedInt(UintTy::U32))), - Some(sym::i64) => no_args!(ReprInt(SignedInt(IntTy::I64))), - Some(sym::u64) => no_args!(ReprInt(UnsignedInt(UintTy::U64))), - Some(sym::i128) => no_args!(ReprInt(SignedInt(IntTy::I128))), - Some(sym::u128) => no_args!(ReprInt(UnsignedInt(UintTy::U128))), - Some(sym::isize) => no_args!(ReprInt(SignedInt(IntTy::Isize))), - Some(sym::usize) => no_args!(ReprInt(UnsignedInt(UintTy::Usize))), + } + + Some(sym::Rust) => { + cx.check_target( + "(Rust)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); + cx.expect_no_args(param.args())?; + Some(ReprRust) + } + Some(sym::C) => { + cx.check_target( + "(C)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), + Warn(Target::MacroCall), + ]), + ); + cx.expect_no_args(param.args())?; + Some(ReprC) + } + Some(sym::simd) => { + cx.check_target( + "(simd)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), // Feature gated in `rustc_ast_passes` + Warn(Target::MacroCall), // FIXME: This is not feature gated (!!) + ]), + ); + cx.expect_no_args(param.args())?; + Some(ReprSimd) + } + Some(sym::transparent) => { + cx.check_target( + "(transparent)", + &AllowedTargets::AllowList(&[ + Allow(Target::Struct), + Allow(Target::Enum), + Allow(Target::Union), // Feature gated in `rustc_hir_analysis` + Warn(Target::MacroCall), + ]), + ); + cx.expect_no_args(param.args())?; + Some(ReprTransparent) + } + + Some(sym::i8) => repr_int!(i8, ReprInt(SignedInt(IntTy::I8))), + Some(sym::u8) => repr_int!(u8, ReprInt(UnsignedInt(UintTy::U8))), + Some(sym::i16) => repr_int!(i16, ReprInt(SignedInt(IntTy::I16))), + Some(sym::u16) => repr_int!(u16, ReprInt(UnsignedInt(UintTy::U16))), + Some(sym::i32) => repr_int!(i32, ReprInt(SignedInt(IntTy::I32))), + Some(sym::u32) => repr_int!(u32, ReprInt(UnsignedInt(UintTy::U32))), + Some(sym::i64) => repr_int!(i64, ReprInt(SignedInt(IntTy::I64))), + Some(sym::u64) => repr_int!(u64, ReprInt(UnsignedInt(UintTy::U64))), + Some(sym::i128) => repr_int!(i128, ReprInt(SignedInt(IntTy::I128))), + Some(sym::u128) => repr_int!(u128, ReprInt(UnsignedInt(UintTy::U128))), + Some(sym::isize) => repr_int!(isize, ReprInt(SignedInt(IntTy::Isize))), + Some(sym::usize) => repr_int!(usize, ReprInt(UnsignedInt(UintTy::Usize))), _ => { cx.adcx().expected_specific_argument( param.span(), diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 61d7f5dc5687a..8d56717be48aa 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -366,6 +366,10 @@ pub struct AcceptContext<'f, 'sess> { /// The name of the attribute we're currently accepting. pub(crate) attr_path: AttrPath, + + /// Used for `AllowedTargets::ManuallyChecked`, to assert that the manual target check has been done + #[cfg(debug_assertions)] + pub(crate) has_target_been_checked: bool, } impl<'f, 'sess: 'f> SharedContext<'f, 'sess> { diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 86bf89dcb9585..6e63bf2d78fdc 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -240,6 +240,8 @@ impl<'sess> AttributeParser<'sess> { template, attr_safety: attr_safety.unwrap_or(Safety::Default), attr_path, + #[cfg(debug_assertions)] + has_target_been_checked: false, }; parse_fn(&mut cx, args) } @@ -410,12 +412,14 @@ impl<'sess> AttributeParser<'sess> { template: &accept.template, attr_safety: n.item.unsafety, attr_path: attr_path.clone(), + #[cfg(debug_assertions)] + has_target_been_checked: false, }; (accept.accept_fn)(&mut cx, &args); finalizers.push(accept.finalizer); - Self::check_target(&accept.allowed_targets, &mut cx); + Self::check_target(&accept.allowed_targets, "", &mut cx); #[cfg(debug_assertions)] if !cx.shared.has_lint_been_emitted.load(Ordering::Relaxed) { cx.shared.cx.check_args_used(&attr, &args) diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 2c28b5b2d8a5a..1d4d8d8123633 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -331,8 +331,8 @@ pub(crate) struct EmptyConfusables { } #[derive(Diagnostic)] -#[help("`#[{$name}]` can {$only}be applied to {$applied}")] -#[diag("`#[{$name}]` attribute cannot be used on {$target}")] +#[help("`#[{$name}{$attribute_args}]` can {$only}be applied to {$applied}")] +#[diag("`#[{$name}{$attribute_args}]` attribute cannot be used on {$target}")] pub(crate) struct InvalidTarget { #[primary_span] #[suggestion( @@ -346,12 +346,23 @@ pub(crate) struct InvalidTarget { pub target: &'static str, pub applied: DiagArgValue, pub only: &'static str, + pub attribute_args: &'static str, + #[subdiagnostic] + pub help: Option, #[warning( "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" )] pub previously_accepted: bool, } +#[derive(Subdiagnostic)] +pub(crate) enum InvalidTargetHelp { + #[help("use `#[rustc_align(...)]` instead")] + UseRustcAlign, + #[help("use `#[rustc_align_static(...)]` instead")] + UseRustcAlignStatic, +} + #[derive(Diagnostic)] #[diag("invalid alignment value: {$error_part}", code = E0589)] pub(crate) struct InvalidAlignmentValue { diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 806c795f4e197..bd592b68dc79e 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -11,7 +11,7 @@ use crate::context::AcceptContext; use crate::errors::{ InvalidAttrAtCrateLevel, ItemFollowingInnerAttr, UnsupportedAttributesInWhere, }; -use crate::session_diagnostics::InvalidTarget; +use crate::session_diagnostics::{InvalidTarget, InvalidTargetHelp}; use crate::target_checking::Policy::Allow; use crate::{AttributeParser, ShouldEmit}; @@ -19,6 +19,10 @@ use crate::{AttributeParser, ShouldEmit}; pub(crate) enum AllowedTargets { AllowList(&'static [Policy]), AllowListWarnRest(&'static [Policy]), + /// This is useful for argument-dependent target checking. + /// If debug assertions are enabled, + /// this emits a delayed bug if the `cx.check_target(...)` method is not called during attribute parsing. + ManuallyChecked, } pub(crate) enum AllowedResult { @@ -52,6 +56,7 @@ impl AllowedTargets { AllowedResult::Warn } } + AllowedTargets::ManuallyChecked => unreachable!(), } } @@ -59,6 +64,7 @@ impl AllowedTargets { match self { AllowedTargets::AllowList(list) => list, AllowedTargets::AllowListWarnRest(list) => list, + AllowedTargets::ManuallyChecked => unreachable!(), } .iter() .filter_map(|target| match target { @@ -89,12 +95,22 @@ pub(crate) enum Policy { impl<'sess> AttributeParser<'sess> { pub(crate) fn check_target( allowed_targets: &AllowedTargets, + attribute_args: &'static str, cx: &mut AcceptContext<'_, 'sess>, ) { if matches!(cx.should_emit, ShouldEmit::Nothing) { return; } + if let AllowedTargets::ManuallyChecked = allowed_targets { + #[cfg(debug_assertions)] + if !cx.has_target_been_checked { + cx.dcx().delayed_bug("Attribute target has not been checked"); + } + + return; + } + // For crate-level attributes we emit a specific set of lints to warn // people about accidentally not using them on the crate. if let &AllowedTargets::AllowList(&[Allow(Target::Crate)]) = allowed_targets { @@ -102,25 +118,6 @@ impl<'sess> AttributeParser<'sess> { return; } - if matches!(cx.attr_path.segments.as_ref(), [sym::repr]) && cx.target == Target::Crate { - // The allowed targets of `repr` depend on its arguments. They can't be checked using - // the `AttributeParser` code. - let span = cx.attr_span; - let item = - cx.cx.first_line_of_next_item(span).map(|span| ItemFollowingInnerAttr { span }); - - let pound_to_opening_bracket = cx.attr_span.until(cx.inner_span); - - cx.dcx() - .create_err(InvalidAttrAtCrateLevel { - span, - pound_to_opening_bracket, - name: sym::repr, - item, - }) - .emit(); - } - let result = allowed_targets.is_allowed(cx.target); if matches!(result, AllowedResult::Allowed) { return; @@ -134,6 +131,8 @@ impl<'sess> AttributeParser<'sess> { target: cx.target.plural_name(), only: if only { "only " } else { "" }, applied: DiagArgValue::StrListSepByAnd(applied.into_iter().map(Cow::Owned).collect()), + attribute_args, + help: Self::target_checking_help(attribute_args, cx), previously_accepted: matches!(result, AllowedResult::Warn), }; @@ -164,6 +163,24 @@ impl<'sess> AttributeParser<'sess> { } } + fn target_checking_help( + attribute_args: &'static str, + cx: &AcceptContext<'_, '_>, + ) -> Option { + match &*cx.attr_path.segments { + [sym::repr] if attribute_args == "(align(...))" => match cx.target { + Target::Fn | Target::Method(..) if cx.features().fn_align() => { + Some(InvalidTargetHelp::UseRustcAlign) + } + Target::Static if cx.features().static_align() => { + Some(InvalidTargetHelp::UseRustcAlignStatic) + } + _ => None, + }, + _ => None, + } + } + pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>) { if cx.target == Target::Crate { return; @@ -399,6 +416,20 @@ fn filter_targets( added_fake_targets.push(target_group_name); } +impl<'f, 'sess> AcceptContext<'f, 'sess> { + pub(crate) fn check_target( + &mut self, + attribute_args: &'static str, + allowed_targets: &AllowedTargets, + ) { + #[cfg(debug_assertions)] + { + self.has_target_been_checked = true; + } + AttributeParser::check_target(allowed_targets, attribute_args, self); + } +} + /// This is the list of all targets to which a attribute can be applied /// This is used for: /// - `rustc_dummy`, which can be applied to all targets diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index 6a0d70790cfef..626b7e1084192 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -5,6 +5,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_index::Idx; use rustc_index::bit_set::SparseBitMatrix; use rustc_index::interval::{IntervalSet, SparseIntervalMatrix}; +use rustc_middle::bug; use rustc_middle::mir::{BasicBlock, Location}; use rustc_middle::ty::{self, RegionVid}; use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex}; @@ -35,6 +36,17 @@ pub(crate) enum RegionElement<'tcx> { PlaceholderRegion(ty::PlaceholderRegion<'tcx>), } +/// Either a mapping of which points a region is live at (for regular bodies), +/// or which regions are live in the body somewhere (for promoteds, which do +/// not care about where they are live, only that they are). +#[derive(Clone)] // FIXME(#146079) +enum LiveRegions { + /// region `'r` is live at locations `L`. + AtPoints(SparseIntervalMatrix), + /// Region `'r` is live in function body. + InBody(FxHashSet), +} + /// Records the CFG locations where each region is live. When we initially compute liveness, we use /// an interval matrix storing liveness ranges for each region-vid. #[derive(Clone)] // FIXME(#146079) @@ -42,15 +54,8 @@ pub(crate) struct LivenessValues { /// The map from locations to points. location_map: Rc, - /// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and - /// currently only used for validating promoteds (which don't care about more precise tracking). - live_regions: Option>, - - /// For each region: the points where it is live. - /// - /// This is not initialized for promoteds, because we don't care *where* within a promoted a - /// region is live, only that it is. - points: Option>, + /// Where a region is live. + live_regions: LiveRegions, /// When using `-Zpolonius=next`, the set of loans that are live at a given point in the CFG. live_loans: Option, @@ -60,8 +65,9 @@ impl LivenessValues { /// Create an empty map of regions to locations where they're live. pub(crate) fn with_specific_points(location_map: Rc) -> Self { LivenessValues { - live_regions: None, - points: Some(SparseIntervalMatrix::new(location_map.num_points())), + live_regions: LiveRegions::AtPoints(SparseIntervalMatrix::new( + location_map.num_points(), + )), location_map, live_loans: None, } @@ -73,8 +79,7 @@ impl LivenessValues { /// which regions are live. pub(crate) fn without_specific_points(location_map: Rc) -> Self { LivenessValues { - live_regions: Some(Default::default()), - points: None, + live_regions: LiveRegions::InBody(Default::default()), location_map, live_loans: None, } @@ -83,14 +88,16 @@ impl LivenessValues { /// Returns the liveness matrix of points where each region is live. Panics if the liveness /// values have been created without any per-point data (that is, for promoteds). pub(crate) fn points(&self) -> &SparseIntervalMatrix { - self.points - .as_ref() - .expect("this `LivenessValues` wasn't created using `with_specific_points`") + if let LiveRegions::AtPoints(points) = &self.live_regions { + points + } else { + bug!("this `LivenessValues` wasn't created using `with_specific_points`") + } } /// Iterate through each region that has a value in this set. pub(crate) fn regions(&self) -> impl Iterator { - self.points.as_ref().expect("use with_specific_points").rows() + self.points().rows() } /// Iterate through each region that has a value in this set. @@ -98,36 +105,53 @@ impl LivenessValues { #[rustc_lint_query_instability] #[allow(rustc::potential_query_instability)] pub(crate) fn live_regions_unordered(&self) -> impl Iterator { - self.live_regions.as_ref().unwrap().iter().copied() + if let LiveRegions::InBody(live_regions) = &self.live_regions { + live_regions.iter().copied() + } else { + bug!("this `LivenessValues` wasn't created using `without_specific_points`") + } } /// Records `region` as being live at the given `location`. pub(crate) fn add_location(&mut self, region: RegionVid, location: Location) { let point = self.location_map.point_from_location(location); debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location); - if let Some(points) = &mut self.points { - points.insert(region, point); - } else if self.location_map.point_in_range(point) { - self.live_regions.as_mut().unwrap().insert(region); - } + match &mut self.live_regions { + LiveRegions::AtPoints(points) => { + points.insert(region, point); + } + + LiveRegions::InBody(live_regions) if self.location_map.point_in_range(point) => { + live_regions.insert(region); + } + + LiveRegions::InBody(_) => (), + }; } /// Records `region` as being live at all the given `points`. pub(crate) fn add_points(&mut self, region: RegionVid, points: &IntervalSet) { debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points); - if let Some(this) = &mut self.points { - this.union_row(region, points); - } else if points.iter().any(|point| self.location_map.point_in_range(point)) { - self.live_regions.as_mut().unwrap().insert(region); - } + match &mut self.live_regions { + LiveRegions::AtPoints(these_points) => { + these_points.union_row(region, points); + } + LiveRegions::InBody(live_regions) + if points.iter().any(|point| self.location_map.point_in_range(point)) => + { + live_regions.insert(region); + } + LiveRegions::InBody(_) => (), + }; } /// Records `region` as being live at all the control-flow points. pub(crate) fn add_all_points(&mut self, region: RegionVid) { - if let Some(points) = &mut self.points { - points.insert_all_into_row(region); - } else { - self.live_regions.as_mut().unwrap().insert(region); + match &mut self.live_regions { + LiveRegions::AtPoints(points) => points.insert_all_into_row(region), + LiveRegions::InBody(live_regions) => { + live_regions.insert(region); + } } } @@ -142,23 +166,12 @@ impl LivenessValues { /// [`point`][rustc_mir_dataflow::points::PointIndex]. #[inline] pub(crate) fn is_live_at_point(&self, region: RegionVid, point: PointIndex) -> bool { - if let Some(points) = &self.points { - points.row(region).is_some_and(|r| r.contains(point)) - } else { - unreachable!( - "Should be using LivenessValues::with_specific_points to ask whether live at a location" - ) - } + self.points().row(region).is_some_and(|r| r.contains(point)) } /// Returns an iterator of all the points where `region` is live. fn live_points(&self, region: RegionVid) -> impl Iterator { - let Some(points) = &self.points else { - unreachable!( - "Should be using LivenessValues::with_specific_points to ask whether live at a location" - ) - }; - points + self.points() .row(region) .into_iter() .flat_map(|set| set.iter()) @@ -328,10 +341,7 @@ impl<'tcx, N: Idx> RegionValues<'tcx, N> { /// elements for the region `from` from `values` and add them to /// the region `to` in `self`. pub(crate) fn merge_liveness(&mut self, to: N, from: RegionVid, values: &LivenessValues) { - let Some(value_points) = &values.points else { - panic!("LivenessValues must track specific points for use in merge_liveness"); - }; - if let Some(set) = value_points.row(from) { + if let Some(set) = values.points().row(from) { self.points.union_row(to, set); } } diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 1dee2f34371e8..b4a97c0b137c9 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -844,14 +844,13 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { // current number of evaluated terminators is a power of 2. The latter gives us a cheap // way to implement exponential backoff. let span = ecx.cur_span(); + let mut warn = + ecx.tcx.dcx().create_warn(LongRunningWarn { span, item_span: ecx.tcx.span }); // We store a unique number in `force_duplicate` to evade `-Z deduplicate-diagnostics`. // `new_steps` is guaranteed to be unique because `ecx.machine.num_evaluated_steps` is // always increasing. - ecx.tcx.dcx().emit_warn(LongRunningWarn { - span, - item_span: ecx.tcx.span, - force_duplicate: new_steps, - }); + warn.arg("force_duplicate", new_steps); + warn.emit(); } } diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 311696a3acc99..9faf9a59fc22a 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -298,8 +298,6 @@ pub(crate) struct LongRunningWarn { pub span: Span, #[help("the constant being evaluated")] pub item_span: Span, - // Used for evading `-Z deduplicate-diagnostics`. - pub force_duplicate: usize, } #[derive(Subdiagnostic)] diff --git a/compiler/rustc_error_codes/src/error_codes/E0517.md b/compiler/rustc_error_codes/src/error_codes/E0517.md index 5354a08bf31a7..1655904722fbc 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0517.md +++ b/compiler/rustc_error_codes/src/error_codes/E0517.md @@ -1,8 +1,12 @@ +#### Note: this error code is no longer emitted by the compiler. +This error code was replaced with the +`attribute cannot be used on...` diagnostic that does not have an error code. + A `#[repr(..)]` attribute was placed on an unsupported item. Examples of erroneous code: -```compile_fail,E0517 +```compile_fail #[repr(C)] type Foo = u8; diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index d51a0bf2c3ef4..7d687099f9715 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -845,7 +845,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut path = None; let mut err = self.dcx().create_err(errors::InvalidCallee { span: callee_expr.span, - ty: callee_ty, found: match &unit_variant { Some((_, kind, path)) => format!("{kind} `{path}`"), None => format!("`{}`", self.tcx.short_string(callee_ty, &mut path)), @@ -949,7 +948,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } if let Some(span) = self.tcx.hir_res_span(def) { - let callee_ty = callee_ty.to_string(); let label = match (unit_variant, inner_callee_path) { (Some((_, kind, path)), _) => { err.arg("kind", kind); @@ -959,6 +957,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (_, Some(hir::QPath::Resolved(_, path))) => { self.tcx.sess.source_map().span_to_snippet(path.span).ok().map(|p| { err.arg("func", p); + err.arg("ty", callee_ty); msg!("`{$func}` defined here returns `{$ty}`") }) } @@ -968,6 +967,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // type definitions themselves, but rather variables *of* that type. Res::Local(hir_id) => { err.arg("local_name", self.tcx.hir_name(hir_id)); + err.arg("ty", callee_ty); Some(msg!("`{$local_name}` has type `{$ty}`")) } Res::Def(kind, def_id) if kind.ns() == Some(Namespace::ValueNS) => { @@ -975,7 +975,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(msg!("`{$path}` defined here")) } _ => { - err.arg("path", callee_ty); + err.arg("path", callee_ty.to_string()); Some(msg!("`{$path}` defined here")) } } diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index 3457cc373413a..a9a819935287c 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -476,10 +476,9 @@ pub(crate) struct SlicingSuggestion { #[derive(Diagnostic)] #[diag("expected function, found {$found}", code = E0618)] -pub(crate) struct InvalidCallee<'tcx> { +pub(crate) struct InvalidCallee { #[primary_span] pub span: Span, - pub ty: Ty<'tcx>, pub found: String, } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index c77e70dcbe9bb..227a413ea9b07 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1562,17 +1562,16 @@ pub(crate) enum NonCamelCaseTypeSub { pub(crate) struct NonSnakeCaseDiag<'a> { pub sort: &'a str, pub name: &'a str, - pub sc: String, #[subdiagnostic] pub sub: NonSnakeCaseDiagSub, } pub(crate) enum NonSnakeCaseDiagSub { Label { span: Span }, - Help, + Help { sc: String }, RenameOrConvertSuggestion { span: Span, suggestion: Ident }, ConvertSuggestion { span: Span, suggestion: String }, - SuggestionAndNote { span: Span }, + SuggestionAndNote { sc: String, span: Span }, } impl Subdiagnostic for NonSnakeCaseDiagSub { @@ -1581,7 +1580,8 @@ impl Subdiagnostic for NonSnakeCaseDiagSub { NonSnakeCaseDiagSub::Label { span } => { diag.span_label(span, msg!("should have a snake_case name")); } - NonSnakeCaseDiagSub::Help => { + NonSnakeCaseDiagSub::Help { sc } => { + diag.arg("sc", sc); diag.help(msg!("convert the identifier to snake case: `{$sc}`")); } NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => { @@ -1600,7 +1600,8 @@ impl Subdiagnostic for NonSnakeCaseDiagSub { Applicability::MaybeIncorrect, ); } - NonSnakeCaseDiagSub::SuggestionAndNote { span } => { + NonSnakeCaseDiagSub::SuggestionAndNote { sc, span } => { + diag.arg("sc", sc); diag.note(msg!("`{$sc}` cannot be used as a raw identifier")); diag.span_suggestion( span, diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index fbbfbd86d319f..e3653c55f53a4 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -311,18 +311,18 @@ impl NonSnakeCase { suggestion: sc_ident, } } else { - NonSnakeCaseDiagSub::SuggestionAndNote { span } + NonSnakeCaseDiagSub::SuggestionAndNote { sc, span } } } else { - NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion: sc.clone() } + NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion: sc } } } else { - NonSnakeCaseDiagSub::Help + NonSnakeCaseDiagSub::Help { sc } } } else { NonSnakeCaseDiagSub::Label { span } }; - cx.emit_span_lint(NON_SNAKE_CASE, span, NonSnakeCaseDiag { sort, name, sc, sub }); + cx.emit_span_lint(NON_SNAKE_CASE, span, NonSnakeCaseDiag { sort, name, sub }); } } } diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 6b19aa17c6d6c..f646a558266e2 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -232,6 +232,5 @@ struct OpaqueHiddenInferredBoundLint<'tcx> { struct AddBound<'tcx> { #[primary_span] suggest_span: Span, - #[skip_arg] trait_ref: TraitPredPrintModifiersAndPath<'tcx>, } diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index 2f7c3cc6a46d2..ac777b37a4303 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -26,7 +26,7 @@ impl<'a> DiagnosticDerive<'a> { let Some(message) = builder.primary_message() else { return DiagnosticDeriveError::ErrorHandled.to_compile_error(); }; - let message = message.diag_message(Some(variant)); + let message = message.diag_message(); let init = quote! { let mut diag = rustc_errors::Diag::new( diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index e335037f2c4c9..cdff1280d69f9 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -1,5 +1,7 @@ #![deny(unused_must_use)] +use std::collections::HashSet; + use proc_macro2::{Ident, Span, TokenStream}; use quote::{format_ident, quote, quote_spanned}; use syn::parse::ParseStream; @@ -52,6 +54,7 @@ where formatting_init: TokenStream::new(), message: None, code: None, + used_fields: HashSet::new(), }; f(builder, variant) }); @@ -83,6 +86,8 @@ pub(crate) struct DiagnosticDeriveVariantBuilder { /// Error codes are a optional part of the struct attribute - this is only set to detect /// multiple specifications. pub code: SpannedOption<()>, + + pub used_fields: HashSet, } impl DiagnosticDeriveVariantBuilder { @@ -107,8 +112,7 @@ impl DiagnosticDeriveVariantBuilder { let ast = variant.ast(); let attrs = &ast.attrs; let preamble = attrs.iter().map(|attr| { - self.generate_structure_code_for_attr(attr, variant) - .unwrap_or_else(|v| v.to_compile_error()) + self.generate_structure_code_for_attr(attr).unwrap_or_else(|v| v.to_compile_error()) }); quote! { @@ -120,23 +124,34 @@ impl DiagnosticDeriveVariantBuilder { /// calls to `arg` when no attributes are present. pub(crate) fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream { let mut body = quote! {}; + let mut second_part = quote! {}; + + // Subdiagnostic additions. + for binding in variant.bindings().iter().filter(|bi| !should_generate_arg(bi.ast())) { + second_part.extend(self.generate_field_attrs_code(binding)); + } // Generate `arg` calls first.. for binding in variant.bindings().iter().filter(|bi| should_generate_arg(bi.ast())) { - body.extend(self.generate_field_code(binding)); - } - // ..and then subdiagnostic additions. - for binding in variant.bindings().iter().filter(|bi| !should_generate_arg(bi.ast())) { - body.extend(self.generate_field_attrs_code(binding, variant)); + if self.is_used_in_message(binding) { + body.extend(self.generate_field_code(binding)); + } } + body.extend(second_part); body } + fn is_used_in_message(&self, binding: &BindingInfo<'_>) -> bool { + binding.ast().ident.as_ref().is_some_and(|ident| self.used_fields.contains(ident)) + } + /// Parse a `SubdiagnosticKind` from an `Attribute`. fn parse_subdiag_attribute( - &self, + &mut self, attr: &Attribute, ) -> Result, DiagnosticDeriveError> { - let Some(subdiag) = SubdiagnosticVariant::from_attr(attr, &self.field_map)? else { + let Some(subdiag) = + SubdiagnosticVariant::from_attr(attr, &self.field_map, &mut self.used_fields)? + else { // Some attributes aren't errors - like documentation comments - but also aren't // subdiagnostics. return Ok(None); @@ -160,7 +175,6 @@ impl DiagnosticDeriveVariantBuilder { fn generate_structure_code_for_attr( &mut self, attr: &Attribute, - variant: &VariantInfo<'_>, ) -> Result { // Always allow documentation comments. if is_doc_comment(attr) { @@ -183,11 +197,14 @@ impl DiagnosticDeriveVariantBuilder { ) .emit(); } - self.message = Some(Message { - attr_span: attr.span(), - message_span: message.span(), - value: message.value(), - }); + let message = Message::new( + attr.span(), + message.span(), + message.value(), + &self.field_map, + &mut self.used_fields, + ); + self.message = Some(message); } // Parse arguments @@ -240,7 +257,7 @@ impl DiagnosticDeriveVariantBuilder { | SubdiagnosticKind::NoteOnce | SubdiagnosticKind::Help | SubdiagnosticKind::HelpOnce - | SubdiagnosticKind::Warn => Ok(self.add_subdiagnostic(&fn_ident, message, variant)), + | SubdiagnosticKind::Warn => Ok(self.add_subdiagnostic(&fn_ident, message)), SubdiagnosticKind::Label | SubdiagnosticKind::Suggestion { .. } => { throw_invalid_attr!(attr, |diag| diag .help("`#[label]` and `#[suggestion]` can only be applied to fields")); @@ -268,11 +285,7 @@ impl DiagnosticDeriveVariantBuilder { } } - fn generate_field_attrs_code( - &mut self, - binding_info: &BindingInfo<'_>, - variant: &VariantInfo<'_>, - ) -> TokenStream { + fn generate_field_attrs_code(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream { let field = binding_info.ast(); let field_binding = &binding_info.binding; @@ -311,7 +324,6 @@ impl DiagnosticDeriveVariantBuilder { attr, FieldInfo { binding: binding_info, ty: inner_ty, span: &field.span() }, binding, - variant ) .unwrap_or_else(|v| v.to_compile_error()); @@ -329,14 +341,10 @@ impl DiagnosticDeriveVariantBuilder { attr: &Attribute, info: FieldInfo<'_>, binding: TokenStream, - variant: &VariantInfo<'_>, ) -> Result { let ident = &attr.path().segments.last().unwrap().ident; let name = ident.to_string(); match (&attr.meta, name.as_str()) { - // Don't need to do anything - by virtue of the attribute existing, the - // `arg` call will not be generated. - (Meta::Path(_), "skip_arg") => return Ok(quote! {}), (Meta::Path(_), "primary_span") => { report_error_if_not_applied_to_span(attr, &info)?; @@ -359,7 +367,7 @@ impl DiagnosticDeriveVariantBuilder { match subdiag { SubdiagnosticKind::Label => { report_error_if_not_applied_to_span(attr, &info)?; - Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, message, variant)) + Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, message)) } SubdiagnosticKind::Note | SubdiagnosticKind::NoteOnce @@ -370,11 +378,11 @@ impl DiagnosticDeriveVariantBuilder { if type_matches_path(inner, &["rustc_span", "Span"]) || type_matches_path(inner, &["rustc_span", "MultiSpan"]) { - Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, message, variant)) + Ok(self.add_spanned_subdiagnostic(binding, &fn_ident, message)) } else if type_is_unit(inner) || (matches!(info.ty, FieldInnerTy::Plain(_)) && type_is_bool(inner)) { - Ok(self.add_subdiagnostic(&fn_ident, message, variant)) + Ok(self.add_subdiagnostic(&fn_ident, message)) } else { report_type_error(attr, "`Span`, `MultiSpan`, `bool` or `()`")? } @@ -400,7 +408,7 @@ impl DiagnosticDeriveVariantBuilder { applicability.set_once(quote! { #static_applicability }, span); } - let message = message.diag_message(Some(variant)); + let message = message.diag_message(); let applicability = applicability .value() .unwrap_or_else(|| quote! { rustc_errors::Applicability::Unspecified }); @@ -428,10 +436,9 @@ impl DiagnosticDeriveVariantBuilder { field_binding: TokenStream, kind: &Ident, message: Message, - variant: &VariantInfo<'_>, ) -> TokenStream { let fn_name = format_ident!("span_{}", kind); - let message = message.diag_message(Some(variant)); + let message = message.diag_message(); quote! { diag.#fn_name( #field_binding, @@ -442,13 +449,8 @@ impl DiagnosticDeriveVariantBuilder { /// Adds a subdiagnostic by generating a `diag.span_$kind` call with the current message /// and `fluent_attr_identifier`. - fn add_subdiagnostic( - &self, - kind: &Ident, - message: Message, - variant: &VariantInfo<'_>, - ) -> TokenStream { - let message = message.diag_message(Some(variant)); + fn add_subdiagnostic(&self, kind: &Ident, message: Message) -> TokenStream { + let message = message.diag_message(); quote! { diag.#kind(#message); } diff --git a/compiler/rustc_macros/src/diagnostics/message.rs b/compiler/rustc_macros/src/diagnostics/message.rs index 11bf904c18e1b..094736e94870b 100644 --- a/compiler/rustc_macros/src/diagnostics/message.rs +++ b/compiler/rustc_macros/src/diagnostics/message.rs @@ -1,11 +1,13 @@ +use std::collections::{HashMap, HashSet}; + use fluent_bundle::FluentResource; use fluent_syntax::ast::{Expression, InlineExpression, Pattern, PatternElement}; use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::ext::IdentExt; -use synstructure::VariantInfo; use crate::diagnostics::error::span_err; +use crate::diagnostics::utils::FieldMap; #[derive(Clone)] pub(crate) struct Message { @@ -15,53 +17,69 @@ pub(crate) struct Message { } impl Message { + // About `allow(rustc::potential_query_instability)`: The order of key/values of `fields` and + // `field_map` doesn't matters. + #[allow(rustc::potential_query_instability)] + pub(crate) fn new( + attr_span: Span, + message_span: Span, + message_str: String, + field_map: &FieldMap, + used_fields: &mut HashSet, + ) -> Self { + // Parse the fluent message + const GENERATED_MSG_ID: &str = "generated_msg"; + let resource = + FluentResource::try_new(format!("{GENERATED_MSG_ID} = {message_str}\n")).unwrap(); + assert_eq!(resource.entries().count(), 1); + let Some(fluent_syntax::ast::Entry::Message(flt_message)) = resource.get_entry(0) else { + panic!("Did not parse into a message") + }; + + let mut fields: HashMap = + HashMap::with_capacity(field_map.len()); + for (_, (ident, _)) in field_map { + fields.insert(ident.unraw().to_string(), (ident, false)); + } + for variable in variable_references(&flt_message) { + match fields.get_mut(variable) { + Some((_, seen)) => *seen = true, + None => { + span_err( + message_span.unwrap(), + format!("Variable `{variable}` not found in diagnostic "), + ) + .help(format!( + "Available fields: {:?}", + fields.keys().map(|s| s.as_str()).collect::>().join(", ") + )) + .emit(); + } + } + } + for (name, seen) in fields.values() { + if *seen { + used_fields.insert((*name).clone()); + } + } + Self { attr_span, message_span, value: message_str } + } + /// Get the diagnostic message for this diagnostic /// The passed `variant` is used to check whether all variables in the message are used. /// For subdiagnostics, we cannot check this. - pub(crate) fn diag_message(&self, variant: Option<&VariantInfo<'_>>) -> TokenStream { + pub(crate) fn diag_message(&self) -> TokenStream { let message = &self.value; - self.verify(variant); + self.verify(); quote! { rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed(#message)) } } - fn verify(&self, variant: Option<&VariantInfo<'_>>) { - verify_variables_used(self.message_span, &self.value, variant); + fn verify(&self) { verify_message_style(self.message_span, &self.value); verify_message_formatting(self.attr_span, self.message_span, &self.value); } } -fn verify_variables_used(msg_span: Span, message_str: &str, variant: Option<&VariantInfo<'_>>) { - // Parse the fluent message - const GENERATED_MSG_ID: &str = "generated_msg"; - let resource = - FluentResource::try_new(format!("{GENERATED_MSG_ID} = {message_str}\n")).unwrap(); - assert_eq!(resource.entries().count(), 1); - let Some(fluent_syntax::ast::Entry::Message(message)) = resource.get_entry(0) else { - panic!("Did not parse into a message") - }; - - // Check if all variables are used - if let Some(variant) = variant { - let fields: Vec = variant - .bindings() - .iter() - .flat_map(|b| b.ast().ident.as_ref()) - .map(|id| id.unraw().to_string()) - .collect(); - for variable in variable_references(&message) { - if !fields.iter().any(|f| f == variable) { - span_err( - msg_span.unwrap(), - format!("Variable `{variable}` not found in diagnostic "), - ) - .help(format!("Available fields: {:?}", fields.join(", "))) - .emit(); - } - } - } -} - fn variable_references<'a>(msg: &fluent_syntax::ast::Message<&'a str>) -> Vec<&'a str> { let mut refs = vec![]; diff --git a/compiler/rustc_macros/src/diagnostics/msg_macro.rs b/compiler/rustc_macros/src/diagnostics/msg_macro.rs index 66bc200707efa..831a94432c29a 100644 --- a/compiler/rustc_macros/src/diagnostics/msg_macro.rs +++ b/compiler/rustc_macros/src/diagnostics/msg_macro.rs @@ -6,5 +6,5 @@ pub(crate) fn msg_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStre let inline = parse_macro_input!(input as LitStr); let message = Message { attr_span: inline.span(), message_span: inline.span(), value: inline.value() }; - message.diag_message(None).into() + message.diag_message().into() } diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index 3e094ee8d42b6..f9ef016a16af6 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -1,5 +1,7 @@ #![deny(unused_must_use)] +use std::collections::HashSet; + use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote}; use syn::parse::ParseStream; @@ -61,6 +63,8 @@ impl SubdiagnosticDerive { } } + let mut used_fields: HashSet = HashSet::new(); + structure.bind_with(|_| synstructure::BindStyle::Move); let variants_ = structure.each_variant(|variant| { let mut builder = SubdiagnosticDeriveVariantBuilder { @@ -74,6 +78,7 @@ impl SubdiagnosticDerive { has_suggestion_parts: false, has_subdiagnostic: false, is_enum, + used_fields: &mut used_fields, }; builder.into_tokens().unwrap_or_else(|v| v.to_compile_error()) }); @@ -142,6 +147,8 @@ struct SubdiagnosticDeriveVariantBuilder<'parent, 'a> { /// Set to true when this variant is an enum variant rather than just the body of a struct. is_enum: bool, + + used_fields: &'parent mut HashSet, } /// Provides frequently-needed information about the diagnostic kinds being derived for this type. @@ -190,7 +197,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { for attr in self.variant.ast().attrs { let Some(SubdiagnosticVariant { kind, message }) = - SubdiagnosticVariant::from_attr(attr, &self.fields)? + SubdiagnosticVariant::from_attr(attr, &self.fields, &mut self.used_fields)? else { // Some attributes aren't errors - like documentation comments - but also aren't // subdiagnostics. @@ -301,7 +308,6 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { let name = name.as_str(); match name { - "skip_arg" => Ok(quote! {}), "primary_span" => { if kind_stats.has_multipart_suggestion { invalid_attr(attr) @@ -391,7 +397,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { invalid_attr(attr) .help(format!( - "only `{}`, `applicability` and `skip_arg` are valid field attributes", + "only `{}`, `applicability` is a valid field attribute", span_attrs.join(", ") )) .emit(); @@ -490,13 +496,17 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { span_attrs.push("primary_span") } diag.help(format!( - "only `{}`, `applicability` and `skip_arg` are valid field attributes", + "only `{}`, `applicability` is a valid field attribute", span_attrs.join(", ") )) }), } } + fn is_used_in_message(&self, binding: &BindingInfo<'_>) -> bool { + binding.ast().ident.as_ref().is_some_and(|ident| self.used_fields.contains(ident)) + } + pub(crate) fn into_tokens(&mut self) -> Result { let kind_messages = self.identify_kind()?; @@ -533,8 +543,13 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { .variant .bindings() .iter() - .filter(|binding| should_generate_arg(binding.ast())) - .map(|binding| self.generate_field_arg(binding)) + .filter_map(|binding| { + if should_generate_arg(binding.ast()) && self.is_used_in_message(binding) { + Some(self.generate_field_arg(binding)) + } else { + None + } + }) .collect(); let plain_args = quote! { let mut sub_args = rustc_errors::DiagArgMap::default(); @@ -546,7 +561,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { let mut calls = TokenStream::new(); for (kind, messages) in kind_messages { let message = format_ident!("__message"); - let message_stream = messages.diag_message(Some(self.variant)); + let message_stream = messages.diag_message(); calls.extend(quote! { let #message = rustc_errors::format_diag_message(&#message_stream, &sub_args); }); let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind); diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs index 55a8445744cba..b65e39469ec51 100644 --- a/compiler/rustc_macros/src/diagnostics/utils.rs +++ b/compiler/rustc_macros/src/diagnostics/utils.rs @@ -1,5 +1,5 @@ use std::cell::RefCell; -use std::collections::{BTreeSet, HashMap}; +use std::collections::{BTreeSet, HashMap, HashSet}; use std::fmt; use std::str::FromStr; @@ -260,7 +260,7 @@ impl SetOnce for SpannedOption { } } -pub(super) type FieldMap = HashMap; +pub(super) type FieldMap = HashMap; /// In the strings in the attributes supplied to this macro, we want callers to be able to /// reference fields in the format string. For example: @@ -344,7 +344,7 @@ pub(super) fn build_format( let args = referenced_fields.into_iter().map(|field: String| { let field_ident = format_ident!("{}", field); let value = match field_map.get(&field) { - Some(value) => value.clone(), + Some(value) => value.1.clone(), // This field doesn't exist. Emit a diagnostic. None => { span_err(span.unwrap(), format!("`{field}` doesn't refer to a field on this type")) @@ -408,11 +408,11 @@ impl quote::ToTokens for Applicability { /// Build the mapping of field names to fields. This allows attributes to peek values from /// other fields. -pub(super) fn build_field_mapping(variant: &VariantInfo<'_>) -> HashMap { +pub(super) fn build_field_mapping(variant: &VariantInfo<'_>) -> FieldMap { let mut fields_map = FieldMap::new(); for binding in variant.bindings() { if let Some(ident) = &binding.ast().ident { - fields_map.insert(ident.to_string(), quote! { #binding }); + fields_map.insert(ident.to_string(), (ident.clone(), quote! { #binding })); } } fields_map @@ -598,6 +598,7 @@ impl SubdiagnosticVariant { pub(super) fn from_attr( attr: &Attribute, fields: &FieldMap, + used_fields: &mut HashSet, ) -> Result, DiagnosticDeriveError> { // Always allow documentation comments. if is_doc_comment(attr) { @@ -708,7 +709,13 @@ impl SubdiagnosticVariant { } if !input.is_empty() { input.parse::()?; } if is_first { - message = Some(Message { attr_span: attr.span(), message_span: inline_message.span(), value: inline_message.value() }); + message = Some(Message::new( + attr.span(), + inline_message.span(), + inline_message.value(), + fields, + used_fields, + )); is_first = false; } else { span_err(inline_message.span().unwrap(), "a diagnostic message must be the first argument to the attribute").emit(); diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 32a5d6a1c6cf2..8624e0524b04e 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -181,7 +181,6 @@ decl_derive!( note_once, warning, // field attributes - skip_arg, primary_span, label, subdiagnostic, @@ -208,7 +207,6 @@ decl_derive!( multipart_suggestion_short, multipart_suggestion_hidden, // field attributes - skip_arg, primary_span, suggestion_part, applicability)] => diagnostics::subdiagnostic_derive diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index c55275962e085..b4dac5b244f10 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -724,9 +724,25 @@ pub(crate) struct NonConstPath { pub(crate) span: Span, } +pub(crate) struct UnreachablePattern<'tcx> { + pub(crate) covered_by_many_n_more_count: Option, + pub(crate) inner: UnreachablePatternInner<'tcx>, +} + +impl<'a, 'tcx, G: EmissionGuarantee> Diagnostic<'a, G> for UnreachablePattern<'tcx> { + #[track_caller] + fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> { + let mut diag = self.inner.into_diag(dcx, level); + if let Some(covered_by_many_n_more_count) = self.covered_by_many_n_more_count { + diag.arg("covered_by_many_n_more_count", covered_by_many_n_more_count); + } + diag + } +} + #[derive(Diagnostic)] #[diag("unreachable pattern")] -pub(crate) struct UnreachablePattern<'tcx> { +pub(crate) struct UnreachablePatternInner<'tcx> { #[label("no value can reach this")] pub(crate) span: Option, #[label("matches no values because `{$matches_no_values_ty}` is uninhabited")] @@ -756,7 +772,6 @@ pub(crate) struct UnreachablePattern<'tcx> { pub(crate) covered_by_one: Option, #[note("multiple earlier patterns match some of the same values")] pub(crate) covered_by_many: Option, - pub(crate) covered_by_many_n_more_count: usize, #[suggestion("remove the match arm", code = "", applicability = "machine-applicable")] pub(crate) suggest_remove: Option, } diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index afd8447b17ede..b4c340cfee2c0 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -953,7 +953,7 @@ fn report_unreachable_pattern<'p, 'tcx>( ) { static CAP_COVERED_BY_MANY: usize = 4; let pat_span = pat.data().span; - let mut lint = UnreachablePattern { + let mut lint = UnreachablePatternInner { span: Some(pat_span), matches_no_values: None, matches_no_values_ty: **pat.ty(), @@ -961,13 +961,13 @@ fn report_unreachable_pattern<'p, 'tcx>( covered_by_catchall: None, covered_by_one: None, covered_by_many: None, - covered_by_many_n_more_count: 0, wanted_constant: None, accessible_constant: None, inaccessible_constant: None, pattern_let_binding: None, suggest_remove: None, }; + let mut covered_by_many_n_more_count = None; match explanation.covered_by.as_slice() { [] => { // Empty pattern; we report the uninhabited type that caused the emptiness. @@ -1006,7 +1006,7 @@ fn report_unreachable_pattern<'p, 'tcx>( if remain == 0 { multispan.push_span_label(pat_span, msg!("collectively making this unreachable")); } else { - lint.covered_by_many_n_more_count = remain; + covered_by_many_n_more_count = Some(remain); multispan.push_span_label( pat_span, msg!("...and {$covered_by_many_n_more_count} other patterns collectively make this unreachable"), @@ -1015,7 +1015,12 @@ fn report_unreachable_pattern<'p, 'tcx>( lint.covered_by_many = Some(multispan); } } - cx.tcx.emit_node_span_lint(UNREACHABLE_PATTERNS, hir_id, pat_span, lint); + cx.tcx.emit_node_span_lint( + UNREACHABLE_PATTERNS, + hir_id, + pat_span, + UnreachablePattern { inner: lint, covered_by_many_n_more_count }, + ); } /// Detect typos that were meant to be a `const` but were interpreted as a new pattern binding. @@ -1023,7 +1028,7 @@ fn find_fallback_pattern_typo<'tcx>( cx: &PatCtxt<'_, 'tcx>, hir_id: HirId, pat: &Pat<'tcx>, - lint: &mut UnreachablePattern<'_>, + lint: &mut UnreachablePatternInner<'_>, ) { if cx.tcx.lint_level_spec_at_node(UNREACHABLE_PATTERNS, hir_id).is_allow() { // This is because we use `with_no_trimmed_paths` later, so if we never emit the lint we'd diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 2d9e0a857bf5e..3a726cbce8182 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -3461,10 +3461,6 @@ pub(crate) struct UnexpectedExpressionInPattern { pub span: Span, /// Was a `RangePatternBound` expected? pub is_bound: bool, - /// The unexpected expr's precedence. Not used directly in the error message, but needed for - /// the stashing of this error to work correctly. We store a `u32` rather than an - /// `ExprPrecedence` to avoid having to impl `IntoDiagArg` for `ExprPrecedence`. - pub expr_precedence: u32, } #[derive(Subdiagnostic)] @@ -4642,7 +4638,7 @@ pub(crate) struct ReservedMultihashLint { #[derive(Subdiagnostic)] #[suggestion( - "if you meant to write a path, use a double colon:", + "if you meant to write a path, use a double colon", code = "::", applicability = "maybe-incorrect" )] @@ -4653,13 +4649,13 @@ pub(crate) struct UseDoubleColonSuggestion { #[derive(Subdiagnostic)] #[multipart_suggestion( - "if you meant to create a regular struct, use curly braces:", + "if you meant to create a regular struct, use curly braces", applicability = "maybe-incorrect" )] pub(crate) struct UseRegularStructSuggestion { - #[suggestion_part(code = "{{")] + #[suggestion_part(code = " {{ ")] pub open: Span, - #[suggestion_part(code = "}}")] + #[suggestion_part(code = " }}")] pub close: Span, #[suggestion_part(code = "")] pub semicolon: Option, diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 3f6429c6a60f0..8f4ffc9a7ec46 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2163,8 +2163,10 @@ impl<'a> Parser<'a> { }) .map(|(r, _)| r) .map_err(|mut error| { - if encountered_colon { + if self.token == token::Colon { error.subdiagnostic(UseDoubleColonSuggestion { colon: self.token.span }); + } + if encountered_colon { self.eat_to_tokens(&[exp!(CloseParen)]); self.bump(); error.subdiagnostic(UseRegularStructSuggestion { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index b8718b503df26..b66dcddc8d333 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -497,18 +497,14 @@ impl<'a> Parser<'a> { && self.look_ahead(1, Token::is_range_separator); let span = expr.span; - - Some(( - self.dcx() - .create_err(UnexpectedExpressionInPattern { - span, - is_bound, - expr_precedence: expr.precedence() as u32, - }) - .stash(span, StashKey::ExprInPat) - .unwrap(), - span, - )) + let mut diag = self.dcx().create_err(UnexpectedExpressionInPattern { span, is_bound }); + // The unexpected expr's precedence. Not used directly in the error message, but + // needed for the stashing of this error to work correctly. We store a `u32` rather + // than an `ExprPrecedence` to avoid having to impl `IntoDiagArg` for + // `ExprPrecedence`. + diag.arg("expr_precedence", expr.precedence() as u32); + + Some((diag.stash(span, StashKey::ExprInPat).unwrap(), span)) } /// Called by [`Parser::parse_stmt_without_recovery`], used to add statement-aware subdiagnostics to the errors stashed diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index f6765d604acb3..a265325fd8e77 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1205,7 +1205,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // #[repr(foo)] // #[repr(bar, align(8))] // ``` - let (reprs, first_attr_span) = + let (reprs, _first_attr_span) = find_attr!(attrs, Repr { reprs, first_span } => (reprs.as_slice(), Some(*first_span))) .unwrap_or((&[], None)); @@ -1215,123 +1215,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let mut is_simd = false; let mut is_transparent = false; - for (repr, repr_span) in reprs { + for (repr, _repr_span) in reprs { match repr { ReprAttr::ReprRust => { is_explicit_rust = true; - match target { - Target::Struct | Target::Union | Target::Enum => continue, - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: *repr_span, - span, - }); - } - } } ReprAttr::ReprC => { is_c = true; - match target { - Target::Struct | Target::Union | Target::Enum => continue, - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: *repr_span, - span, - }); - } - } - } - ReprAttr::ReprAlign(..) => match target { - Target::Struct | Target::Union | Target::Enum => {} - Target::Fn | Target::Method(_) if self.tcx.features().fn_align() => { - self.dcx().emit_err(errors::ReprAlignShouldBeAlign { - span: *repr_span, - item: target.plural_name(), - }); - } - Target::Static if self.tcx.features().static_align() => { - self.dcx().emit_err(errors::ReprAlignShouldBeAlignStatic { - span: *repr_span, - item: target.plural_name(), - }); - } - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: *repr_span, - span, - }); - } - }, - ReprAttr::ReprPacked(_) => { - if target != Target::Struct && target != Target::Union { - self.dcx().emit_err(errors::AttrApplication::StructUnion { - hint_span: *repr_span, - span, - }); - } else { - continue; - } } + ReprAttr::ReprAlign(..) => {} + ReprAttr::ReprPacked(_) => {} ReprAttr::ReprSimd => { is_simd = true; - if target != Target::Struct { - self.dcx().emit_err(errors::AttrApplication::Struct { - hint_span: *repr_span, - span, - }); - } else { - continue; - } } ReprAttr::ReprTransparent => { is_transparent = true; - match target { - Target::Struct | Target::Union | Target::Enum => continue, - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: *repr_span, - span, - }); - } - } } ReprAttr::ReprInt(_) => { int_reprs += 1; - if target != Target::Enum { - self.dcx().emit_err(errors::AttrApplication::Enum { - hint_span: *repr_span, - span, - }); - } else { - continue; - } } }; } - // catch `repr()` with no arguments, applied to an item (i.e. not `#![repr()]`) - if let Some(first_attr_span) = first_attr_span - && reprs.is_empty() - && item.is_some() - { - match target { - Target::Struct | Target::Union | Target::Enum => {} - Target::Fn | Target::Method(_) => { - self.dcx().emit_err(errors::ReprAlignShouldBeAlign { - span: first_attr_span, - item: target.plural_name(), - }); - } - _ => { - self.dcx().emit_err(errors::AttrApplication::StructEnumUnion { - hint_span: first_attr_span, - span, - }); - } - } - return; - } - // Just point at all repr hints if there are any incompatibilities. // This is not ideal, but tracking precisely which ones are at fault is a huge hassle. let hint_spans = reprs.iter().map(|(_, span)| *span); diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 92a0f14f3e94e..b79460afad99e 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -184,15 +184,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { fn handle_res(&mut self, res: Res) { match res { - Res::Def( - DefKind::Const { .. } - | DefKind::AssocConst { .. } - | DefKind::AssocTy - | DefKind::TyAlias, - def_id, - ) => { - self.check_def_id(def_id); - } Res::PrimTy(..) | Res::SelfCtor(..) | Res::Local(..) => {} Res::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => { // Using a variant in patterns should not make the variant live, diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 208aa65cd0424..66c33b3e49756 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -698,38 +698,6 @@ pub(crate) struct UselessAssignment<'a> { )] pub(crate) struct InlineIgnoredForExported; -#[derive(Diagnostic)] -pub(crate) enum AttrApplication { - #[diag("attribute should be applied to an enum", code = E0517)] - Enum { - #[primary_span] - hint_span: Span, - #[label("not an enum")] - span: Span, - }, - #[diag("attribute should be applied to a struct", code = E0517)] - Struct { - #[primary_span] - hint_span: Span, - #[label("not a struct")] - span: Span, - }, - #[diag("attribute should be applied to a struct or union", code = E0517)] - StructUnion { - #[primary_span] - hint_span: Span, - #[label("not a struct or union")] - span: Span, - }, - #[diag("attribute should be applied to a struct, enum, or union", code = E0517)] - StructEnumUnion { - #[primary_span] - hint_span: Span, - #[label("not a struct, enum, or union")] - span: Span, - }, -} - #[derive(Diagnostic)] #[diag("transparent {$target} cannot have other repr hints", code = E0692)] pub(crate) struct TransparentIncompatible { @@ -1154,24 +1122,6 @@ pub(crate) enum UnexportableItem<'a> { }, } -#[derive(Diagnostic)] -#[diag("`#[repr(align(...))]` is not supported on {$item}")] -pub(crate) struct ReprAlignShouldBeAlign { - #[primary_span] - #[help("use `#[rustc_align(...)]` instead")] - pub span: Span, - pub item: &'static str, -} - -#[derive(Diagnostic)] -#[diag("`#[repr(align(...))]` is not supported on {$item}")] -pub(crate) struct ReprAlignShouldBeAlignStatic { - #[primary_span] - #[help("use `#[rustc_align_static(...)]` instead")] - pub span: Span, - pub item: &'static str, -} - #[derive(Diagnostic)] #[diag("`eii_macro_for` is only valid on functions and statics")] pub(crate) struct EiiImplTarget { diff --git a/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs b/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs index 88655c9b22a61..cafb7037c0544 100644 --- a/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs +++ b/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs @@ -25,7 +25,7 @@ pub(crate) fn target() -> Target { options: TargetOptions { cfg_abi: CfgAbi::Spe, endian: Endian::Big, - features: "+secure-plt,+msync".into(), + features: "+secure-plt,+msync,+spe".into(), mcount: "_mcount".into(), ..base }, diff --git a/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs b/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs index c61ceab6bd394..c9427adf8dce5 100644 --- a/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs +++ b/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs @@ -25,7 +25,7 @@ pub(crate) fn target() -> Target { options: TargetOptions { cfg_abi: CfgAbi::Spe, endian: Endian::Big, - features: "+msync".into(), + features: "+msync,+spe".into(), mcount: "_mcount".into(), ..base }, diff --git a/compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs b/compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs index 8f7aaa025bcc1..0a9760d6d1bd7 100644 --- a/compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs +++ b/compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs @@ -26,7 +26,7 @@ pub(crate) fn target() -> Target { cfg_abi: CfgAbi::Spe, endian: Endian::Big, // feature msync would disable instruction 'fsync' which is not supported by fsl_p1p2 - features: "+secure-plt,+msync".into(), + features: "+secure-plt,+msync,+spe".into(), ..base }, } diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 8804cf8459abf..de1aae502c491 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -15,30 +15,20 @@ pub(super) trait Decode<'a, 's, S>: Sized { } macro_rules! rpc_encode_decode { - (le $ty:ident $size:literal) => { + (le $ty:ty) => { impl Encode for $ty { fn encode(self, w: &mut Buffer, _: &mut S) { - const N: usize = size_of::<$ty>(); - - // We can pad with zeros without changing the value because of - // little endian encoding. - let mut bytes = [0; $size]; - bytes[..N].copy_from_slice(&self.to_le_bytes()); - - w.extend_from_array(&bytes); + w.extend_from_array(&self.to_le_bytes()); } } impl Decode<'_, '_, S> for $ty { fn decode(r: &mut &[u8], _: &mut S) -> Self { const N: usize = size_of::<$ty>(); - const { - assert!(N <= $size); - } let mut bytes = [0; N]; bytes.copy_from_slice(&r[..N]); - *r = &r[$size..]; + *r = &r[N..]; Self::from_le_bytes(bytes) } @@ -118,8 +108,42 @@ impl Decode<'_, '_, S> for u8 { } } -rpc_encode_decode!(le u32 4); -rpc_encode_decode!(le usize 8); +rpc_encode_decode!(le u32); +#[cfg(target_pointer_width = "64")] +rpc_encode_decode!(le usize); + +#[cfg(not(target_pointer_width = "64"))] +const MAX_USIZE_SIZE: usize = 8; + +#[cfg(not(target_pointer_width = "64"))] +impl Encode for usize { + fn encode(self, w: &mut Buffer, _: &mut S) { + const N: usize = size_of::(); + + // We can pad with zeros without changing the value because of + // little endian encoding. + let mut bytes = [0; MAX_USIZE_SIZE]; + bytes[..N].copy_from_slice(&self.to_le_bytes()); + + w.extend_from_array(&bytes); + } +} + +#[cfg(not(target_pointer_width = "64"))] +impl Decode<'_, '_, S> for usize { + fn decode(r: &mut &[u8], _: &mut S) -> Self { + const N: usize = size_of::(); + const { + assert!(N <= MAX_USIZE_SIZE); + } + + let mut bytes = [0; N]; + bytes.copy_from_slice(&r[..N]); + *r = &r[MAX_USIZE_SIZE..]; + + Self::from_le_bytes(bytes) + } +} impl Encode for bool { fn encode(self, w: &mut Buffer, s: &mut S) { diff --git a/src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md b/src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md index a3a7a11258c8a..cc3690e1ae481 100644 --- a/src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md +++ b/src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md @@ -49,7 +49,6 @@ translatable error messages are written and how they are generated. Every field of the `Diagnostic` which does not have an annotation is available in Fluent messages as a variable, like `field_name` in the example above. -Fields can be annotated `#[skip_arg]` if this is undesired. Using the `#[primary_span]` attribute on a field (that has type `Span`) indicates the primary span of the diagnostic which will have the main message of the diagnostic. @@ -172,9 +171,6 @@ tcx.dcx().emit_err(FieldAlreadyDeclared { - `#[primary_span]` (_Optional_) - _Applied to `Span` fields on `Subdiagnostic`s. - Indicates the primary span of the diagnostic. -- `#[skip_arg]` (_Optional_) - - _Applied to any field._ - - Prevents the field from being provided as a diagnostic argument. ## `#[derive(Subdiagnostic)]` It is common in the compiler to write a function that conditionally adds a @@ -225,7 +221,6 @@ A primary span is only necessary for a label or suggestion, which can not be spa Every field of the type/variant which does not have an annotation is available in Fluent messages as a variable. -Fields can be annotated `#[skip_arg]` if this is undesired. Like `Diagnostic`, `Subdiagnostic` supports `Option` and `Vec` fields. @@ -348,9 +343,6 @@ to multipart suggestions) - `#[applicability]` (_Optional_; only applicable to (simple and multipart) suggestions) - _Applied to `Applicability` fields._ - Indicates the applicability of the suggestion. -- `#[skip_arg]` (_Optional_) - - _Applied to any field._ - - Prevents the field from being provided as a diagnostic argument. [defn]: https://github.com/rust-lang/rust/blob/6201eabde85db854c1ebb57624be5ec699246b50/compiler/rustc_hir_analysis/src/errors.rs#L68-L77 [use]: https://github.com/rust-lang/rust/blob/f1112099eba41abadb6f921df7edba70affe92c5/compiler/rustc_hir_analysis/src/collect.rs#L823-L827 diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 49a8c077188dd..8385e691ed385 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -628,7 +628,11 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt: let count_types = required_types.len() + provided_types.len(); let count_consts = required_consts.len() + provided_consts.len(); let count_methods = required_methods.len() + provided_methods.len(); - let must_implement_one_of_functions = &tcx.trait_def(t.def_id).must_implement_one_of; + let &rustc_middle::ty::TraitDef { + must_implement_one_of: ref must_implement_one_of_functions, + impl_restriction, + .. + } = tcx.trait_def(t.def_id); // Output the trait definition wrap_item(w, |mut w| { @@ -782,6 +786,25 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt: // Trait documentation write!(w, "{}", document(cx, it, None, HeadingOffset::H2))?; + if let rustc_middle::ty::trait_def::ImplRestrictionKind::Restricted(def_id, _) = + impl_restriction + { + let v1; + let v2; + write!( + w, + "
This trait cannot be implemented outside {}.
", + if cx.cache().document_private { + v1 = + rustc_middle::ty::print::with_resolve_crate_name!(tcx.def_path_str(def_id)); + v1.as_str() + } else { + v2 = tcx.crate_name(def_id.krate); + v2.as_str() + }, + )?; + } + fn trait_item(cx: &Context<'_>, m: &clean::Item, t: &clean::Item) -> impl fmt::Display { fmt::from_fn(|w| { let name = m.name.unwrap(); diff --git a/tests/rustdoc-html/impl/impl-restriction-document-private.rs b/tests/rustdoc-html/impl/impl-restriction-document-private.rs new file mode 100644 index 0000000000000..6ea55eff54cf6 --- /dev/null +++ b/tests/rustdoc-html/impl/impl-restriction-document-private.rs @@ -0,0 +1,15 @@ +//@ compile-flags: --document-private-items +#![crate_name = "c"] +#![feature(impl_restriction)] + +//@ matches c/trait.Foo.html '//*[@class="stab impl_restriction"]' \ +// 'This trait cannot be implemented outside c.$' +//@ has c/trait.Foo.html '//*[@class="stab impl_restriction"]//code' 'c' +pub impl(crate) trait Foo {} + +pub mod inner { + //@ matches c/inner/trait.Bar.html '//*[@class="stab impl_restriction"]' \ + // 'This trait cannot be implemented outside c::inner.$' + //@ has c/inner/trait.Bar.html '//*[@class="stab impl_restriction"]//code' 'c::inner' + pub impl(self) trait Bar {} +} diff --git a/tests/rustdoc-html/impl/impl-restriction.rs b/tests/rustdoc-html/impl/impl-restriction.rs new file mode 100644 index 0000000000000..11df67425f9b9 --- /dev/null +++ b/tests/rustdoc-html/impl/impl-restriction.rs @@ -0,0 +1,14 @@ +#![crate_name = "c"] +#![feature(impl_restriction)] + +//@ matches c/trait.Foo.html '//*[@class="stab impl_restriction"]' \ +// 'This trait cannot be implemented outside c.$' +//@ has c/trait.Foo.html '//*[@class="stab impl_restriction"]//code' 'c' +pub impl(crate) trait Foo {} + +pub mod inner { + //@ matches c/inner/trait.Bar.html '//*[@class="stab impl_restriction"]' \ + // 'This trait cannot be implemented outside c.$' + //@ has c/inner/trait.Bar.html '//*[@class="stab impl_restriction"]//code' 'c' + pub impl(self) trait Bar {} +} diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs index c1146de0fef1f..72b54ed472756 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs @@ -26,7 +26,7 @@ use rustc_span::Span; struct NotIntoDiagArg; #[derive(Diagnostic)] -#[diag("example message")] +#[diag("example message {$arg}")] struct Test { #[primary_span] span: Span, @@ -36,7 +36,7 @@ struct Test { } #[derive(Subdiagnostic)] -#[label("example message")] +#[label("example message {$arg}")] struct SubTest { #[primary_span] span: Span, diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-inline.rs b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-inline.rs index 26d92126fe87a..0956556bf5ef2 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-inline.rs +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-inline.rs @@ -327,7 +327,6 @@ struct ArgFieldWithoutSkip { #[primary_span] span: Span, other: Hello, - //~^ ERROR the trait bound `Hello: IntoDiagArg` is not satisfied } #[derive(Diagnostic)] @@ -335,9 +334,8 @@ struct ArgFieldWithoutSkip { struct ArgFieldWithSkip { #[primary_span] span: Span, - // `Hello` does not implement `IntoDiagArg` so this would result in an error if - // not for `#[skip_arg]`. - #[skip_arg] + // `Hello` does not implement `IntoDiagArg` so this would result if `Diagnostic` + // doesn't skip it correctly. other: Hello, } diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-inline.stderr b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-inline.stderr index 28800016cea9b..486ae9c28e84b 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-inline.stderr +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-inline.stderr @@ -253,61 +253,61 @@ LL | #[label = "bar"] | ^ error: derive(Diagnostic): attribute specified multiple times - --> $DIR/diagnostic-derive-inline.rs:389:5 + --> $DIR/diagnostic-derive-inline.rs:387:5 | LL | #[suggestion("with a suggestion", code = "...", applicability = "maybe-incorrect")] | ^ | note: previously specified here - --> $DIR/diagnostic-derive-inline.rs:391:24 + --> $DIR/diagnostic-derive-inline.rs:389:24 | LL | suggestion: (Span, Applicability), | ^^^^^^^^^^^^^ error: derive(Diagnostic): invalid applicability - --> $DIR/diagnostic-derive-inline.rs:397:69 + --> $DIR/diagnostic-derive-inline.rs:395:69 | LL | #[suggestion("with a suggestion", code = "...", applicability = "batman")] | ^^^^^^^^ error: derive(Diagnostic): the `#[help(...)]` attribute can only be applied to fields of type `Span`, `MultiSpan`, `bool` or `()` - --> $DIR/diagnostic-derive-inline.rs:460:5 + --> $DIR/diagnostic-derive-inline.rs:458:5 | LL | #[help("with a help")] | ^ error: derive(Diagnostic): no nested attribute expected here - --> $DIR/diagnostic-derive-inline.rs:469:29 + --> $DIR/diagnostic-derive-inline.rs:467:29 | LL | #[label("with a label", foo)] | ^^^ error: derive(Diagnostic): a diagnostic message must be the first argument to the attribute - --> $DIR/diagnostic-derive-inline.rs:477:29 + --> $DIR/diagnostic-derive-inline.rs:475:29 | LL | #[label("with a label", "and another one?")] | ^^^^^^^^^^^^^^^^^^ error: derive(Diagnostic): no nested attribute expected here - --> $DIR/diagnostic-derive-inline.rs:485:29 + --> $DIR/diagnostic-derive-inline.rs:483:29 | LL | #[label("with a label", foo = "...")] | ^^^ error: derive(Diagnostic): no nested attribute expected here - --> $DIR/diagnostic-derive-inline.rs:493:29 + --> $DIR/diagnostic-derive-inline.rs:491:29 | LL | #[label("with a label", foo("..."))] | ^^^ error: derive(Diagnostic): `#[error(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:513:1 + --> $DIR/diagnostic-derive-inline.rs:511:1 | LL | #[error("this is an example message", code = E0123)] | ^ error: derive(Diagnostic): diagnostic message not specified - --> $DIR/diagnostic-derive-inline.rs:513:1 + --> $DIR/diagnostic-derive-inline.rs:511:1 | LL | #[error("this is an example message", code = E0123)] | ^ @@ -315,13 +315,13 @@ LL | #[error("this is an example message", code = E0123)] = help: specify the message as the first argument to the `#[diag(...)]` attribute, such as `#[diag("Example error")]` error: derive(Diagnostic): `#[warn_(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:520:1 + --> $DIR/diagnostic-derive-inline.rs:518:1 | LL | #[warn_("this is an example message", code = E0123)] | ^ error: derive(Diagnostic): diagnostic message not specified - --> $DIR/diagnostic-derive-inline.rs:520:1 + --> $DIR/diagnostic-derive-inline.rs:518:1 | LL | #[warn_("this is an example message", code = E0123)] | ^ @@ -329,13 +329,13 @@ LL | #[warn_("this is an example message", code = E0123)] = help: specify the message as the first argument to the `#[diag(...)]` attribute, such as `#[diag("Example error")]` error: derive(Diagnostic): `#[lint(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:527:1 + --> $DIR/diagnostic-derive-inline.rs:525:1 | LL | #[lint("this is an example message", code = E0123)] | ^ error: derive(Diagnostic): diagnostic message not specified - --> $DIR/diagnostic-derive-inline.rs:527:1 + --> $DIR/diagnostic-derive-inline.rs:525:1 | LL | #[lint("this is an example message", code = E0123)] | ^ @@ -343,19 +343,19 @@ LL | #[lint("this is an example message", code = E0123)] = help: specify the message as the first argument to the `#[diag(...)]` attribute, such as `#[diag("Example error")]` error: derive(Diagnostic): attribute specified multiple times - --> $DIR/diagnostic-derive-inline.rs:536:53 + --> $DIR/diagnostic-derive-inline.rs:534:53 | LL | #[suggestion("with a suggestion", code = "...", code = ",,,")] | ^^^^ | note: previously specified here - --> $DIR/diagnostic-derive-inline.rs:536:39 + --> $DIR/diagnostic-derive-inline.rs:534:39 | LL | #[suggestion("with a suggestion", code = "...", code = ",,,")] | ^^^^ error: derive(Diagnostic): wrong types for suggestion - --> $DIR/diagnostic-derive-inline.rs:545:24 + --> $DIR/diagnostic-derive-inline.rs:543:24 | LL | suggestion: (Span, usize), | ^^^^^ @@ -363,7 +363,7 @@ LL | suggestion: (Span, usize), = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` error: derive(Diagnostic): wrong types for suggestion - --> $DIR/diagnostic-derive-inline.rs:553:17 + --> $DIR/diagnostic-derive-inline.rs:551:17 | LL | suggestion: (Span,), | ^^^^^^^ @@ -371,13 +371,13 @@ LL | suggestion: (Span,), = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` error: derive(Diagnostic): suggestion without `code = "..."` - --> $DIR/diagnostic-derive-inline.rs:560:5 + --> $DIR/diagnostic-derive-inline.rs:558:5 | LL | #[suggestion("with a suggestion")] | ^ error: derive(Diagnostic): `#[multipart_suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:567:1 + --> $DIR/diagnostic-derive-inline.rs:565:1 | LL | #[multipart_suggestion("with a suggestion")] | ^ @@ -385,7 +385,7 @@ LL | #[multipart_suggestion("with a suggestion")] = help: consider creating a `Subdiagnostic` instead error: derive(Diagnostic): `#[multipart_suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:570:1 + --> $DIR/diagnostic-derive-inline.rs:568:1 | LL | #[multipart_suggestion()] | ^ @@ -393,7 +393,7 @@ LL | #[multipart_suggestion()] = help: consider creating a `Subdiagnostic` instead error: derive(Diagnostic): `#[multipart_suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:574:5 + --> $DIR/diagnostic-derive-inline.rs:572:5 | LL | #[multipart_suggestion("with a suggestion")] | ^ @@ -401,7 +401,7 @@ LL | #[multipart_suggestion("with a suggestion")] = help: consider creating a `Subdiagnostic` instead error: derive(Diagnostic): `#[suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:582:1 + --> $DIR/diagnostic-derive-inline.rs:580:1 | LL | #[suggestion("with a suggestion", code = "...")] | ^ @@ -409,7 +409,7 @@ LL | #[suggestion("with a suggestion", code = "...")] = help: `#[label]` and `#[suggestion]` can only be applied to fields error: derive(Diagnostic): `#[label]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:591:1 + --> $DIR/diagnostic-derive-inline.rs:589:1 | LL | #[label] | ^ @@ -417,67 +417,67 @@ LL | #[label] = help: subdiagnostic message is missing error: derive(Diagnostic): `#[subdiagnostic(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:625:5 + --> $DIR/diagnostic-derive-inline.rs:623:5 | LL | #[subdiagnostic(bad)] | ^ error: derive(Diagnostic): `#[subdiagnostic = ...]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:633:5 + --> $DIR/diagnostic-derive-inline.rs:631:5 | LL | #[subdiagnostic = "bad"] | ^ error: derive(Diagnostic): `#[subdiagnostic(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:641:5 + --> $DIR/diagnostic-derive-inline.rs:639:5 | LL | #[subdiagnostic(bad, bad)] | ^ error: derive(Diagnostic): `#[subdiagnostic(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:649:5 + --> $DIR/diagnostic-derive-inline.rs:647:5 | LL | #[subdiagnostic("bad")] | ^ error: derive(Diagnostic): `#[subdiagnostic(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:657:5 + --> $DIR/diagnostic-derive-inline.rs:655:5 | LL | #[subdiagnostic(eager)] | ^ error: derive(Diagnostic): `#[subdiagnostic(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:678:5 + --> $DIR/diagnostic-derive-inline.rs:676:5 | LL | #[subdiagnostic(eager)] | ^ error: derive(Diagnostic): expected at least one string literal for `code(...)` - --> $DIR/diagnostic-derive-inline.rs:709:44 + --> $DIR/diagnostic-derive-inline.rs:707:44 | LL | #[suggestion("with a suggestion", code())] | ^ error: derive(Diagnostic): `code(...)` must contain only string literals - --> $DIR/diagnostic-derive-inline.rs:717:44 + --> $DIR/diagnostic-derive-inline.rs:715:44 | LL | #[suggestion("with a suggestion", code(foo))] | ^^^ error: unexpected token, expected `)` - --> $DIR/diagnostic-derive-inline.rs:717:44 + --> $DIR/diagnostic-derive-inline.rs:715:44 | LL | #[suggestion("with a suggestion", code(foo))] | ^^^ error: expected string literal - --> $DIR/diagnostic-derive-inline.rs:726:46 + --> $DIR/diagnostic-derive-inline.rs:724:46 | LL | #[suggestion("with a suggestion", code = 3)] | ^ error: derive(Diagnostic): `#[suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive-inline.rs:741:5 + --> $DIR/diagnostic-derive-inline.rs:739:5 | LL | #[suggestion("with a suggestion", code = "")] | ^ @@ -487,7 +487,7 @@ LL | #[suggestion("with a suggestion", code = "")] = help: to show a variable set of suggestions, use a `Vec` of `Subdiagnostic`s annotated with `#[suggestion(...)]` error: derive(Diagnostic): Variable `nosub` not found in diagnostic - --> $DIR/diagnostic-derive-inline.rs:753:8 + --> $DIR/diagnostic-derive-inline.rs:751:8 | LL | #[diag("does not exist: {$nosub}")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -507,7 +507,7 @@ LL | #[nonsense] | ^^^^^^^^ error: cannot find attribute `error` in this scope - --> $DIR/diagnostic-derive-inline.rs:513:3 + --> $DIR/diagnostic-derive-inline.rs:511:3 | LL | #[error("this is an example message", code = E0123)] | ^^^^^ @@ -519,7 +519,7 @@ LL | struct ErrorAttribute {} | error: cannot find attribute `warn_` in this scope - --> $DIR/diagnostic-derive-inline.rs:520:3 + --> $DIR/diagnostic-derive-inline.rs:518:3 | LL | #[warn_("this is an example message", code = E0123)] | ^^^^^ @@ -531,7 +531,7 @@ LL + #[warn("this is an example message", code = E0123)] | error: cannot find attribute `lint` in this scope - --> $DIR/diagnostic-derive-inline.rs:527:3 + --> $DIR/diagnostic-derive-inline.rs:525:3 | LL | #[lint("this is an example message", code = E0123)] | ^^^^ @@ -543,7 +543,7 @@ LL + #[link("this is an example message", code = E0123)] | error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive-inline.rs:567:3 + --> $DIR/diagnostic-derive-inline.rs:565:3 | LL | #[multipart_suggestion("with a suggestion")] | ^^^^^^^^^^^^^^^^^^^^ @@ -555,7 +555,7 @@ LL | struct MultipartSuggestion { | error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive-inline.rs:570:3 + --> $DIR/diagnostic-derive-inline.rs:568:3 | LL | #[multipart_suggestion()] | ^^^^^^^^^^^^^^^^^^^^ @@ -567,36 +567,12 @@ LL | struct MultipartSuggestion { | error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive-inline.rs:574:7 + --> $DIR/diagnostic-derive-inline.rs:572:7 | LL | #[multipart_suggestion("with a suggestion")] | ^^^^^^^^^^^^^^^^^^^^ | = note: `multipart_suggestion` is an attribute that can be used by the derive macro `Subdiagnostic`, you might be missing a `derive` attribute -error[E0277]: the trait bound `Hello: IntoDiagArg` is not satisfied - --> $DIR/diagnostic-derive-inline.rs:329:12 - | -LL | #[derive(Diagnostic)] - | ---------- required by a bound introduced by this call -... -LL | other: Hello, - | ^^^^^ unsatisfied trait bound - | -help: the nightly-only, unstable trait `IntoDiagArg` is not implemented for `Hello` - --> $DIR/diagnostic-derive-inline.rs:41:1 - | -LL | struct Hello {} - | ^^^^^^^^^^^^ - = help: normalized in stderr - = note: there's an inherent method on `DiagInner` of the same name, which can be auto-dereferenced from `&mut DiagInner` -note: required by a bound in `Diag::<'a, G>::arg` - --> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC - ::: $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC - | - = note: in this macro invocation - = note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 76 previous errors +error: aborting due to 75 previous errors -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive-inline.rs b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive-inline.rs index 2aed4fa9465c4..1bec8ac03c981 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive-inline.rs +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive-inline.rs @@ -290,7 +290,6 @@ struct AA { struct AB { #[primary_span] span: Span, - #[skip_arg] z: Z, } diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive-inline.stderr b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive-inline.stderr index 8e634bf78797f..cf3c9dd9ce10d 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive-inline.stderr +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive-inline.stderr @@ -142,7 +142,7 @@ error: derive(Diagnostic): `#[bar]` is not a valid attribute LL | #[bar] | ^ | - = help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes + = help: only `primary_span`, `applicability` is a valid field attribute error: derive(Diagnostic): `#[bar = ...]` is not a valid attribute --> $DIR/subdiagnostic-derive-inline.rs:271:5 @@ -156,10 +156,10 @@ error: derive(Diagnostic): `#[bar(...)]` is not a valid attribute LL | #[bar("...")] | ^ | - = help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes + = help: only `primary_span`, `applicability` is a valid field attribute error: unexpected unsupported untagged union - --> $DIR/subdiagnostic-derive-inline.rs:298:1 + --> $DIR/subdiagnostic-derive-inline.rs:297:1 | LL | / union AC { LL | | @@ -169,97 +169,97 @@ LL | | } | |_^ error: expected this path to be an identifier - --> $DIR/subdiagnostic-derive-inline.rs:313:28 + --> $DIR/subdiagnostic-derive-inline.rs:312:28 | LL | #[label("example message", no_crate::example)] | ^^^^^^^^^^^^^^^^^ error: derive(Diagnostic): attribute specified multiple times - --> $DIR/subdiagnostic-derive-inline.rs:326:5 + --> $DIR/subdiagnostic-derive-inline.rs:325:5 | LL | #[primary_span] | ^ | note: previously specified here - --> $DIR/subdiagnostic-derive-inline.rs:323:5 + --> $DIR/subdiagnostic-derive-inline.rs:322:5 | LL | #[primary_span] | ^ error: derive(Diagnostic): subdiagnostic kind not specified - --> $DIR/subdiagnostic-derive-inline.rs:332:8 + --> $DIR/subdiagnostic-derive-inline.rs:331:8 | LL | struct AG { | ^^ error: derive(Diagnostic): attribute specified multiple times - --> $DIR/subdiagnostic-derive-inline.rs:369:47 + --> $DIR/subdiagnostic-derive-inline.rs:368:47 | LL | #[suggestion("example message", code = "...", code = "...")] | ^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive-inline.rs:369:33 + --> $DIR/subdiagnostic-derive-inline.rs:368:33 | LL | #[suggestion("example message", code = "...", code = "...")] | ^^^^ error: derive(Diagnostic): attribute specified multiple times - --> $DIR/subdiagnostic-derive-inline.rs:387:5 + --> $DIR/subdiagnostic-derive-inline.rs:386:5 | LL | #[applicability] | ^ | note: previously specified here - --> $DIR/subdiagnostic-derive-inline.rs:384:5 + --> $DIR/subdiagnostic-derive-inline.rs:383:5 | LL | #[applicability] | ^ error: derive(Diagnostic): the `#[applicability]` attribute can only be applied to fields of type `Applicability` - --> $DIR/subdiagnostic-derive-inline.rs:397:5 + --> $DIR/subdiagnostic-derive-inline.rs:396:5 | LL | #[applicability] | ^ error: derive(Diagnostic): suggestion without `code = "..."` - --> $DIR/subdiagnostic-derive-inline.rs:410:1 + --> $DIR/subdiagnostic-derive-inline.rs:409:1 | LL | #[suggestion("example message")] | ^ error: derive(Diagnostic): invalid applicability - --> $DIR/subdiagnostic-derive-inline.rs:420:63 + --> $DIR/subdiagnostic-derive-inline.rs:419:63 | LL | #[suggestion("example message", code = "...", applicability = "foo")] | ^^^^^ error: derive(Diagnostic): suggestion without `#[primary_span]` field - --> $DIR/subdiagnostic-derive-inline.rs:438:1 + --> $DIR/subdiagnostic-derive-inline.rs:437:1 | LL | #[suggestion("example message", code = "...")] | ^ error: derive(Diagnostic): unsupported type attribute for subdiagnostic enum - --> $DIR/subdiagnostic-derive-inline.rs:452:1 + --> $DIR/subdiagnostic-derive-inline.rs:451:1 | LL | #[label] | ^ error: derive(Diagnostic): `var` doesn't refer to a field on this type - --> $DIR/subdiagnostic-derive-inline.rs:472:40 + --> $DIR/subdiagnostic-derive-inline.rs:471:40 | LL | #[suggestion("example message", code = "{var}", applicability = "machine-applicable")] | ^^^^^^^ error: derive(Diagnostic): `var` doesn't refer to a field on this type - --> $DIR/subdiagnostic-derive-inline.rs:491:44 + --> $DIR/subdiagnostic-derive-inline.rs:490:44 | LL | #[suggestion("example message", code = "{var}", applicability = "machine-applicable")] | ^^^^^^^ error: derive(Diagnostic): `#[suggestion_part]` is not a valid attribute - --> $DIR/subdiagnostic-derive-inline.rs:514:5 + --> $DIR/subdiagnostic-derive-inline.rs:513:5 | LL | #[suggestion_part] | ^ @@ -267,7 +267,7 @@ LL | #[suggestion_part] = help: `#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead error: derive(Diagnostic): `#[suggestion_part(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive-inline.rs:517:5 + --> $DIR/subdiagnostic-derive-inline.rs:516:5 | LL | #[suggestion_part(code = "...")] | ^ @@ -275,13 +275,13 @@ LL | #[suggestion_part(code = "...")] = help: `#[suggestion_part(...)]` is only valid in multipart suggestions error: derive(Diagnostic): suggestion without `#[primary_span]` field - --> $DIR/subdiagnostic-derive-inline.rs:511:1 + --> $DIR/subdiagnostic-derive-inline.rs:510:1 | LL | #[suggestion("example message", code = "...")] | ^ error: derive(Diagnostic): invalid nested attribute - --> $DIR/subdiagnostic-derive-inline.rs:526:43 + --> $DIR/subdiagnostic-derive-inline.rs:525:43 | LL | #[multipart_suggestion("example message", code = "...", applicability = "machine-applicable")] | ^^^^ @@ -289,25 +289,25 @@ LL | #[multipart_suggestion("example message", code = "...", applicability = "ma = help: only `style` and `applicability` are valid nested attributes error: derive(Diagnostic): multipart suggestion without any `#[suggestion_part(...)]` fields - --> $DIR/subdiagnostic-derive-inline.rs:526:1 + --> $DIR/subdiagnostic-derive-inline.rs:525:1 | LL | #[multipart_suggestion("example message", code = "...", applicability = "machine-applicable")] | ^ error: derive(Diagnostic): `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive-inline.rs:536:5 + --> $DIR/subdiagnostic-derive-inline.rs:535:5 | LL | #[suggestion_part] | ^ error: derive(Diagnostic): `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive-inline.rs:544:5 + --> $DIR/subdiagnostic-derive-inline.rs:543:5 | LL | #[suggestion_part()] | ^ error: derive(Diagnostic): `#[primary_span]` is not a valid attribute - --> $DIR/subdiagnostic-derive-inline.rs:553:5 + --> $DIR/subdiagnostic-derive-inline.rs:552:5 | LL | #[primary_span] | ^ @@ -315,127 +315,127 @@ LL | #[primary_span] = help: multipart suggestions use one or more `#[suggestion_part]`s rather than one `#[primary_span]` error: derive(Diagnostic): multipart suggestion without any `#[suggestion_part(...)]` fields - --> $DIR/subdiagnostic-derive-inline.rs:550:1 + --> $DIR/subdiagnostic-derive-inline.rs:549:1 | LL | #[multipart_suggestion("example message")] | ^ error: derive(Diagnostic): `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive-inline.rs:561:5 + --> $DIR/subdiagnostic-derive-inline.rs:560:5 | LL | #[suggestion_part] | ^ error: derive(Diagnostic): `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive-inline.rs:564:5 + --> $DIR/subdiagnostic-derive-inline.rs:563:5 | LL | #[suggestion_part()] | ^ error: derive(Diagnostic): `code` is the only valid nested attribute - --> $DIR/subdiagnostic-derive-inline.rs:567:23 + --> $DIR/subdiagnostic-derive-inline.rs:566:23 | LL | #[suggestion_part(foo = "bar")] | ^^^ error: derive(Diagnostic): the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/subdiagnostic-derive-inline.rs:571:5 + --> $DIR/subdiagnostic-derive-inline.rs:570:5 | LL | #[suggestion_part(code = "...")] | ^ error: derive(Diagnostic): the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/subdiagnostic-derive-inline.rs:574:5 + --> $DIR/subdiagnostic-derive-inline.rs:573:5 | LL | #[suggestion_part()] | ^ error: expected `,` - --> $DIR/subdiagnostic-derive-inline.rs:567:27 + --> $DIR/subdiagnostic-derive-inline.rs:566:27 | LL | #[suggestion_part(foo = "bar")] | ^ error: derive(Diagnostic): attribute specified multiple times - --> $DIR/subdiagnostic-derive-inline.rs:582:37 + --> $DIR/subdiagnostic-derive-inline.rs:581:37 | LL | #[suggestion_part(code = "...", code = ",,,")] | ^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive-inline.rs:582:23 + --> $DIR/subdiagnostic-derive-inline.rs:581:23 | LL | #[suggestion_part(code = "...", code = ",,,")] | ^^^^ error: derive(Diagnostic): `#[applicability]` has no effect if all `#[suggestion]`/`#[multipart_suggestion]` attributes have a static `applicability = "..."` - --> $DIR/subdiagnostic-derive-inline.rs:611:5 + --> $DIR/subdiagnostic-derive-inline.rs:610:5 | LL | #[applicability] | ^ error: derive(Diagnostic): expected exactly one string literal for `code = ...` - --> $DIR/subdiagnostic-derive-inline.rs:659:28 + --> $DIR/subdiagnostic-derive-inline.rs:658:28 | LL | #[suggestion_part(code("foo"))] | ^^^^^ error: unexpected token, expected `)` - --> $DIR/subdiagnostic-derive-inline.rs:659:28 + --> $DIR/subdiagnostic-derive-inline.rs:658:28 | LL | #[suggestion_part(code("foo"))] | ^^^^^ error: derive(Diagnostic): expected exactly one string literal for `code = ...` - --> $DIR/subdiagnostic-derive-inline.rs:669:28 + --> $DIR/subdiagnostic-derive-inline.rs:668:28 | LL | #[suggestion_part(code("foo", "bar"))] | ^^^^^ error: unexpected token, expected `)` - --> $DIR/subdiagnostic-derive-inline.rs:669:28 + --> $DIR/subdiagnostic-derive-inline.rs:668:28 | LL | #[suggestion_part(code("foo", "bar"))] | ^^^^^ error: derive(Diagnostic): expected exactly one string literal for `code = ...` - --> $DIR/subdiagnostic-derive-inline.rs:679:28 + --> $DIR/subdiagnostic-derive-inline.rs:678:28 | LL | #[suggestion_part(code(3))] | ^ error: unexpected token, expected `)` - --> $DIR/subdiagnostic-derive-inline.rs:679:28 + --> $DIR/subdiagnostic-derive-inline.rs:678:28 | LL | #[suggestion_part(code(3))] | ^ error: derive(Diagnostic): expected exactly one string literal for `code = ...` - --> $DIR/subdiagnostic-derive-inline.rs:689:28 + --> $DIR/subdiagnostic-derive-inline.rs:688:28 | LL | #[suggestion_part(code())] | ^ error: expected string literal - --> $DIR/subdiagnostic-derive-inline.rs:698:30 + --> $DIR/subdiagnostic-derive-inline.rs:697:30 | LL | #[suggestion_part(code = 3)] | ^ error: derive(Diagnostic): attribute specified multiple times - --> $DIR/subdiagnostic-derive-inline.rs:740:1 + --> $DIR/subdiagnostic-derive-inline.rs:739:1 | LL | #[suggestion("example message", code = "", style = "hidden", style = "normal")] | ^ | note: previously specified here - --> $DIR/subdiagnostic-derive-inline.rs:740:1 + --> $DIR/subdiagnostic-derive-inline.rs:739:1 | LL | #[suggestion("example message", code = "", style = "hidden", style = "normal")] | ^ error: derive(Diagnostic): `#[suggestion_hidden(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive-inline.rs:749:1 + --> $DIR/subdiagnostic-derive-inline.rs:748:1 | LL | #[suggestion_hidden("example message", code = "")] | ^ @@ -443,7 +443,7 @@ LL | #[suggestion_hidden("example message", code = "")] = help: Use `#[suggestion(..., style = "hidden")]` instead error: derive(Diagnostic): `#[suggestion_hidden(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive-inline.rs:757:1 + --> $DIR/subdiagnostic-derive-inline.rs:756:1 | LL | #[suggestion_hidden("example message", code = "", style = "normal")] | ^ @@ -451,7 +451,7 @@ LL | #[suggestion_hidden("example message", code = "", style = "normal")] = help: Use `#[suggestion(..., style = "hidden")]` instead error: derive(Diagnostic): invalid suggestion style - --> $DIR/subdiagnostic-derive-inline.rs:765:52 + --> $DIR/subdiagnostic-derive-inline.rs:764:52 | LL | #[suggestion("example message", code = "", style = "foo")] | ^^^^^ @@ -459,25 +459,25 @@ LL | #[suggestion("example message", code = "", style = "foo")] = help: valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only` error: expected string literal - --> $DIR/subdiagnostic-derive-inline.rs:773:52 + --> $DIR/subdiagnostic-derive-inline.rs:772:52 | LL | #[suggestion("example message", code = "", style = 42)] | ^^ error: expected `=` - --> $DIR/subdiagnostic-derive-inline.rs:781:49 + --> $DIR/subdiagnostic-derive-inline.rs:780:49 | LL | #[suggestion("example message", code = "", style)] | ^ error: expected `=` - --> $DIR/subdiagnostic-derive-inline.rs:789:49 + --> $DIR/subdiagnostic-derive-inline.rs:788:49 | LL | #[suggestion("example message", code = "", style("foo"))] | ^ error: derive(Diagnostic): `#[primary_span]` is not a valid attribute - --> $DIR/subdiagnostic-derive-inline.rs:800:5 + --> $DIR/subdiagnostic-derive-inline.rs:799:5 | LL | #[primary_span] | ^ @@ -486,7 +486,7 @@ LL | #[primary_span] = help: to create a suggestion with multiple spans, use `#[multipart_suggestion]` instead error: derive(Diagnostic): suggestion without `#[primary_span]` field - --> $DIR/subdiagnostic-derive-inline.rs:797:1 + --> $DIR/subdiagnostic-derive-inline.rs:796:1 | LL | #[suggestion("example message", code = "")] | ^ diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs b/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs index 45f1f092e5268..f224eafa4cdf1 100644 --- a/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs @@ -4,7 +4,7 @@ use std::arch::asm; #[repr(simd)] -//~^ ERROR attribute should be applied to a struct +//~^ ERROR attribute cannot be used on //~| ERROR unsupported representation for zero-variant enum enum Es {} diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr index 6992d03f4fa68..29e30bd7c5078 100644 --- a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr @@ -1,11 +1,10 @@ -error[E0517]: attribute should be applied to a struct - --> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8 +error: `#[repr(simd)]` attribute cannot be used on enums + --> $DIR/invalid-repr-simd-on-enum-148634.rs:6:1 | LL | #[repr(simd)] - | ^^^^ -... -LL | enum Es {} - | ---------- not a struct + | ^^^^^^^^^^^^^ + | + = help: `#[repr(simd)]` can only be applied to structs error[E0084]: unsupported representation for zero-variant enum --> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8 @@ -18,5 +17,4 @@ LL | enum Es {} error: aborting due to 2 previous errors -Some errors have detailed explanations: E0084, E0517. -For more information about an error, try `rustc --explain E0084`. +For more information about this error, try `rustc --explain E0084`. diff --git a/tests/ui/asm/naked-with-invalid-repr-attr.rs b/tests/ui/asm/naked-with-invalid-repr-attr.rs index 4620d007e4ec9..333fb0c4e544d 100644 --- a/tests/ui/asm/naked-with-invalid-repr-attr.rs +++ b/tests/ui/asm/naked-with-invalid-repr-attr.rs @@ -8,45 +8,39 @@ use std::arch::naked_asm; #[repr(C)] -//~^ ERROR attribute should be applied to a struct, enum, or union [E0517] +//~^ ERROR attribute cannot be used on #[unsafe(naked)] extern "C" fn example1() { - //~^ NOTE not a struct, enum, or union naked_asm!("") } #[repr(transparent)] -//~^ ERROR attribute should be applied to a struct, enum, or union [E0517] +//~^ ERROR attribute cannot be used on #[unsafe(naked)] extern "C" fn example2() { - //~^ NOTE not a struct, enum, or union naked_asm!("") } #[repr(C)] -//~^ ERROR attribute should be applied to a struct, enum, or union [E0517] +//~^ ERROR attribute cannot be used on #[rustc_align(16)] #[unsafe(naked)] extern "C" fn example3() { - //~^ NOTE not a struct, enum, or union naked_asm!("") } // note: two errors because of packed and C #[repr(C, packed)] -//~^ ERROR attribute should be applied to a struct or union [E0517] -//~| ERROR attribute should be applied to a struct, enum, or union [E0517] +//~^ ERROR attribute cannot be used on +//~| ERROR attribute cannot be used on #[unsafe(naked)] extern "C" fn example4() { - //~^ NOTE not a struct, enum, or union - //~| NOTE not a struct or union naked_asm!("") } #[repr(u8)] -//~^ ERROR attribute should be applied to an enum [E0517] +//~^ ERROR attribute cannot be used on #[unsafe(naked)] extern "C" fn example5() { - //~^ NOTE not an enum naked_asm!("") } diff --git a/tests/ui/asm/naked-with-invalid-repr-attr.stderr b/tests/ui/asm/naked-with-invalid-repr-attr.stderr index 8530495be667a..f98feb5e34b70 100644 --- a/tests/ui/asm/naked-with-invalid-repr-attr.stderr +++ b/tests/ui/asm/naked-with-invalid-repr-attr.stderr @@ -1,77 +1,50 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:10:8 +error: `#[repr(C)]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:10:1 | -LL | #[repr(C)] - | ^ -... -LL | / extern "C" fn example1() { -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct, enum, or union +LL | #[repr(C)] + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:18:8 +error: `#[repr(transparent)]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:17:1 + | +LL | #[repr(transparent)] + | ^^^^^^^^^^^^^^^^^^^^ | -LL | #[repr(transparent)] - | ^^^^^^^^^^^ -... -LL | / extern "C" fn example2() { -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct, enum, or union + = help: `#[repr(transparent)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:26:8 +error: `#[repr(C)]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:24:1 + | +LL | #[repr(C)] + | ^^^^^^^^^^ | -LL | #[repr(C)] - | ^ -... -LL | / extern "C" fn example3() { -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct, enum, or union + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/naked-with-invalid-repr-attr.rs:36:8 +error: `#[repr(C)]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:33:1 | -LL | #[repr(C, packed)] - | ^ -... -LL | / extern "C" fn example4() { -LL | | -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct, enum, or union +LL | #[repr(C, packed)] + | ^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct or union - --> $DIR/naked-with-invalid-repr-attr.rs:36:11 +error: `#[repr(packed)]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:33:1 + | +LL | #[repr(C, packed)] + | ^^^^^^^^^^^^^^^^^^ | -LL | #[repr(C, packed)] - | ^^^^^^ -... -LL | / extern "C" fn example4() { -LL | | -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not a struct or union + = help: `#[repr(packed)]` can only be applied to data types -error[E0517]: attribute should be applied to an enum - --> $DIR/naked-with-invalid-repr-attr.rs:46:8 +error: `#[repr(u8)]` attribute cannot be used on functions + --> $DIR/naked-with-invalid-repr-attr.rs:41:1 + | +LL | #[repr(u8)] + | ^^^^^^^^^^^ | -LL | #[repr(u8)] - | ^^ -... -LL | / extern "C" fn example5() { -LL | | -LL | | naked_asm!("") -LL | | } - | |_- not an enum + = help: `#[repr(u8)]` can only be applied to enums error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/attributes/attr-on-mac-call.rs b/tests/ui/attributes/attr-on-mac-call.rs index 577272a99a0d9..2498682503e6b 100644 --- a/tests/ui/attributes/attr-on-mac-call.rs +++ b/tests/ui/attributes/attr-on-mac-call.rs @@ -70,4 +70,34 @@ fn main() { //~^ WARN attribute cannot be used on macro calls //~| WARN previously accepted unreachable!(); + + #[repr()] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + //~| WARN unused attribute + unreachable!(); + #[repr(u8)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(align(8))] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(packed)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(C)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(Rust)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); + #[repr(simd)] + //~^ WARN attribute cannot be used on macro calls + //~| WARN previously accepted + unreachable!(); } diff --git a/tests/ui/attributes/attr-on-mac-call.stderr b/tests/ui/attributes/attr-on-mac-call.stderr index 1171d4ff96f94..5881685313e96 100644 --- a/tests/ui/attributes/attr-on-mac-call.stderr +++ b/tests/ui/attributes/attr-on-mac-call.stderr @@ -201,5 +201,76 @@ LL | #[should_panic] = help: `#[should_panic]` can only be applied to functions = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -warning: 22 warnings emitted +warning: `#[repr()]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:74:5 + | +LL | #[repr()] + | ^^^^^^^^^ + | + = help: `#[repr()]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: unused attribute + --> $DIR/attr-on-mac-call.rs:74:5 + | +LL | #[repr()] + | ^^^^^^^^^ help: remove this attribute + | + = note: using `repr` with an empty list has no effect + +warning: `#[repr(u8)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:79:5 + | +LL | #[repr(u8)] + | ^^^^^^^^^^^ + | + = help: `#[repr(u8)]` can only be applied to enums + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(align(...))]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:83:5 + | +LL | #[repr(align(8))] + | ^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(align(...))]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(packed)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:87:5 + | +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ + | + = help: `#[repr(packed)]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(C)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:91:5 + | +LL | #[repr(C)] + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(Rust)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:95:5 + | +LL | #[repr(Rust)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(Rust)]` can only be applied to data types + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: `#[repr(simd)]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:99:5 + | +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(simd)]` can only be applied to structs + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +warning: 30 warnings emitted diff --git a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs index f295ecf302598..36c69f0660925 100644 --- a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs +++ b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs @@ -1,5 +1,5 @@ //! Regression test for fn main() { #[inline] struct Foo; //~ ERROR attribute cannot be used on - #[repr(C)] fn foo() {} //~ ERROR attribute should be applied to a struct, enum, or union + #[repr(C)] fn foo() {} //~ ERROR attribute cannot be used on } diff --git a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr index fc8e22f171c20..0f03232cd5cc6 100644 --- a/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr +++ b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr @@ -6,12 +6,13 @@ LL | #[inline] struct Foo; | = help: `#[inline]` can only be applied to functions -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/dont-allow-inline-and-repr-at-invalid-positions.rs:4:12 +error: `#[repr(C)]` attribute cannot be used on functions + --> $DIR/dont-allow-inline-and-repr-at-invalid-positions.rs:4:5 | LL | #[repr(C)] fn foo() {} - | ^ ----------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/attributes/empty-repr.rs b/tests/ui/attributes/empty-repr.rs index e6ba1baf031ab..10bd15af0f0f0 100644 --- a/tests/ui/attributes/empty-repr.rs +++ b/tests/ui/attributes/empty-repr.rs @@ -9,6 +9,7 @@ fn main() { fn test() where #[repr()] //~^ ERROR unused attribute +//~| ERROR attribute cannot be used on (): Sized { } diff --git a/tests/ui/attributes/empty-repr.stderr b/tests/ui/attributes/empty-repr.stderr index 6dfa2df75b737..5ef0f4c6d652c 100644 --- a/tests/ui/attributes/empty-repr.stderr +++ b/tests/ui/attributes/empty-repr.stderr @@ -1,3 +1,11 @@ +error: `#[repr()]` attribute cannot be used on where predicates + --> $DIR/empty-repr.rs:10:1 + | +LL | #[repr()] + | ^^^^^^^^^ + | + = help: `#[repr()]` can only be applied to data types + error: unused attribute --> $DIR/empty-repr.rs:10:1 | @@ -11,5 +19,5 @@ note: the lint level is defined here LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/attributes/invalid-repr.rs b/tests/ui/attributes/invalid-repr.rs index d7933533405c4..e88a51e9a3ab6 100644 --- a/tests/ui/attributes/invalid-repr.rs +++ b/tests/ui/attributes/invalid-repr.rs @@ -1,5 +1,5 @@ #[repr(align(16))] -//~^ ERROR attribute should be applied to a struct, enum, or union +//~^ ERROR attribute cannot be used on pub type Foo = i32; fn main() {} diff --git a/tests/ui/attributes/invalid-repr.stderr b/tests/ui/attributes/invalid-repr.stderr index 3f5a305c6b700..4eadc9cc16f87 100644 --- a/tests/ui/attributes/invalid-repr.stderr +++ b/tests/ui/attributes/invalid-repr.stderr @@ -1,12 +1,10 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/invalid-repr.rs:1:8 +error: `#[repr(align(...))]` attribute cannot be used on type aliases + --> $DIR/invalid-repr.rs:1:1 | LL | #[repr(align(16))] - | ^^^^^^^^^ -LL | -LL | pub type Foo = i32; - | ------------------- not a struct, enum, or union + | ^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(align(...))]` can only be applied to data types error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index c73feb9110f11..8eb1f3bcfd346 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -45,7 +45,6 @@ //~| ERROR attribute cannot be used on #[repr] //~^ ERROR malformed -//~| ERROR is not supported on functions #[rustc_as_ptr = 5] //~^ ERROR malformed #[inline = 5] diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index b31e4976837cf..4026c49295138 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -1,5 +1,5 @@ error[E0539]: malformed `cfg` attribute input - --> $DIR/malformed-attrs.rs:106:1 + --> $DIR/malformed-attrs.rs:105:1 | LL | #[cfg] | ^^^^^^ expected this to be a list @@ -11,7 +11,7 @@ LL | #[cfg(predicate)] | +++++++++++ error[E0539]: malformed `cfg_attr` attribute input - --> $DIR/malformed-attrs.rs:108:1 + --> $DIR/malformed-attrs.rs:107:1 | LL | #[cfg_attr] | ^^^^^^^^^^^ expected this to be a list @@ -23,13 +23,13 @@ LL | #[cfg_attr(predicate, attr1, attr2, ...)] | ++++++++++++++++++++++++++++++ error[E0463]: can't find crate for `wloop` - --> $DIR/malformed-attrs.rs:210:1 + --> $DIR/malformed-attrs.rs:209:1 | LL | extern crate wloop; | ^^^^^^^^^^^^^^^^^^^ can't find crate error: malformed `allow` attribute input - --> $DIR/malformed-attrs.rs:176:1 + --> $DIR/malformed-attrs.rs:175:1 | LL | #[allow] | ^^^^^^^^ @@ -45,7 +45,7 @@ LL | #[allow(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `expect` attribute input - --> $DIR/malformed-attrs.rs:178:1 + --> $DIR/malformed-attrs.rs:177:1 | LL | #[expect] | ^^^^^^^^^ @@ -61,7 +61,7 @@ LL | #[expect(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `warn` attribute input - --> $DIR/malformed-attrs.rs:180:1 + --> $DIR/malformed-attrs.rs:179:1 | LL | #[warn] | ^^^^^^^ @@ -77,7 +77,7 @@ LL | #[warn(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `deny` attribute input - --> $DIR/malformed-attrs.rs:182:1 + --> $DIR/malformed-attrs.rs:181:1 | LL | #[deny] | ^^^^^^^ @@ -93,7 +93,7 @@ LL | #[deny(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `forbid` attribute input - --> $DIR/malformed-attrs.rs:184:1 + --> $DIR/malformed-attrs.rs:183:1 | LL | #[forbid] | ^^^^^^^^^ @@ -109,19 +109,19 @@ LL | #[forbid(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:103:1 + --> $DIR/malformed-attrs.rs:102:1 | LL | #[proc_macro = 18] | ^^^^^^^^^^^^^^^^^^ error: the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:120:1 + --> $DIR/malformed-attrs.rs:119:1 | LL | #[proc_macro_attribute = 19] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:127:1 + --> $DIR/malformed-attrs.rs:126:1 | LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ @@ -224,7 +224,7 @@ LL | #[repr] = note: for more information, visit error[E0565]: malformed `rustc_as_ptr` attribute input - --> $DIR/malformed-attrs.rs:49:1 + --> $DIR/malformed-attrs.rs:48:1 | LL | #[rustc_as_ptr = 5] | ^^^^^^^^^^^^^^^---^ @@ -238,7 +238,7 @@ LL + #[rustc_as_ptr] | error[E0539]: malformed `rustc_align` attribute input - --> $DIR/malformed-attrs.rs:54:1 + --> $DIR/malformed-attrs.rs:53:1 | LL | #[rustc_align] | ^^^^^^^^^^^^^^ expected this to be a list @@ -249,7 +249,7 @@ LL | #[rustc_align()] | ++++++++++++++++++++++ error[E0539]: malformed `optimize` attribute input - --> $DIR/malformed-attrs.rs:56:1 + --> $DIR/malformed-attrs.rs:55:1 | LL | #[optimize] | ^^^^^^^^^^^ expected this to be a list @@ -264,7 +264,7 @@ LL | #[optimize(speed)] | +++++++ error[E0565]: malformed `cold` attribute input - --> $DIR/malformed-attrs.rs:58:1 + --> $DIR/malformed-attrs.rs:57:1 | LL | #[cold = 1] | ^^^^^^^---^ @@ -278,7 +278,7 @@ LL + #[cold] | error[E0539]: malformed `must_use` attribute input - --> $DIR/malformed-attrs.rs:60:1 + --> $DIR/malformed-attrs.rs:59:1 | LL | #[must_use()] | ^^^^^^^^^^--^ @@ -296,7 +296,7 @@ LL + #[must_use] | error[E0565]: malformed `no_mangle` attribute input - --> $DIR/malformed-attrs.rs:62:1 + --> $DIR/malformed-attrs.rs:61:1 | LL | #[no_mangle = 1] | ^^^^^^^^^^^^---^ @@ -310,7 +310,7 @@ LL + #[no_mangle] | error[E0565]: malformed `naked` attribute input - --> $DIR/malformed-attrs.rs:64:1 + --> $DIR/malformed-attrs.rs:63:1 | LL | #[unsafe(naked())] | ^^^^^^^^^^^^^^--^^ @@ -324,7 +324,7 @@ LL + #[unsafe(naked)] | error[E0565]: malformed `track_caller` attribute input - --> $DIR/malformed-attrs.rs:66:1 + --> $DIR/malformed-attrs.rs:65:1 | LL | #[track_caller()] | ^^^^^^^^^^^^^^--^ @@ -338,7 +338,7 @@ LL + #[track_caller] | error[E0539]: malformed `export_name` attribute input - --> $DIR/malformed-attrs.rs:68:1 + --> $DIR/malformed-attrs.rs:67:1 | LL | #[export_name()] | ^^^^^^^^^^^^^^^^ @@ -350,7 +350,7 @@ LL + #[export_name = "name"] | error[E0805]: malformed `used` attribute input - --> $DIR/malformed-attrs.rs:70:1 + --> $DIR/malformed-attrs.rs:69:1 | LL | #[used()] | ^^^^^^--^ @@ -368,7 +368,7 @@ LL + #[used] | error: `#[used]` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:70:1 + --> $DIR/malformed-attrs.rs:69:1 | LL | #[used()] | ^^^^^^^^^ @@ -376,7 +376,7 @@ LL | #[used()] = help: `#[used]` can only be applied to statics error[E0539]: malformed `crate_name` attribute input - --> $DIR/malformed-attrs.rs:73:1 + --> $DIR/malformed-attrs.rs:72:1 | LL | #[crate_name] | ^^^^^^^^^^^^^ @@ -387,7 +387,7 @@ LL | #[crate_name = "name"] | ++++++++ error[E0539]: malformed `target_feature` attribute input - --> $DIR/malformed-attrs.rs:78:1 + --> $DIR/malformed-attrs.rs:77:1 | LL | #[target_feature] | ^^^^^^^^^^^^^^^^^ expected this to be a list @@ -398,7 +398,7 @@ LL | #[target_feature(enable = "feat1, feat2")] | +++++++++++++++++++++++++ error[E0565]: malformed `export_stable` attribute input - --> $DIR/malformed-attrs.rs:80:1 + --> $DIR/malformed-attrs.rs:79:1 | LL | #[export_stable = 1] | ^^^^^^^^^^^^^^^^---^ @@ -412,7 +412,7 @@ LL + #[export_stable] | error[E0539]: malformed `link` attribute input - --> $DIR/malformed-attrs.rs:82:1 + --> $DIR/malformed-attrs.rs:81:1 | LL | #[link] | ^^^^^^^ expected this to be a list @@ -420,7 +420,7 @@ LL | #[link] = note: for more information, visit error[E0539]: malformed `link_name` attribute input - --> $DIR/malformed-attrs.rs:86:1 + --> $DIR/malformed-attrs.rs:85:1 | LL | #[link_name] | ^^^^^^^^^^^^ @@ -432,7 +432,7 @@ LL | #[link_name = "name"] | ++++++++ error[E0539]: malformed `link_section` attribute input - --> $DIR/malformed-attrs.rs:90:1 + --> $DIR/malformed-attrs.rs:89:1 | LL | #[link_section] | ^^^^^^^^^^^^^^^ @@ -444,7 +444,7 @@ LL | #[link_section = "name"] | ++++++++ error[E0539]: malformed `coverage` attribute input - --> $DIR/malformed-attrs.rs:92:1 + --> $DIR/malformed-attrs.rs:91:1 | LL | #[coverage] | ^^^^^^^^^^^ expected this to be a list @@ -457,13 +457,13 @@ LL | #[coverage(on)] | ++++ error[E0539]: malformed `sanitize` attribute input - --> $DIR/malformed-attrs.rs:94:1 + --> $DIR/malformed-attrs.rs:93:1 | LL | #[sanitize] | ^^^^^^^^^^^ expected this to be a list error[E0565]: malformed `no_implicit_prelude` attribute input - --> $DIR/malformed-attrs.rs:99:1 + --> $DIR/malformed-attrs.rs:98:1 | LL | #[no_implicit_prelude = 23] | ^^^^^^^^^^^^^^^^^^^^^^----^ @@ -477,7 +477,7 @@ LL + #[no_implicit_prelude] | error[E0565]: malformed `proc_macro` attribute input - --> $DIR/malformed-attrs.rs:103:1 + --> $DIR/malformed-attrs.rs:102:1 | LL | #[proc_macro = 18] | ^^^^^^^^^^^^^----^ @@ -491,7 +491,7 @@ LL + #[proc_macro] | error[E0539]: malformed `instruction_set` attribute input - --> $DIR/malformed-attrs.rs:110:1 + --> $DIR/malformed-attrs.rs:109:1 | LL | #[instruction_set] | ^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -503,7 +503,7 @@ LL | #[instruction_set(set)] | +++++ error[E0539]: malformed `patchable_function_entry` attribute input - --> $DIR/malformed-attrs.rs:112:1 + --> $DIR/malformed-attrs.rs:111:1 | LL | #[patchable_function_entry] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -514,7 +514,7 @@ LL | #[patchable_function_entry(prefix_nops = m, entry_nops = n)] | +++++++++++++++++++++++++++++++++ error[E0565]: malformed `coroutine` attribute input - --> $DIR/malformed-attrs.rs:115:5 + --> $DIR/malformed-attrs.rs:114:5 | LL | #[coroutine = 63] || {} | ^^^^^^^^^^^^----^ @@ -528,7 +528,7 @@ LL + #[coroutine] || {} | error[E0565]: malformed `proc_macro_attribute` attribute input - --> $DIR/malformed-attrs.rs:120:1 + --> $DIR/malformed-attrs.rs:119:1 | LL | #[proc_macro_attribute = 19] | ^^^^^^^^^^^^^^^^^^^^^^^----^ @@ -542,7 +542,7 @@ LL + #[proc_macro_attribute] | error[E0539]: malformed `must_use` attribute input - --> $DIR/malformed-attrs.rs:123:1 + --> $DIR/malformed-attrs.rs:122:1 | LL | #[must_use = 1] | ^^^^^^^^^^^^^-^ @@ -560,7 +560,7 @@ LL + #[must_use] | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/malformed-attrs.rs:127:1 + --> $DIR/malformed-attrs.rs:126:1 | LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -574,7 +574,7 @@ LL | #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] | ++++++++++++++++++++++++++++++++++++++++++ error[E0539]: malformed `must_not_suspend` attribute input - --> $DIR/malformed-attrs.rs:132:1 + --> $DIR/malformed-attrs.rs:131:1 | LL | #[must_not_suspend()] | ^^^^^^^^^^^^^^^^^^--^ @@ -590,7 +590,7 @@ LL + #[must_not_suspend] | error[E0539]: malformed `cfi_encoding` attribute input - --> $DIR/malformed-attrs.rs:134:1 + --> $DIR/malformed-attrs.rs:133:1 | LL | #[cfi_encoding = ""] | ^^^^^^^^^^^^^^^^^--^ @@ -603,7 +603,7 @@ LL | #[cfi_encoding = "encoding"] | ++++++++ error[E0565]: malformed `marker` attribute input - --> $DIR/malformed-attrs.rs:153:1 + --> $DIR/malformed-attrs.rs:152:1 | LL | #[marker = 3] | ^^^^^^^^^---^ @@ -617,7 +617,7 @@ LL + #[marker] | error[E0565]: malformed `fundamental` attribute input - --> $DIR/malformed-attrs.rs:155:1 + --> $DIR/malformed-attrs.rs:154:1 | LL | #[fundamental()] | ^^^^^^^^^^^^^--^ @@ -631,7 +631,7 @@ LL + #[fundamental] | error[E0565]: malformed `ffi_pure` attribute input - --> $DIR/malformed-attrs.rs:163:5 + --> $DIR/malformed-attrs.rs:162:5 | LL | #[unsafe(ffi_pure = 1)] | ^^^^^^^^^^^^^^^^^^---^^ @@ -645,7 +645,7 @@ LL + #[unsafe(ffi_pure)] | error[E0539]: malformed `link_ordinal` attribute input - --> $DIR/malformed-attrs.rs:165:5 + --> $DIR/malformed-attrs.rs:164:5 | LL | #[link_ordinal] | ^^^^^^^^^^^^^^^ expected this to be a list @@ -657,7 +657,7 @@ LL | #[link_ordinal(ordinal)] | +++++++++ error[E0565]: malformed `ffi_const` attribute input - --> $DIR/malformed-attrs.rs:169:5 + --> $DIR/malformed-attrs.rs:168:5 | LL | #[unsafe(ffi_const = 1)] | ^^^^^^^^^^^^^^^^^^^---^^ @@ -671,13 +671,13 @@ LL + #[unsafe(ffi_const)] | error[E0539]: malformed `linkage` attribute input - --> $DIR/malformed-attrs.rs:171:5 + --> $DIR/malformed-attrs.rs:170:5 | LL | #[linkage] | ^^^^^^^^^^ expected this to be of the form `linkage = "..."` error[E0539]: malformed `debugger_visualizer` attribute input - --> $DIR/malformed-attrs.rs:186:1 + --> $DIR/malformed-attrs.rs:185:1 | LL | #[debugger_visualizer] | ^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -689,7 +689,7 @@ LL | #[debugger_visualizer(natvis_file = "...", gdb_script_file = "...")] | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0565]: malformed `automatically_derived` attribute input - --> $DIR/malformed-attrs.rs:188:1 + --> $DIR/malformed-attrs.rs:187:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^----^ @@ -703,7 +703,7 @@ LL + #[automatically_derived] | error[E0565]: malformed `non_exhaustive` attribute input - --> $DIR/malformed-attrs.rs:196:1 + --> $DIR/malformed-attrs.rs:195:1 | LL | #[non_exhaustive = 1] | ^^^^^^^^^^^^^^^^^---^ @@ -717,7 +717,7 @@ LL + #[non_exhaustive] | error[E0565]: malformed `thread_local` attribute input - --> $DIR/malformed-attrs.rs:202:1 + --> $DIR/malformed-attrs.rs:201:1 | LL | #[thread_local()] | ^^^^^^^^^^^^^^--^ @@ -731,7 +731,7 @@ LL + #[thread_local] | error[E0565]: malformed `no_link` attribute input - --> $DIR/malformed-attrs.rs:206:1 + --> $DIR/malformed-attrs.rs:205:1 | LL | #[no_link()] | ^^^^^^^^^--^ @@ -745,7 +745,7 @@ LL + #[no_link] | error[E0539]: malformed `macro_use` attribute input - --> $DIR/malformed-attrs.rs:208:1 + --> $DIR/malformed-attrs.rs:207:1 | LL | #[macro_use = 1] | ^^^^^^^^^^^^---^ @@ -763,7 +763,7 @@ LL + #[macro_use] | error[E0539]: malformed `macro_export` attribute input - --> $DIR/malformed-attrs.rs:213:1 + --> $DIR/malformed-attrs.rs:212:1 | LL | #[macro_export = 18] | ^^^^^^^^^^^^^^^----^ @@ -780,7 +780,7 @@ LL + #[macro_export] | error[E0658]: allow_internal_unsafe side-steps the unsafe_code lint - --> $DIR/malformed-attrs.rs:215:1 + --> $DIR/malformed-attrs.rs:214:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -789,7 +789,7 @@ LL | #[allow_internal_unsafe = 1] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0565]: malformed `allow_internal_unsafe` attribute input - --> $DIR/malformed-attrs.rs:215:1 + --> $DIR/malformed-attrs.rs:214:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^---^ @@ -815,7 +815,7 @@ LL | | } | |_- not a `const fn` warning: attribute should be applied to an `extern` block with non-Rust ABI - --> $DIR/malformed-attrs.rs:82:1 + --> $DIR/malformed-attrs.rs:81:1 | LL | #[link] | ^^^^^^^ @@ -829,18 +829,6 @@ LL | | } = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: requested on the command line with `-W unused-attributes` -error: `#[repr(align(...))]` is not supported on functions - --> $DIR/malformed-attrs.rs:46:1 - | -LL | #[repr] - | ^^^^^^^ - | -help: use `#[rustc_align(...)]` instead - --> $DIR/malformed-attrs.rs:46:1 - | -LL | #[repr] - | ^^^^^^^ - error: valid forms for the attribute are `#[doc = "string"]`, `#[doc(alias)]`, `#[doc(attribute)]`, `#[doc(auto_cfg)]`, `#[doc(cfg)]`, `#[doc(fake_variadic)]`, `#[doc(hidden)]`, `#[doc(html_favicon_url)]`, `#[doc(html_logo_url)]`, `#[doc(html_no_source)]`, `#[doc(html_playground_url)]`, `#[doc(html_root_url)]`, `#[doc(include)]`, `#[doc(inline)]`, `#[doc(issue_tracker_base_url)]`, `#[doc(keyword)]`, `#[doc(masked)]`, `#[doc(no_default_passes)]`, `#[doc(no_inline)]`, `#[doc(notable_trait)]`, `#[doc(passes)]`, `#[doc(plugins)]`, `#[doc(rust_logo)]`, `#[doc(search_unbox)]`, `#[doc(spotlight)]`, and `#[doc(test)]` --> $DIR/malformed-attrs.rs:41:1 | @@ -854,7 +842,7 @@ LL | #![deny(invalid_doc_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^ error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` - --> $DIR/malformed-attrs.rs:51:1 + --> $DIR/malformed-attrs.rs:50:1 | LL | #[inline = 5] | ^^^^^^^^^^^^^ @@ -864,13 +852,13 @@ LL | #[inline = 5] = note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/malformed-attrs.rs:73:1 + --> $DIR/malformed-attrs.rs:72:1 | LL | #[crate_name] | ^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/malformed-attrs.rs:114:1 + --> $DIR/malformed-attrs.rs:113:1 | LL | / fn test() { LL | | #[coroutine = 63] || {} @@ -879,13 +867,13 @@ LL | | } | |_^ error: valid forms for the attribute are `#[doc = "string"]`, `#[doc(alias)]`, `#[doc(attribute)]`, `#[doc(auto_cfg)]`, `#[doc(cfg)]`, `#[doc(fake_variadic)]`, `#[doc(hidden)]`, `#[doc(html_favicon_url)]`, `#[doc(html_logo_url)]`, `#[doc(html_no_source)]`, `#[doc(html_playground_url)]`, `#[doc(html_root_url)]`, `#[doc(include)]`, `#[doc(inline)]`, `#[doc(issue_tracker_base_url)]`, `#[doc(keyword)]`, `#[doc(masked)]`, `#[doc(no_default_passes)]`, `#[doc(no_inline)]`, `#[doc(notable_trait)]`, `#[doc(passes)]`, `#[doc(plugins)]`, `#[doc(rust_logo)]`, `#[doc(search_unbox)]`, `#[doc(spotlight)]`, and `#[doc(test)]` - --> $DIR/malformed-attrs.rs:76:1 + --> $DIR/malformed-attrs.rs:75:1 | LL | #[doc] | ^^^^^^ warning: `#[link_name]` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:86:1 + --> $DIR/malformed-attrs.rs:85:1 | LL | #[link_name] | ^^^^^^^^^^^^ @@ -894,7 +882,7 @@ LL | #[link_name] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:96:1 + --> $DIR/malformed-attrs.rs:95:1 | LL | #[ignore()] | ^^^^^^^^^^^ @@ -903,7 +891,7 @@ LL | #[ignore()] = note: for more information, see issue #57571 warning: `#[no_implicit_prelude]` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:99:1 + --> $DIR/malformed-attrs.rs:98:1 | LL | #[no_implicit_prelude = 23] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -912,7 +900,7 @@ LL | #[no_implicit_prelude = 23] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: missing options for `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:138:1 + --> $DIR/malformed-attrs.rs:137:1 | LL | #[diagnostic::on_unimplemented] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -921,7 +909,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:140:1 + --> $DIR/malformed-attrs.rs:139:1 | LL | #[diagnostic::on_unimplemented = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here @@ -929,13 +917,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:147:1 + --> $DIR/malformed-attrs.rs:146:1 | LL | #[diagnostic::do_not_recommend()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: `#[automatically_derived]` attribute cannot be used on modules - --> $DIR/malformed-attrs.rs:188:1 + --> $DIR/malformed-attrs.rs:187:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -944,7 +932,7 @@ LL | #[automatically_derived = 18] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:222:1 + --> $DIR/malformed-attrs.rs:221:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ @@ -953,7 +941,7 @@ LL | #[ignore = 1] = note: for more information, see issue #57571 error[E0308]: mismatched types - --> $DIR/malformed-attrs.rs:115:23 + --> $DIR/malformed-attrs.rs:114:23 | LL | fn test() { | - help: a return type might be missing here: `-> _` @@ -961,15 +949,15 @@ LL | #[coroutine = 63] || {} | ^^^^^ expected `()`, found coroutine | = note: expected unit type `()` - found coroutine `{coroutine@$DIR/malformed-attrs.rs:115:23: 115:25}` + found coroutine `{coroutine@$DIR/malformed-attrs.rs:114:23: 114:25}` -error: aborting due to 73 previous errors; 8 warnings emitted +error: aborting due to 72 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`. Future incompatibility report: Future breakage diagnostic: error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` - --> $DIR/malformed-attrs.rs:51:1 + --> $DIR/malformed-attrs.rs:50:1 | LL | #[inline = 5] | ^^^^^^^^^^^^^ @@ -980,7 +968,7 @@ LL | #[inline = 5] Future breakage diagnostic: error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:96:1 + --> $DIR/malformed-attrs.rs:95:1 | LL | #[ignore()] | ^^^^^^^^^^^ @@ -991,7 +979,7 @@ LL | #[ignore()] Future breakage diagnostic: error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:222:1 + --> $DIR/malformed-attrs.rs:221:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ diff --git a/tests/ui/attributes/malformed-fn-align.rs b/tests/ui/attributes/malformed-fn-align.rs index 219218f034793..737bdf6ffbe81 100644 --- a/tests/ui/attributes/malformed-fn-align.rs +++ b/tests/ui/attributes/malformed-fn-align.rs @@ -23,7 +23,7 @@ fn f2() {} #[rustc_align(0)] //~ ERROR invalid alignment value: not a power of two fn f3() {} -#[repr(align(16))] //~ ERROR `#[repr(align(...))]` is not supported on functions +#[repr(align(16))] //~ ERROR attribute cannot be used on fn f4() {} #[rustc_align(-1)] //~ ERROR expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found diff --git a/tests/ui/attributes/malformed-fn-align.stderr b/tests/ui/attributes/malformed-fn-align.stderr index e5aa500a562d3..59cab345c9b7a 100644 --- a/tests/ui/attributes/malformed-fn-align.stderr +++ b/tests/ui/attributes/malformed-fn-align.stderr @@ -49,6 +49,15 @@ error[E0589]: invalid alignment value: not a power of two LL | #[rustc_align(0)] | ^ +error: `#[repr(align(...))]` attribute cannot be used on functions + --> $DIR/malformed-fn-align.rs:26:1 + | +LL | #[repr(align(16))] + | ^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(align(...))]` can only be applied to data types + = help: use `#[rustc_align(...)]` instead + error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression --> $DIR/malformed-fn-align.rs:29:15 | @@ -119,18 +128,6 @@ LL | #[rustc_align(32)] | = help: `#[rustc_align]` can only be applied to functions -error: `#[repr(align(...))]` is not supported on functions - --> $DIR/malformed-fn-align.rs:26:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - | -help: use `#[rustc_align(...)]` instead - --> $DIR/malformed-fn-align.rs:26:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - error: aborting due to 15 previous errors Some errors have detailed explanations: E0539, E0589, E0805. diff --git a/tests/ui/attributes/malformed-reprs.rs b/tests/ui/attributes/malformed-reprs.rs index 9827d10c4ba71..258aee76fea7d 100644 --- a/tests/ui/attributes/malformed-reprs.rs +++ b/tests/ui/attributes/malformed-reprs.rs @@ -3,7 +3,6 @@ // This is a regression test for https://github.com/rust-lang/rust/issues/143522 #![repr] //~^ ERROR malformed `repr` attribute input [E0539] -//~| ERROR `repr` attribute cannot be used at crate level // This is a regression test for https://github.com/rust-lang/rust/issues/143479 #[repr(align(0))] diff --git a/tests/ui/attributes/malformed-reprs.stderr b/tests/ui/attributes/malformed-reprs.stderr index 6a5f6492fcab0..9250fb83f6d58 100644 --- a/tests/ui/attributes/malformed-reprs.stderr +++ b/tests/ui/attributes/malformed-reprs.stderr @@ -6,29 +6,14 @@ LL | #![repr] | = note: for more information, visit -error: `repr` attribute cannot be used at crate level - --> $DIR/malformed-reprs.rs:4:1 - | -LL | #![repr] - | ^^^^^^^^ -... -LL | enum Foo {} - | ----------- the inner attribute doesn't annotate this item - | -help: perhaps you meant to use an outer attribute - | -LL - #![repr] -LL + #[repr] - | - error[E0589]: invalid alignment value: not a power of two - --> $DIR/malformed-reprs.rs:9:14 + --> $DIR/malformed-reprs.rs:8:14 | LL | #[repr(align(0))] | ^ error[E0084]: unsupported representation for zero-variant enum - --> $DIR/malformed-reprs.rs:9:1 + --> $DIR/malformed-reprs.rs:8:1 | LL | #[repr(align(0))] | ^^^^^^^^^^^^^^^^^ @@ -36,7 +21,7 @@ LL | #[repr(align(0))] LL | enum Foo {} | -------- zero-variant enum -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0084, E0539, E0589. For more information about an error, try `rustc --explain E0084`. diff --git a/tests/ui/attributes/malformed-static-align.rs b/tests/ui/attributes/malformed-static-align.rs index 305d8acf8af24..83fc8bae54fda 100644 --- a/tests/ui/attributes/malformed-static-align.rs +++ b/tests/ui/attributes/malformed-static-align.rs @@ -10,7 +10,7 @@ static S2: () = (); #[rustc_align_static(0)] //~ ERROR invalid alignment value: not a power of two static S3: () = (); -#[repr(align(16))] //~ ERROR `#[repr(align(...))]` is not supported on static +#[repr(align(16))] //~ ERROR attribute cannot be used on static S4: () = (); #[rustc_align_static(16)] //~ ERROR `#[rustc_align_static]` attribute cannot be used on structs diff --git a/tests/ui/attributes/malformed-static-align.stderr b/tests/ui/attributes/malformed-static-align.stderr index 15f0dc71830a7..dd449f56ac005 100644 --- a/tests/ui/attributes/malformed-static-align.stderr +++ b/tests/ui/attributes/malformed-static-align.stderr @@ -24,6 +24,15 @@ error[E0589]: invalid alignment value: not a power of two LL | #[rustc_align_static(0)] | ^ +error: `#[repr(align(...))]` attribute cannot be used on statics + --> $DIR/malformed-static-align.rs:13:1 + | +LL | #[repr(align(16))] + | ^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(align(...))]` can only be applied to data types + = help: use `#[rustc_align_static(...)]` instead + error: `#[rustc_align_static]` attribute cannot be used on structs --> $DIR/malformed-static-align.rs:16:1 | @@ -32,18 +41,6 @@ LL | #[rustc_align_static(16)] | = help: `#[rustc_align_static]` can be applied to foreign statics and statics -error: `#[repr(align(...))]` is not supported on statics - --> $DIR/malformed-static-align.rs:13:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - | -help: use `#[rustc_align_static(...)]` instead - --> $DIR/malformed-static-align.rs:13:8 - | -LL | #[repr(align(16))] - | ^^^^^^^^^ - error: aborting due to 5 previous errors Some errors have detailed explanations: E0539, E0589. diff --git a/tests/ui/attributes/repr-align-in-trait-issue-132391.rs b/tests/ui/attributes/repr-align-in-trait-issue-132391.rs index 7b9f6c12deadb..43d222f1c3a03 100644 --- a/tests/ui/attributes/repr-align-in-trait-issue-132391.rs +++ b/tests/ui/attributes/repr-align-in-trait-issue-132391.rs @@ -1,5 +1,7 @@ trait MyTrait { - #[repr(align)] //~ ERROR malformed `repr` attribute input + #[repr(align)] + //~^ ERROR malformed `repr` attribute input + //~| ERROR attribute cannot be used on fn myfun(); } diff --git a/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr b/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr index a8f5d3bab584a..3d3af82d6dbd1 100644 --- a/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr +++ b/tests/ui/attributes/repr-align-in-trait-issue-132391.stderr @@ -1,3 +1,11 @@ +error: `#[repr(align(...))]` attribute cannot be used on required trait methods + --> $DIR/repr-align-in-trait-issue-132391.rs:2:5 + | +LL | #[repr(align)] + | ^^^^^^^^^^^^^^ + | + = help: `#[repr(align(...))]` can only be applied to data types + error[E0539]: malformed `repr` attribute input --> $DIR/repr-align-in-trait-issue-132391.rs:2:5 | @@ -8,6 +16,6 @@ LL | #[repr(align)] | = note: for more information, visit -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0539`. diff --git a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.rs b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.rs index 106b9ae269068..e228533b67574 100644 --- a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.rs +++ b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.rs @@ -9,7 +9,7 @@ pub struct Bar<#[cold] const N: usize>; //~^ ERROR attribute cannot be used on //~| WARN previously accepted pub struct Baz<#[repr(C)] const N: usize>; -//~^ ERROR attribute should be applied to a struct, enum, or union +//~^ ERROR attribute cannot be used on // pub struct Foo2<#[inline] 'a>(PhantomData<&'a ()>); //~^ ERROR attribute cannot be used on @@ -17,7 +17,7 @@ pub struct Bar2<#[cold] 'a>(PhantomData<&'a ()>); //~^ ERROR attribute cannot be used on //~| WARN previously accepted pub struct Baz2<#[repr(C)] 'a>(PhantomData<&'a ()>); -//~^ ERROR attribute should be applied to a struct, enum, or union +//~^ ERROR attribute cannot be used on // pub struct Foo3<#[inline] T>(PhantomData); //~^ ERROR attribute cannot be used on @@ -25,6 +25,6 @@ pub struct Bar3<#[cold] T>(PhantomData); //~^ ERROR attribute cannot be used on //~| WARN previously accepted pub struct Baz3<#[repr(C)] T>(PhantomData); -//~^ ERROR attribute should be applied to a struct, enum, or union +//~^ ERROR attribute cannot be used on fn main() {} diff --git a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr index 7b30a783fcffc..cbf9a5a03f881 100644 --- a/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr +++ b/tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr @@ -6,6 +6,14 @@ LL | pub struct Foo<#[inline] const N: usize>; | = help: `#[inline]` can only be applied to functions +error: `#[repr(C)]` attribute cannot be used on const parameters + --> $DIR/invalid-attributes-on-const-params-78957.rs:11:16 + | +LL | pub struct Baz<#[repr(C)] const N: usize>; + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types + error: `#[inline]` attribute cannot be used on lifetime parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:14:17 | @@ -14,6 +22,14 @@ LL | pub struct Foo2<#[inline] 'a>(PhantomData<&'a ()>); | = help: `#[inline]` can only be applied to functions +error: `#[repr(C)]` attribute cannot be used on lifetime parameters + --> $DIR/invalid-attributes-on-const-params-78957.rs:19:17 + | +LL | pub struct Baz2<#[repr(C)] 'a>(PhantomData<&'a ()>); + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types + error: `#[inline]` attribute cannot be used on type parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:22:17 | @@ -22,23 +38,13 @@ LL | pub struct Foo3<#[inline] T>(PhantomData); | = help: `#[inline]` can only be applied to functions -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/invalid-attributes-on-const-params-78957.rs:11:23 - | -LL | pub struct Baz<#[repr(C)] const N: usize>; - | ^ -------------- not a struct, enum, or union - -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/invalid-attributes-on-const-params-78957.rs:19:24 - | -LL | pub struct Baz2<#[repr(C)] 'a>(PhantomData<&'a ()>); - | ^ -- not a struct, enum, or union - -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/invalid-attributes-on-const-params-78957.rs:27:24 +error: `#[repr(C)]` attribute cannot be used on type parameters + --> $DIR/invalid-attributes-on-const-params-78957.rs:27:17 | LL | pub struct Baz3<#[repr(C)] T>(PhantomData); - | ^ - not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types error: `#[cold]` attribute cannot be used on const parameters --> $DIR/invalid-attributes-on-const-params-78957.rs:8:16 @@ -74,4 +80,3 @@ LL | pub struct Bar3<#[cold] T>(PhantomData); error: aborting due to 9 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/eii/auxiliary/other_crate_privacy2.rs b/tests/ui/eii/auxiliary/other_crate_privacy2.rs index 9fb19298f09f0..7577a500231e7 100644 --- a/tests/ui/eii/auxiliary/other_crate_privacy2.rs +++ b/tests/ui/eii/auxiliary/other_crate_privacy2.rs @@ -14,8 +14,10 @@ mod private { pub fn decl3(x: u64); } -pub use private::eii3 as eii4; -pub use private::decl3 as decl4; +pub use private::{decl3 as decl4, eii3 as eii4}; + +#[eii(eii5)] +static FOO: u8; pub fn local_call_decl1(x: u64) { decl1(x) diff --git a/tests/ui/eii/privacy2.rs b/tests/ui/eii/privacy2.rs index b5d8660fa4248..a096266703015 100644 --- a/tests/ui/eii/privacy2.rs +++ b/tests/ui/eii/privacy2.rs @@ -7,6 +7,7 @@ extern crate other_crate_privacy2 as codegen; // has a span but in the other crate //~? ERROR `#[eii2]` function required, but not found //~? ERROR `#[eii3]` function required, but not found +//~? ERROR `#[eii5]` static required, but not found #[codegen::eii1] fn eii1_impl(x: u64) { diff --git a/tests/ui/eii/privacy2.stderr b/tests/ui/eii/privacy2.stderr index bf84385add65f..92d09d72276d0 100644 --- a/tests/ui/eii/privacy2.stderr +++ b/tests/ui/eii/privacy2.stderr @@ -1,11 +1,11 @@ error[E0433]: cannot find `eii3` in `codegen` - --> $DIR/privacy2.rs:16:12 + --> $DIR/privacy2.rs:17:12 | LL | #[codegen::eii3] | ^^^^ could not find `eii3` in `codegen` error[E0603]: function `decl1` is private - --> $DIR/privacy2.rs:26:14 + --> $DIR/privacy2.rs:27:14 | LL | codegen::decl1(42); | ^^^^^ private function @@ -32,7 +32,15 @@ LL | #[eii(eii3)] | = help: expected at least one implementation in crate `privacy2` or any of its dependencies -error: aborting due to 4 previous errors +error: `#[eii5]` static required, but not found + --> $DIR/auxiliary/other_crate_privacy2.rs:19:7 + | +LL | #[eii(eii5)] + | ^^^^ expected because `#[eii5]` was declared here in crate `other_crate_privacy2` + | + = help: expected at least one implementation in crate `privacy2` or any of its dependencies + +error: aborting due to 5 previous errors Some errors have detailed explanations: E0433, E0603. For more information about an error, try `rustc --explain E0433`. diff --git a/tests/ui/enum-discriminant/eval-error.rs b/tests/ui/enum-discriminant/eval-error.rs index 45ac9472a4b7b..fa7576b4fadb8 100644 --- a/tests/ui/enum-discriminant/eval-error.rs +++ b/tests/ui/enum-discriminant/eval-error.rs @@ -22,7 +22,7 @@ enum Bar2 { } #[repr(u8, packed)] -//~^ ERROR attribute should be applied to a struct or union +//~^ ERROR attribute cannot be used on enum Foo3 { A } diff --git a/tests/ui/enum-discriminant/eval-error.stderr b/tests/ui/enum-discriminant/eval-error.stderr index 77449656ea6a8..d355ac3ec04b0 100644 --- a/tests/ui/enum-discriminant/eval-error.stderr +++ b/tests/ui/enum-discriminant/eval-error.stderr @@ -4,16 +4,13 @@ error: unions cannot have zero fields LL | union Foo2 {} | ^^^^^^^^^^^^^ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/eval-error.rs:24:12 - | -LL | #[repr(u8, packed)] - | ^^^^^^ -LL | -LL | / enum Foo3 { -LL | | A -LL | | } - | |_- not a struct or union +error: `#[repr(packed)]` attribute cannot be used on enums + --> $DIR/eval-error.rs:24:1 + | +LL | #[repr(u8, packed)] + | ^^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(packed)]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/eval-error.rs:2:5 @@ -53,5 +50,5 @@ LL | let _: Option = None; error: aborting due to 5 previous errors -Some errors have detailed explanations: E0080, E0277, E0517, E0740. +Some errors have detailed explanations: E0080, E0277, E0740. For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/error-codes/E0517.rs b/tests/ui/error-codes/E0517.rs deleted file mode 100644 index 1dcaa2d741f6f..0000000000000 --- a/tests/ui/error-codes/E0517.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[repr(C)] //~ ERROR: E0517 -type Foo = u8; - -#[repr(packed)] //~ ERROR: E0517 -enum Foo2 {Bar, Baz} - -#[repr(u8)] //~ ERROR: E0517 -struct Foo3 {bar: bool, baz: bool} - -#[repr(C)] //~ ERROR: E0517 -impl Foo3 { -} - -fn main() { -} diff --git a/tests/ui/error-codes/E0517.stderr b/tests/ui/error-codes/E0517.stderr deleted file mode 100644 index 2f90d4d0baa5e..0000000000000 --- a/tests/ui/error-codes/E0517.stderr +++ /dev/null @@ -1,36 +0,0 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/E0517.rs:1:8 - | -LL | #[repr(C)] - | ^ -LL | type Foo = u8; - | -------------- not a struct, enum, or union - -error[E0517]: attribute should be applied to a struct or union - --> $DIR/E0517.rs:4:8 - | -LL | #[repr(packed)] - | ^^^^^^ -LL | enum Foo2 {Bar, Baz} - | -------------------- not a struct or union - -error[E0517]: attribute should be applied to an enum - --> $DIR/E0517.rs:7:8 - | -LL | #[repr(u8)] - | ^^ -LL | struct Foo3 {bar: bool, baz: bool} - | ---------------------------------- not an enum - -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/E0517.rs:10:8 - | -LL | #[repr(C)] - | ^ -LL | / impl Foo3 { -LL | | } - | |_- not a struct, enum, or union - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/feature-gates/feature-gate-repr-simd.rs b/tests/ui/feature-gates/feature-gate-repr-simd.rs index 091dc479ef3d4..e73ad1e536aa3 100644 --- a/tests/ui/feature-gates/feature-gate-repr-simd.rs +++ b/tests/ui/feature-gates/feature-gate-repr-simd.rs @@ -7,11 +7,11 @@ struct Foo([u64; 2]); struct Bar([u64; 2]); #[repr(simd)] //~ ERROR: SIMD types are experimental -//~^ ERROR: attribute should be applied to a struct +//~^ ERROR: attribute cannot be used on union U {f: u32} #[repr(simd)] //~ ERROR: SIMD types are experimental -//~^ error: attribute should be applied to a struct +//~^ error: attribute cannot be used on enum E { X } fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-repr-simd.stderr b/tests/ui/feature-gates/feature-gate-repr-simd.stderr index 0f1929038fe00..1eab0a04988a5 100644 --- a/tests/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/tests/ui/feature-gates/feature-gate-repr-simd.stderr @@ -38,6 +38,22 @@ LL | #[repr(simd)] = help: add `#![feature(repr_simd)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date +error: `#[repr(simd)]` attribute cannot be used on unions + --> $DIR/feature-gate-repr-simd.rs:9:1 + | +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(simd)]` can only be applied to structs + +error: `#[repr(simd)]` attribute cannot be used on enums + --> $DIR/feature-gate-repr-simd.rs:13:1 + | +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(simd)]` can only be applied to structs + error[E0566]: conflicting representation hints --> $DIR/feature-gate-repr-simd.rs:4:8 | @@ -51,28 +67,10 @@ LL | #[repr(simd)] = note: for more information, see issue #68585 = note: `#[deny(conflicting_repr_hints)]` (part of `#[deny(future_incompatible)]`) on by default -error[E0517]: attribute should be applied to a struct - --> $DIR/feature-gate-repr-simd.rs:9:8 - | -LL | #[repr(simd)] - | ^^^^ -LL | -LL | union U {f: u32} - | ---------------- not a struct - -error[E0517]: attribute should be applied to a struct - --> $DIR/feature-gate-repr-simd.rs:13:8 - | -LL | #[repr(simd)] - | ^^^^ -LL | -LL | enum E { X } - | ------------ not a struct - error: aborting due to 7 previous errors -Some errors have detailed explanations: E0517, E0566, E0658. -For more information about an error, try `rustc --explain E0517`. +Some errors have detailed explanations: E0566, E0658. +For more information about an error, try `rustc --explain E0566`. Future incompatibility report: Future breakage diagnostic: error[E0566]: conflicting representation hints --> $DIR/feature-gate-repr-simd.rs:4:8 diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs index 66d36d9a5d6de..d11326d994f23 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs @@ -14,7 +14,7 @@ //~| NOTE: the `#[rustc_main]` attribute is an internal implementation detail that will never be stable //~| NOTE: the `#[rustc_main]` attribute is used internally to specify test entry point function #![repr()] -//~^ ERROR: `repr` attribute cannot be used at crate level +//~^ ERROR: attribute cannot be used //~| WARN unused attribute //~| NOTE empty list has no effect #![path = "3800"] @@ -37,8 +37,6 @@ #[inline] //~^ ERROR attribute cannot be used on mod inline { - //~^ NOTE the inner attribute doesn't annotate this item - mod inner { #![inline] } //~^ ERROR attribute cannot be used on @@ -121,50 +119,40 @@ mod export_name { } #[repr(C)] -//~^ ERROR: attribute should be applied to a struct, enum, or union +//~^ ERROR: attribute cannot be used on mod repr { -//~^ NOTE not a struct, enum, or union mod inner { #![repr(C)] } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on #[repr(C)] fn f() { } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on struct S; #[repr(C)] type T = S; - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on #[repr(C)] impl S { } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on } #[repr(Rust)] -//~^ ERROR: attribute should be applied to a struct, enum, or union +//~^ ERROR: attribute cannot be used on mod repr_rust { -//~^ NOTE not a struct, enum, or union mod inner { #![repr(Rust)] } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on #[repr(Rust)] fn f() { } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on struct S; #[repr(Rust)] type T = S; - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on #[repr(Rust)] impl S { } - //~^ ERROR: attribute should be applied to a struct, enum, or union - //~| NOTE not a struct, enum, or union + //~^ ERROR: attribute cannot be used on } fn main() {} diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr index 04cfdc4bea8b8..7d252af4f94fe 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr @@ -24,20 +24,13 @@ LL | #![rustc_main] | = help: `#[rustc_main]` can only be applied to functions -error: `repr` attribute cannot be used at crate level +error: `#[repr()]` attribute cannot be used on crates --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1 | LL | #![repr()] | ^^^^^^^^^^ -... -LL | mod inline { - | ------------ the inner attribute doesn't annotate this item - | -help: perhaps you meant to use an outer attribute - | -LL - #![repr()] -LL + #[repr()] | + = help: `#[repr()]` can only be applied to data types error: `#[path]` attribute cannot be used on crates --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:20:1 @@ -88,7 +81,7 @@ LL | #[inline] = help: `#[inline]` can only be applied to functions error: `#[inline]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:42:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:40:17 | LL | mod inner { #![inline] } | ^^^^^^^^^^ @@ -96,7 +89,7 @@ LL | mod inner { #![inline] } = help: `#[inline]` can only be applied to functions error: `#[inline]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:51:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:49:5 | LL | #[inline] struct S; | ^^^^^^^^^ @@ -104,7 +97,7 @@ LL | #[inline] struct S; = help: `#[inline]` can only be applied to functions error: `#[inline]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:52:5 | LL | #[inline] type T = S; | ^^^^^^^^^ @@ -112,7 +105,7 @@ LL | #[inline] type T = S; = help: `#[inline]` can only be applied to functions error: `#[inline]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:57:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:55:5 | LL | #[inline] impl S { } | ^^^^^^^^^ @@ -120,7 +113,7 @@ LL | #[inline] impl S { } = help: `#[inline]` can only be applied to functions error: `#[no_link]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:61:1 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:59:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -128,7 +121,7 @@ LL | #[no_link] = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:64:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:62:17 | LL | mod inner { #![no_link] } | ^^^^^^^^^^^ @@ -136,7 +129,7 @@ LL | mod inner { #![no_link] } = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on functions - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:65:5 | LL | #[no_link] fn f() { | ^^^^^^^^^^ @@ -144,7 +137,7 @@ LL | #[no_link] fn f() { = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:77:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:75:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -152,7 +145,7 @@ LL | #[no_link] = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:86:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:84:5 | LL | #[no_link]type T = S; | ^^^^^^^^^^ @@ -160,7 +153,7 @@ LL | #[no_link]type T = S; = help: `#[no_link]` can only be applied to extern crates error: `#[no_link]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:89:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:87:5 | LL | #[no_link] impl S { } | ^^^^^^^^^^ @@ -168,7 +161,7 @@ LL | #[no_link] impl S { } = help: `#[no_link]` can only be applied to extern crates error: `#[export_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:98:1 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:96:1 | LL | #[export_name = "2200"] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -176,7 +169,7 @@ LL | #[export_name = "2200"] = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:101:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:99:17 | LL | mod inner { #![export_name="2200"] } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -184,7 +177,7 @@ LL | mod inner { #![export_name="2200"] } = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on structs - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:106:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:104:5 | LL | #[export_name = "2200"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,7 +185,7 @@ LL | #[export_name = "2200"] struct S; = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on type aliases - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:107:5 | LL | #[export_name = "2200"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -200,7 +193,7 @@ LL | #[export_name = "2200"] type T = S; = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on inherent impl blocks - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:112:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:110:5 | LL | #[export_name = "2200"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -208,106 +201,112 @@ LL | #[export_name = "2200"] impl S { } = help: `#[export_name]` can be applied to functions and statics error: `#[export_name]` attribute cannot be used on required trait methods - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:116:9 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:114:9 | LL | #[export_name = "2200"] fn foo(); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: `#[export_name]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:8 - | -LL | #[repr(C)] - | ^ -LL | -LL | / mod repr { -LL | | -LL | | mod inner { #![repr(C)] } -... | -LL | | } - | |_- not a struct, enum, or union - -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:147:8 - | -LL | #[repr(Rust)] - | ^^^^ -LL | -LL | / mod repr_rust { -LL | | -LL | | mod inner { #![repr(Rust)] } -... | -LL | | } - | |_- not a struct, enum, or union - -warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]` - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1 - | -LL | #![no_mangle] - | ^^^^^^^^^^^^^ `#[no_mangle]` is ignored - | -note: `#[export_name]` takes precedence - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:1 - | -LL | #![export_name = "2200"] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - = note: requested on the command line with `-W unused-attributes` -help: remove the `#[no_mangle]` attribute +error: `#[repr(C)]` attribute cannot be used on modules + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:121:1 | -LL - #![no_mangle] +LL | #[repr(C)] + | ^^^^^^^^^^ | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:25 +error: `#[repr(C)]` attribute cannot be used on modules + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:124:17 | LL | mod inner { #![repr(C)] } - | --------------------^---- not a struct, enum, or union + | ^^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:131:12 +error: `#[repr(C)]` attribute cannot be used on functions + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:5 | LL | #[repr(C)] fn f() { } - | ^ ---------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:137:12 +error: `#[repr(C)]` attribute cannot be used on type aliases + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:132:5 | LL | #[repr(C)] type T = S; - | ^ ----------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:141:12 +error: `#[repr(C)]` attribute cannot be used on inherent impl blocks + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:135:5 | LL | #[repr(C)] impl S { } - | ^ ---------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:25 +error: `#[repr(Rust)]` attribute cannot be used on modules + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:140:1 + | +LL | #[repr(Rust)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(Rust)]` can only be applied to data types + +error: `#[repr(Rust)]` attribute cannot be used on modules + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:143:17 | LL | mod inner { #![repr(Rust)] } - | --------------------^^^^---- not a struct, enum, or union + | ^^^^^^^^^^^^^^ + | + = help: `#[repr(Rust)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:155:12 +error: `#[repr(Rust)]` attribute cannot be used on functions + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:146:5 | LL | #[repr(Rust)] fn f() { } - | ^^^^ ---------- not a struct, enum, or union + | ^^^^^^^^^^^^^ + | + = help: `#[repr(Rust)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:161:12 +error: `#[repr(Rust)]` attribute cannot be used on type aliases + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:5 | LL | #[repr(Rust)] type T = S; - | ^^^^ ----------- not a struct, enum, or union + | ^^^^^^^^^^^^^ + | + = help: `#[repr(Rust)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:165:12 +error: `#[repr(Rust)]` attribute cannot be used on inherent impl blocks + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:154:5 | LL | #[repr(Rust)] impl S { } - | ^^^^ ---------- not a struct, enum, or union + | ^^^^^^^^^^^^^ + | + = help: `#[repr(Rust)]` can only be applied to data types + +warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]` + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1 + | +LL | #![no_mangle] + | ^^^^^^^^^^^^^ `#[no_mangle]` is ignored + | +note: `#[export_name]` takes precedence + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:1 + | +LL | #![export_name = "2200"] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: requested on the command line with `-W unused-attributes` +help: remove the `#[no_mangle]` attribute + | +LL - #![no_mangle] + | error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:45:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:43:5 | LL | #[inline = "2100"] fn f() { } | ^^^^^^^^^^^^^^^^^^ @@ -317,7 +316,7 @@ LL | #[inline = "2100"] fn f() { } = note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default warning: `#[no_link]` attribute cannot be used on match arms - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:70:13 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:68:13 | LL | #[no_link] | ^^^^^^^^^^ @@ -326,7 +325,7 @@ LL | #[no_link] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[no_link]` attribute cannot be used on struct fields - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:80:9 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:78:9 | LL | #[no_link] | ^^^^^^^^^^ @@ -335,7 +334,7 @@ LL | #[no_link] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[no_link]` attribute cannot be used on macro defs - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:92:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:90:5 | LL | #[no_link] | ^^^^^^^^^^ @@ -362,11 +361,10 @@ LL | #![no_mangle] error: aborting due to 37 previous errors; 6 warnings emitted -Some errors have detailed explanations: E0517, E0658. -For more information about an error, try `rustc --explain E0517`. +For more information about this error, try `rustc --explain E0658`. Future incompatibility report: Future breakage diagnostic: error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:45:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:43:5 | LL | #[inline = "2100"] fn f() { } | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/layout/thaw-transmute-invalid-enum.rs b/tests/ui/layout/thaw-transmute-invalid-enum.rs index 20fc8d463594b..d6326a0852cd3 100644 --- a/tests/ui/layout/thaw-transmute-invalid-enum.rs +++ b/tests/ui/layout/thaw-transmute-invalid-enum.rs @@ -20,7 +20,7 @@ enum Ox00 { } #[repr(C, packed(2))] -//~^ ERROR: attribute should be applied to a struct +//~^ ERROR: attribute cannot be used on enum OxFF { V = 0xFF, } diff --git a/tests/ui/layout/thaw-transmute-invalid-enum.stderr b/tests/ui/layout/thaw-transmute-invalid-enum.stderr index f57f0a2ad6981..7732e21409fc4 100644 --- a/tests/ui/layout/thaw-transmute-invalid-enum.stderr +++ b/tests/ui/layout/thaw-transmute-invalid-enum.stderr @@ -9,16 +9,13 @@ help: you might be missing a type parameter LL | fn test() { | ++++++++ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/thaw-transmute-invalid-enum.rs:22:11 - | -LL | #[repr(C, packed(2))] - | ^^^^^^^^^ -LL | -LL | / enum OxFF { -LL | | V = 0xFF, -LL | | } - | |_- not a struct or union +error: `#[repr(packed)]` attribute cannot be used on enums + --> $DIR/thaw-transmute-invalid-enum.rs:22:1 + | +LL | #[repr(C, packed(2))] + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(packed)]` can be applied to structs and unions error[E0658]: use of unstable library feature `transmutability` --> $DIR/thaw-transmute-invalid-enum.rs:4:20 @@ -75,5 +72,5 @@ LL | a: std::mem::ManuallyDrop, error: aborting due to 7 previous errors -Some errors have detailed explanations: E0425, E0517, E0658, E0740. +Some errors have detailed explanations: E0425, E0658, E0740. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/layout/thaw-validate-invalid-enum.rs b/tests/ui/layout/thaw-validate-invalid-enum.rs index 51aff7fb556c2..cc954661e4fbe 100644 --- a/tests/ui/layout/thaw-validate-invalid-enum.rs +++ b/tests/ui/layout/thaw-validate-invalid-enum.rs @@ -1,6 +1,6 @@ //@ compile-flags: -Zvalidate-mir -#[repr(packed)] //~ ERROR: attribute should be applied to a struct +#[repr(packed)] //~ ERROR: attribute cannot be used on #[repr(u32)] enum E { A, diff --git a/tests/ui/layout/thaw-validate-invalid-enum.stderr b/tests/ui/layout/thaw-validate-invalid-enum.stderr index 9e522cba96aa1..c7076d9162ea1 100644 --- a/tests/ui/layout/thaw-validate-invalid-enum.stderr +++ b/tests/ui/layout/thaw-validate-invalid-enum.stderr @@ -1,15 +1,10 @@ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/thaw-validate-invalid-enum.rs:3:8 +error: `#[repr(packed)]` attribute cannot be used on enums + --> $DIR/thaw-validate-invalid-enum.rs:3:1 | -LL | #[repr(packed)] - | ^^^^^^ -LL | #[repr(u32)] -LL | / enum E { -LL | | A, -LL | | B, -LL | | C, -LL | | } - | |_- not a struct or union +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ + | + = help: `#[repr(packed)]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/thaw-validate-invalid-enum.rs:14:9 @@ -25,5 +20,4 @@ LL | e: std::mem::ManuallyDrop, error: aborting due to 2 previous errors -Some errors have detailed explanations: E0517, E0740. -For more information about an error, try `rustc --explain E0517`. +For more information about this error, try `rustc --explain E0740`. diff --git a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs index 2b93d0f8a609d..d765675fd4163 100644 --- a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs +++ b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.rs @@ -4,7 +4,7 @@ // which is a repr not supported for enums #[repr(packed)] -//~^ ERROR attribute should be applied to a struct or union +//~^ ERROR attribute cannot be used on #[repr(u32)] enum E { A, diff --git a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr index 44dde6120e8d6..4aff0575e5f56 100644 --- a/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr +++ b/tests/ui/lint/ice-const-prop-unions-known-panics-lint-123710.stderr @@ -1,15 +1,10 @@ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:6:8 +error: `#[repr(packed)]` attribute cannot be used on enums + --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:6:1 | -LL | #[repr(packed)] - | ^^^^^^ -... -LL | / enum E { -LL | | A, -LL | | B, -LL | | C, -LL | | } - | |_- not a struct or union +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ + | + = help: `#[repr(packed)]` can be applied to structs and unions error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union --> $DIR/ice-const-prop-unions-known-panics-lint-123710.rs:18:9 @@ -25,5 +20,4 @@ LL | e: std::mem::ManuallyDrop, error: aborting due to 2 previous errors -Some errors have detailed explanations: E0517, E0740. -For more information about an error, try `rustc --explain E0517`. +For more information about this error, try `rustc --explain E0740`. diff --git a/tests/ui/parser/colon-in-tuple-struct.rs b/tests/ui/parser/colon-in-tuple-struct.rs new file mode 100644 index 0000000000000..2ed0d0fbc11a4 --- /dev/null +++ b/tests/ui/parser/colon-in-tuple-struct.rs @@ -0,0 +1,5 @@ +// Suggest the user to use double colon when there's a colon in tuple struct + +struct Foo(std::string:String); +//~^ ERROR expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:` +//~| HELP if you meant to write a path, use a double colon diff --git a/tests/ui/parser/colon-in-tuple-struct.stderr b/tests/ui/parser/colon-in-tuple-struct.stderr new file mode 100644 index 0000000000000..c0108779d4042 --- /dev/null +++ b/tests/ui/parser/colon-in-tuple-struct.stderr @@ -0,0 +1,13 @@ +error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:` + --> $DIR/colon-in-tuple-struct.rs:3:23 + | +LL | struct Foo(std::string:String); + | ^ expected one of 7 possible tokens + | +help: if you meant to write a path, use a double colon + | +LL | struct Foo(std::string::String); + | + + +error: aborting due to 1 previous error + diff --git a/tests/ui/parser/field-name-in-tuple-struct.rs b/tests/ui/parser/field-name-in-tuple-struct.rs index f2ccdd8cfdf29..128c6b2f226e2 100644 --- a/tests/ui/parser/field-name-in-tuple-struct.rs +++ b/tests/ui/parser/field-name-in-tuple-struct.rs @@ -2,5 +2,5 @@ struct Foo(a:u8,b:u8); //~^ ERROR expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:` -//~| HELP if you meant to write a path, use a double colon: -//~| HELP if you meant to create a regular struct, use curly braces: +//~| HELP if you meant to write a path, use a double colon +//~| HELP if you meant to create a regular struct, use curly braces diff --git a/tests/ui/parser/field-name-in-tuple-struct.stderr b/tests/ui/parser/field-name-in-tuple-struct.stderr index 0b0964f29033d..bf15aba41bdb3 100644 --- a/tests/ui/parser/field-name-in-tuple-struct.stderr +++ b/tests/ui/parser/field-name-in-tuple-struct.stderr @@ -4,14 +4,14 @@ error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:` LL | struct Foo(a:u8,b:u8); | ^ expected one of 7 possible tokens | -help: if you meant to write a path, use a double colon: +help: if you meant to write a path, use a double colon | LL | struct Foo(a::u8,b:u8); | + -help: if you meant to create a regular struct, use curly braces: +help: if you meant to create a regular struct, use curly braces | LL - struct Foo(a:u8,b:u8); -LL + struct Foo{a:u8,b:u8} +LL + struct Foo { a:u8,b:u8 } | error: aborting due to 1 previous error diff --git a/tests/ui/proc-macro/ambiguous-builtin-attrs.rs b/tests/ui/proc-macro/ambiguous-builtin-attrs.rs index e36a12beb8182..922a2e4c1f463 100644 --- a/tests/ui/proc-macro/ambiguous-builtin-attrs.rs +++ b/tests/ui/proc-macro/ambiguous-builtin-attrs.rs @@ -20,11 +20,11 @@ fn bench() {} fn non_macro_expanded_location<#[repr(C)] T>() { //~^ ERROR `repr` is ambiguous - //~| ERROR attribute should be applied to a struct, enum, or union + //~| ERROR attribute cannot be used on match 0u8 { #[repr(C)] //~^ ERROR `repr` is ambiguous - //~| ERROR attribute should be applied to a struct, enum, or union + //~| ERROR attribute cannot be used on _ => {} } } diff --git a/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr b/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr index d057019862604..f14acd1b78532 100644 --- a/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr +++ b/tests/ui/proc-macro/ambiguous-builtin-attrs.stderr @@ -94,22 +94,23 @@ LL | use builtin_attrs::*; | ^^^^^^^^^^^^^^^^ = help: use `crate::feature` to refer to this attribute macro unambiguously -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/ambiguous-builtin-attrs.rs:21:39 +error: `#[repr(C)]` attribute cannot be used on match arms + --> $DIR/ambiguous-builtin-attrs.rs:25:9 | -LL | fn non_macro_expanded_location<#[repr(C)] T>() { - | ^ - not a struct, enum, or union +LL | #[repr(C)] + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/ambiguous-builtin-attrs.rs:25:16 +error: `#[repr(C)]` attribute cannot be used on type parameters + --> $DIR/ambiguous-builtin-attrs.rs:21:32 | -LL | #[repr(C)] - | ^ -... -LL | _ => {} - | ------- not a struct, enum, or union +LL | fn non_macro_expanded_location<#[repr(C)] T>() { + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types error: aborting due to 9 previous errors -Some errors have detailed explanations: E0425, E0517, E0659. +Some errors have detailed explanations: E0425, E0659. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/repr/attr-usage-repr.rs b/tests/ui/repr/attr-usage-repr.rs index 10256a7619e51..ecb2be07bc587 100644 --- a/tests/ui/repr/attr-usage-repr.rs +++ b/tests/ui/repr/attr-usage-repr.rs @@ -1,6 +1,6 @@ #![feature(repr_simd)] -#[repr(C)] //~ ERROR: attribute should be applied to a struct, enum, or union +#[repr(C)] //~ ERROR: attribute cannot be used on fn f() {} #[repr(C)] @@ -12,7 +12,7 @@ struct SPacked(f64, f64); #[repr(simd)] struct SSimd([f64; 2]); -#[repr(i8)] //~ ERROR: attribute should be applied to an enum +#[repr(i8)] //~ ERROR: attribute cannot be used on struct SInt(f64, f64); #[repr(C)] @@ -27,13 +27,13 @@ enum EAlign { B, } -#[repr(packed)] //~ ERROR: attribute should be applied to a struct +#[repr(packed)] //~ ERROR: attribute cannot be used on enum EPacked { A, B, } -#[repr(simd)] //~ ERROR: attribute should be applied to a struct +#[repr(simd)] //~ ERROR: attribute cannot be used on enum ESimd { A, B, @@ -45,7 +45,7 @@ enum EInt { B, } -#[repr()] //~ ERROR attribute should be applied to a struct, enum, or union [E0517] +#[repr()] //~ ERROR attribute cannot be used on //~^ WARN unused attribute type SirThisIsAType = i32; diff --git a/tests/ui/repr/attr-usage-repr.stderr b/tests/ui/repr/attr-usage-repr.stderr index 33aa3c2f9f21a..5511f90582d66 100644 --- a/tests/ui/repr/attr-usage-repr.stderr +++ b/tests/ui/repr/attr-usage-repr.stderr @@ -1,49 +1,42 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/attr-usage-repr.rs:3:8 +error: `#[repr(C)]` attribute cannot be used on functions + --> $DIR/attr-usage-repr.rs:3:1 | LL | #[repr(C)] - | ^ -LL | fn f() {} - | --------- not a struct, enum, or union + | ^^^^^^^^^^ + | + = help: `#[repr(C)]` can only be applied to data types -error[E0517]: attribute should be applied to an enum - --> $DIR/attr-usage-repr.rs:15:8 +error: `#[repr(i8)]` attribute cannot be used on structs + --> $DIR/attr-usage-repr.rs:15:1 | LL | #[repr(i8)] - | ^^ -LL | struct SInt(f64, f64); - | ---------------------- not an enum + | ^^^^^^^^^^^ + | + = help: `#[repr(i8)]` can only be applied to enums -error[E0517]: attribute should be applied to a struct or union - --> $DIR/attr-usage-repr.rs:30:8 +error: `#[repr(packed)]` attribute cannot be used on enums + --> $DIR/attr-usage-repr.rs:30:1 + | +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ | -LL | #[repr(packed)] - | ^^^^^^ -LL | / enum EPacked { -LL | | A, -LL | | B, -LL | | } - | |_- not a struct or union + = help: `#[repr(packed)]` can be applied to structs and unions -error[E0517]: attribute should be applied to a struct - --> $DIR/attr-usage-repr.rs:36:8 +error: `#[repr(simd)]` attribute cannot be used on enums + --> $DIR/attr-usage-repr.rs:36:1 | -LL | #[repr(simd)] - | ^^^^ -LL | / enum ESimd { -LL | | A, -LL | | B, -LL | | } - | |_- not a struct +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(simd)]` can only be applied to structs -error[E0517]: attribute should be applied to a struct, enum, or union +error: `#[repr()]` attribute cannot be used on type aliases --> $DIR/attr-usage-repr.rs:48:1 | LL | #[repr()] | ^^^^^^^^^ -LL | -LL | type SirThisIsAType = i32; - | -------------------------- not a struct, enum, or union + | + = help: `#[repr()]` can only be applied to data types warning: unused attribute --> $DIR/attr-usage-repr.rs:48:1 @@ -64,4 +57,3 @@ LL | #[repr()] error: aborting due to 5 previous errors; 2 warnings emitted -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/repr/invalid-repr-on-structs-74082.rs b/tests/ui/repr/invalid-repr-on-structs-74082.rs index 8b9807fad8ce2..776c87a877d39 100644 --- a/tests/ui/repr/invalid-repr-on-structs-74082.rs +++ b/tests/ui/repr/invalid-repr-on-structs-74082.rs @@ -1,10 +1,10 @@ // https://github.com/rust-lang/rust/issues/74082 #![allow(dead_code)] -#[repr(i128)] //~ ERROR: attribute should be applied to an enum +#[repr(i128)] //~ ERROR: attribute cannot be used on struct Foo; -#[repr(u128)] //~ ERROR: attribute should be applied to an enum +#[repr(u128)] //~ ERROR: attribute cannot be used on struct Bar; fn main() {} diff --git a/tests/ui/repr/invalid-repr-on-structs-74082.stderr b/tests/ui/repr/invalid-repr-on-structs-74082.stderr index e11beb811fbff..a9dc539f62ce6 100644 --- a/tests/ui/repr/invalid-repr-on-structs-74082.stderr +++ b/tests/ui/repr/invalid-repr-on-structs-74082.stderr @@ -1,19 +1,18 @@ -error[E0517]: attribute should be applied to an enum - --> $DIR/invalid-repr-on-structs-74082.rs:4:8 +error: `#[repr(i128)]` attribute cannot be used on structs + --> $DIR/invalid-repr-on-structs-74082.rs:4:1 | LL | #[repr(i128)] - | ^^^^ -LL | struct Foo; - | ----------- not an enum + | ^^^^^^^^^^^^^ + | + = help: `#[repr(i128)]` can only be applied to enums -error[E0517]: attribute should be applied to an enum - --> $DIR/invalid-repr-on-structs-74082.rs:7:8 +error: `#[repr(u128)]` attribute cannot be used on structs + --> $DIR/invalid-repr-on-structs-74082.rs:7:1 | LL | #[repr(u128)] - | ^^^^ -LL | struct Bar; - | ----------- not an enum + | ^^^^^^^^^^^^^ + | + = help: `#[repr(u128)]` can only be applied to enums error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/repr/issue-83505-repr-simd.rs b/tests/ui/repr/issue-83505-repr-simd.rs index bebbc636728fd..1b649ac763497 100644 --- a/tests/ui/repr/issue-83505-repr-simd.rs +++ b/tests/ui/repr/issue-83505-repr-simd.rs @@ -3,7 +3,7 @@ #![crate_type="lib"] #[repr(simd)] -//~^ ERROR: attribute should be applied to a struct [E0517] +//~^ ERROR: attribute cannot be used on //~| ERROR: unsupported representation for zero-variant enum [E0084] //~| ERROR: SIMD types are experimental and possibly buggy [E0658] diff --git a/tests/ui/repr/issue-83505-repr-simd.stderr b/tests/ui/repr/issue-83505-repr-simd.stderr index 57cfbeb95de87..4694fa770b6c2 100644 --- a/tests/ui/repr/issue-83505-repr-simd.stderr +++ b/tests/ui/repr/issue-83505-repr-simd.stderr @@ -16,14 +16,13 @@ LL | #[repr(simd)] = help: add `#![feature(repr_simd)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0517]: attribute should be applied to a struct - --> $DIR/issue-83505-repr-simd.rs:5:8 +error: `#[repr(simd)]` attribute cannot be used on enums + --> $DIR/issue-83505-repr-simd.rs:5:1 | LL | #[repr(simd)] - | ^^^^ -... -LL | enum Es {} - | ---------- not a struct + | ^^^^^^^^^^^^^ + | + = help: `#[repr(simd)]` can only be applied to structs error[E0084]: unsupported representation for zero-variant enum --> $DIR/issue-83505-repr-simd.rs:5:8 @@ -36,5 +35,5 @@ LL | enum Es {} error: aborting due to 4 previous errors -Some errors have detailed explanations: E0084, E0517, E0658. +Some errors have detailed explanations: E0084, E0658. For more information about an error, try `rustc --explain E0084`. diff --git a/tests/ui/repr/repr-disallow-on-variant.rs b/tests/ui/repr/repr-disallow-on-variant.rs index d9bd0b0e38a69..384a1701c11de 100644 --- a/tests/ui/repr/repr-disallow-on-variant.rs +++ b/tests/ui/repr/repr-disallow-on-variant.rs @@ -2,7 +2,7 @@ struct Test; enum Foo { #[repr(u8)] - //~^ ERROR attribute should be applied to an enum + //~^ ERROR attribute cannot be used on Variant, } diff --git a/tests/ui/repr/repr-disallow-on-variant.stderr b/tests/ui/repr/repr-disallow-on-variant.stderr index ebdb851b7a64f..39556fb589b5d 100644 --- a/tests/ui/repr/repr-disallow-on-variant.stderr +++ b/tests/ui/repr/repr-disallow-on-variant.stderr @@ -1,12 +1,10 @@ -error[E0517]: attribute should be applied to an enum - --> $DIR/repr-disallow-on-variant.rs:4:12 +error: `#[repr(u8)]` attribute cannot be used on enum variants + --> $DIR/repr-disallow-on-variant.rs:4:5 | LL | #[repr(u8)] - | ^^ -LL | -LL | Variant, - | ------- not an enum + | ^^^^^^^^^^^ + | + = help: `#[repr(u8)]` can only be applied to enums error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/repr/repr-empty-packed.rs b/tests/ui/repr/repr-empty-packed.rs index 6e390a12b15ac..6caa4667e73b7 100644 --- a/tests/ui/repr/repr-empty-packed.rs +++ b/tests/ui/repr/repr-empty-packed.rs @@ -2,7 +2,7 @@ #![deny(unused_attributes)] #[repr()] //~ ERROR unused attribute -#[repr(packed)] //~ ERROR attribute should be applied to a struct or union +#[repr(packed)] //~ ERROR attribute cannot be used on enums pub enum Foo { Bar, Baz(i32), diff --git a/tests/ui/repr/repr-empty-packed.stderr b/tests/ui/repr/repr-empty-packed.stderr index adf32c9552967..903a5ff6fea21 100644 --- a/tests/ui/repr/repr-empty-packed.stderr +++ b/tests/ui/repr/repr-empty-packed.stderr @@ -1,13 +1,10 @@ -error[E0517]: attribute should be applied to a struct or union - --> $DIR/repr-empty-packed.rs:5:8 +error: `#[repr(packed)]` attribute cannot be used on enums + --> $DIR/repr-empty-packed.rs:5:1 | -LL | #[repr(packed)] - | ^^^^^^ -LL | / pub enum Foo { -LL | | Bar, -LL | | Baz(i32), -LL | | } - | |_- not a struct or union +LL | #[repr(packed)] + | ^^^^^^^^^^^^^^^ + | + = help: `#[repr(packed)]` can be applied to structs and unions error: unused attribute --> $DIR/repr-empty-packed.rs:4:1 @@ -24,4 +21,3 @@ LL | #![deny(unused_attributes)] error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/repr/repr-transparent-other-items.rs b/tests/ui/repr/repr-transparent-other-items.rs index e537e3e1a6365..4c3ef28a2f18f 100644 --- a/tests/ui/repr/repr-transparent-other-items.rs +++ b/tests/ui/repr/repr-transparent-other-items.rs @@ -1,9 +1,9 @@ // See also repr-transparent.rs -#[repr(transparent)] //~ ERROR should be applied to a struct +#[repr(transparent)] //~ ERROR attribute cannot be used on fn cant_repr_this() {} -#[repr(transparent)] //~ ERROR should be applied to a struct +#[repr(transparent)] //~ ERROR attribute cannot be used on static CANT_REPR_THIS: u32 = 0; fn main() {} diff --git a/tests/ui/repr/repr-transparent-other-items.stderr b/tests/ui/repr/repr-transparent-other-items.stderr index 14e6f13e1ae44..ddab462eb162f 100644 --- a/tests/ui/repr/repr-transparent-other-items.stderr +++ b/tests/ui/repr/repr-transparent-other-items.stderr @@ -1,19 +1,18 @@ -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/repr-transparent-other-items.rs:3:8 +error: `#[repr(transparent)]` attribute cannot be used on functions + --> $DIR/repr-transparent-other-items.rs:3:1 | LL | #[repr(transparent)] - | ^^^^^^^^^^^ -LL | fn cant_repr_this() {} - | ---------------------- not a struct, enum, or union + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(transparent)]` can only be applied to data types -error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/repr-transparent-other-items.rs:6:8 +error: `#[repr(transparent)]` attribute cannot be used on statics + --> $DIR/repr-transparent-other-items.rs:6:1 | LL | #[repr(transparent)] - | ^^^^^^^^^^^ -LL | static CANT_REPR_THIS: u32 = 0; - | ------------------------------- not a struct, enum, or union + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[repr(transparent)]` can only be applied to data types error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0517`. diff --git a/tests/ui/simd/repr-simd-on-enum.rs b/tests/ui/simd/repr-simd-on-enum.rs index 49cf9e92d36cf..4762b43487122 100644 --- a/tests/ui/simd/repr-simd-on-enum.rs +++ b/tests/ui/simd/repr-simd-on-enum.rs @@ -2,7 +2,7 @@ #![feature(repr_simd)] -#[repr(simd)] //~ ERROR attribute should be applied to a struct +#[repr(simd)] //~ ERROR attribute cannot be used on enum Aligned { Zero = 0, One = 1, diff --git a/tests/ui/simd/repr-simd-on-enum.stderr b/tests/ui/simd/repr-simd-on-enum.stderr index 6a19a16e8eae5..5edbcb71be6a0 100644 --- a/tests/ui/simd/repr-simd-on-enum.stderr +++ b/tests/ui/simd/repr-simd-on-enum.stderr @@ -1,14 +1,10 @@ -error[E0517]: attribute should be applied to a struct - --> $DIR/repr-simd-on-enum.rs:5:8 +error: `#[repr(simd)]` attribute cannot be used on enums + --> $DIR/repr-simd-on-enum.rs:5:1 | -LL | #[repr(simd)] - | ^^^^ -LL | / enum Aligned { -LL | | Zero = 0, -LL | | One = 1, -LL | | } - | |_- not a struct +LL | #[repr(simd)] + | ^^^^^^^^^^^^^ + | + = help: `#[repr(simd)]` can only be applied to structs error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0517`.