Skip to content

Commit bfdcf97

Browse files
committed
Put spans in all parsed attributes
1 parent 9c4ff56 commit bfdcf97

File tree

26 files changed

+157
-114
lines changed

26 files changed

+157
-114
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ pub enum AttributeKind {
187187
Align { align: Align, span: Span },
188188

189189
/// Represents `#[rustc_allow_const_fn_unstable]`.
190-
AllowConstFnUnstable(ThinVec<Symbol>),
190+
AllowConstFnUnstable { features: ThinVec<(Symbol, Span)> },
191191

192192
/// Represents `#[allow_internal_unstable]`.
193-
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
193+
AllowInternalUnstable { features: ThinVec<(Symbol, Span)> },
194194

195195
/// Represents `#[rustc_as_ptr]` (used by the `dangling_pointers_from_temporaries` lint).
196-
AsPtr(Span),
196+
AsPtr { span: Span },
197197

198198
/// Represents `#[rustc_default_body_unstable]`.
199199
BodyStability {
@@ -217,7 +217,7 @@ pub enum AttributeKind {
217217
},
218218

219219
/// Represents `#[rustc_const_stable_indirect]`.
220-
ConstStabilityIndirect,
220+
ConstStabilityIndirect { span: Span },
221221

222222
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).
223223
Deprecation { deprecation: Deprecation, span: Span },
@@ -226,14 +226,14 @@ pub enum AttributeKind {
226226
DocComment { style: AttrStyle, kind: CommentKind, span: Span, comment: Symbol },
227227

228228
/// Represents `#[inline]` and `#[rustc_force_inline]`.
229-
Inline(InlineAttr, Span),
229+
Inline { kind: InlineAttr, span: Span },
230230

231231
/// Represents `#[rustc_macro_transparency]`.
232-
MacroTransparency(Transparency),
232+
MacroTransparency { transparency: Transparency, span: Span },
233233
/// Represents `#[optimize(size|speed)]`
234-
Optimize(OptimizeAttr, Span),
234+
Optimize { kind: OptimizeAttr, span: Span },
235235
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
236-
Repr(ThinVec<(ReprAttr, Span)>),
236+
Repr { reprs: ThinVec<(ReprAttr, Span)> },
237237

238238
/// Represents `#[stable]`, `#[unstable]` and `#[rustc_allowed_through_unstable_modules]`.
239239
Stability {

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::iter;
2-
31
use rustc_attr_data_structures::AttributeKind;
42
use rustc_feature::{AttributeTemplate, template};
53
use rustc_span::{Span, Symbol, sym};
@@ -13,24 +11,24 @@ pub(crate) struct AllowInternalUnstableParser;
1311
impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser {
1412
const PATH: &[Symbol] = &[sym::allow_internal_unstable];
1513
type Item = (Symbol, Span);
16-
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowInternalUnstable;
14+
const CONVERT: ConvertFn<Self::Item> =
15+
|features| AttributeKind::AllowInternalUnstable { features };
1716
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
1817

1918
fn extend<'c>(
2019
cx: &'c mut AcceptContext<'_, '_, S>,
2120
args: &'c ArgParser<'_>,
2221
) -> impl IntoIterator<Item = Self::Item> {
2322
parse_unstable(cx, args, <Self as CombineAttributeParser<S>>::PATH[0])
24-
.into_iter()
25-
.zip(iter::repeat(cx.attr_span))
2623
}
2724
}
2825

2926
pub(crate) struct AllowConstFnUnstableParser;
3027
impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
3128
const PATH: &[Symbol] = &[sym::rustc_allow_const_fn_unstable];
32-
type Item = Symbol;
33-
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowConstFnUnstable;
29+
type Item = (Symbol, Span);
30+
const CONVERT: ConvertFn<Self::Item> =
31+
|features| AttributeKind::AllowConstFnUnstable { features };
3432
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
3533

3634
fn extend<'c>(
@@ -45,7 +43,7 @@ fn parse_unstable<S: Stage>(
4543
cx: &AcceptContext<'_, '_, S>,
4644
args: &ArgParser<'_>,
4745
symbol: Symbol,
48-
) -> impl IntoIterator<Item = Symbol> {
46+
) -> impl IntoIterator<Item = (Symbol, Span)> {
4947
let mut res = Vec::new();
5048

5149
let Some(list) = args.list() else {
@@ -59,7 +57,7 @@ fn parse_unstable<S: Stage>(
5957
for param in list.mixed() {
6058
let param_span = param.span();
6159
if let Some(ident) = param.meta_item().and_then(|i| i.path().word()) {
62-
res.push(ident.name);
60+
res.push((ident.name, param_span));
6361
} else {
6462
cx.emit_err(session_diagnostics::ExpectsFeatures {
6563
span: param_span,

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
2525
return None;
2626
};
2727

28-
let res = match single.meta_item().and_then(|i| i.path().word().map(|i| i.name)) {
28+
let kind = match single.meta_item().and_then(|i| i.path().word().map(|i| i.name)) {
2929
Some(sym::size) => OptimizeAttr::Size,
3030
Some(sym::speed) => OptimizeAttr::Speed,
3131
Some(sym::none) => OptimizeAttr::DoNotOptimize,
@@ -35,6 +35,6 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
3535
}
3636
};
3737

38-
Some(AttributeKind::Optimize(res, cx.attr_span))
38+
Some(AttributeKind::Optimize { kind, span: cx.attr_span })
3939
}
4040
}

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
2121
const TEMPLATE: AttributeTemplate = template!(Word, List: "always|never");
2222

2323
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
24+
let span = cx.attr_span;
2425
match args {
25-
ArgParser::NoArgs => Some(AttributeKind::Inline(InlineAttr::Hint, cx.attr_span)),
26+
ArgParser::NoArgs => Some(AttributeKind::Inline { kind: InlineAttr::Hint, span }),
2627
ArgParser::List(list) => {
2728
let Some(l) = list.single() else {
2829
cx.expected_single_argument(list.span);
@@ -31,10 +32,10 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
3132

3233
match l.meta_item().and_then(|i| i.path().word_sym()) {
3334
Some(sym::always) => {
34-
Some(AttributeKind::Inline(InlineAttr::Always, cx.attr_span))
35+
Some(AttributeKind::Inline { kind: InlineAttr::Always, span })
3536
}
3637
Some(sym::never) => {
37-
Some(AttributeKind::Inline(InlineAttr::Never, cx.attr_span))
38+
Some(AttributeKind::Inline { kind: InlineAttr::Never, span })
3839
}
3940
_ => {
4041
cx.expected_specific_argument(l.span(), vec!["always", "never"]);
@@ -89,9 +90,9 @@ impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
8990
}
9091
};
9192

92-
Some(AttributeKind::Inline(
93-
InlineAttr::Force { attr_span: cx.attr_span, reason },
94-
cx.attr_span,
95-
))
93+
Some(AttributeKind::Inline {
94+
kind: InlineAttr::Force { attr_span: cx.attr_span, reason },
95+
span: cx.attr_span,
96+
})
9697
}
9798
}

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ impl<S: Stage> SingleAttributeParser<S> for AsPtrParser {
1616

1717
fn convert(cx: &mut AcceptContext<'_, '_, S>, _args: &ArgParser<'_>) -> Option<AttributeKind> {
1818
// FIXME: check that there's no args (this is currently checked elsewhere)
19-
Some(AttributeKind::AsPtr(cx.attr_span))
19+
Some(AttributeKind::AsPtr { span: cx.attr_span })
2020
}
2121
}

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) struct ReprParser;
2323
impl<S: Stage> CombineAttributeParser<S> for ReprParser {
2424
type Item = (ReprAttr, Span);
2525
const PATH: &[Symbol] = &[sym::repr];
26-
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Repr;
26+
const CONVERT: ConvertFn<Self::Item> = |reprs| AttributeKind::Repr { reprs };
2727
// FIXME(jdonszelmann): never used
2828
const TEMPLATE: AttributeTemplate = template!(List: "C");
2929

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ impl<S: Stage> SingleAttributeParser<S> for ConstStabilityIndirectParser {
139139
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
140140
const TEMPLATE: AttributeTemplate = template!(Word);
141141

142-
fn convert(_cx: &mut AcceptContext<'_, '_, S>, _args: &ArgParser<'_>) -> Option<AttributeKind> {
143-
Some(AttributeKind::ConstStabilityIndirect)
142+
fn convert(cx: &mut AcceptContext<'_, '_, S>, _args: &ArgParser<'_>) -> Option<AttributeKind> {
143+
Some(AttributeKind::ConstStabilityIndirect { span: cx.attr_span })
144144
}
145145
}
146146

compiler/rustc_attr_parsing/src/attributes/transparency.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ impl<S: Stage> SingleAttributeParser<S> for TransparencyParser {
2626
cx.expected_name_value(cx.attr_span, None);
2727
return None;
2828
};
29-
match nv.value_as_str() {
30-
Some(sym::transparent) => Some(Transparency::Transparent),
31-
Some(sym::semiopaque | sym::semitransparent) => Some(Transparency::SemiOpaque),
32-
Some(sym::opaque) => Some(Transparency::Opaque),
33-
Some(_) => {
29+
30+
let transparency = match nv.value_as_str()? {
31+
sym::transparent => Transparency::Transparent,
32+
sym::semiopaque | sym::semitransparent => Transparency::SemiOpaque,
33+
sym::opaque => Transparency::Opaque,
34+
_ => {
3435
cx.expected_specific_argument_strings(
3536
nv.value_span,
3637
vec!["transparent", "semitransparent", "opaque"],
3738
);
38-
None
39+
return None;
3940
}
40-
None => None,
41-
}
42-
.map(AttributeKind::MacroTransparency)
41+
};
42+
Some(AttributeKind::MacroTransparency { transparency, span: cx.attr_span })
4343
}
4444
}

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<'a> TraitDef<'a> {
485485
Annotatable::Item(item) => {
486486
let is_packed = matches!(
487487
AttributeParser::parse_limited(cx.sess, &item.attrs, sym::repr, item.span, item.id),
488-
Some(Attribute::Parsed(AttributeKind::Repr(r))) if r.iter().any(|(x, _)| matches!(x, ReprPacked(..)))
488+
Some(Attribute::Parsed(AttributeKind::Repr{reprs})) if reprs.iter().any(|(x, _)| matches!(x, ReprPacked(..)))
489489
);
490490

491491
let newitem = match &item.kind {

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
442442

443443
let inline_span;
444444
(codegen_fn_attrs.inline, inline_span) = if let Some((inline_attr, span)) =
445-
find_attr!(attrs, AttributeKind::Inline(i, span) => (*i, *span))
445+
find_attr!(attrs, AttributeKind::Inline{kind, span} => (*kind, *span))
446446
{
447447
(inline_attr, Some(span))
448448
} else {
@@ -456,8 +456,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
456456
codegen_fn_attrs.inline = InlineAttr::Never;
457457
}
458458

459-
codegen_fn_attrs.optimize =
460-
find_attr!(attrs, AttributeKind::Optimize(i, _) => *i).unwrap_or(OptimizeAttr::Default);
459+
codegen_fn_attrs.optimize = find_attr!(attrs, AttributeKind::Optimize{kind, ..} => *kind)
460+
.unwrap_or(OptimizeAttr::Default);
461461

462462
// #73631: closures inherit `#[target_feature]` annotations
463463
//

0 commit comments

Comments
 (0)