Skip to content

Commit 3dfa938

Browse files
Remove from MetaItemParser::from_attr
1 parent 5bc3450 commit 3dfa938

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::{AttrStyle, NodeId, Safety};
@@ -12,7 +13,7 @@ use rustc_session::lint::BuiltinLintDiag;
1213
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
1314

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

@@ -143,22 +144,23 @@ impl<'sess> AttributeParser<'sess, Early> {
143144
};
144145
let parts =
145146
normal_attr.item.path.segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>();
146-
let meta_parser = MetaItemParser::from_attr(normal_attr, &parts, &sess.psess, emit_errors)?;
147-
let path = meta_parser.path();
148-
let args = meta_parser.args();
147+
148+
let path = AttrPath::from_ast(&normal_attr.item.path, identity);
149+
let args =
150+
ArgParser::from_attr_args(&normal_attr.item.args, &parts, &sess.psess, emit_errors)?;
149151
Self::parse_single_args(
150152
sess,
151153
attr.span,
152154
normal_attr.item.span(),
153155
attr.style,
154-
path.get_attribute_path(),
156+
path,
155157
Some(normal_attr.item.unsafety),
156158
ParsedDescription::Attribute,
157159
target_span,
158160
target_node_id,
159161
features,
160162
emit_errors,
161-
args,
163+
&args,
162164
parse_fn,
163165
template,
164166
)
@@ -325,15 +327,14 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
325327
n.item.path.segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>();
326328

327329
if let Some(accepts) = S::parsers().accepters.get(parts.as_slice()) {
328-
let Some(parser) = MetaItemParser::from_attr(
329-
n,
330+
let Some(args) = ArgParser::from_attr_args(
331+
&n.item.args,
330332
&parts,
331333
&self.sess.psess,
332334
self.stage.should_emit(),
333335
) else {
334336
continue;
335337
};
336-
let args = parser.args();
337338
for accept in accepts {
338339
let mut cx: AcceptContext<'_, 'sess, S> = AcceptContext {
339340
shared: SharedContext {
@@ -350,7 +351,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
350351
attr_path: attr_path.clone(),
351352
};
352353

353-
(accept.accept_fn)(&mut cx, args);
354+
(accept.accept_fn)(&mut cx, &args);
354355
if !matches!(cx.stage.should_emit(), ShouldEmit::Nothing) {
355356
Self::check_target(&accept.allowed_targets, target, &mut cx);
356357
}

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};
11+
use rustc_ast::{AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, Path};
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)