Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub(crate) struct ExportNameParser;

impl SingleAttributeParser for ExportNameParser {
const PATH: &[rustc_span::Symbol] = &[sym::export_name];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::DenyAndFutureError;
const SAFETY: AttributeSafety = AttributeSafety::Unsafe {
note: "the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them",
unsafe_since: Some(Edition2024),
Expand All @@ -122,10 +122,10 @@ impl SingleAttributeParser for ExportNameParser {
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
Warn(Target::Field),
Warn(Target::Arm),
Warn(Target::MacroDef),
Warn(Target::MacroCall),
Deny(Target::Field),
Deny(Target::Arm),
Deny(Target::MacroDef),
Deny(Target::MacroCall),
]);
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
const STABILITY: AttributeStability = AttributeStability::Stable;
Expand Down Expand Up @@ -233,7 +233,7 @@ impl AttributeParser for NakedParser {
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
Warn(Target::MacroCall),
Deny(Target::MacroCall),
]);

fn finalize(self, cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
Expand Down Expand Up @@ -386,7 +386,7 @@ impl NoArgsAttributeParser for NoMangleParser {
note: "the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them",
unsafe_since: Some(Edition2024),
};
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListDenyRest(&[
Allow(Target::Fn),
Allow(Target::Static),
Allow(Target::Method(MethodKind::Inherent)),
Expand Down Expand Up @@ -556,11 +556,11 @@ impl CombineAttributeParser for TargetFeatureParser {
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
Warn(Target::Statement),
Warn(Target::Field),
Warn(Target::Arm),
Warn(Target::MacroDef),
Warn(Target::MacroCall),
Deny(Target::Statement),
Deny(Target::Field),
Deny(Target::Arm),
Deny(Target::MacroDef),
Deny(Target::MacroCall),
]);
const STABILITY: AttributeStability = AttributeStability::Stable;

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) struct CrateNameParser;

impl SingleAttributeParser for CrateNameParser {
const PATH: &[Symbol] = &[sym::crate_name];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnAndFutureError;
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
Expand Down Expand Up @@ -78,7 +78,7 @@ pub(crate) struct RecursionLimitParser;

impl SingleAttributeParser for RecursionLimitParser {
const PATH: &[Symbol] = &[sym::recursion_limit];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnAndFutureError;
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute");
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
Expand Down Expand Up @@ -110,7 +110,7 @@ pub(crate) struct TypeLengthLimitParser;

impl SingleAttributeParser for TypeLengthLimitParser {
const PATH: &[Symbol] = &[sym::type_length_limit];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnAndFutureError;
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
Expand Down Expand Up @@ -185,7 +185,7 @@ pub(crate) struct WindowsSubsystemParser;

impl SingleAttributeParser for WindowsSubsystemParser {
const PATH: &[Symbol] = &[sym::windows_subsystem];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnAndFutureError;
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
const TEMPLATE: AttributeTemplate = template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) struct InlineParser;

impl SingleAttributeParser for InlineParser {
const PATH: &[Symbol] = &[sym::inline];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnAndFutureError;
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) struct InstructionSetParser;

impl SingleAttributeParser for InstructionSetParser {
const PATH: &[Symbol] = &[sym::instruction_set];
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListDenyRest(&[
Allow(Target::Fn),
Allow(Target::Closure),
Allow(Target::Method(MethodKind::Inherent)),
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub(crate) struct LinkNameParser;

impl SingleAttributeParser for LinkNameParser {
const PATH: &[Symbol] = &[sym::link_name];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
const ON_DUPLICATE: OnDuplicate = OnDuplicate::DenyAndFutureError;
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListDenyRest(&[
Allow(Target::ForeignFn),
Allow(Target::ForeignStatic),
]);
Expand Down Expand Up @@ -72,7 +72,7 @@ impl CombineAttributeParser for LinkParser {
r#"name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated""#,
], "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute");
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowListWarnRest(&[Allow(Target::ForeignMod)]);
AllowedTargets::AllowListDenyRest(&[Allow(Target::ForeignMod)]);
const STABILITY: AttributeStability = AttributeStability::Stable;

fn extend(
Expand Down Expand Up @@ -494,13 +494,13 @@ fn check_link_section_macho(name: Symbol) -> Result<(), InvalidMachoSectionReaso

impl SingleAttributeParser for LinkSectionParser {
const PATH: &[Symbol] = &[sym::link_section];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::DenyAndFutureError;
const SAFETY: AttributeSafety = AttributeSafety::Unsafe {
note: "the program's behavior with overridden link sections on items is unpredictable and Rust cannot provide guarantees when you manually override them",
unsafe_since: Some(Edition2024),
};
const STABILITY: AttributeStability = AttributeStability::Stable;
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListDenyRest(&[
Allow(Target::Static),
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Expand Down Expand Up @@ -612,7 +612,7 @@ impl SingleAttributeParser for LinkOrdinalParser {
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
Allow(Target::ForeignFn),
Allow(Target::ForeignStatic),
Warn(Target::MacroCall),
Deny(Target::MacroCall),
]);
const TEMPLATE: AttributeTemplate = template!(
List: &["ordinal"],
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ pub(crate) enum OnDuplicate {
Warn,

/// Duplicates will be a warning, with a note that this will be an error in the future.
WarnButFutureError,
WarnAndFutureError,

/// Duplicates will be a deny by default warning,
/// with a note that this will be an error in the future.
DenyAndFutureError,

/// Give a default error
Error,
Expand All @@ -234,7 +238,8 @@ impl OnDuplicate {
) {
match self {
OnDuplicate::Warn => cx.warn_unused_duplicate(used, unused),
OnDuplicate::WarnButFutureError => cx.warn_unused_duplicate_future_error(used, unused),
OnDuplicate::WarnAndFutureError => cx.warn_unused_duplicate_future_error(used, unused),
OnDuplicate::DenyAndFutureError => cx.deny_unused_duplicate_future_error(used, unused),
OnDuplicate::Error => {
cx.emit_err(UnusedMultiple {
this: unused,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/must_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) struct MustUseParser;

impl SingleAttributeParser for MustUseParser {
const PATH: &[Symbol] = &[sym::must_use];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnAndFutureError;
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
Allow(Target::Fn),
Allow(Target::Enum),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_attr_parsing/src/attributes/non_exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ impl NoArgsAttributeParser for NonExhaustiveParser {
Allow(Target::Enum),
Allow(Target::Struct),
Allow(Target::Variant),
Warn(Target::Field),
Warn(Target::Arm),
Warn(Target::MacroDef),
Warn(Target::MacroCall),
Deny(Target::Field),
Deny(Target::Arm),
Deny(Target::MacroDef),
Deny(Target::MacroCall),
]);
const STABILITY: AttributeStability = AttributeStability::Stable;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NonExhaustive;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) struct PathParser;

impl SingleAttributeParser for PathParser {
const PATH: &[Symbol] = &[sym::path];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnAndFutureError;
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Mod), Error(Target::Crate)]);
const TEMPLATE: AttributeTemplate = template!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(super) use crate::context::{AcceptContext, FinalizeCheckContext, FinalizeCon
pub(super) use crate::parser::*;
// target checking
#[doc(hidden)]
pub(super) use crate::target_checking::Policy::{Allow, Error, Warn};
pub(super) use crate::target_checking::Policy::{Allow, Deny, Error, Warn};
#[doc(hidden)]
pub(super) use crate::target_checking::{ALL_TARGETS, AllowedTargets};
#[doc(hidden)]
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl CombineAttributeParser for ReprParser {
Allow(Target::Struct),
Allow(Target::Enum),
Allow(Target::Union),
Warn(Target::MacroCall),
Deny(Target::MacroCall),
]),
);

Expand Down Expand Up @@ -75,7 +75,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option<
($arg: ident, $constructor: expr) => {{
cx.check_target(
concat!("(", stringify!($arg), ")"),
&AllowedTargets::AllowList(&[Allow(Target::Enum), Warn(Target::MacroCall)]),
&AllowedTargets::AllowList(&[Allow(Target::Enum), Deny(Target::MacroCall)]),
);
cx.expect_no_args(param.args())?;
Some($constructor)
Expand All @@ -90,7 +90,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option<
Allow(Target::Struct),
Allow(Target::Enum),
Allow(Target::Union),
Warn(Target::MacroCall),
Deny(Target::MacroCall),
]),
);
let l = cx.expect_list(param.args(), param.span())?;
Expand All @@ -102,7 +102,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option<
&AllowedTargets::AllowList(&[
Allow(Target::Struct),
Allow(Target::Union),
Warn(Target::MacroCall),
Deny(Target::MacroCall),
]),
);
match param.args() {
Expand All @@ -122,7 +122,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option<
Allow(Target::Struct),
Allow(Target::Enum),
Allow(Target::Union),
Warn(Target::MacroCall),
Deny(Target::MacroCall),
]),
);
cx.expect_no_args(param.args())?;
Expand All @@ -135,7 +135,7 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option<
Allow(Target::Struct),
Allow(Target::Enum),
Allow(Target::Union),
Warn(Target::MacroCall),
Deny(Target::MacroCall),
]),
);
cx.expect_no_args(param.args())?;
Expand All @@ -161,8 +161,8 @@ fn parse_repr(cx: &mut AcceptContext<'_, '_>, param: &MetaItemParser) -> Option<
&AllowedTargets::AllowList(&[
Allow(Target::Struct),
Allow(Target::Enum),
Allow(Target::Union), // Feature gated in `rustc_attr_ir_analysis`
Warn(Target::MacroCall),
Allow(Target::Union), // Feature gated in `rustc_hir_analysis`
Deny(Target::MacroCall),
]),
);
cx.expect_no_args(param.args())?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/test_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(crate) struct ShouldPanicParser;

impl SingleAttributeParser for ShouldPanicParser {
const PATH: &[Symbol] = &[sym::should_panic];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnAndFutureError;
const ALLOWED_TARGETS: AllowedTargets<'_> =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Fn), Error(Target::WherePredicate)]);
const TEMPLATE: AttributeTemplate = template!(
Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_attr_ir::{AttrPath, Attribute, AttributeKind};
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan};
use rustc_feature::AttributeStability;
use rustc_lint_defs::builtin::UNUSED_ATTRIBUTES;
use rustc_lint_defs::builtin::{HARMFUL_UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES};
use rustc_lint_defs::{Lint, LintId};
use rustc_parse::parser::Recovery;
use rustc_session::Session;
Expand Down Expand Up @@ -478,6 +478,18 @@ impl<'f, 'sess: 'f> SharedContext<'f, 'sess> {
unused_span,
)
}

pub(crate) fn deny_unused_duplicate_future_error(
&mut self,
used_span: Span,
unused_span: Span,
) {
self.emit_lint(
HARMFUL_UNUSED_ATTRIBUTES,
UnusedDuplicate { this: unused_span, other: used_span, warning: true },
unused_span,
)
}
}

impl<'f, 'sess: 'f> AcceptContext<'f, 'sess> {
Expand Down
Loading
Loading