Skip to content

Commit

Permalink
Auto merge of #131235 - codemountains:rename-nestedmetaitem-to-metait…
Browse files Browse the repository at this point in the history
…emlnner, r=nnethercote

Rename `NestedMetaItem` to `MetaItemInner`

Fixes #131087

r? `@nnethercote`
  • Loading branch information
bors committed Oct 7, 2024
2 parents 690332a + fc64ff7 commit 0b16baa
Show file tree
Hide file tree
Showing 43 changed files with 186 additions and 191 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ pub enum MetaItemKind {
/// List meta item.
///
/// E.g., `#[derive(..)]`, where the field represents the `..`.
List(ThinVec<NestedMetaItem>),
List(ThinVec<MetaItemInner>),

/// Name value meta item.
///
Expand All @@ -523,7 +523,7 @@ pub enum MetaItemKind {
///
/// E.g., each of `Clone`, `Copy` in `#[derive(Clone, Copy)]`.
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum NestedMetaItem {
pub enum MetaItemInner {
/// A full MetaItem, for recursive meta items.
MetaItem(MetaItem),

Expand Down
48 changes: 24 additions & 24 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use thin_vec::{ThinVec, thin_vec};

use crate::ast::{
AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, DUMMY_NODE_ID,
DelimArgs, Expr, ExprKind, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem,
DelimArgs, Expr, ExprKind, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit,
NormalAttr, Path, PathSegment, Safety,
};
use crate::ptr::P;
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Attribute {
}
}

pub fn meta_item_list(&self) -> Option<ThinVec<NestedMetaItem>> {
pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
match &self.kind {
AttrKind::Normal(normal) => normal.item.meta_item_list(),
AttrKind::DocComment(..) => None,
Expand Down Expand Up @@ -223,7 +223,7 @@ impl AttrItem {
self.args.span().map_or(self.path.span, |args_span| self.path.span.to(args_span))
}

fn meta_item_list(&self) -> Option<ThinVec<NestedMetaItem>> {
fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
match &self.args {
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
MetaItemKind::list_from_tokens(args.tokens.clone())
Expand Down Expand Up @@ -285,7 +285,7 @@ impl MetaItem {
matches!(self.kind, MetaItemKind::Word)
}

pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
pub fn meta_item_list(&self) -> Option<&[MetaItemInner]> {
match &self.kind {
MetaItemKind::List(l) => Some(&**l),
_ => None,
Expand Down Expand Up @@ -393,11 +393,11 @@ impl MetaItem {
}

impl MetaItemKind {
fn list_from_tokens(tokens: TokenStream) -> Option<ThinVec<NestedMetaItem>> {
fn list_from_tokens(tokens: TokenStream) -> Option<ThinVec<MetaItemInner>> {
let mut tokens = tokens.trees().peekable();
let mut result = ThinVec::new();
while tokens.peek().is_some() {
let item = NestedMetaItem::from_tokens(&mut tokens)?;
let item = MetaItemInner::from_tokens(&mut tokens)?;
result.push(item);
match tokens.next() {
None | Some(TokenTree::Token(Token { kind: token::Comma, .. }, _)) => {}
Expand Down Expand Up @@ -460,11 +460,11 @@ impl MetaItemKind {
}
}

impl NestedMetaItem {
impl MetaItemInner {
pub fn span(&self) -> Span {
match self {
NestedMetaItem::MetaItem(item) => item.span,
NestedMetaItem::Lit(lit) => lit.span,
MetaItemInner::MetaItem(item) => item.span,
MetaItemInner::Lit(lit) => lit.span,
}
}

Expand All @@ -488,7 +488,7 @@ impl NestedMetaItem {
}

/// Gets a list of inner meta items from a list `MetaItem` type.
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
pub fn meta_item_list(&self) -> Option<&[MetaItemInner]> {
self.meta_item().and_then(|meta_item| meta_item.meta_item_list())
}

Expand Down Expand Up @@ -519,28 +519,28 @@ impl NestedMetaItem {
self.meta_item().and_then(|meta_item| meta_item.value_str())
}

/// Returns the `MetaItemLit` if `self` is a `NestedMetaItem::Literal`s.
/// Returns the `MetaItemLit` if `self` is a `MetaItemInner::Literal`s.
pub fn lit(&self) -> Option<&MetaItemLit> {
match self {
NestedMetaItem::Lit(lit) => Some(lit),
MetaItemInner::Lit(lit) => Some(lit),
_ => None,
}
}

/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem` or if it's
/// `NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
pub fn meta_item_or_bool(&self) -> Option<&NestedMetaItem> {
/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem` or if it's
/// `MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
pub fn meta_item_or_bool(&self) -> Option<&MetaItemInner> {
match self {
NestedMetaItem::MetaItem(_item) => Some(self),
NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(_), .. }) => Some(self),
MetaItemInner::MetaItem(_item) => Some(self),
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. }) => Some(self),
_ => None,
}
}

/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem`.
pub fn meta_item(&self) -> Option<&MetaItem> {
match self {
NestedMetaItem::MetaItem(item) => Some(item),
MetaItemInner::MetaItem(item) => Some(item),
_ => None,
}
}
Expand All @@ -550,22 +550,22 @@ impl NestedMetaItem {
self.meta_item().is_some()
}

fn from_tokens<'a, I>(tokens: &mut iter::Peekable<I>) -> Option<NestedMetaItem>
fn from_tokens<'a, I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItemInner>
where
I: Iterator<Item = &'a TokenTree>,
{
match tokens.peek() {
Some(TokenTree::Token(token, _)) if let Some(lit) = MetaItemLit::from_token(token) => {
tokens.next();
return Some(NestedMetaItem::Lit(lit));
return Some(MetaItemInner::Lit(lit));
}
Some(TokenTree::Delimited(.., Delimiter::Invisible, inner_tokens)) => {
tokens.next();
return NestedMetaItem::from_tokens(&mut inner_tokens.trees().peekable());
return MetaItemInner::from_tokens(&mut inner_tokens.trees().peekable());
}
_ => {}
}
MetaItem::from_tokens(tokens).map(NestedMetaItem::MetaItem)
MetaItem::from_tokens(tokens).map(MetaItemInner::MetaItem)
}
}

Expand Down Expand Up @@ -676,6 +676,6 @@ pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {
find_by_name(attrs, name).is_some()
}

pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
pub fn list_contains_name(items: &[MetaItemInner], name: Symbol) -> bool {
items.iter().any(|item| item.has_name(name))
}
8 changes: 4 additions & 4 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub trait MutVisitor: Sized {
walk_crate(self, c)
}

fn visit_meta_list_item(&mut self, list_item: &mut NestedMetaItem) {
fn visit_meta_list_item(&mut self, list_item: &mut MetaItemInner) {
walk_meta_list_item(self, list_item);
}

Expand Down Expand Up @@ -659,10 +659,10 @@ fn walk_macro_def<T: MutVisitor>(vis: &mut T, macro_def: &mut MacroDef) {
visit_delim_args(vis, body);
}

fn walk_meta_list_item<T: MutVisitor>(vis: &mut T, li: &mut NestedMetaItem) {
fn walk_meta_list_item<T: MutVisitor>(vis: &mut T, li: &mut MetaItemInner) {
match li {
NestedMetaItem::MetaItem(mi) => vis.visit_meta_item(mi),
NestedMetaItem::Lit(_lit) => {}
MetaItemInner::MetaItem(mi) => vis.visit_meta_item(mi),
MetaItemInner::Lit(_lit) => {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
// Check unstable flavors of the `#[doc]` attribute.
if attr.has_name(sym::doc) {
for nested_meta in attr.meta_item_list().unwrap_or_default() {
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
$($(if nested_meta.has_name(sym::$name) {
$($(if meta_item_inner.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
gate!(self, $feature, attr.span, msg);
})*)*
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn vis_to_string(v: &ast::Visibility) -> String {
State::new().vis_to_string(v)
}

pub fn meta_list_item_to_string(li: &ast::NestedMetaItem) -> String {
pub fn meta_list_item_to_string(li: &ast::MetaItemInner) -> String {
State::new().meta_list_item_to_string(li)
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2006,10 +2006,10 @@ impl<'a> State<'a> {
self.print_attribute_inline(attr, false)
}

fn print_meta_list_item(&mut self, item: &ast::NestedMetaItem) {
fn print_meta_list_item(&mut self, item: &ast::MetaItemInner) {
match item {
ast::NestedMetaItem::MetaItem(mi) => self.print_meta_item(mi),
ast::NestedMetaItem::Lit(lit) => self.print_meta_item_lit(lit),
ast::MetaItemInner::MetaItem(mi) => self.print_meta_item(mi),
ast::MetaItemInner::Lit(lit) => self.print_meta_item_lit(lit),
}
}

Expand Down Expand Up @@ -2054,7 +2054,7 @@ impl<'a> State<'a> {
Self::to_string(|s| s.print_path_segment(p, false))
}

pub(crate) fn meta_list_item_to_string(&self, li: &ast::NestedMetaItem) -> String {
pub(crate) fn meta_list_item_to_string(&self, li: &ast::MetaItemInner) -> String {
Self::to_string(|s| s.print_meta_list_item(li))
}

Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::num::NonZero;

use rustc_abi::Align;
use rustc_ast::{
self as ast, Attribute, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem, NodeId,
self as ast, Attribute, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NodeId,
attr,
};
use rustc_ast_pretty::pprust;
Expand Down Expand Up @@ -534,7 +534,7 @@ pub struct Condition {

/// Tests if a cfg-pattern matches the cfg set
pub fn cfg_matches(
cfg: &ast::NestedMetaItem,
cfg: &ast::MetaItemInner,
sess: &Session,
lint_node_id: NodeId,
features: Option<&Features>,
Expand Down Expand Up @@ -605,16 +605,16 @@ pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
/// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to
/// evaluate individual items.
pub fn eval_condition(
cfg: &ast::NestedMetaItem,
cfg: &ast::MetaItemInner,
sess: &Session,
features: Option<&Features>,
eval: &mut impl FnMut(Condition) -> bool,
) -> bool {
let dcx = sess.dcx();

let cfg = match cfg {
ast::NestedMetaItem::MetaItem(meta_item) => meta_item,
ast::NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
ast::MetaItemInner::MetaItem(meta_item) => meta_item,
ast::MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
if let Some(features) = features {
// we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
// and `true`, and we want to keep the former working without feature gate
Expand Down Expand Up @@ -646,12 +646,12 @@ pub fn eval_condition(
ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
try_gate_cfg(sym::version, cfg.span, sess, features);
let (min_version, span) = match &mis[..] {
[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
(sym, span)
}
[
NestedMetaItem::Lit(MetaItemLit { span, .. })
| NestedMetaItem::MetaItem(MetaItem { span, .. }),
MetaItemInner::Lit(MetaItemLit { span, .. })
| MetaItemInner::MetaItem(MetaItem { span, .. }),
] => {
dcx.emit_err(session_diagnostics::ExpectedVersionLiteral { span: *span });
return false;
Expand Down Expand Up @@ -729,7 +729,7 @@ pub fn eval_condition(
}

res & eval_condition(
&ast::NestedMetaItem::MetaItem(mi),
&ast::MetaItemInner::MetaItem(mi),
sess,
features,
eval,
Expand Down Expand Up @@ -873,7 +873,7 @@ pub fn find_deprecation(

for meta in list {
match meta {
NestedMetaItem::MetaItem(mi) => match mi.name_or_empty() {
MetaItemInner::MetaItem(mi) => match mi.name_or_empty() {
sym::since => {
if !get(mi, &mut since) {
continue 'outer;
Expand Down Expand Up @@ -912,7 +912,7 @@ pub fn find_deprecation(
continue 'outer;
}
},
NestedMetaItem::Lit(lit) => {
MetaItemInner::Lit(lit) => {
sess.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
span: lit.span,
reason: UnsupportedLiteralReason::DeprecatedKvPair,
Expand Down Expand Up @@ -1277,7 +1277,7 @@ pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
let mut candidates = Vec::new();

for meta in metas {
let NestedMetaItem::Lit(meta_lit) = meta else {
let MetaItemInner::Lit(meta_lit) = meta else {
return None;
};
candidates.push(meta_lit.symbol);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn parse_cfg<'a>(
cx: &ExtCtxt<'a>,
span: Span,
tts: TokenStream,
) -> PResult<'a, ast::NestedMetaItem> {
) -> PResult<'a, ast::MetaItemInner> {
let mut p = cx.new_parser_from_tts(tts);

if p.token == token::Eof {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_builtin_macros/src/derive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_ast as ast;
use rustc_ast::{GenericParamKind, ItemKind, MetaItemKind, NestedMetaItem, StmtKind};
use rustc_ast::{GenericParamKind, ItemKind, MetaItemInner, MetaItemKind, StmtKind};
use rustc_expand::base::{
Annotatable, DeriveResolution, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier,
};
Expand Down Expand Up @@ -49,9 +49,9 @@ impl MultiItemModifier for Expander {
let mut resolutions = match &meta_item.kind {
MetaItemKind::List(list) => {
list.iter()
.filter_map(|nested_meta| match nested_meta {
NestedMetaItem::MetaItem(meta) => Some(meta),
NestedMetaItem::Lit(lit) => {
.filter_map(|meta_item_inner| match meta_item_inner {
MetaItemInner::MetaItem(meta) => Some(meta),
MetaItemInner::Lit(lit) => {
// Reject `#[derive("Debug")]`.
report_unexpected_meta_item_lit(sess, lit);
None
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_ast::{MetaItemKind, NestedMetaItem, ast, attr};
use rustc_ast::{MetaItemInner, MetaItemKind, ast, attr};
use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr, list_contains_name};
use rustc_errors::codes::*;
use rustc_errors::{DiagMessage, SubdiagMessage, struct_span_code_err};
Expand Down Expand Up @@ -357,7 +357,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
sym::instruction_set => {
codegen_fn_attrs.instruction_set =
attr.meta_item_list().and_then(|l| match &l[..] {
[NestedMetaItem::MetaItem(set)] => {
[MetaItemInner::MetaItem(set)] => {
let segments =
set.path.segments.iter().map(|x| x.ident.name).collect::<Vec<_>>();
match segments.as_slice() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub struct NativeLib {
pub kind: NativeLibKind,
pub name: Symbol,
pub filename: Option<Symbol>,
pub cfg: Option<ast::NestedMetaItem>,
pub cfg: Option<ast::MetaItemInner>,
pub verbatim: bool,
pub dll_imports: Vec<cstore::DllImport>,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use rustc_span::{DUMMY_SP, FileName, Span};
use smallvec::{SmallVec, smallvec};
use thin_vec::ThinVec;

use crate::base::ast::NestedMetaItem;
use crate::base::ast::MetaItemInner;
use crate::errors;
use crate::expand::{self, AstFragment, Invocation};
use crate::module::DirOwnership;
Expand Down Expand Up @@ -783,7 +783,7 @@ impl SyntaxExtension {

fn collapse_debuginfo_by_name(attr: &Attribute) -> Result<CollapseMacroDebuginfo, Span> {
let list = attr.meta_item_list();
let Some([NestedMetaItem::MetaItem(item)]) = list.as_deref() else {
let Some([MetaItemInner::MetaItem(item)]) = list.as_deref() else {
return Err(attr.span);
};
if !item.is_word() {
Expand Down
Loading

0 comments on commit 0b16baa

Please sign in to comment.