Auto merge of #131235 - codemountains:rename-nestedmetaitem-to-metaitemlnner, r=nnethercote
Rename `NestedMetaItem` to `MetaItemInner` Fixes #131087 r? `@nnethercote`
This commit is contained in:
commit
0b16baa570
43 changed files with 186 additions and 191 deletions
|
@ -511,7 +511,7 @@ pub enum MetaItemKind {
|
||||||
/// List meta item.
|
/// List meta item.
|
||||||
///
|
///
|
||||||
/// E.g., `#[derive(..)]`, where the field represents the `..`.
|
/// E.g., `#[derive(..)]`, where the field represents the `..`.
|
||||||
List(ThinVec<NestedMetaItem>),
|
List(ThinVec<MetaItemInner>),
|
||||||
|
|
||||||
/// Name value meta item.
|
/// Name value meta item.
|
||||||
///
|
///
|
||||||
|
@ -523,7 +523,7 @@ pub enum MetaItemKind {
|
||||||
///
|
///
|
||||||
/// E.g., each of `Clone`, `Copy` in `#[derive(Clone, Copy)]`.
|
/// E.g., each of `Clone`, `Copy` in `#[derive(Clone, Copy)]`.
|
||||||
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
|
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||||
pub enum NestedMetaItem {
|
pub enum MetaItemInner {
|
||||||
/// A full MetaItem, for recursive meta items.
|
/// A full MetaItem, for recursive meta items.
|
||||||
MetaItem(MetaItem),
|
MetaItem(MetaItem),
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use thin_vec::{ThinVec, thin_vec};
|
||||||
|
|
||||||
use crate::ast::{
|
use crate::ast::{
|
||||||
AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, DUMMY_NODE_ID,
|
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,
|
NormalAttr, Path, PathSegment, Safety,
|
||||||
};
|
};
|
||||||
use crate::ptr::P;
|
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 {
|
match &self.kind {
|
||||||
AttrKind::Normal(normal) => normal.item.meta_item_list(),
|
AttrKind::Normal(normal) => normal.item.meta_item_list(),
|
||||||
AttrKind::DocComment(..) => None,
|
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))
|
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 {
|
match &self.args {
|
||||||
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
|
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
|
||||||
MetaItemKind::list_from_tokens(args.tokens.clone())
|
MetaItemKind::list_from_tokens(args.tokens.clone())
|
||||||
|
@ -285,7 +285,7 @@ impl MetaItem {
|
||||||
matches!(self.kind, MetaItemKind::Word)
|
matches!(self.kind, MetaItemKind::Word)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
|
pub fn meta_item_list(&self) -> Option<&[MetaItemInner]> {
|
||||||
match &self.kind {
|
match &self.kind {
|
||||||
MetaItemKind::List(l) => Some(&**l),
|
MetaItemKind::List(l) => Some(&**l),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -393,11 +393,11 @@ impl MetaItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetaItemKind {
|
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 tokens = tokens.trees().peekable();
|
||||||
let mut result = ThinVec::new();
|
let mut result = ThinVec::new();
|
||||||
while tokens.peek().is_some() {
|
while tokens.peek().is_some() {
|
||||||
let item = NestedMetaItem::from_tokens(&mut tokens)?;
|
let item = MetaItemInner::from_tokens(&mut tokens)?;
|
||||||
result.push(item);
|
result.push(item);
|
||||||
match tokens.next() {
|
match tokens.next() {
|
||||||
None | Some(TokenTree::Token(Token { kind: token::Comma, .. }, _)) => {}
|
None | Some(TokenTree::Token(Token { kind: token::Comma, .. }, _)) => {}
|
||||||
|
@ -460,11 +460,11 @@ impl MetaItemKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NestedMetaItem {
|
impl MetaItemInner {
|
||||||
pub fn span(&self) -> Span {
|
pub fn span(&self) -> Span {
|
||||||
match self {
|
match self {
|
||||||
NestedMetaItem::MetaItem(item) => item.span,
|
MetaItemInner::MetaItem(item) => item.span,
|
||||||
NestedMetaItem::Lit(lit) => lit.span,
|
MetaItemInner::Lit(lit) => lit.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,7 +488,7 @@ impl NestedMetaItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a list of inner meta items from a list `MetaItem` type.
|
/// 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())
|
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())
|
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> {
|
pub fn lit(&self) -> Option<&MetaItemLit> {
|
||||||
match self {
|
match self {
|
||||||
NestedMetaItem::Lit(lit) => Some(lit),
|
MetaItemInner::Lit(lit) => Some(lit),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem` or if it's
|
/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem` or if it's
|
||||||
/// `NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
|
/// `MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
|
||||||
pub fn meta_item_or_bool(&self) -> Option<&NestedMetaItem> {
|
pub fn meta_item_or_bool(&self) -> Option<&MetaItemInner> {
|
||||||
match self {
|
match self {
|
||||||
NestedMetaItem::MetaItem(_item) => Some(self),
|
MetaItemInner::MetaItem(_item) => Some(self),
|
||||||
NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(_), .. }) => Some(self),
|
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. }) => Some(self),
|
||||||
_ => None,
|
_ => 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> {
|
pub fn meta_item(&self) -> Option<&MetaItem> {
|
||||||
match self {
|
match self {
|
||||||
NestedMetaItem::MetaItem(item) => Some(item),
|
MetaItemInner::MetaItem(item) => Some(item),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -550,22 +550,22 @@ impl NestedMetaItem {
|
||||||
self.meta_item().is_some()
|
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
|
where
|
||||||
I: Iterator<Item = &'a TokenTree>,
|
I: Iterator<Item = &'a TokenTree>,
|
||||||
{
|
{
|
||||||
match tokens.peek() {
|
match tokens.peek() {
|
||||||
Some(TokenTree::Token(token, _)) if let Some(lit) = MetaItemLit::from_token(token) => {
|
Some(TokenTree::Token(token, _)) if let Some(lit) = MetaItemLit::from_token(token) => {
|
||||||
tokens.next();
|
tokens.next();
|
||||||
return Some(NestedMetaItem::Lit(lit));
|
return Some(MetaItemInner::Lit(lit));
|
||||||
}
|
}
|
||||||
Some(TokenTree::Delimited(.., Delimiter::Invisible, inner_tokens)) => {
|
Some(TokenTree::Delimited(.., Delimiter::Invisible, inner_tokens)) => {
|
||||||
tokens.next();
|
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()
|
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))
|
items.iter().any(|item| item.has_name(name))
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub trait MutVisitor: Sized {
|
||||||
walk_crate(self, c)
|
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);
|
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);
|
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 {
|
match li {
|
||||||
NestedMetaItem::MetaItem(mi) => vis.visit_meta_item(mi),
|
MetaItemInner::MetaItem(mi) => vis.visit_meta_item(mi),
|
||||||
NestedMetaItem::Lit(_lit) => {}
|
MetaItemInner::Lit(_lit) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,9 +186,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
}
|
}
|
||||||
// Check unstable flavors of the `#[doc]` attribute.
|
// Check unstable flavors of the `#[doc]` attribute.
|
||||||
if attr.has_name(sym::doc) {
|
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)* })*) => {
|
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);
|
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
|
||||||
gate!(self, $feature, attr.span, msg);
|
gate!(self, $feature, attr.span, msg);
|
||||||
})*)*
|
})*)*
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub fn vis_to_string(v: &ast::Visibility) -> String {
|
||||||
State::new().vis_to_string(v)
|
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)
|
State::new().meta_list_item_to_string(li)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2006,10 +2006,10 @@ impl<'a> State<'a> {
|
||||||
self.print_attribute_inline(attr, false)
|
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 {
|
match item {
|
||||||
ast::NestedMetaItem::MetaItem(mi) => self.print_meta_item(mi),
|
ast::MetaItemInner::MetaItem(mi) => self.print_meta_item(mi),
|
||||||
ast::NestedMetaItem::Lit(lit) => self.print_meta_item_lit(lit),
|
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))
|
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))
|
Self::to_string(|s| s.print_meta_list_item(li))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::num::NonZero;
|
||||||
|
|
||||||
use rustc_abi::Align;
|
use rustc_abi::Align;
|
||||||
use rustc_ast::{
|
use rustc_ast::{
|
||||||
self as ast, Attribute, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem, NodeId,
|
self as ast, Attribute, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NodeId,
|
||||||
attr,
|
attr,
|
||||||
};
|
};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
|
@ -534,7 +534,7 @@ pub struct Condition {
|
||||||
|
|
||||||
/// Tests if a cfg-pattern matches the cfg set
|
/// Tests if a cfg-pattern matches the cfg set
|
||||||
pub fn cfg_matches(
|
pub fn cfg_matches(
|
||||||
cfg: &ast::NestedMetaItem,
|
cfg: &ast::MetaItemInner,
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
lint_node_id: NodeId,
|
lint_node_id: NodeId,
|
||||||
features: Option<&Features>,
|
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 a cfg-like condition (with `any` and `all`), using `eval` to
|
||||||
/// evaluate individual items.
|
/// evaluate individual items.
|
||||||
pub fn eval_condition(
|
pub fn eval_condition(
|
||||||
cfg: &ast::NestedMetaItem,
|
cfg: &ast::MetaItemInner,
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
features: Option<&Features>,
|
features: Option<&Features>,
|
||||||
eval: &mut impl FnMut(Condition) -> bool,
|
eval: &mut impl FnMut(Condition) -> bool,
|
||||||
|
@ -613,8 +613,8 @@ pub fn eval_condition(
|
||||||
let dcx = sess.dcx();
|
let dcx = sess.dcx();
|
||||||
|
|
||||||
let cfg = match cfg {
|
let cfg = match cfg {
|
||||||
ast::NestedMetaItem::MetaItem(meta_item) => meta_item,
|
ast::MetaItemInner::MetaItem(meta_item) => meta_item,
|
||||||
ast::NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
|
ast::MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
|
||||||
if let Some(features) = features {
|
if let Some(features) = features {
|
||||||
// we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
|
// 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
|
// 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 => {
|
ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
|
||||||
try_gate_cfg(sym::version, cfg.span, sess, features);
|
try_gate_cfg(sym::version, cfg.span, sess, features);
|
||||||
let (min_version, span) = match &mis[..] {
|
let (min_version, span) = match &mis[..] {
|
||||||
[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
|
[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
|
||||||
(sym, span)
|
(sym, span)
|
||||||
}
|
}
|
||||||
[
|
[
|
||||||
NestedMetaItem::Lit(MetaItemLit { span, .. })
|
MetaItemInner::Lit(MetaItemLit { span, .. })
|
||||||
| NestedMetaItem::MetaItem(MetaItem { span, .. }),
|
| MetaItemInner::MetaItem(MetaItem { span, .. }),
|
||||||
] => {
|
] => {
|
||||||
dcx.emit_err(session_diagnostics::ExpectedVersionLiteral { span: *span });
|
dcx.emit_err(session_diagnostics::ExpectedVersionLiteral { span: *span });
|
||||||
return false;
|
return false;
|
||||||
|
@ -729,7 +729,7 @@ pub fn eval_condition(
|
||||||
}
|
}
|
||||||
|
|
||||||
res & eval_condition(
|
res & eval_condition(
|
||||||
&ast::NestedMetaItem::MetaItem(mi),
|
&ast::MetaItemInner::MetaItem(mi),
|
||||||
sess,
|
sess,
|
||||||
features,
|
features,
|
||||||
eval,
|
eval,
|
||||||
|
@ -873,7 +873,7 @@ pub fn find_deprecation(
|
||||||
|
|
||||||
for meta in list {
|
for meta in list {
|
||||||
match meta {
|
match meta {
|
||||||
NestedMetaItem::MetaItem(mi) => match mi.name_or_empty() {
|
MetaItemInner::MetaItem(mi) => match mi.name_or_empty() {
|
||||||
sym::since => {
|
sym::since => {
|
||||||
if !get(mi, &mut since) {
|
if !get(mi, &mut since) {
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
|
@ -912,7 +912,7 @@ pub fn find_deprecation(
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NestedMetaItem::Lit(lit) => {
|
MetaItemInner::Lit(lit) => {
|
||||||
sess.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
|
sess.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
|
||||||
span: lit.span,
|
span: lit.span,
|
||||||
reason: UnsupportedLiteralReason::DeprecatedKvPair,
|
reason: UnsupportedLiteralReason::DeprecatedKvPair,
|
||||||
|
@ -1277,7 +1277,7 @@ pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
|
||||||
let mut candidates = Vec::new();
|
let mut candidates = Vec::new();
|
||||||
|
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
let NestedMetaItem::Lit(meta_lit) = meta else {
|
let MetaItemInner::Lit(meta_lit) = meta else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
candidates.push(meta_lit.symbol);
|
candidates.push(meta_lit.symbol);
|
||||||
|
|
|
@ -39,7 +39,7 @@ fn parse_cfg<'a>(
|
||||||
cx: &ExtCtxt<'a>,
|
cx: &ExtCtxt<'a>,
|
||||||
span: Span,
|
span: Span,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
) -> PResult<'a, ast::NestedMetaItem> {
|
) -> PResult<'a, ast::MetaItemInner> {
|
||||||
let mut p = cx.new_parser_from_tts(tts);
|
let mut p = cx.new_parser_from_tts(tts);
|
||||||
|
|
||||||
if p.token == token::Eof {
|
if p.token == token::Eof {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use rustc_ast as ast;
|
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::{
|
use rustc_expand::base::{
|
||||||
Annotatable, DeriveResolution, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier,
|
Annotatable, DeriveResolution, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier,
|
||||||
};
|
};
|
||||||
|
@ -49,9 +49,9 @@ impl MultiItemModifier for Expander {
|
||||||
let mut resolutions = match &meta_item.kind {
|
let mut resolutions = match &meta_item.kind {
|
||||||
MetaItemKind::List(list) => {
|
MetaItemKind::List(list) => {
|
||||||
list.iter()
|
list.iter()
|
||||||
.filter_map(|nested_meta| match nested_meta {
|
.filter_map(|meta_item_inner| match meta_item_inner {
|
||||||
NestedMetaItem::MetaItem(meta) => Some(meta),
|
MetaItemInner::MetaItem(meta) => Some(meta),
|
||||||
NestedMetaItem::Lit(lit) => {
|
MetaItemInner::Lit(lit) => {
|
||||||
// Reject `#[derive("Debug")]`.
|
// Reject `#[derive("Debug")]`.
|
||||||
report_unexpected_meta_item_lit(sess, lit);
|
report_unexpected_meta_item_lit(sess, lit);
|
||||||
None
|
None
|
||||||
|
|
|
@ -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_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr, list_contains_name};
|
||||||
use rustc_errors::codes::*;
|
use rustc_errors::codes::*;
|
||||||
use rustc_errors::{DiagMessage, SubdiagMessage, struct_span_code_err};
|
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 => {
|
sym::instruction_set => {
|
||||||
codegen_fn_attrs.instruction_set =
|
codegen_fn_attrs.instruction_set =
|
||||||
attr.meta_item_list().and_then(|l| match &l[..] {
|
attr.meta_item_list().and_then(|l| match &l[..] {
|
||||||
[NestedMetaItem::MetaItem(set)] => {
|
[MetaItemInner::MetaItem(set)] => {
|
||||||
let segments =
|
let segments =
|
||||||
set.path.segments.iter().map(|x| x.ident.name).collect::<Vec<_>>();
|
set.path.segments.iter().map(|x| x.ident.name).collect::<Vec<_>>();
|
||||||
match segments.as_slice() {
|
match segments.as_slice() {
|
||||||
|
|
|
@ -156,7 +156,7 @@ pub struct NativeLib {
|
||||||
pub kind: NativeLibKind,
|
pub kind: NativeLibKind,
|
||||||
pub name: Symbol,
|
pub name: Symbol,
|
||||||
pub filename: Option<Symbol>,
|
pub filename: Option<Symbol>,
|
||||||
pub cfg: Option<ast::NestedMetaItem>,
|
pub cfg: Option<ast::MetaItemInner>,
|
||||||
pub verbatim: bool,
|
pub verbatim: bool,
|
||||||
pub dll_imports: Vec<cstore::DllImport>,
|
pub dll_imports: Vec<cstore::DllImport>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ use rustc_span::{DUMMY_SP, FileName, Span};
|
||||||
use smallvec::{SmallVec, smallvec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use thin_vec::ThinVec;
|
use thin_vec::ThinVec;
|
||||||
|
|
||||||
use crate::base::ast::NestedMetaItem;
|
use crate::base::ast::MetaItemInner;
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::expand::{self, AstFragment, Invocation};
|
use crate::expand::{self, AstFragment, Invocation};
|
||||||
use crate::module::DirOwnership;
|
use crate::module::DirOwnership;
|
||||||
|
@ -783,7 +783,7 @@ impl SyntaxExtension {
|
||||||
|
|
||||||
fn collapse_debuginfo_by_name(attr: &Attribute) -> Result<CollapseMacroDebuginfo, Span> {
|
fn collapse_debuginfo_by_name(attr: &Attribute) -> Result<CollapseMacroDebuginfo, Span> {
|
||||||
let list = attr.meta_item_list();
|
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);
|
return Err(attr.span);
|
||||||
};
|
};
|
||||||
if !item.is_word() {
|
if !item.is_word() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_ast::tokenstream::{
|
||||||
AttrTokenStream, AttrTokenTree, LazyAttrTokenStream, Spacing, TokenTree,
|
AttrTokenStream, AttrTokenTree, LazyAttrTokenStream, Spacing, TokenTree,
|
||||||
};
|
};
|
||||||
use rustc_ast::{
|
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_attr as attr;
|
||||||
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
|
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
|
||||||
|
@ -40,7 +40,7 @@ pub struct StripUnconfigured<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -> Features {
|
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)
|
if attr.has_name(sym::feature)
|
||||||
&& let Some(list) = attr.meta_item_list()
|
&& let Some(list) = attr.meta_item_list()
|
||||||
{
|
{
|
||||||
|
@ -442,7 +442,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;
|
let span = meta_item.span;
|
||||||
match meta_item.meta_item_list() {
|
match meta_item.meta_item_list() {
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use rustc_ast::tokenstream::TokenStream;
|
||||||
use rustc_ast::visit::{self, AssocCtxt, Visitor, VisitorResult, try_visit, walk_list};
|
use rustc_ast::visit::{self, AssocCtxt, Visitor, VisitorResult, try_visit, walk_list};
|
||||||
use rustc_ast::{
|
use rustc_ast::{
|
||||||
AssocItemKind, AstNodeWrapper, AttrArgs, AttrStyle, AttrVec, ExprKind, ForeignItemKind,
|
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,
|
NodeId, PatKind, StmtKind, TyKind,
|
||||||
};
|
};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
|
@ -1863,8 +1863,8 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|a| a.has_name(sym::derive))
|
.filter(|a| a.has_name(sym::derive))
|
||||||
.flat_map(|a| a.meta_item_list().unwrap_or_default())
|
.flat_map(|a| a.meta_item_list().unwrap_or_default())
|
||||||
.filter_map(|nested_meta| match nested_meta {
|
.filter_map(|meta_item_inner| match meta_item_inner {
|
||||||
NestedMetaItem::MetaItem(ast::MetaItem {
|
MetaItemInner::MetaItem(ast::MetaItem {
|
||||||
kind: MetaItemKind::Word,
|
kind: MetaItemKind::Word,
|
||||||
path,
|
path,
|
||||||
..
|
..
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
//! Errors are reported if we are in the suitable configuration but
|
//! Errors are reported if we are in the suitable configuration but
|
||||||
//! the required condition is not met.
|
//! 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::fx::FxHashSet;
|
||||||
use rustc_data_structures::unord::UnordSet;
|
use rustc_data_structures::unord::UnordSet;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
|
@ -307,7 +307,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
|
||||||
(name, labels)
|
(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();
|
let mut out = Labels::default();
|
||||||
for label in value.as_str().split(',') {
|
for label in value.as_str().split(',') {
|
||||||
let label = label.trim();
|
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() {
|
if let Some(value) = item.value_str() {
|
||||||
value
|
value
|
||||||
} else if let Some(ident) = item.ident() {
|
} else if let Some(ident) = item.ident() {
|
||||||
|
|
|
@ -669,7 +669,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||||
|
|
||||||
let sp = li.span();
|
let sp = li.span();
|
||||||
let meta_item = match li {
|
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 sub = if let Some(item) = li.meta_item()
|
||||||
&& let ast::MetaItemKind::NameValue(_) = item.kind
|
&& let ast::MetaItemKind::NameValue(_) = item.kind
|
||||||
|
|
|
@ -1451,9 +1451,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
debug!("layout_scalar_valid_range: attr={:?}", attr);
|
debug!("layout_scalar_valid_range: attr={:?}", attr);
|
||||||
if let Some(
|
if let Some(
|
||||||
&[
|
&[
|
||||||
ast::NestedMetaItem::Lit(ast::MetaItemLit {
|
ast::MetaItemInner::Lit(ast::MetaItemLit {
|
||||||
kind: ast::LitKind::Int(a, _),
|
kind: ast::LitKind::Int(a, _), ..
|
||||||
..
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
) = attr.meta_item_list().as_deref()
|
) = attr.meta_item_list().as_deref()
|
||||||
|
|
|
@ -367,7 +367,7 @@ impl RustcMirAttrs {
|
||||||
fn set_field<T>(
|
fn set_field<T>(
|
||||||
field: &mut Option<T>,
|
field: &mut Option<T>,
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
attr: &ast::NestedMetaItem,
|
attr: &ast::MetaItemInner,
|
||||||
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
|
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
if field.is_some() {
|
if field.is_some() {
|
||||||
|
|
|
@ -18,7 +18,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast::tokenstream::TokenStream;
|
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_ast_pretty::pprust;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_errors::{Diag, FatalError, PResult};
|
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(
|
pub fn parse_cfg_attr(
|
||||||
cfg_attr: &Attribute,
|
cfg_attr: &Attribute,
|
||||||
psess: &ParseSess,
|
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_GRAMMAR_HELP: &str = "#[cfg_attr(condition, attribute, other_attribute, ...)]";
|
||||||
const CFG_ATTR_NOTE_REF: &str = "for more information, visit \
|
const CFG_ATTR_NOTE_REF: &str = "for more information, visit \
|
||||||
<https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>";
|
<https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>";
|
||||||
|
|
|
@ -358,7 +358,7 @@ impl<'a> Parser<'a> {
|
||||||
/// Parses `cfg_attr(pred, attr_item_list)` where `attr_item_list` is comma-delimited.
|
/// Parses `cfg_attr(pred, attr_item_list)` where `attr_item_list` is comma-delimited.
|
||||||
pub fn parse_cfg_attr(
|
pub fn parse_cfg_attr(
|
||||||
&mut self,
|
&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()?;
|
let cfg_predicate = self.parse_meta_item_inner()?;
|
||||||
self.expect(&token::Comma)?;
|
self.expect(&token::Comma)?;
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Matches `COMMASEP(meta_item_inner)`.
|
/// 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.
|
// Presumably, the majority of the time there will only be one attr.
|
||||||
let mut nmis = ThinVec::with_capacity(1);
|
let mut nmis = ThinVec::with_capacity(1);
|
||||||
while self.token != token::Eof {
|
while self.token != token::Eof {
|
||||||
|
@ -454,14 +454,14 @@ impl<'a> Parser<'a> {
|
||||||
/// ```ebnf
|
/// ```ebnf
|
||||||
/// MetaItemInner = UNSUFFIXED_LIT | MetaItem ;
|
/// 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() {
|
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
|
Err(err) => err.cancel(), // we provide a better error below
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.parse_meta_item(AllowLeadingUnsafe::No) {
|
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
|
Err(err) => err.cancel(), // we provide a better error below
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
use rustc_ast::token::Delimiter;
|
use rustc_ast::token::Delimiter;
|
||||||
use rustc_ast::tokenstream::DelimSpan;
|
use rustc_ast::tokenstream::DelimSpan;
|
||||||
use rustc_ast::{
|
use rustc_ast::{
|
||||||
self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, MetaItemKind,
|
self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind,
|
||||||
NestedMetaItem, Safety,
|
Safety,
|
||||||
};
|
};
|
||||||
use rustc_errors::{Applicability, FatalError, PResult};
|
use rustc_errors::{Applicability, FatalError, PResult};
|
||||||
use rustc_feature::{AttributeSafety, AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
|
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`.
|
/// Checks that the given meta-item is compatible with this `AttributeTemplate`.
|
||||||
fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaItemKind) -> bool {
|
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)),
|
[item] => item.is_word() && template.one_of.iter().any(|&word| item.has_name(word)),
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::cell::Cell;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
use rustc_ast::{
|
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_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{Applicability, DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey};
|
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 });
|
self.dcx().emit_err(errors::DocExpectStr { attr_span: meta.span(), attr_name });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_doc_alias_value(
|
fn check_doc_alias_value(
|
||||||
&self,
|
&self,
|
||||||
meta: &NestedMetaItem,
|
meta: &MetaItemInner,
|
||||||
doc_alias: Symbol,
|
doc_alias: Symbol,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
target: Target,
|
target: Target,
|
||||||
|
@ -850,7 +850,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
|
|
||||||
fn check_doc_alias(
|
fn check_doc_alias(
|
||||||
&self,
|
&self,
|
||||||
meta: &NestedMetaItem,
|
meta: &MetaItemInner,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
target: Target,
|
target: Target,
|
||||||
aliases: &mut FxHashMap<String, Span>,
|
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);
|
let doc_keyword = meta.value_str().unwrap_or(kw::Empty);
|
||||||
if doc_keyword == kw::Empty {
|
if doc_keyword == kw::Empty {
|
||||||
self.doc_attr_str_error(meta, "keyword");
|
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) {
|
let item_kind = match self.tcx.hir_node(hir_id) {
|
||||||
hir::Node::Item(item) => Some(&item.kind),
|
hir::Node::Item(item) => Some(&item.kind),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -957,7 +957,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
fn check_doc_inline(
|
fn check_doc_inline(
|
||||||
&self,
|
&self,
|
||||||
attr: &Attribute,
|
attr: &Attribute,
|
||||||
meta: &NestedMetaItem,
|
meta: &MetaItemInner,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
target: Target,
|
target: Target,
|
||||||
specified_inline: &mut Option<(bool, Span)>,
|
specified_inline: &mut Option<(bool, Span)>,
|
||||||
|
@ -997,7 +997,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
fn check_doc_masked(
|
fn check_doc_masked(
|
||||||
&self,
|
&self,
|
||||||
attr: &Attribute,
|
attr: &Attribute,
|
||||||
meta: &NestedMetaItem,
|
meta: &MetaItemInner,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
target: Target,
|
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.
|
/// Checks that an attribute is *not* used at the crate level. Returns `true` if valid.
|
||||||
fn check_attr_not_crate_level(
|
fn check_attr_not_crate_level(
|
||||||
&self,
|
&self,
|
||||||
meta: &NestedMetaItem,
|
meta: &MetaItemInner,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
attr_name: &str,
|
attr_name: &str,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
@ -1047,7 +1047,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
fn check_attr_crate_level(
|
fn check_attr_crate_level(
|
||||||
&self,
|
&self,
|
||||||
attr: &Attribute,
|
attr: &Attribute,
|
||||||
meta: &NestedMetaItem,
|
meta: &MetaItemInner,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if hir_id != CRATE_HIR_ID {
|
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
|
/// Checks that `doc(test(...))` attribute contains only valid attributes. Returns `true` if
|
||||||
/// valid.
|
/// 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() {
|
if let Some(metas) = meta.meta_item_list() {
|
||||||
for i_meta in metas {
|
for i_meta in metas {
|
||||||
match (i_meta.name_or_empty(), i_meta.meta_item()) {
|
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.
|
/// 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() {
|
if meta.meta_item_list().is_none() {
|
||||||
self.tcx.emit_node_span_lint(
|
self.tcx.emit_node_span_lint(
|
||||||
INVALID_DOC_ATTRIBUTES,
|
INVALID_DOC_ATTRIBUTES,
|
||||||
|
@ -1499,8 +1499,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if !matches!(&list[..], &[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Int(..), .. })])
|
if !matches!(&list[..], &[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Int(..), .. })]) {
|
||||||
{
|
|
||||||
self.tcx
|
self.tcx
|
||||||
.dcx()
|
.dcx()
|
||||||
.emit_err(errors::RustcLayoutScalarValidRangeArg { attr_span: attr.span });
|
.emit_err(errors::RustcLayoutScalarValidRangeArg { attr_span: attr.span });
|
||||||
|
@ -2073,7 +2072,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
let mut candidates = Vec::new();
|
let mut candidates = Vec::new();
|
||||||
|
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
let NestedMetaItem::Lit(meta_lit) = meta else {
|
let MetaItemInner::Lit(meta_lit) = meta else {
|
||||||
self.dcx().emit_err(errors::IncorrectMetaItem {
|
self.dcx().emit_err(errors::IncorrectMetaItem {
|
||||||
span: meta.span(),
|
span: meta.span(),
|
||||||
suggestion: errors::IncorrectMetaItemSuggestion {
|
suggestion: errors::IncorrectMetaItemSuggestion {
|
||||||
|
|
|
@ -1072,13 +1072,13 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
||||||
import_all = Some(meta.span);
|
import_all = Some(meta.span);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
MetaItemKind::List(nested_metas) => {
|
MetaItemKind::List(meta_item_inners) => {
|
||||||
for nested_meta in nested_metas {
|
for meta_item_inner in meta_item_inners {
|
||||||
match nested_meta.ident() {
|
match meta_item_inner.ident() {
|
||||||
Some(ident) if nested_meta.is_word() => {
|
Some(ident) if meta_item_inner.is_word() => {
|
||||||
single_imports.push(ident)
|
single_imports.push(ident)
|
||||||
}
|
}
|
||||||
_ => ill_formed(nested_meta.span()),
|
_ => ill_formed(meta_item_inner.span()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1198,8 +1198,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
||||||
} else if attr::contains_name(&item.attrs, sym::proc_macro_attribute) {
|
} else if attr::contains_name(&item.attrs, sym::proc_macro_attribute) {
|
||||||
return Some((MacroKind::Attr, item.ident, item.span));
|
return Some((MacroKind::Attr, item.ident, item.span));
|
||||||
} else if let Some(attr) = attr::find_by_name(&item.attrs, sym::proc_macro_derive) {
|
} else if let Some(attr) = attr::find_by_name(&item.attrs, sym::proc_macro_derive) {
|
||||||
if let Some(nested_meta) = attr.meta_item_list().and_then(|list| list.get(0).cloned()) {
|
if let Some(meta_item_inner) =
|
||||||
if let Some(ident) = nested_meta.ident() {
|
attr.meta_item_list().and_then(|list| list.get(0).cloned())
|
||||||
|
{
|
||||||
|
if let Some(ident) = meta_item_inner.ident() {
|
||||||
return Some((MacroKind::Derive, ident, ident.span));
|
return Some((MacroKind::Derive, ident, ident.span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@ use rustc_ast::expand::StrippedCfgItem;
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::visit::{self, Visitor};
|
use rustc_ast::visit::{self, Visitor};
|
||||||
use rustc_ast::{
|
use rustc_ast::{
|
||||||
self as ast, CRATE_NODE_ID, Crate, ItemKind, MetaItemKind, ModKind, NestedMetaItem, NodeId,
|
self as ast, CRATE_NODE_ID, Crate, ItemKind, MetaItemInner, MetaItemKind, ModKind, NodeId, Path,
|
||||||
Path,
|
|
||||||
};
|
};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
|
@ -2541,7 +2540,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
err.subdiagnostic(note);
|
err.subdiagnostic(note);
|
||||||
|
|
||||||
if let MetaItemKind::List(nested) = &cfg.kind
|
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 MetaItemKind::NameValue(feature_name) = &meta_item.kind
|
||||||
{
|
{
|
||||||
let note = errors::ItemWasBehindFeature {
|
let note = errors::ItemWasBehindFeature {
|
||||||
|
|
|
@ -129,8 +129,8 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
|
||||||
let mut registered_tools = RegisteredTools::default();
|
let mut registered_tools = RegisteredTools::default();
|
||||||
let (_, pre_configured_attrs) = &*tcx.crate_for_resolver(()).borrow();
|
let (_, pre_configured_attrs) = &*tcx.crate_for_resolver(()).borrow();
|
||||||
for attr in attr::filter_by_name(pre_configured_attrs, sym::register_tool) {
|
for attr in attr::filter_by_name(pre_configured_attrs, sym::register_tool) {
|
||||||
for nested_meta in attr.meta_item_list().unwrap_or_default() {
|
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
|
||||||
match nested_meta.ident() {
|
match meta_item_inner.ident() {
|
||||||
Some(ident) => {
|
Some(ident) => {
|
||||||
if let Some(old_ident) = registered_tools.replace(ident) {
|
if let Some(old_ident) = registered_tools.replace(ident) {
|
||||||
tcx.dcx().emit_err(errors::ToolWasAlreadyRegistered {
|
tcx.dcx().emit_err(errors::ToolWasAlreadyRegistered {
|
||||||
|
@ -142,7 +142,7 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
tcx.dcx().emit_err(errors::ToolOnlyAcceptsIdentifiers {
|
tcx.dcx().emit_err(errors::ToolOnlyAcceptsIdentifiers {
|
||||||
span: nested_meta.span(),
|
span: meta_item_inner.span(),
|
||||||
tool: sym::register_tool,
|
tool: sym::register_tool,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ pub struct NativeLib {
|
||||||
pub name: Symbol,
|
pub name: Symbol,
|
||||||
/// If packed_bundled_libs enabled, actual filename of library is stored.
|
/// If packed_bundled_libs enabled, actual filename of library is stored.
|
||||||
pub filename: Option<Symbol>,
|
pub filename: Option<Symbol>,
|
||||||
pub cfg: Option<ast::NestedMetaItem>,
|
pub cfg: Option<ast::MetaItemInner>,
|
||||||
pub foreign_module: Option<DefId>,
|
pub foreign_module: Option<DefId>,
|
||||||
pub verbatim: Option<bool>,
|
pub verbatim: Option<bool>,
|
||||||
pub dll_imports: Vec<DllImport>,
|
pub dll_imports: Vec<DllImport>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::path::PathBuf;
|
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_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::codes::*;
|
use rustc_errors::codes::*;
|
||||||
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
|
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
|
||||||
|
@ -282,7 +282,7 @@ pub struct OnUnimplementedFormatString {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct OnUnimplementedDirective {
|
pub struct OnUnimplementedDirective {
|
||||||
pub condition: Option<NestedMetaItem>,
|
pub condition: Option<MetaItemInner>,
|
||||||
pub subcommands: Vec<OnUnimplementedDirective>,
|
pub subcommands: Vec<OnUnimplementedDirective>,
|
||||||
pub message: Option<OnUnimplementedFormatString>,
|
pub message: Option<OnUnimplementedFormatString>,
|
||||||
pub label: Option<OnUnimplementedFormatString>,
|
pub label: Option<OnUnimplementedFormatString>,
|
||||||
|
@ -389,7 +389,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
fn parse(
|
fn parse(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
item_def_id: DefId,
|
item_def_id: DefId,
|
||||||
items: &[NestedMetaItem],
|
items: &[MetaItemInner],
|
||||||
span: Span,
|
span: Span,
|
||||||
is_root: bool,
|
is_root: bool,
|
||||||
is_diagnostic_namespace_variant: bool,
|
is_diagnostic_namespace_variant: bool,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::{mem, ops};
|
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_data_structures::fx::FxHashSet;
|
||||||
use rustc_feature::Features;
|
use rustc_feature::Features;
|
||||||
use rustc_session::parse::ParseSess;
|
use rustc_session::parse::ParseSess;
|
||||||
|
@ -41,18 +41,18 @@ pub(crate) struct InvalidCfgError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cfg {
|
impl Cfg {
|
||||||
/// Parses a `NestedMetaItem` into a `Cfg`.
|
/// Parses a `MetaItemInner` into a `Cfg`.
|
||||||
fn parse_nested(
|
fn parse_nested(
|
||||||
nested_cfg: &NestedMetaItem,
|
nested_cfg: &MetaItemInner,
|
||||||
exclude: &FxHashSet<Cfg>,
|
exclude: &FxHashSet<Cfg>,
|
||||||
) -> Result<Option<Cfg>, InvalidCfgError> {
|
) -> Result<Option<Cfg>, InvalidCfgError> {
|
||||||
match nested_cfg {
|
match nested_cfg {
|
||||||
NestedMetaItem::MetaItem(ref cfg) => Cfg::parse_without(cfg, exclude),
|
MetaItemInner::MetaItem(ref cfg) => Cfg::parse_without(cfg, exclude),
|
||||||
NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => match *b {
|
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => match *b {
|
||||||
true => Ok(Some(Cfg::True)),
|
true => Ok(Some(Cfg::True)),
|
||||||
false => Ok(Some(Cfg::False)),
|
false => Ok(Some(Cfg::False)),
|
||||||
},
|
},
|
||||||
NestedMetaItem::Lit(ref lit) => {
|
MetaItemInner::Lit(ref lit) => {
|
||||||
Err(InvalidCfgError { msg: "unexpected literal", span: lit.span })
|
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
|
/// If the content is not properly formatted, it will return an error indicating what and where
|
||||||
/// the error is.
|
/// 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())
|
Self::parse_nested(cfg, &FxHashSet::default()).map(|ret| ret.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use rustc_ast::ast::LitIntType;
|
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::symbol::{Ident, kw};
|
||||||
use rustc_span::{DUMMY_SP, create_default_session_globals_then};
|
use rustc_span::{DUMMY_SP, create_default_session_globals_then};
|
||||||
use thin_vec::thin_vec;
|
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)))
|
Cfg::Cfg(Symbol::intern(name), Some(Symbol::intern(value)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dummy_lit(symbol: Symbol, kind: LitKind) -> NestedMetaItem {
|
fn dummy_lit(symbol: Symbol, kind: LitKind) -> MetaItemInner {
|
||||||
NestedMetaItem::Lit(MetaItemLit { symbol, suffix: None, kind, span: DUMMY_SP })
|
MetaItemInner::Lit(MetaItemLit { symbol, suffix: None, kind, span: DUMMY_SP })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dummy_meta_item_word(name: &str) -> NestedMetaItem {
|
fn dummy_meta_item_word(name: &str) -> MetaItemInner {
|
||||||
NestedMetaItem::MetaItem(MetaItem {
|
MetaItemInner::MetaItem(MetaItem {
|
||||||
unsafety: Safety::Default,
|
unsafety: Safety::Default,
|
||||||
path: Path::from_ident(Ident::from_str(name)),
|
path: Path::from_ident(Ident::from_str(name)),
|
||||||
kind: MetaItemKind::Word,
|
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 };
|
let lit = MetaItemLit { symbol, suffix: None, kind, span: DUMMY_SP };
|
||||||
NestedMetaItem::MetaItem(MetaItem {
|
MetaItemInner::MetaItem(MetaItem {
|
||||||
unsafety: Safety::Default,
|
unsafety: Safety::Default,
|
||||||
path: Path::from_ident(Ident::from_str(name)),
|
path: Path::from_ident(Ident::from_str(name)),
|
||||||
kind: MetaItemKind::NameValue(lit),
|
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 {
|
macro_rules! dummy_meta_item_list {
|
||||||
($name:ident, [$($list:ident),* $(,)?]) => {
|
($name:ident, [$($list:ident),* $(,)?]) => {
|
||||||
NestedMetaItem::MetaItem(MetaItem {
|
MetaItemInner::MetaItem(MetaItem {
|
||||||
unsafety: Safety::Default,
|
unsafety: Safety::Default,
|
||||||
path: Path::from_ident(Ident::from_str(stringify!($name))),
|
path: Path::from_ident(Ident::from_str(stringify!($name))),
|
||||||
kind: MetaItemKind::List(thin_vec![
|
kind: MetaItemKind::List(thin_vec![
|
||||||
|
@ -52,7 +52,7 @@ macro_rules! dummy_meta_item_list {
|
||||||
};
|
};
|
||||||
|
|
||||||
($name:ident, [$($list:expr),* $(,)?]) => {
|
($name:ident, [$($list:expr),* $(,)?]) => {
|
||||||
NestedMetaItem::MetaItem(MetaItem {
|
MetaItemInner::MetaItem(MetaItem {
|
||||||
unsafety: Safety::Default,
|
unsafety: Safety::Default,
|
||||||
path: Path::from_ident(Ident::from_str(stringify!($name))),
|
path: Path::from_ident(Ident::from_str(stringify!($name))),
|
||||||
kind: MetaItemKind::List(thin_vec![
|
kind: MetaItemKind::List(thin_vec![
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::sync::{Arc, OnceLock as OnceCell};
|
||||||
use std::{fmt, iter};
|
use std::{fmt, iter};
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use rustc_ast::NestedMetaItem;
|
use rustc_ast::MetaItemInner;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_attr::{ConstStability, Deprecation, Stability, StableSince};
|
use rustc_attr::{ConstStability, Deprecation, Stability, StableSince};
|
||||||
use rustc_const_eval::const_eval::is_unstable_const_fn;
|
use rustc_const_eval::const_eval::is_unstable_const_fn;
|
||||||
|
@ -953,7 +953,7 @@ pub(crate) struct Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait AttributesExt {
|
pub(crate) trait AttributesExt {
|
||||||
type AttributeIterator<'a>: Iterator<Item = ast::NestedMetaItem>
|
type AttributeIterator<'a>: Iterator<Item = ast::MetaItemInner>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
type Attributes<'a>: Iterator<Item = &'a ast::Attribute>
|
type Attributes<'a>: Iterator<Item = &'a ast::Attribute>
|
||||||
|
@ -1043,7 +1043,7 @@ pub(crate) trait AttributesExt {
|
||||||
let mut meta = attr.meta_item().unwrap().clone();
|
let mut meta = attr.meta_item().unwrap().clone();
|
||||||
meta.path = ast::Path::from_ident(Ident::with_dummy_span(sym::target_feature));
|
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;
|
cfg &= feat_cfg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1055,7 +1055,7 @@ pub(crate) trait AttributesExt {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AttributesExt for [ast::Attribute] {
|
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;
|
type Attributes<'a> = impl Iterator<Item = &'a ast::Attribute> + 'a;
|
||||||
|
|
||||||
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_> {
|
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_> {
|
||||||
|
@ -1072,7 +1072,7 @@ impl AttributesExt for [ast::Attribute] {
|
||||||
|
|
||||||
impl AttributesExt for [(Cow<'_, ast::Attribute>, Option<DefId>)] {
|
impl AttributesExt for [(Cow<'_, ast::Attribute>, Option<DefId>)] {
|
||||||
type AttributeIterator<'a>
|
type AttributeIterator<'a>
|
||||||
= impl Iterator<Item = ast::NestedMetaItem> + 'a
|
= impl Iterator<Item = ast::MetaItemInner> + 'a
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
type Attributes<'a>
|
type Attributes<'a>
|
||||||
|
@ -1106,11 +1106,11 @@ pub(crate) trait NestedAttributesExt {
|
||||||
|
|
||||||
/// Returns `Some(attr)` if the attribute list contains 'attr'
|
/// Returns `Some(attr)` if the attribute list contains 'attr'
|
||||||
/// corresponding to a specific `word`
|
/// 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 {
|
impl<I: Iterator<Item = ast::MetaItemInner>> NestedAttributesExt for I {
|
||||||
fn get_word_attr(mut self, word: Symbol) -> Option<ast::NestedMetaItem> {
|
fn get_word_attr(mut self, word: Symbol) -> Option<ast::MetaItemInner> {
|
||||||
self.find(|attr| attr.is_word() && attr.has_name(word))
|
self.find(|attr| attr.is_word() && attr.has_name(word))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1157,7 +1157,7 @@ pub(crate) struct Attributes {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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)
|
self.other_attrs.lists(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
use super::{ALLOW_ATTRIBUTES_WITHOUT_REASON, Attribute};
|
use super::{ALLOW_ATTRIBUTES_WITHOUT_REASON, Attribute};
|
||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::is_from_proc_macro;
|
use clippy_utils::is_from_proc_macro;
|
||||||
use rustc_ast::{MetaItemKind, NestedMetaItem};
|
use rustc_ast::{MetaItemInner, MetaItemKind};
|
||||||
use rustc_lint::{LateContext, LintContext};
|
use rustc_lint::{LateContext, LintContext};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
use rustc_span::symbol::Symbol;
|
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
|
// 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
|
&& let MetaItemKind::NameValue(_) = &item.kind
|
||||||
&& item.path == sym::reason
|
&& item.path == sym::reason
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
|
use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
|
||||||
use super::utils::extract_clippy_lint;
|
use super::utils::extract_clippy_lint;
|
||||||
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
|
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_lint::{LateContext, Level, LintContext};
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_span::{DUMMY_SP, sym};
|
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 {
|
for lint in items {
|
||||||
if let Some(lint_name) = extract_clippy_lint(lint) {
|
if let Some(lint_name) = extract_clippy_lint(lint) {
|
||||||
if lint_name.as_str() == "restriction" && name != sym::allow {
|
if lint_name.as_str() == "restriction" && name != sym::allow {
|
||||||
|
|
|
@ -14,7 +14,7 @@ mod utils;
|
||||||
|
|
||||||
use clippy_config::Conf;
|
use clippy_config::Conf;
|
||||||
use clippy_config::msrvs::{self, Msrv};
|
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_hir::{ImplItem, Item, ItemKind, TraitItem};
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
|
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
|
@ -456,7 +456,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for item in items {
|
for item in items {
|
||||||
if let NestedMetaItem::MetaItem(mi) = &item
|
if let MetaItemInner::MetaItem(mi) = &item
|
||||||
&& let MetaItemKind::NameValue(lit) = &mi.kind
|
&& let MetaItemKind::NameValue(lit) = &mi.kind
|
||||||
&& mi.has_name(sym::since)
|
&& mi.has_name(sym::since)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::{Attribute, NON_MINIMAL_CFG};
|
use super::{Attribute, NON_MINIMAL_CFG};
|
||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::source::SpanRangeExt;
|
use clippy_utils::source::SpanRangeExt;
|
||||||
use rustc_ast::{MetaItemKind, NestedMetaItem};
|
use rustc_ast::{MetaItemInner, MetaItemKind};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_lint::EarlyContext;
|
use rustc_lint::EarlyContext;
|
||||||
use rustc_span::sym;
|
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 {
|
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) {
|
if !meta.has_name(sym::any) && !meta.has_name(sym::all) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::utils::{extract_clippy_lint, is_lint_level, is_word};
|
||||||
use super::{Attribute, USELESS_ATTRIBUTE};
|
use super::{Attribute, USELESS_ATTRIBUTE};
|
||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
|
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
|
||||||
use rustc_ast::NestedMetaItem;
|
use rustc_ast::MetaItemInner;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Item, ItemKind};
|
use rustc_hir::{Item, ItemKind};
|
||||||
use rustc_lint::{LateContext, LintContext};
|
use rustc_lint::{LateContext, LintContext};
|
||||||
|
@ -21,7 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute])
|
||||||
for lint in lint_list {
|
for lint in lint_list {
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::Use(..) => {
|
ItemKind::Use(..) => {
|
||||||
if let NestedMetaItem::MetaItem(meta_item) = lint
|
if let MetaItemInner::MetaItem(meta_item) = lint
|
||||||
&& meta_item.is_word()
|
&& meta_item.is_word()
|
||||||
&& let Some(ident) = meta_item.ident()
|
&& let Some(ident) = meta_item.ident()
|
||||||
&& matches!(
|
&& matches!(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use clippy_utils::macros::{is_panic, macro_backtrace};
|
use clippy_utils::macros::{is_panic, macro_backtrace};
|
||||||
use rustc_ast::{AttrId, NestedMetaItem};
|
use rustc_ast::{AttrId, MetaItemInner};
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
|
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::sym;
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
|
|
||||||
pub(super) fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
|
pub(super) fn is_word(nmi: &MetaItemInner, expected: Symbol) -> bool {
|
||||||
if let NestedMetaItem::MetaItem(mi) = &nmi {
|
if let MetaItemInner::MetaItem(mi) = &nmi {
|
||||||
mi.is_word() && mi.has_name(expected)
|
mi.is_word() && mi.has_name(expected)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -74,7 +74,7 @@ fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the lint name if it is clippy lint.
|
/// 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()
|
if let Some(meta_item) = lint.meta_item()
|
||||||
&& meta_item.path.segments.len() > 1
|
&& meta_item.path.segments.len() > 1
|
||||||
&& let tool_name = meta_item.path.segments[0].ident
|
&& let tool_name = meta_item.path.segments[0].ident
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use rustc_ast::NestedMetaItem;
|
use rustc_ast::MetaItemInner;
|
||||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||||
use rustc_session::declare_lint_pass;
|
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.is_some_and(|list| {
|
||||||
list.iter().any(|item| {
|
list.iter().any(|item| {
|
||||||
item.ident().is_some_and(|ident| match ident.name {
|
item.ident().is_some_and(|ident| match ident.name {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use clippy_utils::{
|
||||||
path_to_local_id, span_contains_cfg, span_find_starting_semi,
|
path_to_local_id, span_contains_cfg, span_find_starting_semi,
|
||||||
};
|
};
|
||||||
use core::ops::ControlFlow;
|
use core::ops::ControlFlow;
|
||||||
use rustc_ast::NestedMetaItem;
|
use rustc_ast::MetaItemInner;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::LangItem::ResultErr;
|
use rustc_hir::LangItem::ResultErr;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
|
@ -421,7 +421,7 @@ fn check_final_expr<'tcx>(
|
||||||
if matches!(Level::from_attr(attr), Some(Level::Expect(_)))
|
if matches!(Level::from_attr(attr), Some(Level::Expect(_)))
|
||||||
&& let metas = attr.meta_item_list()
|
&& let metas = attr.meta_item_list()
|
||||||
&& let Some(lst) = metas
|
&& 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()
|
&& let [tool, lint_name] = meta_item.path.segments.as_slice()
|
||||||
&& tool.ident.name == sym::clippy
|
&& tool.ident.name == sym::clippy
|
||||||
&& matches!(
|
&& matches!(
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn format_derive(
|
||||||
let item_spans = attr.meta_item_list().map(|meta_item_list| {
|
let item_spans = attr.meta_item_list().map(|meta_item_list| {
|
||||||
meta_item_list
|
meta_item_list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|nested_meta_item| nested_meta_item.span())
|
.map(|meta_item_inner| meta_item_inner.span())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let items = itemize_list(
|
let items = itemize_list(
|
||||||
|
@ -243,17 +243,15 @@ fn rewrite_initial_doc_comments(
|
||||||
Ok((0, None))
|
Ok((0, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rewrite for ast::NestedMetaItem {
|
impl Rewrite for ast::MetaItemInner {
|
||||||
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
|
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
|
||||||
self.rewrite_result(context, shape).ok()
|
self.rewrite_result(context, shape).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
|
fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
|
||||||
match self {
|
match self {
|
||||||
ast::NestedMetaItem::MetaItem(ref meta_item) => {
|
ast::MetaItemInner::MetaItem(ref meta_item) => meta_item.rewrite_result(context, shape),
|
||||||
meta_item.rewrite_result(context, shape)
|
ast::MetaItemInner::Lit(ref l) => {
|
||||||
}
|
|
||||||
ast::NestedMetaItem::Lit(ref l) => {
|
|
||||||
rewrite_literal(context, l.as_token_lit(), l.span, shape)
|
rewrite_literal(context, l.as_token_lit(), l.span, shape)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -535,10 +533,10 @@ pub(crate) trait MetaVisitor<'ast> {
|
||||||
fn visit_meta_list(
|
fn visit_meta_list(
|
||||||
&mut self,
|
&mut self,
|
||||||
_meta_item: &'ast ast::MetaItem,
|
_meta_item: &'ast ast::MetaItem,
|
||||||
list: &'ast [ast::NestedMetaItem],
|
list: &'ast [ast::MetaItemInner],
|
||||||
) {
|
) {
|
||||||
for nm in list {
|
for nm in list {
|
||||||
self.visit_nested_meta_item(nm);
|
self.visit_meta_item_inner(nm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,10 +549,10 @@ pub(crate) trait MetaVisitor<'ast> {
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) {
|
fn visit_meta_item_inner(&mut self, nm: &'ast ast::MetaItemInner) {
|
||||||
match nm {
|
match nm {
|
||||||
ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
|
ast::MetaItemInner::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
|
||||||
ast::NestedMetaItem::Lit(ref lit) => self.visit_meta_item_lit(lit),
|
ast::MetaItemInner::Lit(ref lit) => self.visit_meta_item_lit(lit),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ pub(crate) enum OverflowableItem<'a> {
|
||||||
Expr(&'a ast::Expr),
|
Expr(&'a ast::Expr),
|
||||||
GenericParam(&'a ast::GenericParam),
|
GenericParam(&'a ast::GenericParam),
|
||||||
MacroArg(&'a MacroArg),
|
MacroArg(&'a MacroArg),
|
||||||
NestedMetaItem(&'a ast::NestedMetaItem),
|
MetaItemInner(&'a ast::MetaItemInner),
|
||||||
SegmentParam(&'a SegmentParam<'a>),
|
SegmentParam(&'a SegmentParam<'a>),
|
||||||
FieldDef(&'a ast::FieldDef),
|
FieldDef(&'a ast::FieldDef),
|
||||||
TuplePatField(&'a TuplePatField<'a>),
|
TuplePatField(&'a TuplePatField<'a>),
|
||||||
|
@ -123,7 +123,7 @@ impl<'a> OverflowableItem<'a> {
|
||||||
OverflowableItem::Expr(expr) => f(*expr),
|
OverflowableItem::Expr(expr) => f(*expr),
|
||||||
OverflowableItem::GenericParam(gp) => f(*gp),
|
OverflowableItem::GenericParam(gp) => f(*gp),
|
||||||
OverflowableItem::MacroArg(macro_arg) => f(*macro_arg),
|
OverflowableItem::MacroArg(macro_arg) => f(*macro_arg),
|
||||||
OverflowableItem::NestedMetaItem(nmi) => f(*nmi),
|
OverflowableItem::MetaItemInner(nmi) => f(*nmi),
|
||||||
OverflowableItem::SegmentParam(sp) => f(*sp),
|
OverflowableItem::SegmentParam(sp) => f(*sp),
|
||||||
OverflowableItem::FieldDef(sf) => f(*sf),
|
OverflowableItem::FieldDef(sf) => f(*sf),
|
||||||
OverflowableItem::TuplePatField(pat) => f(*pat),
|
OverflowableItem::TuplePatField(pat) => f(*pat),
|
||||||
|
@ -138,9 +138,9 @@ impl<'a> OverflowableItem<'a> {
|
||||||
OverflowableItem::Expr(expr) => is_simple_expr(expr),
|
OverflowableItem::Expr(expr) => is_simple_expr(expr),
|
||||||
OverflowableItem::MacroArg(MacroArg::Keyword(..)) => true,
|
OverflowableItem::MacroArg(MacroArg::Keyword(..)) => true,
|
||||||
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
|
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => is_simple_expr(expr),
|
||||||
OverflowableItem::NestedMetaItem(nested_meta_item) => match nested_meta_item {
|
OverflowableItem::MetaItemInner(meta_item_inner) => match meta_item_inner {
|
||||||
ast::NestedMetaItem::Lit(..) => true,
|
ast::MetaItemInner::Lit(..) => true,
|
||||||
ast::NestedMetaItem::MetaItem(ref meta_item) => {
|
ast::MetaItemInner::MetaItem(ref meta_item) => {
|
||||||
matches!(meta_item.kind, ast::MetaItemKind::Word)
|
matches!(meta_item.kind, ast::MetaItemKind::Word)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -184,12 +184,10 @@ impl<'a> OverflowableItem<'a> {
|
||||||
MacroArg::Item(..) => len == 1,
|
MacroArg::Item(..) => len == 1,
|
||||||
MacroArg::Keyword(..) => false,
|
MacroArg::Keyword(..) => false,
|
||||||
},
|
},
|
||||||
OverflowableItem::NestedMetaItem(nested_meta_item) if len == 1 => {
|
OverflowableItem::MetaItemInner(meta_item_inner) if len == 1 => match meta_item_inner {
|
||||||
match nested_meta_item {
|
ast::MetaItemInner::Lit(..) => false,
|
||||||
ast::NestedMetaItem::Lit(..) => false,
|
ast::MetaItemInner::MetaItem(..) => true,
|
||||||
ast::NestedMetaItem::MetaItem(..) => true,
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
OverflowableItem::SegmentParam(SegmentParam::Type(ty)) => {
|
OverflowableItem::SegmentParam(SegmentParam::Type(ty)) => {
|
||||||
can_be_overflowed_type(context, ty, len)
|
can_be_overflowed_type(context, ty, len)
|
||||||
}
|
}
|
||||||
|
@ -202,7 +200,7 @@ impl<'a> OverflowableItem<'a> {
|
||||||
fn special_cases(&self, config: &Config) -> impl Iterator<Item = &(&'static str, usize)> {
|
fn special_cases(&self, config: &Config) -> impl Iterator<Item = &(&'static str, usize)> {
|
||||||
let base_cases = match self {
|
let base_cases = match self {
|
||||||
OverflowableItem::MacroArg(..) => SPECIAL_CASE_MACROS,
|
OverflowableItem::MacroArg(..) => SPECIAL_CASE_MACROS,
|
||||||
OverflowableItem::NestedMetaItem(..) => SPECIAL_CASE_ATTR,
|
OverflowableItem::MetaItemInner(..) => SPECIAL_CASE_ATTR,
|
||||||
_ => &[],
|
_ => &[],
|
||||||
};
|
};
|
||||||
let additional_cases = match self {
|
let additional_cases = match self {
|
||||||
|
@ -261,7 +259,7 @@ macro_rules! impl_into_overflowable_item_for_rustfmt_types {
|
||||||
impl_into_overflowable_item_for_ast_node!(
|
impl_into_overflowable_item_for_ast_node!(
|
||||||
Expr,
|
Expr,
|
||||||
GenericParam,
|
GenericParam,
|
||||||
NestedMetaItem,
|
MetaItemInner,
|
||||||
FieldDef,
|
FieldDef,
|
||||||
Ty,
|
Ty,
|
||||||
Pat,
|
Pat,
|
||||||
|
|
|
@ -116,8 +116,8 @@ fn get_skip_names(kind: &str, attrs: &[ast::Attribute]) -> Vec<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(list) = attr.meta_item_list() {
|
if let Some(list) = attr.meta_item_list() {
|
||||||
for nested_meta_item in list {
|
for meta_item_inner in list {
|
||||||
if let Some(name) = nested_meta_item.ident() {
|
if let Some(name) = meta_item_inner.ident() {
|
||||||
skip_names.push(name.to_string());
|
skip_names.push(name.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ impl Spanned for MacroArg {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Spanned for ast::NestedMetaItem {
|
impl Spanned for ast::MetaItemInner {
|
||||||
fn span(&self) -> Span {
|
fn span(&self) -> Span {
|
||||||
self.span()
|
self.span()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use rustc_ast::ast::{
|
use rustc_ast::ast::{
|
||||||
self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
|
self, Attribute, MetaItem, MetaItemInner, MetaItemKind, NodeId, Path, Visibility,
|
||||||
VisibilityKind,
|
VisibilityKind,
|
||||||
};
|
};
|
||||||
use rustc_ast::ptr;
|
use rustc_ast::ptr;
|
||||||
|
@ -257,10 +257,10 @@ fn is_skip(meta_item: &MetaItem) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_skip_nested(meta_item: &NestedMetaItem) -> bool {
|
fn is_skip_nested(meta_item: &MetaItemInner) -> bool {
|
||||||
match meta_item {
|
match meta_item {
|
||||||
NestedMetaItem::MetaItem(ref mi) => is_skip(mi),
|
MetaItemInner::MetaItem(ref mi) => is_skip(mi),
|
||||||
NestedMetaItem::Lit(_) => false,
|
MetaItemInner::Lit(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue