Rename NestedMetaItem to MetaItemInner

This commit is contained in:
codemountains 2024-10-04 21:59:04 +09:00
parent 68301a6a96
commit 6dfc4a0473
39 changed files with 167 additions and 173 deletions

View File

@ -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.
///
@ -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),

View File

@ -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;
@ -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,
@ -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())
@ -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,
@ -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, .. }, _)) => {}
@ -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,
}
}
@ -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())
}
@ -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,
}
}
@ -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)
}
}
@ -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))
}

View File

@ -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);
}
@ -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) => {}
}
}

View File

@ -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)
}

View File

@ -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),
}
}
@ -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))
}

View File

@ -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;
@ -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>,
@ -605,7 +605,7 @@ 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,
@ -613,8 +613,8 @@ pub fn eval_condition(
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
@ -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;
@ -729,7 +729,7 @@ pub fn eval_condition(
}
res & eval_condition(
&ast::NestedMetaItem::MetaItem(mi),
&ast::MetaItemInner::MetaItem(mi),
sess,
features,
eval,
@ -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;
@ -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,
@ -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);

View File

@ -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 {

View File

@ -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,
};
@ -50,8 +50,8 @@ impl MultiItemModifier for Expander {
MetaItemKind::List(list) => {
list.iter()
.filter_map(|nested_meta| match nested_meta {
NestedMetaItem::MetaItem(meta) => Some(meta),
NestedMetaItem::Lit(lit) => {
MetaItemInner::MetaItem(meta) => Some(meta),
MetaItemInner::Lit(lit) => {
// Reject `#[derive("Debug")]`.
report_unexpected_meta_item_lit(sess, lit);
None

View File

@ -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};
@ -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() {

View File

@ -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>,
}

View File

@ -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;
@ -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() {

View File

@ -6,7 +6,7 @@ use rustc_ast::tokenstream::{
AttrTokenStream, AttrTokenTree, LazyAttrTokenStream, Spacing, TokenTree,
};
use rustc_ast::{
self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem, NestedMetaItem, NodeId,
self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem, MetaItemInner, NodeId,
};
use rustc_attr as attr;
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
@ -39,7 +39,7 @@ pub struct StripUnconfigured<'a> {
}
pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -> Features {
fn feature_list(attr: &Attribute) -> ThinVec<ast::NestedMetaItem> {
fn feature_list(attr: &Attribute) -> ThinVec<ast::MetaItemInner> {
if attr.has_name(sym::feature)
&& let Some(list) = attr.meta_item_list()
{
@ -451,7 +451,7 @@ impl<'a> StripUnconfigured<'a> {
}
}
pub fn parse_cfg<'a>(meta_item: &'a MetaItem, sess: &Session) -> Option<&'a NestedMetaItem> {
pub fn parse_cfg<'a>(meta_item: &'a MetaItem, sess: &Session) -> Option<&'a MetaItemInner> {
let span = meta_item.span;
match meta_item.meta_item_list() {
None => {

View File

@ -11,7 +11,7 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_ast::visit::{self, AssocCtxt, Visitor, VisitorResult, try_visit, walk_list};
use rustc_ast::{
AssocItemKind, AstNodeWrapper, AttrArgs, AttrStyle, AttrVec, ExprKind, ForeignItemKind,
HasAttrs, HasNodeId, Inline, ItemKind, MacStmtStyle, MetaItemKind, ModKind, NestedMetaItem,
HasAttrs, HasNodeId, Inline, ItemKind, MacStmtStyle, MetaItemInner, MetaItemKind, ModKind,
NodeId, PatKind, StmtKind, TyKind,
};
use rustc_ast_pretty::pprust;
@ -1864,7 +1864,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
.filter(|a| a.has_name(sym::derive))
.flat_map(|a| a.meta_item_list().unwrap_or_default())
.filter_map(|nested_meta| match nested_meta {
NestedMetaItem::MetaItem(ast::MetaItem {
MetaItemInner::MetaItem(ast::MetaItem {
kind: MetaItemKind::Word,
path,
..

View File

@ -19,7 +19,7 @@
//! Errors are reported if we are in the suitable configuration but
//! the required condition is not met.
use rustc_ast::{self as ast, Attribute, NestedMetaItem};
use rustc_ast::{self as ast, Attribute, MetaItemInner};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::unord::UnordSet;
use rustc_hir::def_id::LocalDefId;
@ -307,7 +307,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
(name, labels)
}
fn resolve_labels(&self, item: &NestedMetaItem, value: Symbol) -> Labels {
fn resolve_labels(&self, item: &MetaItemInner, value: Symbol) -> Labels {
let mut out = Labels::default();
for label in value.as_str().split(',') {
let label = label.trim();
@ -415,7 +415,7 @@ fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
}
}
fn expect_associated_value(tcx: TyCtxt<'_>, item: &NestedMetaItem) -> Symbol {
fn expect_associated_value(tcx: TyCtxt<'_>, item: &MetaItemInner) -> Symbol {
if let Some(value) = item.value_str() {
value
} else if let Some(ident) = item.ident() {

View File

@ -669,7 +669,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
let sp = li.span();
let meta_item = match li {
ast::NestedMetaItem::MetaItem(meta_item) if meta_item.is_word() => meta_item,
ast::MetaItemInner::MetaItem(meta_item) if meta_item.is_word() => meta_item,
_ => {
let sub = if let Some(item) = li.meta_item()
&& let ast::MetaItemKind::NameValue(_) = item.kind

View File

@ -1451,9 +1451,8 @@ impl<'tcx> TyCtxt<'tcx> {
debug!("layout_scalar_valid_range: attr={:?}", attr);
if let Some(
&[
ast::NestedMetaItem::Lit(ast::MetaItemLit {
kind: ast::LitKind::Int(a, _),
..
ast::MetaItemInner::Lit(ast::MetaItemLit {
kind: ast::LitKind::Int(a, _), ..
}),
],
) = attr.meta_item_list().as_deref()

View File

@ -367,7 +367,7 @@ impl RustcMirAttrs {
fn set_field<T>(
field: &mut Option<T>,
tcx: TyCtxt<'_>,
attr: &ast::NestedMetaItem,
attr: &ast::MetaItemInner,
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
) -> Result<(), ()> {
if field.is_some() {

View File

@ -18,7 +18,7 @@ use std::path::Path;
use rustc_ast as ast;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{AttrItem, Attribute, NestedMetaItem, token};
use rustc_ast::{AttrItem, Attribute, MetaItemInner, token};
use rustc_ast_pretty::pprust;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{Diag, FatalError, PResult};
@ -160,7 +160,7 @@ pub fn fake_token_stream_for_crate(psess: &ParseSess, krate: &ast::Crate) -> Tok
pub fn parse_cfg_attr(
cfg_attr: &Attribute,
psess: &ParseSess,
) -> Option<(NestedMetaItem, Vec<(AttrItem, Span)>)> {
) -> Option<(MetaItemInner, Vec<(AttrItem, Span)>)> {
const CFG_ATTR_GRAMMAR_HELP: &str = "#[cfg_attr(condition, attribute, other_attribute, ...)]";
const CFG_ATTR_NOTE_REF: &str = "for more information, visit \
<https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>";

View File

@ -358,7 +358,7 @@ impl<'a> Parser<'a> {
/// Parses `cfg_attr(pred, attr_item_list)` where `attr_item_list` is comma-delimited.
pub fn parse_cfg_attr(
&mut self,
) -> PResult<'a, (ast::NestedMetaItem, Vec<(ast::AttrItem, Span)>)> {
) -> PResult<'a, (ast::MetaItemInner, Vec<(ast::AttrItem, Span)>)> {
let cfg_predicate = self.parse_meta_item_inner()?;
self.expect(&token::Comma)?;
@ -377,7 +377,7 @@ impl<'a> Parser<'a> {
}
/// Matches `COMMASEP(meta_item_inner)`.
pub(crate) fn parse_meta_seq_top(&mut self) -> PResult<'a, ThinVec<ast::NestedMetaItem>> {
pub(crate) fn parse_meta_seq_top(&mut self) -> PResult<'a, ThinVec<ast::MetaItemInner>> {
// Presumably, the majority of the time there will only be one attr.
let mut nmis = ThinVec::with_capacity(1);
while self.token != token::Eof {
@ -454,14 +454,14 @@ impl<'a> Parser<'a> {
/// ```ebnf
/// MetaItemInner = UNSUFFIXED_LIT | MetaItem ;
/// ```
pub fn parse_meta_item_inner(&mut self) -> PResult<'a, ast::NestedMetaItem> {
pub fn parse_meta_item_inner(&mut self) -> PResult<'a, ast::MetaItemInner> {
match self.parse_unsuffixed_meta_item_lit() {
Ok(lit) => return Ok(ast::NestedMetaItem::Lit(lit)),
Ok(lit) => return Ok(ast::MetaItemInner::Lit(lit)),
Err(err) => err.cancel(), // we provide a better error below
}
match self.parse_meta_item(AllowLeadingUnsafe::No) {
Ok(mi) => return Ok(ast::NestedMetaItem::MetaItem(mi)),
Ok(mi) => return Ok(ast::MetaItemInner::MetaItem(mi)),
Err(err) => err.cancel(), // we provide a better error below
}

View File

@ -3,8 +3,8 @@
use rustc_ast::token::Delimiter;
use rustc_ast::tokenstream::DelimSpan;
use rustc_ast::{
self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, MetaItemKind,
NestedMetaItem, Safety,
self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind,
Safety,
};
use rustc_errors::{Applicability, FatalError, PResult};
use rustc_feature::{AttributeSafety, AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
@ -143,7 +143,7 @@ pub(super) fn check_cfg_attr_bad_delim(psess: &ParseSess, span: DelimSpan, delim
/// Checks that the given meta-item is compatible with this `AttributeTemplate`.
fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaItemKind) -> bool {
let is_one_allowed_subword = |items: &[NestedMetaItem]| match items {
let is_one_allowed_subword = |items: &[MetaItemInner]| match items {
[item] => item.is_word() && template.one_of.iter().any(|&word| item.has_name(word)),
_ => false,
};

View File

@ -8,7 +8,7 @@ use std::cell::Cell;
use std::collections::hash_map::Entry;
use rustc_ast::{
AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem, ast,
AttrKind, AttrStyle, Attribute, LitKind, MetaItemInner, MetaItemKind, MetaItemLit, ast,
};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Applicability, DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey};
@ -742,13 +742,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
fn doc_attr_str_error(&self, meta: &NestedMetaItem, attr_name: &str) {
fn doc_attr_str_error(&self, meta: &MetaItemInner, attr_name: &str) {
self.dcx().emit_err(errors::DocExpectStr { attr_span: meta.span(), attr_name });
}
fn check_doc_alias_value(
&self,
meta: &NestedMetaItem,
meta: &MetaItemInner,
doc_alias: Symbol,
hir_id: HirId,
target: Target,
@ -850,7 +850,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_doc_alias(
&self,
meta: &NestedMetaItem,
meta: &MetaItemInner,
hir_id: HirId,
target: Target,
aliases: &mut FxHashMap<String, Span>,
@ -882,7 +882,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
fn check_doc_keyword(&self, meta: &NestedMetaItem, hir_id: HirId) {
fn check_doc_keyword(&self, meta: &MetaItemInner, hir_id: HirId) {
let doc_keyword = meta.value_str().unwrap_or(kw::Empty);
if doc_keyword == kw::Empty {
self.doc_attr_str_error(meta, "keyword");
@ -912,7 +912,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
fn check_doc_fake_variadic(&self, meta: &NestedMetaItem, hir_id: HirId) {
fn check_doc_fake_variadic(&self, meta: &MetaItemInner, hir_id: HirId) {
let item_kind = match self.tcx.hir_node(hir_id) {
hir::Node::Item(item) => Some(&item.kind),
_ => None,
@ -957,7 +957,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_doc_inline(
&self,
attr: &Attribute,
meta: &NestedMetaItem,
meta: &MetaItemInner,
hir_id: HirId,
target: Target,
specified_inline: &mut Option<(bool, Span)>,
@ -997,7 +997,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_doc_masked(
&self,
attr: &Attribute,
meta: &NestedMetaItem,
meta: &MetaItemInner,
hir_id: HirId,
target: Target,
) {
@ -1032,7 +1032,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
/// Checks that an attribute is *not* used at the crate level. Returns `true` if valid.
fn check_attr_not_crate_level(
&self,
meta: &NestedMetaItem,
meta: &MetaItemInner,
hir_id: HirId,
attr_name: &str,
) -> bool {
@ -1047,7 +1047,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_attr_crate_level(
&self,
attr: &Attribute,
meta: &NestedMetaItem,
meta: &MetaItemInner,
hir_id: HirId,
) -> bool {
if hir_id != CRATE_HIR_ID {
@ -1071,7 +1071,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
/// Checks that `doc(test(...))` attribute contains only valid attributes. Returns `true` if
/// valid.
fn check_test_attr(&self, meta: &NestedMetaItem, hir_id: HirId) {
fn check_test_attr(&self, meta: &MetaItemInner, hir_id: HirId) {
if let Some(metas) = meta.meta_item_list() {
for i_meta in metas {
match (i_meta.name_or_empty(), i_meta.meta_item()) {
@ -1108,7 +1108,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
/// Check that the `#![doc(cfg_hide(...))]` attribute only contains a list of attributes.
///
fn check_doc_cfg_hide(&self, meta: &NestedMetaItem, hir_id: HirId) {
fn check_doc_cfg_hide(&self, meta: &MetaItemInner, hir_id: HirId) {
if meta.meta_item_list().is_none() {
self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES,
@ -1499,8 +1499,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
return;
};
if !matches!(&list[..], &[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Int(..), .. })])
{
if !matches!(&list[..], &[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Int(..), .. })]) {
self.tcx
.dcx()
.emit_err(errors::RustcLayoutScalarValidRangeArg { attr_span: attr.span });
@ -2073,7 +2072,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
let mut candidates = Vec::new();
for meta in metas {
let NestedMetaItem::Lit(meta_lit) = meta else {
let MetaItemInner::Lit(meta_lit) = meta else {
self.dcx().emit_err(errors::IncorrectMetaItem {
span: meta.span(),
suggestion: errors::IncorrectMetaItemSuggestion {

View File

@ -2,8 +2,7 @@ use rustc_ast::expand::StrippedCfgItem;
use rustc_ast::ptr::P;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{
self as ast, CRATE_NODE_ID, Crate, ItemKind, MetaItemKind, ModKind, NestedMetaItem, NodeId,
Path,
self as ast, CRATE_NODE_ID, Crate, ItemKind, MetaItemInner, MetaItemKind, ModKind, NodeId, Path,
};
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet;
@ -2541,7 +2540,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
err.subdiagnostic(note);
if let MetaItemKind::List(nested) = &cfg.kind
&& let NestedMetaItem::MetaItem(meta_item) = &nested[0]
&& let MetaItemInner::MetaItem(meta_item) = &nested[0]
&& let MetaItemKind::NameValue(feature_name) = &meta_item.kind
{
let note = errors::ItemWasBehindFeature {

View File

@ -72,7 +72,7 @@ pub struct NativeLib {
pub name: Symbol,
/// If packed_bundled_libs enabled, actual filename of library is stored.
pub filename: Option<Symbol>,
pub cfg: Option<ast::NestedMetaItem>,
pub cfg: Option<ast::MetaItemInner>,
pub foreign_module: Option<DefId>,
pub verbatim: Option<bool>,
pub dll_imports: Vec<DllImport>,

View File

@ -1,7 +1,7 @@
use std::iter;
use std::path::PathBuf;
use rustc_ast::{AttrArgs, AttrArgsEq, AttrKind, Attribute, NestedMetaItem};
use rustc_ast::{AttrArgs, AttrArgsEq, AttrKind, Attribute, MetaItemInner};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::codes::*;
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
@ -282,7 +282,7 @@ pub struct OnUnimplementedFormatString {
#[derive(Debug)]
pub struct OnUnimplementedDirective {
pub condition: Option<NestedMetaItem>,
pub condition: Option<MetaItemInner>,
pub subcommands: Vec<OnUnimplementedDirective>,
pub message: Option<OnUnimplementedFormatString>,
pub label: Option<OnUnimplementedFormatString>,
@ -389,7 +389,7 @@ impl<'tcx> OnUnimplementedDirective {
fn parse(
tcx: TyCtxt<'tcx>,
item_def_id: DefId,
items: &[NestedMetaItem],
items: &[MetaItemInner],
span: Span,
is_root: bool,
is_diagnostic_namespace_variant: bool,

View File

@ -6,7 +6,7 @@
use std::fmt::{self, Write};
use std::{mem, ops};
use rustc_ast::{LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem};
use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit};
use rustc_data_structures::fx::FxHashSet;
use rustc_feature::Features;
use rustc_session::parse::ParseSess;
@ -41,18 +41,18 @@ pub(crate) struct InvalidCfgError {
}
impl Cfg {
/// Parses a `NestedMetaItem` into a `Cfg`.
/// Parses a `MetaItemInner` into a `Cfg`.
fn parse_nested(
nested_cfg: &NestedMetaItem,
nested_cfg: &MetaItemInner,
exclude: &FxHashSet<Cfg>,
) -> Result<Option<Cfg>, InvalidCfgError> {
match nested_cfg {
NestedMetaItem::MetaItem(ref cfg) => Cfg::parse_without(cfg, exclude),
NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => match *b {
MetaItemInner::MetaItem(ref cfg) => Cfg::parse_without(cfg, exclude),
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => match *b {
true => Ok(Some(Cfg::True)),
false => Ok(Some(Cfg::False)),
},
NestedMetaItem::Lit(ref lit) => {
MetaItemInner::Lit(ref lit) => {
Err(InvalidCfgError { msg: "unexpected literal", span: lit.span })
}
}
@ -124,7 +124,7 @@ impl Cfg {
///
/// If the content is not properly formatted, it will return an error indicating what and where
/// the error is.
pub(crate) fn parse(cfg: &NestedMetaItem) -> Result<Cfg, InvalidCfgError> {
pub(crate) fn parse(cfg: &MetaItemInner) -> Result<Cfg, InvalidCfgError> {
Self::parse_nested(cfg, &FxHashSet::default()).map(|ret| ret.unwrap())
}

View File

@ -1,5 +1,5 @@
use rustc_ast::ast::LitIntType;
use rustc_ast::{MetaItemLit, NestedMetaItem, Path, Safety, StrStyle};
use rustc_ast::{MetaItemInner, MetaItemLit, Path, Safety, StrStyle};
use rustc_span::symbol::{Ident, kw};
use rustc_span::{DUMMY_SP, create_default_session_globals_then};
use thin_vec::thin_vec;
@ -14,12 +14,12 @@ fn name_value_cfg(name: &str, value: &str) -> Cfg {
Cfg::Cfg(Symbol::intern(name), Some(Symbol::intern(value)))
}
fn dummy_lit(symbol: Symbol, kind: LitKind) -> NestedMetaItem {
NestedMetaItem::Lit(MetaItemLit { symbol, suffix: None, kind, span: DUMMY_SP })
fn dummy_lit(symbol: Symbol, kind: LitKind) -> MetaItemInner {
MetaItemInner::Lit(MetaItemLit { symbol, suffix: None, kind, span: DUMMY_SP })
}
fn dummy_meta_item_word(name: &str) -> NestedMetaItem {
NestedMetaItem::MetaItem(MetaItem {
fn dummy_meta_item_word(name: &str) -> MetaItemInner {
MetaItemInner::MetaItem(MetaItem {
unsafety: Safety::Default,
path: Path::from_ident(Ident::from_str(name)),
kind: MetaItemKind::Word,
@ -27,9 +27,9 @@ fn dummy_meta_item_word(name: &str) -> NestedMetaItem {
})
}
fn dummy_meta_item_name_value(name: &str, symbol: Symbol, kind: LitKind) -> NestedMetaItem {
fn dummy_meta_item_name_value(name: &str, symbol: Symbol, kind: LitKind) -> MetaItemInner {
let lit = MetaItemLit { symbol, suffix: None, kind, span: DUMMY_SP };
NestedMetaItem::MetaItem(MetaItem {
MetaItemInner::MetaItem(MetaItem {
unsafety: Safety::Default,
path: Path::from_ident(Ident::from_str(name)),
kind: MetaItemKind::NameValue(lit),
@ -39,7 +39,7 @@ fn dummy_meta_item_name_value(name: &str, symbol: Symbol, kind: LitKind) -> Nest
macro_rules! dummy_meta_item_list {
($name:ident, [$($list:ident),* $(,)?]) => {
NestedMetaItem::MetaItem(MetaItem {
MetaItemInner::MetaItem(MetaItem {
unsafety: Safety::Default,
path: Path::from_ident(Ident::from_str(stringify!($name))),
kind: MetaItemKind::List(thin_vec![
@ -52,7 +52,7 @@ macro_rules! dummy_meta_item_list {
};
($name:ident, [$($list:expr),* $(,)?]) => {
NestedMetaItem::MetaItem(MetaItem {
MetaItemInner::MetaItem(MetaItem {
unsafety: Safety::Default,
path: Path::from_ident(Ident::from_str(stringify!($name))),
kind: MetaItemKind::List(thin_vec![

View File

@ -5,7 +5,7 @@ use std::sync::{Arc, OnceLock as OnceCell};
use std::{fmt, iter};
use arrayvec::ArrayVec;
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_ast_pretty::pprust;
use rustc_attr::{ConstStability, Deprecation, Stability, StableSince};
use rustc_const_eval::const_eval::is_unstable_const_fn;
@ -953,7 +953,7 @@ pub(crate) struct Module {
}
pub(crate) trait AttributesExt {
type AttributeIterator<'a>: Iterator<Item = ast::NestedMetaItem>
type AttributeIterator<'a>: Iterator<Item = ast::MetaItemInner>
where
Self: 'a;
type Attributes<'a>: Iterator<Item = &'a ast::Attribute>
@ -1043,7 +1043,7 @@ pub(crate) trait AttributesExt {
let mut meta = attr.meta_item().unwrap().clone();
meta.path = ast::Path::from_ident(Ident::with_dummy_span(sym::target_feature));
if let Ok(feat_cfg) = Cfg::parse(&NestedMetaItem::MetaItem(meta)) {
if let Ok(feat_cfg) = Cfg::parse(&MetaItemInner::MetaItem(meta)) {
cfg &= feat_cfg;
}
}
@ -1055,7 +1055,7 @@ pub(crate) trait AttributesExt {
}
impl AttributesExt for [ast::Attribute] {
type AttributeIterator<'a> = impl Iterator<Item = ast::NestedMetaItem> + 'a;
type AttributeIterator<'a> = impl Iterator<Item = ast::MetaItemInner> + 'a;
type Attributes<'a> = impl Iterator<Item = &'a ast::Attribute> + 'a;
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_> {
@ -1072,7 +1072,7 @@ impl AttributesExt for [ast::Attribute] {
impl AttributesExt for [(Cow<'_, ast::Attribute>, Option<DefId>)] {
type AttributeIterator<'a>
= impl Iterator<Item = ast::NestedMetaItem> + 'a
= impl Iterator<Item = ast::MetaItemInner> + 'a
where
Self: 'a;
type Attributes<'a>
@ -1106,11 +1106,11 @@ pub(crate) trait NestedAttributesExt {
/// Returns `Some(attr)` if the attribute list contains 'attr'
/// corresponding to a specific `word`
fn get_word_attr(self, word: Symbol) -> Option<ast::NestedMetaItem>;
fn get_word_attr(self, word: Symbol) -> Option<ast::MetaItemInner>;
}
impl<I: Iterator<Item = ast::NestedMetaItem>> NestedAttributesExt for I {
fn get_word_attr(mut self, word: Symbol) -> Option<ast::NestedMetaItem> {
impl<I: Iterator<Item = ast::MetaItemInner>> NestedAttributesExt for I {
fn get_word_attr(mut self, word: Symbol) -> Option<ast::MetaItemInner> {
self.find(|attr| attr.is_word() && attr.has_name(word))
}
}
@ -1157,7 +1157,7 @@ pub(crate) struct Attributes {
}
impl Attributes {
pub(crate) fn lists(&self, name: Symbol) -> impl Iterator<Item = ast::NestedMetaItem> + '_ {
pub(crate) fn lists(&self, name: Symbol) -> impl Iterator<Item = ast::MetaItemInner> + '_ {
self.other_attrs.lists(name)
}

View File

@ -1,15 +1,15 @@
use super::{ALLOW_ATTRIBUTES_WITHOUT_REASON, Attribute};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::is_from_proc_macro;
use rustc_ast::{MetaItemKind, NestedMetaItem};
use rustc_ast::{MetaItemInner, MetaItemKind};
use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::sym;
use rustc_span::symbol::Symbol;
pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[NestedMetaItem], attr: &'cx Attribute) {
pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[MetaItemInner], attr: &'cx Attribute) {
// Check if the reason is present
if let Some(item) = items.last().and_then(NestedMetaItem::meta_item)
if let Some(item) = items.last().and_then(MetaItemInner::meta_item)
&& let MetaItemKind::NameValue(_) = &item.kind
&& item.path == sym::reason
{

View File

@ -1,12 +1,12 @@
use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
use super::utils::extract_clippy_lint;
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_lint::{LateContext, Level, LintContext};
use rustc_span::symbol::Symbol;
use rustc_span::{DUMMY_SP, sym};
pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) {
pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[MetaItemInner]) {
for lint in items {
if let Some(lint_name) = extract_clippy_lint(lint) {
if lint_name.as_str() == "restriction" && name != sym::allow {

View File

@ -14,7 +14,7 @@ mod utils;
use clippy_config::Conf;
use clippy_config::msrvs::{self, Msrv};
use rustc_ast::{Attribute, MetaItemKind, NestedMetaItem};
use rustc_ast::{Attribute, MetaItemInner, MetaItemKind};
use rustc_hir::{ImplItem, Item, ItemKind, TraitItem};
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
@ -456,7 +456,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
return;
}
for item in items {
if let NestedMetaItem::MetaItem(mi) = &item
if let MetaItemInner::MetaItem(mi) = &item
&& let MetaItemKind::NameValue(lit) = &mi.kind
&& mi.has_name(sym::since)
{

View File

@ -1,7 +1,7 @@
use super::{Attribute, NON_MINIMAL_CFG};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::SpanRangeExt;
use rustc_ast::{MetaItemKind, NestedMetaItem};
use rustc_ast::{MetaItemInner, MetaItemKind};
use rustc_errors::Applicability;
use rustc_lint::EarlyContext;
use rustc_span::sym;
@ -14,9 +14,9 @@ pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) {
}
}
fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[MetaItemInner]) {
for item in items {
if let NestedMetaItem::MetaItem(meta) = item {
if let MetaItemInner::MetaItem(meta) = item {
if !meta.has_name(sym::any) && !meta.has_name(sym::all) {
continue;
}

View File

@ -2,7 +2,7 @@ use super::utils::{extract_clippy_lint, is_lint_level, is_word};
use super::{Attribute, USELESS_ATTRIBUTE};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LintContext};
@ -21,7 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute])
for lint in lint_list {
match item.kind {
ItemKind::Use(..) => {
if let NestedMetaItem::MetaItem(meta_item) = lint
if let MetaItemInner::MetaItem(meta_item) = lint
&& meta_item.is_word()
&& let Some(ident) = meta_item.ident()
&& matches!(

View File

@ -1,5 +1,5 @@
use clippy_utils::macros::{is_panic, macro_backtrace};
use rustc_ast::{AttrId, NestedMetaItem};
use rustc_ast::{AttrId, MetaItemInner};
use rustc_hir::{
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
};
@ -8,8 +8,8 @@ use rustc_middle::ty;
use rustc_span::sym;
use rustc_span::symbol::Symbol;
pub(super) fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
if let NestedMetaItem::MetaItem(mi) = &nmi {
pub(super) fn is_word(nmi: &MetaItemInner, expected: Symbol) -> bool {
if let MetaItemInner::MetaItem(mi) = &nmi {
mi.is_word() && mi.has_name(expected)
} else {
false
@ -74,7 +74,7 @@ fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>
}
/// Returns the lint name if it is clippy lint.
pub(super) fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<Symbol> {
pub(super) fn extract_clippy_lint(lint: &MetaItemInner) -> Option<Symbol> {
if let Some(meta_item) = lint.meta_item()
&& meta_item.path.segments.len() > 1
&& let tool_name = meta_item.path.segments[0].ident

View File

@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_then;
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::declare_lint_pass;
@ -47,7 +47,7 @@ impl EarlyLintPass for CfgNotTest {
}
}
fn contains_not_test(list: Option<&[NestedMetaItem]>, not: bool) -> bool {
fn contains_not_test(list: Option<&[MetaItemInner]>, not: bool) -> bool {
list.is_some_and(|list| {
list.iter().any(|item| {
item.ident().is_some_and(|ident| match ident.name {

View File

@ -7,7 +7,7 @@ use clippy_utils::{
path_to_local_id, span_contains_cfg, span_find_starting_semi,
};
use core::ops::ControlFlow;
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_errors::Applicability;
use rustc_hir::LangItem::ResultErr;
use rustc_hir::intravisit::FnKind;
@ -421,7 +421,7 @@ fn check_final_expr<'tcx>(
if matches!(Level::from_attr(attr), Some(Level::Expect(_)))
&& let metas = attr.meta_item_list()
&& let Some(lst) = metas
&& let [NestedMetaItem::MetaItem(meta_item), ..] = lst.as_slice()
&& let [MetaItemInner::MetaItem(meta_item), ..] = lst.as_slice()
&& let [tool, lint_name] = meta_item.path.segments.as_slice()
&& tool.ident.name == sym::clippy
&& matches!(

View File

@ -243,17 +243,15 @@ fn rewrite_initial_doc_comments(
Ok((0, None))
}
impl Rewrite for ast::NestedMetaItem {
impl Rewrite for ast::MetaItemInner {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
self.rewrite_result(context, shape).ok()
}
fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
match self {
ast::NestedMetaItem::MetaItem(ref meta_item) => {
meta_item.rewrite_result(context, shape)
}
ast::NestedMetaItem::Lit(ref l) => {
ast::MetaItemInner::MetaItem(ref meta_item) => meta_item.rewrite_result(context, shape),
ast::MetaItemInner::Lit(ref l) => {
rewrite_literal(context, l.as_token_lit(), l.span, shape)
}
}
@ -535,7 +533,7 @@ pub(crate) trait MetaVisitor<'ast> {
fn visit_meta_list(
&mut self,
_meta_item: &'ast ast::MetaItem,
list: &'ast [ast::NestedMetaItem],
list: &'ast [ast::MetaItemInner],
) {
for nm in list {
self.visit_nested_meta_item(nm);
@ -551,10 +549,10 @@ pub(crate) trait MetaVisitor<'ast> {
) {
}
fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) {
fn visit_nested_meta_item(&mut self, nm: &'ast ast::MetaItemInner) {
match nm {
ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
ast::NestedMetaItem::Lit(ref lit) => self.visit_meta_item_lit(lit),
ast::MetaItemInner::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
ast::MetaItemInner::Lit(ref lit) => self.visit_meta_item_lit(lit),
}
}

View File

@ -78,7 +78,7 @@ pub(crate) enum OverflowableItem<'a> {
Expr(&'a ast::Expr),
GenericParam(&'a ast::GenericParam),
MacroArg(&'a MacroArg),
NestedMetaItem(&'a ast::NestedMetaItem),
MetaItemInner(&'a ast::MetaItemInner),
SegmentParam(&'a SegmentParam<'a>),
FieldDef(&'a ast::FieldDef),
TuplePatField(&'a TuplePatField<'a>),
@ -123,7 +123,7 @@ impl<'a> OverflowableItem<'a> {
OverflowableItem::Expr(expr) => f(*expr),
OverflowableItem::GenericParam(gp) => f(*gp),
OverflowableItem::MacroArg(macro_arg) => f(*macro_arg),
OverflowableItem::NestedMetaItem(nmi) => f(*nmi),
OverflowableItem::MetaItemInner(nmi) => f(*nmi),
OverflowableItem::SegmentParam(sp) => f(*sp),
OverflowableItem::FieldDef(sf) => f(*sf),
OverflowableItem::TuplePatField(pat) => f(*pat),
@ -138,9 +138,9 @@ impl<'a> OverflowableItem<'a> {
OverflowableItem::Expr(expr) => is_simple_expr(expr),
OverflowableItem::MacroArg(MacroArg::Keyword(..)) => true,
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
OverflowableItem::NestedMetaItem(nested_meta_item) => match nested_meta_item {
ast::NestedMetaItem::Lit(..) => true,
ast::NestedMetaItem::MetaItem(ref meta_item) => {
OverflowableItem::MetaItemInner(nested_meta_item) => match nested_meta_item {
ast::MetaItemInner::Lit(..) => true,
ast::MetaItemInner::MetaItem(ref meta_item) => {
matches!(meta_item.kind, ast::MetaItemKind::Word)
}
},
@ -184,12 +184,11 @@ impl<'a> OverflowableItem<'a> {
MacroArg::Item(..) => len == 1,
MacroArg::Keyword(..) => false,
},
OverflowableItem::NestedMetaItem(nested_meta_item) if len == 1 => {
match nested_meta_item {
ast::NestedMetaItem::Lit(..) => false,
ast::NestedMetaItem::MetaItem(..) => true,
}
}
OverflowableItem::MetaItemInner(nested_meta_item) if len == 1 => match nested_meta_item
{
ast::MetaItemInner::Lit(..) => false,
ast::MetaItemInner::MetaItem(..) => true,
},
OverflowableItem::SegmentParam(SegmentParam::Type(ty)) => {
can_be_overflowed_type(context, ty, len)
}
@ -202,7 +201,7 @@ impl<'a> OverflowableItem<'a> {
fn special_cases(&self, config: &Config) -> impl Iterator<Item = &(&'static str, usize)> {
let base_cases = match self {
OverflowableItem::MacroArg(..) => SPECIAL_CASE_MACROS,
OverflowableItem::NestedMetaItem(..) => SPECIAL_CASE_ATTR,
OverflowableItem::MetaItemInner(..) => SPECIAL_CASE_ATTR,
_ => &[],
};
let additional_cases = match self {
@ -261,7 +260,7 @@ macro_rules! impl_into_overflowable_item_for_rustfmt_types {
impl_into_overflowable_item_for_ast_node!(
Expr,
GenericParam,
NestedMetaItem,
MetaItemInner,
FieldDef,
Ty,
Pat,

View File

@ -199,7 +199,7 @@ impl Spanned for MacroArg {
}
}
impl Spanned for ast::NestedMetaItem {
impl Spanned for ast::MetaItemInner {
fn span(&self) -> Span {
self.span()
}

View File

@ -1,7 +1,7 @@
use std::borrow::Cow;
use rustc_ast::ast::{
self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
self, Attribute, MetaItem, MetaItemInner, MetaItemKind, NodeId, Path, Visibility,
VisibilityKind,
};
use rustc_ast::ptr;
@ -257,10 +257,10 @@ fn is_skip(meta_item: &MetaItem) -> bool {
}
#[inline]
fn is_skip_nested(meta_item: &NestedMetaItem) -> bool {
fn is_skip_nested(meta_item: &MetaItemInner) -> bool {
match meta_item {
NestedMetaItem::MetaItem(ref mi) => is_skip(mi),
NestedMetaItem::Lit(_) => false,
MetaItemInner::MetaItem(ref mi) => is_skip(mi),
MetaItemInner::Lit(_) => false,
}
}