Skip to content

Commit f2001ec

Browse files
authored
Unrolled build for #141271
Rollup merge of #141271 - nnethercote:attr-streamline, r=jdonszelmann Streamline some attr parsing APIs r? ``@jdonszelmann``
2 parents df8102f + e5c78de commit f2001ec

File tree

6 files changed

+19
-64
lines changed

6 files changed

+19
-64
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn parse_unstable<'a>(
5353

5454
for param in list.mixed() {
5555
let param_span = param.span();
56-
if let Some(ident) = param.meta_item().and_then(|i| i.path_without_args().word()) {
56+
if let Some(ident) = param.meta_item().and_then(|i| i.path().word()) {
5757
res.push(ident.name);
5858
} else {
5959
cx.emit_err(session_diagnostics::ExpectsFeatures {

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl SingleAttributeParser for DeprecationParser {
7979
return None;
8080
};
8181

82-
let ident_name = param.path_without_args().word_sym();
82+
let ident_name = param.path().word_sym();
8383

8484
match ident_name {
8585
Some(name @ sym::since) => {
@@ -102,7 +102,7 @@ impl SingleAttributeParser for DeprecationParser {
102102
_ => {
103103
cx.emit_err(session_diagnostics::UnknownMetaItem {
104104
span: param_span,
105-
item: param.path_without_args().to_string(),
105+
item: param.path().to_string(),
106106
expected: if features.deprecated_suggestion() {
107107
&["since", "note", "suggestion"]
108108
} else {

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
9696

9797
// FIXME(jdonszelmann): invert the parsing here to match on the word first and then the
9898
// structure.
99-
let (name, ident_span) = if let Some(ident) = param.path_without_args().word() {
99+
let (name, ident_span) = if let Some(ident) = param.path().word() {
100100
(Some(ident.name), ident.span)
101101
} else {
102102
(None, DUMMY_SP)

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn insert_value_into_option_or_error(
204204
if item.is_some() {
205205
cx.emit_err(session_diagnostics::MultipleItem {
206206
span: param.span(),
207-
item: param.path_without_args().to_string(),
207+
item: param.path().to_string(),
208208
});
209209
None
210210
} else if let Some(v) = param.args().name_value()
@@ -242,13 +242,13 @@ pub(crate) fn parse_stability(
242242
return None;
243243
};
244244

245-
match param.path_without_args().word_sym() {
245+
match param.path().word_sym() {
246246
Some(sym::feature) => insert_value_into_option_or_error(cx, &param, &mut feature)?,
247247
Some(sym::since) => insert_value_into_option_or_error(cx, &param, &mut since)?,
248248
_ => {
249249
cx.emit_err(session_diagnostics::UnknownMetaItem {
250250
span: param_span,
251-
item: param.path_without_args().to_string(),
251+
item: param.path().to_string(),
252252
expected: &["feature", "since"],
253253
});
254254
return None;
@@ -310,7 +310,7 @@ pub(crate) fn parse_unstability(
310310
return None;
311311
};
312312

313-
match param.path_without_args().word_sym() {
313+
match param.path().word_sym() {
314314
Some(sym::feature) => insert_value_into_option_or_error(cx, &param, &mut feature)?,
315315
Some(sym::reason) => insert_value_into_option_or_error(cx, &param, &mut reason)?,
316316
Some(sym::issue) => {
@@ -349,7 +349,7 @@ pub(crate) fn parse_unstability(
349349
_ => {
350350
cx.emit_err(session_diagnostics::UnknownMetaItem {
351351
span: param.span(),
352-
item: param.path_without_args().to_string(),
352+
item: param.path().to_string(),
353353
expected: &["feature", "reason", "issue", "soft", "implied_by"],
354354
});
355355
return None;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ impl<'sess> AttributeParser<'sess> {
264264
// }
265265
ast::AttrKind::Normal(n) => {
266266
let parser = MetaItemParser::from_attr(n, self.dcx());
267-
let (path, args) = parser.deconstruct();
267+
let path = parser.path();
268+
let args = parser.args();
268269
let parts = path.segments().map(|i| i.name).collect::<Vec<_>>();
269270

270271
if let Some(accept) = ATTRIBUTE_MAPPING.0.get(parts.as_slice()) {

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -252,35 +252,18 @@ impl<'a> MetaItemParser<'a> {
252252
}
253253
}
254254

255-
/// Gets just the path, without the args.
256-
pub fn path_without_args(&self) -> PathParser<'a> {
257-
self.path.clone()
258-
}
259-
260-
/// Gets just the args parser, without caring about the path.
261-
pub fn args(&self) -> &ArgParser<'a> {
262-
&self.args
263-
}
264-
265-
pub fn deconstruct(&self) -> (PathParser<'a>, &ArgParser<'a>) {
266-
(self.path_without_args(), self.args())
267-
}
268-
269-
/// Asserts that this MetaItem starts with a path. Some examples:
255+
/// Gets just the path, without the args. Some examples:
270256
///
271257
/// - `#[rustfmt::skip]`: `rustfmt::skip` is a path
272258
/// - `#[allow(clippy::complexity)]`: `clippy::complexity` is a path
273259
/// - `#[inline]`: `inline` is a single segment path
274-
pub fn path(&self) -> (PathParser<'a>, &ArgParser<'a>) {
275-
self.deconstruct()
260+
pub fn path(&self) -> &PathParser<'a> {
261+
&self.path
276262
}
277263

278-
/// Asserts that this MetaItem starts with a word, or single segment path.
279-
/// Doesn't return the args parser.
280-
///
281-
/// For examples. see [`Self::word`]
282-
pub fn word_without_args(&self) -> Option<Ident> {
283-
Some(self.word()?.0)
264+
/// Gets just the args parser, without caring about the path.
265+
pub fn args(&self) -> &ArgParser<'a> {
266+
&self.args
284267
}
285268

286269
/// Asserts that this MetaItem starts with a word, or single segment path.
@@ -289,23 +272,8 @@ impl<'a> MetaItemParser<'a> {
289272
/// - `#[inline]`: `inline` is a word
290273
/// - `#[rustfmt::skip]`: `rustfmt::skip` is a path,
291274
/// and not a word and should instead be parsed using [`path`](Self::path)
292-
pub fn word(&self) -> Option<(Ident, &ArgParser<'a>)> {
293-
let (path, args) = self.deconstruct();
294-
Some((path.word()?, args))
295-
}
296-
297-
/// Asserts that this MetaItem starts with some specific word.
298-
///
299-
/// See [`word`](Self::word) for examples of what a word is.
300275
pub fn word_is(&self, sym: Symbol) -> Option<&ArgParser<'a>> {
301-
self.path_without_args().word_is(sym).then(|| self.args())
302-
}
303-
304-
/// Asserts that this MetaItem starts with some specific path.
305-
///
306-
/// See [`word`](Self::path) for examples of what a word is.
307-
pub fn path_is(&self, segments: &[Symbol]) -> Option<&ArgParser<'a>> {
308-
self.path_without_args().segments_is(segments).then(|| self.args())
276+
self.path().word_is(sym).then(|| self.args())
309277
}
310278
}
311279

@@ -548,7 +516,7 @@ impl<'a> MetaItemListParser<'a> {
548516
}
549517

550518
/// Lets you pick and choose as what you want to parse each element in the list
551-
pub fn mixed<'s>(&'s self) -> impl Iterator<Item = &'s MetaItemOrLitParser<'a>> + 's {
519+
pub fn mixed(&self) -> impl Iterator<Item = &MetaItemOrLitParser<'a>> {
552520
self.sub_parsers.iter()
553521
}
554522

@@ -560,20 +528,6 @@ impl<'a> MetaItemListParser<'a> {
560528
self.len() == 0
561529
}
562530

563-
/// Asserts that every item in the list is another list starting with a word.
564-
///
565-
/// See [`MetaItemParser::word`] for examples of words.
566-
pub fn all_word_list<'s>(&'s self) -> Option<Vec<(Ident, &'s ArgParser<'a>)>> {
567-
self.mixed().map(|i| i.meta_item()?.word()).collect()
568-
}
569-
570-
/// Asserts that every item in the list is another list starting with a full path.
571-
///
572-
/// See [`MetaItemParser::path`] for examples of paths.
573-
pub fn all_path_list<'s>(&'s self) -> Option<Vec<(PathParser<'a>, &'s ArgParser<'a>)>> {
574-
self.mixed().map(|i| Some(i.meta_item()?.path())).collect()
575-
}
576-
577531
/// Returns Some if the list contains only a single element.
578532
///
579533
/// Inside the Some is the parser to parse this single element.

0 commit comments

Comments
 (0)