Skip to content
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3586,6 +3586,7 @@ dependencies = [
"rustc_feature",
"rustc_hir",
"rustc_lexer",
"rustc_lint_defs",
"rustc_macros",
"rustc_parse",
"rustc_parse_format",
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (binder_clause, generic_params) = self.lower_closure_binder(binder);

let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
let mut coroutine_kind = find_attr!(attrs, Coroutine(_) => hir::CoroutineKind::Coroutine(Movability::Movable));
let mut coroutine_kind =
find_attr!(attrs, Coroutine => hir::CoroutineKind::Coroutine(Movability::Movable));

// FIXME(contracts): Support contracts on closures?
let body_id = this.lower_fn_body(decl, None, |this| {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ struct LoweringContext<'a, 'hir> {

impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn new(tcx: TyCtxt<'hir>, resolver: &'a ResolverAstLowering<'hir>) -> Self {
let registered_tools = tcx.registered_tools(()).iter().map(|x| x.name).collect();
Self {
tcx,
resolver,
Expand Down Expand Up @@ -220,7 +219,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
attribute_parser: AttributeParser::new(
tcx.sess,
tcx.features(),
registered_tools,
tcx.registered_tools(()),
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
),
delayed_lints: Vec::new(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_hir = { path = "../rustc_hir" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" }
rustc_parse = { path = "../rustc_parse" }
rustc_parse_format = { path = "../rustc_parse_format" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub(crate) struct CoroutineParser;
impl NoArgsAttributeParser for CoroutineParser {
const PATH: &[Symbol] = &[sym::coroutine];
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Closure)]);
const CREATE: fn(rustc_span::Span) -> AttributeKind = |span| AttributeKind::Coroutine(span);
const CREATE: fn(rustc_span::Span) -> AttributeKind = |_| AttributeKind::Coroutine;
}
24 changes: 16 additions & 8 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl NoArgsAttributeParser for ColdParser {
Allow(Target::ForeignFn),
Allow(Target::Closure),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::Cold;
}

pub(crate) struct CoverageParser;
Expand Down Expand Up @@ -94,7 +94,7 @@ impl SingleAttributeParser for CoverageParser {
}
};

Some(AttributeKind::Coverage(cx.attr_span, kind))
Some(AttributeKind::Coverage(kind))
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ impl SingleAttributeParser for RustcObjcClassParser {
cx.emit_err(NullOnObjcClass { span: nv.value_span });
return None;
}
Some(AttributeKind::RustcObjcClass { classname, span: cx.attr_span })
Some(AttributeKind::RustcObjcClass { classname })
}
}

Expand All @@ -183,7 +183,7 @@ impl SingleAttributeParser for RustcObjcSelectorParser {
cx.emit_err(NullOnObjcSelector { span: nv.value_span });
return None;
}
Some(AttributeKind::RustcObjcSelector { methname, span: cx.attr_span })
Some(AttributeKind::RustcObjcSelector { methname })
}
}

Expand Down Expand Up @@ -264,10 +264,18 @@ impl AttributeParser for NakedParser {

let span = self.span?;

let Some(tools) = cx.tools else {
unreachable!("tools required while parsing attributes");
};

// only if we found a naked attribute do we do the somewhat expensive check
'outer: for other_attr in cx.all_attrs {
for allowed_attr in ALLOW_LIST {
if other_attr.segments().next().is_some_and(|i| cx.tools.contains(&i.name)) {
if other_attr
.segments()
.next()
.is_some_and(|i| tools.iter().any(|tool| tool.name == i.name))
{
// effectively skips the error message being emitted below
// if it's a tool attribute
continue 'outer;
Expand Down Expand Up @@ -436,9 +444,9 @@ impl AttributeParser for UsedParser {
// If a specific form of `used` is specified, it takes precedence over generic `#[used]`.
// If both `linker` and `compiler` are specified, use `linker`.
Some(match (self.first_compiler, self.first_linker, self.first_default) {
(_, Some(span), _) => AttributeKind::Used { used_by: UsedBy::Linker, span },
(Some(span), _, _) => AttributeKind::Used { used_by: UsedBy::Compiler, span },
(_, _, Some(span)) => AttributeKind::Used { used_by: UsedBy::Default, span },
(_, Some(_), _) => AttributeKind::Used { used_by: UsedBy::Linker },
(Some(_), _, _) => AttributeKind::Used { used_by: UsedBy::Compiler },
(_, _, Some(_)) => AttributeKind::Used { used_by: UsedBy::Default },
(None, None, None) => return None,
})
}
Expand Down
34 changes: 9 additions & 25 deletions compiler/rustc_attr_parsing/src/attributes/crate_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ impl SingleAttributeParser for RecursionLimitParser {
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
let nv = cx.expect_name_value(args, cx.attr_span, None)?;

Some(AttributeKind::RecursionLimit {
limit: cx.parse_limit_int(nv)?,
attr_span: cx.attr_span,
limit_span: nv.value_span,
})
Some(AttributeKind::RecursionLimit { limit: cx.parse_limit_int(nv)? })
}
}

Expand All @@ -102,11 +98,7 @@ impl SingleAttributeParser for MoveSizeLimitParser {
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
let nv = cx.expect_name_value(args, cx.attr_span, None)?;

Some(AttributeKind::MoveSizeLimit {
limit: cx.parse_limit_int(nv)?,
attr_span: cx.attr_span,
limit_span: nv.value_span,
})
Some(AttributeKind::MoveSizeLimit { limit: cx.parse_limit_int(nv)? })
}
}

Expand All @@ -121,11 +113,7 @@ impl SingleAttributeParser for TypeLengthLimitParser {
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
let nv = cx.expect_name_value(args, cx.attr_span, None)?;

Some(AttributeKind::TypeLengthLimit {
limit: cx.parse_limit_int(nv)?,
attr_span: cx.attr_span,
limit_span: nv.value_span,
})
Some(AttributeKind::TypeLengthLimit { limit: cx.parse_limit_int(nv)? })
}
}

Expand All @@ -139,11 +127,7 @@ impl SingleAttributeParser for PatternComplexityLimitParser {
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
let nv = cx.expect_name_value(args, cx.attr_span, None)?;

Some(AttributeKind::PatternComplexityLimit {
limit: cx.parse_limit_int(nv)?,
attr_span: cx.attr_span,
limit_span: nv.value_span,
})
Some(AttributeKind::PatternComplexityLimit { limit: cx.parse_limit_int(nv)? })
}
}

Expand All @@ -152,7 +136,7 @@ pub(crate) struct NoCoreParser;
impl NoArgsAttributeParser for NoCoreParser {
const PATH: &[Symbol] = &[sym::no_core];
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoCore;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoCore;
}

pub(crate) struct NoStdParser;
Expand All @@ -161,7 +145,7 @@ impl NoArgsAttributeParser for NoStdParser {
const PATH: &[Symbol] = &[sym::no_std];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoStd;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoStd;
}

pub(crate) struct NoMainParser;
Expand All @@ -178,7 +162,7 @@ pub(crate) struct RustcCoherenceIsCoreParser;
impl NoArgsAttributeParser for RustcCoherenceIsCoreParser {
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcCoherenceIsCore;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcCoherenceIsCore;
}

pub(crate) struct WindowsSubsystemParser;
Expand All @@ -204,7 +188,7 @@ impl SingleAttributeParser for WindowsSubsystemParser {
}
};

Some(AttributeKind::WindowsSubsystem(kind, cx.attr_span))
Some(AttributeKind::WindowsSubsystem(kind))
}
}

Expand Down Expand Up @@ -314,7 +298,7 @@ pub(crate) struct RegisterToolParser;
impl CombineAttributeParser for RegisterToolParser {
const PATH: &[Symbol] = &[sym::register_tool];
type Item = Ident;
const CONVERT: ConvertFn<Self::Item> = AttributeKind::RegisterTool;
const CONVERT: ConvertFn<Self::Item> = |tools, _span| AttributeKind::RegisterTool(tools);
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
const TEMPLATE: AttributeTemplate = template!(List: &["tool1, tool2, ..."]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ impl SingleAttributeParser for DoNotRecommendParser {
return None;
}

Some(AttributeKind::DoNotRecommend { attr_span })
Some(AttributeKind::DoNotRecommend)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl AttributeParser for OnMoveParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);

fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
if let Some(span) = self.span {
Some(AttributeKind::OnMove { span, directive: self.directive.map(|d| Box::new(d.1)) })
if let Some(_span) = self.span {
Some(AttributeKind::OnMove { directive: self.directive.map(|d| Box::new(d.1)) })
} else {
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ impl AttributeParser for OnUnimplementedParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);

fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
if let Some(span) = self.span {
if let Some(_span) = self.span {
Some(AttributeKind::OnUnimplemented {
span,
directive: self.directive.map(|d| Box::new(d.1)),
})
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,8 @@ impl AttributeParser for OnUnknownParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);

fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
if let Some(span) = self.span {
Some(AttributeKind::OnUnknown {
span,
directive: self.directive.map(|d| Box::new(d.1)),
})
if let Some(_span) = self.span {
Some(AttributeKind::OnUnknown { directive: self.directive.map(|d| Box::new(d.1)) })
} else {
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ impl AttributeParser for OnUnmatchArgsParser {
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);

fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
if let Some(span) = self.span {
Some(AttributeKind::OnUnmatchArgs {
span,
directive: self.directive.map(|d| Box::new(d.1)),
})
if let Some(_span) = self.span {
Some(AttributeKind::OnUnmatchArgs { directive: self.directive.map(|d| Box::new(d.1)) })
} else {
None
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl SingleAttributeParser for LinkSectionParser {
BinaryFormat::Coff | BinaryFormat::Elf | BinaryFormat::Wasm | BinaryFormat::Xcoff => {}
}

Some(LinkSection { name, span: cx.attr_span })
Some(LinkSection { name })
}
}

Expand All @@ -537,7 +537,7 @@ impl NoArgsAttributeParser for FfiConstParser {
const PATH: &[Symbol] = &[sym::ffi_const];
const SAFETY: AttributeSafety = AttributeSafety::Unsafe { unsafe_since: None };
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::ForeignFn)]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::FfiConst;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::FfiConst;
}

pub(crate) struct FfiPureParser;
Expand All @@ -557,7 +557,7 @@ impl NoArgsAttributeParser for RustcStdInternalSymbolParser {
Allow(Target::Static),
Allow(Target::ForeignStatic),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcStdInternalSymbol;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcStdInternalSymbol;
}

pub(crate) struct LinkOrdinalParser;
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl NoArgsAttributeParser for RustcAsPtrParser {
Allow(Target::Method(MethodKind::Trait { body: true })),
Allow(Target::Method(MethodKind::TraitImpl)),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcAsPtr;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAsPtr;
}

pub(crate) struct RustcPubTransparentParser;
Expand All @@ -32,7 +32,7 @@ impl NoArgsAttributeParser for RustcPassByValueParser {
Allow(Target::Enum),
Allow(Target::TyAlias),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcPassByValue;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcPassByValue;
}

pub(crate) struct RustcShouldNotBeCalledOnConstItemsParser;
Expand All @@ -42,7 +42,7 @@ impl NoArgsAttributeParser for RustcShouldNotBeCalledOnConstItemsParser {
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::TraitImpl)),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcShouldNotBeCalledOnConstItems;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcShouldNotBeCalledOnConstItems;
}

pub(crate) struct AutomaticallyDerivedParser;
Expand All @@ -54,5 +54,5 @@ impl NoArgsAttributeParser for AutomaticallyDerivedParser {
Error(Target::Crate),
Error(Target::WherePredicate),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AutomaticallyDerived;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::AutomaticallyDerived;
}
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl NoArgsAttributeParser for MacroEscapeParser {
const PATH: &[Symbol] = &[sym::macro_escape];
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets = MACRO_USE_ALLOWED_TARGETS;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::MacroEscape;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::MacroEscape;
}

/// `#[macro_use]` attributes can either:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ impl NoArgsAttributeParser for NoImplicitPreludeParser {
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets =
AllowedTargets::AllowListWarnRest(&[Allow(Target::Mod), Allow(Target::Crate)]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoImplicitPrelude;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoImplicitPrelude;
}
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 @@ -19,6 +19,6 @@ impl SingleAttributeParser for PathParser {
return None;
};

Some(AttributeKind::Path(path, cx.attr_span))
Some(AttributeKind::Path(path))
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/pin_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ impl NoArgsAttributeParser for PinV2Parser {
Allow(Target::Struct),
Allow(Target::Union),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PinV2;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::PinV2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ pub(crate) struct ProcMacroParser;
impl NoArgsAttributeParser for ProcMacroParser {
const PATH: &[Symbol] = &[sym::proc_macro];
const ALLOWED_TARGETS: AllowedTargets = PROC_MACRO_ALLOWED_TARGETS;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::ProcMacro;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ProcMacro;
}

pub(crate) struct ProcMacroAttributeParser;
impl NoArgsAttributeParser for ProcMacroAttributeParser {
const PATH: &[Symbol] = &[sym::proc_macro_attribute];
const ALLOWED_TARGETS: AllowedTargets = PROC_MACRO_ALLOWED_TARGETS;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::ProcMacroAttribute;
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ProcMacroAttribute;
}

pub(crate) struct ProcMacroDeriveParser;
Expand All @@ -33,7 +33,6 @@ impl SingleAttributeParser for ProcMacroDeriveParser {
Some(AttributeKind::ProcMacroDerive {
trait_name: trait_name.expect("Trait name is mandatory, so it is present"),
helper_attrs,
span: cx.attr_span,
})
}
}
Expand All @@ -47,7 +46,7 @@ impl SingleAttributeParser for RustcBuiltinMacroParser {

fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
let (builtin_name, helper_attrs) = parse_derive_like(cx, args, false)?;
Some(AttributeKind::RustcBuiltinMacro { builtin_name, helper_attrs, span: cx.attr_span })
Some(AttributeKind::RustcBuiltinMacro { builtin_name, helper_attrs })
}
}

Expand Down
Loading
Loading