Skip to content

Commit 97252d3

Browse files
Remove from MetaItemParser::from_attr
1 parent 5b150d2 commit 97252d3

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::borrow::Cow;
2+
use std::convert::identity;
23

34
use rustc_ast as ast;
45
use rustc_ast::token::DocFragmentKind;
@@ -13,7 +14,7 @@ use rustc_session::lint::BuiltinLintDiag;
1314
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
1415

1516
use crate::context::{AcceptContext, FinalizeContext, SharedContext, Stage};
16-
use crate::parser::{ArgParser, MetaItemParser, PathParser};
17+
use crate::parser::{ArgParser, PathParser};
1718
use crate::session_diagnostics::ParsedDescription;
1819
use crate::{Early, Late, OmitDoc, ShouldEmit};
1920

@@ -144,22 +145,23 @@ impl<'sess> AttributeParser<'sess, Early> {
144145
};
145146
let parts =
146147
normal_attr.item.path.segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>();
147-
let meta_parser = MetaItemParser::from_attr(normal_attr, &parts, &sess.psess, emit_errors)?;
148-
let path = meta_parser.path();
149-
let args = meta_parser.args();
148+
149+
let path = AttrPath::from_ast(&normal_attr.item.path, identity);
150+
let args =
151+
ArgParser::from_attr_args(&normal_attr.item.args, &parts, &sess.psess, emit_errors)?;
150152
Self::parse_single_args(
151153
sess,
152154
attr.span,
153155
normal_attr.item.span(),
154156
attr.style,
155-
path.get_attribute_path(),
157+
path,
156158
Some(normal_attr.item.unsafety),
157159
ParsedDescription::Attribute,
158160
target_span,
159161
target_node_id,
160162
features,
161163
emit_errors,
162-
args,
164+
&args,
163165
parse_fn,
164166
template,
165167
)
@@ -316,15 +318,14 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
316318
n.item.path.segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>();
317319

318320
if let Some(accepts) = S::parsers().accepters.get(parts.as_slice()) {
319-
let Some(parser) = MetaItemParser::from_attr(
320-
n,
321+
let Some(args) = ArgParser::from_attr_args(
322+
&n.item.args,
321323
&parts,
322324
&self.sess.psess,
323325
self.stage.should_emit(),
324326
) else {
325327
continue;
326328
};
327-
let args = parser.args();
328329

329330
// Special-case handling for `#[doc = "..."]`: if we go through with
330331
// `DocParser`, the order of doc comments will be messed up because `///`
@@ -373,7 +374,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
373374
attr_path: attr_path.clone(),
374375
};
375376

376-
(accept.accept_fn)(&mut cx, args);
377+
(accept.accept_fn)(&mut cx, &args);
377378
if !matches!(cx.stage.should_emit(), ShouldEmit::Nothing) {
378379
Self::check_target(&accept.allowed_targets, target, &mut cx);
379380
}

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::fmt::{Debug, Display};
88

99
use rustc_ast::token::{self, Delimiter, MetaVarKind};
1010
use rustc_ast::tokenstream::TokenStream;
11-
use rustc_ast::{AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, NormalAttr, Path, StmtKind, UnOp};
11+
use rustc_ast::{AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, Path, StmtKind, UnOp};
1212
use rustc_ast_pretty::pprust;
1313
use rustc_errors::{Diag, PResult};
1414
use rustc_hir::{self as hir, AttrPath};
@@ -252,22 +252,6 @@ impl<'a> Debug for MetaItemParser<'a> {
252252
}
253253
}
254254

255-
impl<'a> MetaItemParser<'a> {
256-
/// Create a new parser from a [`NormalAttr`], which is stored inside of any
257-
/// [`ast::Attribute`](rustc_ast::Attribute)
258-
pub fn from_attr<'sess>(
259-
attr: &'a NormalAttr,
260-
parts: &[Symbol],
261-
psess: &'sess ParseSess,
262-
should_emit: ShouldEmit,
263-
) -> Option<Self> {
264-
Some(Self {
265-
path: PathParser(Cow::Borrowed(&attr.item.path)),
266-
args: ArgParser::from_attr_args(&attr.item.args, parts, psess, should_emit)?,
267-
})
268-
}
269-
}
270-
271255
impl<'a> MetaItemParser<'a> {
272256
pub fn span(&self) -> Span {
273257
if let Some(other) = self.args.span() {

0 commit comments

Comments
 (0)