Skip to content

Commit fc6070c

Browse files
authored
Rollup merge of #124324 - nnethercote:minor-ast-cleanups, r=estebank
Minor AST cleanups r? ``@estebank``
2 parents a2d6b1b + 2ae0765 commit fc6070c

File tree

7 files changed

+79
-90
lines changed

7 files changed

+79
-90
lines changed

compiler/rustc_ast/src/ast.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2786,6 +2786,7 @@ pub enum AttrKind {
27862786
#[derive(Clone, Encodable, Decodable, Debug)]
27872787
pub struct NormalAttr {
27882788
pub item: AttrItem,
2789+
// Tokens for the full attribute, e.g. `#[foo]`, `#![bar]`.
27892790
pub tokens: Option<LazyAttrTokenStream>,
27902791
}
27912792

@@ -2802,6 +2803,7 @@ impl NormalAttr {
28022803
pub struct AttrItem {
28032804
pub path: Path,
28042805
pub args: AttrArgs,
2806+
// Tokens for the meta item, e.g. just the `foo` within `#[foo]` or `#![foo]`.
28052807
pub tokens: Option<LazyAttrTokenStream>,
28062808
}
28072809

compiler/rustc_ast/src/attr/mod.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ impl MetaItem {
298298
}
299299

300300
pub fn value_str(&self) -> Option<Symbol> {
301-
self.kind.value_str()
301+
match &self.kind {
302+
MetaItemKind::NameValue(v) => v.kind.str(),
303+
_ => None,
304+
}
302305
}
303306

304307
fn from_tokens<'a, I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItem>
@@ -362,13 +365,6 @@ impl MetaItem {
362365
}
363366

364367
impl MetaItemKind {
365-
pub fn value_str(&self) -> Option<Symbol> {
366-
match self {
367-
MetaItemKind::NameValue(v) => v.kind.str(),
368-
_ => None,
369-
}
370-
}
371-
372368
fn list_from_tokens(tokens: TokenStream) -> Option<ThinVec<NestedMetaItem>> {
373369
let mut tokens = tokens.trees().peekable();
374370
let mut result = ThinVec::new();
@@ -468,8 +464,9 @@ impl NestedMetaItem {
468464
self.meta_item().and_then(|meta_item| meta_item.meta_item_list())
469465
}
470466

471-
/// Returns a name and single literal value tuple of the `MetaItem`.
472-
pub fn name_value_literal(&self) -> Option<(Symbol, &MetaItemLit)> {
467+
/// If it's a singleton list of the form `foo(lit)`, returns the `foo` and
468+
/// the `lit`.
469+
pub fn singleton_lit_list(&self) -> Option<(Symbol, &MetaItemLit)> {
473470
self.meta_item().and_then(|meta_item| {
474471
meta_item.meta_item_list().and_then(|meta_item_list| {
475472
if meta_item_list.len() == 1

0 commit comments

Comments
 (0)