Skip to content

Commit 545613b

Browse files
Port #[rustc_object_lifetime_default] to the new attribute parsing infrastructure
1 parent f191420 commit 545613b

File tree

6 files changed

+61
-8
lines changed

6 files changed

+61
-8
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ pub enum UsedBy {
195195
pub enum AttributeKind {
196196
// tidy-alphabetical-start
197197
/// Represents `#[align(N)]`.
198-
Align { align: Align, span: Span },
198+
Align {
199+
align: Align,
200+
span: Span,
201+
},
199202

200203
/// Represents `#[rustc_allow_const_fn_unstable]`.
201204
AllowConstFnUnstable(ThinVec<Symbol>),
@@ -237,10 +240,18 @@ pub enum AttributeKind {
237240
ConstStabilityIndirect,
238241

239242
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).
240-
Deprecation { deprecation: Deprecation, span: Span },
243+
Deprecation {
244+
deprecation: Deprecation,
245+
span: Span,
246+
},
241247

242248
/// Represents [`#[doc]`](https://doc.rust-lang.org/stable/rustdoc/write-documentation/the-doc-attribute.html).
243-
DocComment { style: AttrStyle, kind: CommentKind, span: Span, comment: Symbol },
249+
DocComment {
250+
style: AttrStyle,
251+
kind: CommentKind,
252+
span: Span,
253+
comment: Symbol,
254+
},
244255

245256
/// Represents [`#[export_name]`](https://doc.rust-lang.org/reference/abi.html#the-export_name-attribute).
246257
ExportName {
@@ -254,7 +265,10 @@ pub enum AttributeKind {
254265
Inline(InlineAttr, Span),
255266

256267
/// Represents `#[link_name]`.
257-
LinkName { name: Symbol, span: Span },
268+
LinkName {
269+
name: Symbol,
270+
span: Span,
271+
},
258272

259273
/// Represents `#[loop_match]`.
260274
LoopMatch(Span),
@@ -287,8 +301,14 @@ pub enum AttributeKind {
287301
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
288302
Repr(ThinVec<(ReprAttr, Span)>),
289303

304+
RustcObjectLifetimeDefault,
305+
290306
/// Represents `#[rustc_skip_during_method_dispatch]`.
291-
SkipDuringMethodDispatch { array: bool, boxed_slice: bool, span: Span },
307+
SkipDuringMethodDispatch {
308+
array: bool,
309+
boxed_slice: bool,
310+
span: Span,
311+
},
292312

293313
/// Represents `#[stable]`, `#[unstable]` and `#[rustc_allowed_through_unstable_modules]`.
294314
Stability {
@@ -301,6 +321,9 @@ pub enum AttributeKind {
301321
TrackCaller(Span),
302322

303323
/// Represents `#[used]`
304-
Used { used_by: UsedBy, span: Span },
324+
Used {
325+
used_by: UsedBy,
326+
span: Span,
327+
},
305328
// tidy-alphabetical-end
306329
}

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl AttributeKind {
3737
NoMangle(..) => No,
3838
Optimize(..) => No,
3939
PubTransparent(..) => Yes,
40+
RustcObjectLifetimeDefault => No,
4041
SkipDuringMethodDispatch { .. } => No,
4142
TrackCaller(..) => Yes,
4243
Used { .. } => No,

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub(crate) mod lint_helpers;
3636
pub(crate) mod loop_match;
3737
pub(crate) mod must_use;
3838
pub(crate) mod repr;
39+
pub(crate) mod rustc_internal;
3940
pub(crate) mod semantics;
4041
pub(crate) mod stability;
4142
pub(crate) mod traits;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use rustc_attr_data_structures::AttributeKind;
2+
use rustc_feature::{AttributeTemplate, template};
3+
use rustc_span::sym;
4+
5+
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
6+
use crate::context::{AcceptContext, Stage};
7+
use crate::parser::ArgParser;
8+
9+
pub(crate) struct RustcObjectLifetimeDefaultParser;
10+
11+
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {
12+
const PATH: &[rustc_span::Symbol] = &[sym::rustc_object_lifetime_default];
13+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
14+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
15+
const TEMPLATE: AttributeTemplate = template!(Word);
16+
17+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
18+
if let Err(span) = args.no_args() {
19+
cx.expected_no_args(span);
20+
return None;
21+
}
22+
23+
Some(AttributeKind::RustcObjectLifetimeDefault)
24+
}
25+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
2727
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
2828
use crate::attributes::must_use::MustUseParser;
2929
use crate::attributes::repr::{AlignParser, ReprParser};
30+
use crate::attributes::rustc_internal::RustcObjectLifetimeDefaultParser;
3031
use crate::attributes::semantics::MayDangleParser;
3132
use crate::attributes::stability::{
3233
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
@@ -130,6 +131,7 @@ attribute_parsers!(
130131
Single<OptimizeParser>,
131132
Single<PubTransparentParser>,
132133
Single<RustcForceInlineParser>,
134+
Single<RustcObjectLifetimeDefaultParser>,
133135
Single<SkipDuringMethodDispatchParser>,
134136
Single<TrackCallerParser>,
135137
Single<TransparencyParser>,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
164164
}
165165
Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */
166166
}
167-
167+
Attribute::Parsed(AttributeKind::RustcObjectLifetimeDefault) => {
168+
self.check_object_lifetime_default(hir_id);
169+
}
168170
&Attribute::Parsed(AttributeKind::PubTransparent(attr_span)) => {
169171
self.check_rustc_pub_transparent(attr_span, span, attrs)
170172
}
@@ -301,7 +303,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
301303
[sym::no_implicit_prelude, ..] => {
302304
self.check_generic_attr(hir_id, attr, target, Target::Mod)
303305
}
304-
[sym::rustc_object_lifetime_default, ..] => self.check_object_lifetime_default(hir_id),
305306
[sym::proc_macro, ..] => {
306307
self.check_proc_macro(hir_id, target, ProcMacroKind::FunctionLike)
307308
}

0 commit comments

Comments
 (0)