Skip to content

Commit 6c3a59c

Browse files
Remove Stage
1 parent c63bc4b commit 6c3a59c

3 files changed

Lines changed: 9 additions & 64 deletions

File tree

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use std::mem;
55
use std::ops::{Deref, DerefMut};
66
use std::sync::LazyLock;
77

8-
use rustc_ast::{AttrStyle, MetaItemLit, NodeId};
8+
use rustc_ast::{AttrStyle, MetaItemLit};
99
use rustc_data_structures::sync::{DynSend, DynSync};
1010
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan};
1111
use rustc_feature::{AttrSuggestionStyle, AttributeTemplate};
1212
use rustc_hir::AttrPath;
1313
use rustc_hir::attrs::AttributeKind;
14-
use rustc_hir::{AttrPath, HirId};
1514
use rustc_parse::parser::Recovery;
15+
use rustc_session::Session;
1616
use rustc_session::lint::{Lint, LintId};
1717
use rustc_span::{ErrorGuaranteed, Span, Symbol};
1818

@@ -66,7 +66,6 @@ use crate::session_diagnostics::{
6666
};
6767
use crate::target_checking::AllowedTargets;
6868
use crate::{AttributeParser, EmitAttribute};
69-
use crate::context::private::Sealed;
7069

7170
type GroupType = LazyLock<GroupTypeInner>;
7271

@@ -89,20 +88,6 @@ pub(crate) type FinalizeFn = fn(&mut FinalizeContext<'_, '_>) -> Option<Attribut
8988
macro_rules! attribute_parsers {
9089
(
9190
pub(crate) static $name: ident = [$($names: ty),* $(,)?];
92-
) => {
93-
mod early {
94-
use super::*;
95-
96-
attribute_parsers!(@[Early] pub(crate) static $name = [$($names),*];);
97-
}
98-
mod late {
99-
use super::*;
100-
101-
attribute_parsers!(@[Late] pub(crate) static $name = [$($names),*];);
102-
}
103-
};
104-
(
105-
@[$stage: ty] pub(crate) static $name: ident = [$($names: ty),* $(,)?];
10691
) => {
10792
pub(crate) static $name: GroupType = LazyLock::new(|| {
10893
let mut accepters = BTreeMap::<_, GroupTypeInnerAccept>::new();
@@ -337,46 +322,6 @@ attribute_parsers!(
337322
];
338323
);
339324

340-
mod private {
341-
pub trait Sealed {}
342-
impl Sealed for super::Early {}
343-
impl Sealed for super::Late {}
344-
}
345-
346-
// allow because it's a sealed trait
347-
#[allow(private_interfaces)]
348-
pub trait Stage: Sized + 'static + Sealed {
349-
type Id: Copy;
350-
351-
fn parsers() -> &'static GroupType;
352-
}
353-
354-
// allow because it's a sealed trait
355-
#[allow(private_interfaces)]
356-
impl Stage for Early {
357-
type Id = NodeId;
358-
359-
fn parsers() -> &'static GroupType {
360-
&early::ATTRIBUTE_PARSERS
361-
}
362-
}
363-
364-
// allow because it's a sealed trait
365-
#[allow(private_interfaces)]
366-
impl Stage for Late {
367-
type Id = HirId;
368-
369-
fn parsers() -> &'static GroupType {
370-
&late::ATTRIBUTE_PARSERS
371-
}
372-
}
373-
374-
/// Used when parsing attributes for miscellaneous things *before* ast lowering
375-
pub struct Early;
376-
377-
/// used when parsing attributes during ast lowering
378-
pub struct Late;
379-
380325
/// Context given to every attribute parser when accepting
381326
///
382327
/// Gives [`AttributeParser`]s enough information to create errors, for example.
@@ -610,8 +555,6 @@ pub struct SharedContext<'p, 'sess> {
610555
pub(crate) target_span: Span,
611556
pub(crate) target: rustc_hir::Target,
612557

613-
/// The second argument of the closure is a [`NodeId`] if `S` is `Early` and a [`HirId`] if `S`
614-
/// is `Late` and is the ID of the syntactical component this attribute was applied to.
615558
pub(crate) emit_lint: &'p mut dyn FnMut(LintId, MultiSpan, EmitAttribute),
616559
}
617560

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ use rustc_session::lint::LintId;
1313
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1414

1515
use crate::attributes::AttributeSafety;
16-
use crate::context::{AcceptContext, FinalizeContext, FinalizeFn, SharedContext, Stage};
16+
use crate::context::{
17+
ATTRIBUTE_PARSERS, AcceptContext, FinalizeContext, FinalizeFn, SharedContext,
18+
};
1719
use crate::early_parsed::{EARLY_PARSED_ATTRIBUTES, EarlyParsedState};
1820
use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser};
1921
use crate::session_diagnostics::ParsedDescription;
20-
use crate::{Late, OmitDoc, ShouldEmit};
22+
use crate::{OmitDoc, ShouldEmit};
2123

2224
pub struct EmitAttribute(
2325
pub Box<
@@ -333,7 +335,7 @@ impl<'sess> AttributeParser<'sess> {
333335
let parts =
334336
n.item.path.segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>();
335337

336-
if let Some(accept) = Late::parsers().accepters.get(parts.as_slice()) {
338+
if let Some(accept) = ATTRIBUTE_PARSERS.accepters.get(parts.as_slice()) {
337339
self.check_attribute_safety(
338340
&attr_path,
339341
lower_span(n.item.span()),
@@ -472,7 +474,7 @@ impl<'sess> AttributeParser<'sess> {
472474
&[sym::cfg_attr],
473475
];
474476

475-
Late::parsers().accepters.contains_key(path)
477+
ATTRIBUTE_PARSERS.accepters.contains_key(path)
476478
|| EARLY_PARSED_ATTRIBUTES.contains(&path)
477479
|| SPECIAL_ATTRIBUTES.contains(&path)
478480
}

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub use attributes::cfg::{
112112
};
113113
pub use attributes::cfg_select::*;
114114
pub use attributes::util::{is_builtin_attr, parse_version};
115-
pub use context::{Early, Late, OmitDoc, ShouldEmit};
115+
pub use context::{OmitDoc, ShouldEmit};
116116
pub use interface::{AttributeParser, EmitAttribute};
117117
pub use rustc_parse::parser::Recovery;
118118
pub use session_diagnostics::ParsedDescription;

0 commit comments

Comments
 (0)