Rename value
field to expr
to simplify later commits' diffs
This commit is contained in:
parent
a611773d80
commit
53b2c7cc95
14 changed files with 28 additions and 30 deletions
|
@ -1759,7 +1759,7 @@ pub enum AttrArgs {
|
||||||
/// Span of the `=` token.
|
/// Span of the `=` token.
|
||||||
eq_span: Span,
|
eq_span: Span,
|
||||||
|
|
||||||
value: AttrArgsEq,
|
expr: AttrArgsEq,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1804,7 +1804,7 @@ impl AttrArgs {
|
||||||
match self {
|
match self {
|
||||||
AttrArgs::Empty => None,
|
AttrArgs::Empty => None,
|
||||||
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
|
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
|
||||||
AttrArgs::Eq { eq_span, value } => Some(eq_span.to(value.span())),
|
AttrArgs::Eq { eq_span, expr } => Some(eq_span.to(expr.span())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1814,7 +1814,7 @@ impl AttrArgs {
|
||||||
match self {
|
match self {
|
||||||
AttrArgs::Empty => TokenStream::default(),
|
AttrArgs::Empty => TokenStream::default(),
|
||||||
AttrArgs::Delimited(args) => args.tokens.clone(),
|
AttrArgs::Delimited(args) => args.tokens.clone(),
|
||||||
AttrArgs::Eq { value, .. } => TokenStream::from_ast(value.unwrap_ast()),
|
AttrArgs::Eq { expr, .. } => TokenStream::from_ast(expr.unwrap_ast()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1828,10 +1828,10 @@ where
|
||||||
match self {
|
match self {
|
||||||
AttrArgs::Empty => {}
|
AttrArgs::Empty => {}
|
||||||
AttrArgs::Delimited(args) => args.hash_stable(ctx, hasher),
|
AttrArgs::Delimited(args) => args.hash_stable(ctx, hasher),
|
||||||
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => {
|
AttrArgs::Eq { expr: AttrArgsEq::Ast(expr), .. } => {
|
||||||
unreachable!("hash_stable {:?}", expr);
|
unreachable!("hash_stable {:?}", expr);
|
||||||
}
|
}
|
||||||
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(lit) } => {
|
AttrArgs::Eq { eq_span, expr: AttrArgsEq::Hir(lit) } => {
|
||||||
eq_span.hash_stable(ctx, hasher);
|
eq_span.hash_stable(ctx, hasher);
|
||||||
lit.hash_stable(ctx, hasher);
|
lit.hash_stable(ctx, hasher);
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,7 +268,7 @@ impl AttrItem {
|
||||||
/// ```
|
/// ```
|
||||||
fn value_str(&self) -> Option<Symbol> {
|
fn value_str(&self) -> Option<Symbol> {
|
||||||
match &self.args {
|
match &self.args {
|
||||||
AttrArgs::Eq { value, .. } => value.value_str(),
|
AttrArgs::Eq { expr, .. } => expr.value_str(),
|
||||||
AttrArgs::Delimited(_) | AttrArgs::Empty => None,
|
AttrArgs::Delimited(_) | AttrArgs::Empty => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,7 +492,7 @@ impl MetaItemKind {
|
||||||
MetaItemKind::list_from_tokens(tokens.clone()).map(MetaItemKind::List)
|
MetaItemKind::list_from_tokens(tokens.clone()).map(MetaItemKind::List)
|
||||||
}
|
}
|
||||||
AttrArgs::Delimited(..) => None,
|
AttrArgs::Delimited(..) => None,
|
||||||
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => match expr.kind {
|
AttrArgs::Eq { expr: AttrArgsEq::Ast(expr), .. } => match expr.kind {
|
||||||
ExprKind::Lit(token_lit) => {
|
ExprKind::Lit(token_lit) => {
|
||||||
// Turn failures to `None`, we'll get parse errors elsewhere.
|
// Turn failures to `None`, we'll get parse errors elsewhere.
|
||||||
MetaItemLit::from_token_lit(token_lit, expr.span)
|
MetaItemLit::from_token_lit(token_lit, expr.span)
|
||||||
|
@ -501,7 +501,7 @@ impl MetaItemKind {
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
|
AttrArgs::Eq { expr: AttrArgsEq::Hir(lit), .. } => {
|
||||||
Some(MetaItemKind::NameValue(lit.clone()))
|
Some(MetaItemKind::NameValue(lit.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -704,7 +704,7 @@ pub fn mk_attr_name_value_str(
|
||||||
tokens: None,
|
tokens: None,
|
||||||
});
|
});
|
||||||
let path = Path::from_ident(Ident::new(name, span));
|
let path = Path::from_ident(Ident::new(name, span));
|
||||||
let args = AttrArgs::Eq { eq_span: span, value: AttrArgsEq::Ast(expr) };
|
let args = AttrArgs::Eq { eq_span: span, expr: AttrArgsEq::Ast(expr) };
|
||||||
mk_attr(g, style, unsafety, path, args, span)
|
mk_attr(g, style, unsafety, path, args, span)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -451,8 +451,8 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
|
||||||
match args {
|
match args {
|
||||||
AttrArgs::Empty => {}
|
AttrArgs::Empty => {}
|
||||||
AttrArgs::Delimited(args) => visit_delim_args(vis, args),
|
AttrArgs::Delimited(args) => visit_delim_args(vis, args),
|
||||||
AttrArgs::Eq { eq_span, value } => {
|
AttrArgs::Eq { eq_span, expr } => {
|
||||||
vis.visit_expr(value.unwrap_ast_mut());
|
vis.visit_expr(expr.unwrap_ast_mut());
|
||||||
vis.visit_span(eq_span);
|
vis.visit_span(eq_span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1287,7 +1287,7 @@ pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -
|
||||||
match args {
|
match args {
|
||||||
AttrArgs::Empty => {}
|
AttrArgs::Empty => {}
|
||||||
AttrArgs::Delimited(_args) => {}
|
AttrArgs::Delimited(_args) => {}
|
||||||
AttrArgs::Eq { value, .. } => try_visit!(visitor.visit_expr(value.unwrap_ast())),
|
AttrArgs::Eq { expr, .. } => try_visit!(visitor.visit_expr(expr.unwrap_ast())),
|
||||||
}
|
}
|
||||||
V::Result::output()
|
V::Result::output()
|
||||||
}
|
}
|
||||||
|
|
|
@ -896,8 +896,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// This is an inert key-value attribute - it will never be visible to macros
|
// This is an inert key-value attribute - it will never be visible to macros
|
||||||
// after it gets lowered to HIR. Therefore, we can extract literals to handle
|
// after it gets lowered to HIR. Therefore, we can extract literals to handle
|
||||||
// nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
|
// nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
|
||||||
&AttrArgs::Eq { eq_span, ref value } => {
|
&AttrArgs::Eq { eq_span, ref expr } => {
|
||||||
let expr = value.unwrap_ast();
|
let expr = expr.unwrap_ast();
|
||||||
// In valid code the value always ends up as a single literal. Otherwise, a dummy
|
// In valid code the value always ends up as a single literal. Otherwise, a dummy
|
||||||
// literal suffices because the error is handled elsewhere.
|
// literal suffices because the error is handled elsewhere.
|
||||||
let lit = if let ExprKind::Lit(token_lit) = expr.kind
|
let lit = if let ExprKind::Lit(token_lit) = expr.kind
|
||||||
|
@ -913,7 +913,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(lit) }
|
AttrArgs::Eq { eq_span, expr: AttrArgsEq::Hir(lit) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -648,14 +648,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||||
AttrArgs::Empty => {
|
AttrArgs::Empty => {
|
||||||
self.print_path(&item.path, false, 0);
|
self.print_path(&item.path, false, 0);
|
||||||
}
|
}
|
||||||
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => {
|
AttrArgs::Eq { expr: AttrArgsEq::Ast(expr), .. } => {
|
||||||
self.print_path(&item.path, false, 0);
|
self.print_path(&item.path, false, 0);
|
||||||
self.space();
|
self.space();
|
||||||
self.word_space("=");
|
self.word_space("=");
|
||||||
let token_str = self.expr_to_string(expr);
|
let token_str = self.expr_to_string(expr);
|
||||||
self.word(token_str);
|
self.word(token_str);
|
||||||
}
|
}
|
||||||
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
|
AttrArgs::Eq { expr: AttrArgsEq::Hir(lit), .. } => {
|
||||||
self.print_path(&item.path, false, 0);
|
self.print_path(&item.path, false, 0);
|
||||||
self.space();
|
self.space();
|
||||||
self.word_space("=");
|
self.word_space("=");
|
||||||
|
|
|
@ -1376,7 +1376,7 @@ impl<'a> Parser<'a> {
|
||||||
AttrArgs::Delimited(args)
|
AttrArgs::Delimited(args)
|
||||||
} else if self.eat(&token::Eq) {
|
} else if self.eat(&token::Eq) {
|
||||||
let eq_span = self.prev_token.span;
|
let eq_span = self.prev_token.span;
|
||||||
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(self.parse_expr_force_collect()?) }
|
AttrArgs::Eq { eq_span, expr: AttrArgsEq::Ast(self.parse_expr_force_collect()?) }
|
||||||
} else {
|
} else {
|
||||||
AttrArgs::Empty
|
AttrArgs::Empty
|
||||||
})
|
})
|
||||||
|
|
|
@ -70,7 +70,7 @@ pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Met
|
||||||
parse_in(psess, tokens.clone(), "meta list", |p| p.parse_meta_seq_top())?;
|
parse_in(psess, tokens.clone(), "meta list", |p| p.parse_meta_seq_top())?;
|
||||||
MetaItemKind::List(nmis)
|
MetaItemKind::List(nmis)
|
||||||
}
|
}
|
||||||
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => {
|
AttrArgs::Eq { expr: AttrArgsEq::Ast(expr), .. } => {
|
||||||
if let ast::ExprKind::Lit(token_lit) = expr.kind {
|
if let ast::ExprKind::Lit(token_lit) = expr.kind {
|
||||||
let res = ast::MetaItemLit::from_token_lit(token_lit, expr.span);
|
let res = ast::MetaItemLit::from_token_lit(token_lit, expr.span);
|
||||||
let res = match res {
|
let res = match res {
|
||||||
|
@ -116,9 +116,7 @@ pub fn parse_meta<'a>(psess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Met
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
|
AttrArgs::Eq { expr: AttrArgsEq::Hir(lit), .. } => MetaItemKind::NameValue(lit.clone()),
|
||||||
MetaItemKind::NameValue(lit.clone())
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,9 +220,9 @@ pub fn attrs_to_doc_fragments<'a>(
|
||||||
|
|
||||||
fn span_for_value(attr: &ast::Attribute) -> Span {
|
fn span_for_value(attr: &ast::Attribute) -> Span {
|
||||||
if let ast::AttrKind::Normal(normal) = &attr.kind
|
if let ast::AttrKind::Normal(normal) = &attr.kind
|
||||||
&& let ast::AttrArgs::Eq { value, .. } = &normal.item.args
|
&& let ast::AttrArgs::Eq { expr, .. } = &normal.item.args
|
||||||
{
|
{
|
||||||
value.span().with_ctxt(attr.span.ctxt())
|
expr.span().with_ctxt(attr.span.ctxt())
|
||||||
} else {
|
} else {
|
||||||
attr.span
|
attr.span
|
||||||
}
|
}
|
||||||
|
|
|
@ -639,7 +639,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
let report_span = match &item.args {
|
let report_span = match &item.args {
|
||||||
AttrArgs::Empty => item.path.span,
|
AttrArgs::Empty => item.path.span,
|
||||||
AttrArgs::Delimited(args) => args.dspan.entire(),
|
AttrArgs::Delimited(args) => args.dspan.entire(),
|
||||||
AttrArgs::Eq { eq_span, value } => eq_span.to(value.span()),
|
AttrArgs::Eq { eq_span, expr } => eq_span.to(expr.span()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(item_def_id) = item_def_id.as_local() {
|
if let Some(item_def_id) = item_def_id.as_local() {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use rustc_span::sym;
|
||||||
|
|
||||||
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) {
|
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) {
|
||||||
if let AttrKind::Normal(normal_attr) = &attr.kind {
|
if let AttrKind::Normal(normal_attr) = &attr.kind {
|
||||||
if let AttrArgs::Eq { value: AttrArgsEq::Ast(_), .. } = &normal_attr.item.args {
|
if let AttrArgs::Eq { expr: AttrArgsEq::Ast(_), .. } = &normal_attr.item.args {
|
||||||
// `#[should_panic = ".."]` found, good
|
// `#[should_panic = ".."]` found, good
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub fn check(cx: &LateContext<'_>, attrs: &[Attribute]) {
|
||||||
if !attr.span.from_expansion()
|
if !attr.span.from_expansion()
|
||||||
&& let AttrKind::Normal(ref normal) = attr.kind
|
&& let AttrKind::Normal(ref normal) = attr.kind
|
||||||
&& normal.item.path == sym::doc
|
&& normal.item.path == sym::doc
|
||||||
&& let AttrArgs::Eq { value: AttrArgsEq::Hir(ref meta), .. } = normal.item.args
|
&& let AttrArgs::Eq { expr: AttrArgsEq::Hir(ref meta), .. } = normal.item.args
|
||||||
&& !attr.span.contains(meta.span)
|
&& !attr.span.contains(meta.span)
|
||||||
// Since the `include_str` is already expanded at this point, we can only take the
|
// Since the `include_str` is already expanded at this point, we can only take the
|
||||||
// whole attribute snippet and then modify for our suggestion.
|
// whole attribute snippet and then modify for our suggestion.
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl LateLintPass<'_> for LargeIncludeFile {
|
||||||
&& let AttrKind::Normal(ref normal) = attr.kind
|
&& let AttrKind::Normal(ref normal) = attr.kind
|
||||||
&& let Some(doc) = attr.doc_str()
|
&& let Some(doc) = attr.doc_str()
|
||||||
&& doc.as_str().len() as u64 > self.max_file_size
|
&& doc.as_str().len() as u64 > self.max_file_size
|
||||||
&& let AttrArgs::Eq { value: AttrArgsEq::Hir(ref meta), .. } = normal.item.args
|
&& let AttrArgs::Eq { expr: AttrArgsEq::Hir(ref meta), .. } = normal.item.args
|
||||||
&& !attr.span.contains(meta.span)
|
&& !attr.span.contains(meta.span)
|
||||||
// Since the `include_str` is already expanded at this point, we can only take the
|
// Since the `include_str` is already expanded at this point, we can only take the
|
||||||
// whole attribute snippet and then modify for our suggestion.
|
// whole attribute snippet and then modify for our suggestion.
|
||||||
|
|
|
@ -872,8 +872,8 @@ pub fn eq_attr_args(l: &AttrArgs, r: &AttrArgs) -> bool {
|
||||||
match (l, r) {
|
match (l, r) {
|
||||||
(Empty, Empty) => true,
|
(Empty, Empty) => true,
|
||||||
(Delimited(la), Delimited(ra)) => eq_delim_args(la, ra),
|
(Delimited(la), Delimited(ra)) => eq_delim_args(la, ra),
|
||||||
(Eq { value: AttrArgsEq::Ast(le), .. }, Eq{ value: AttrArgsEq::Ast(re), .. }) => eq_expr(le, re),
|
(Eq { expr: AttrArgsEq::Ast(le), .. }, Eq{ expr: AttrArgsEq::Ast(re), .. }) => eq_expr(le, re),
|
||||||
(Eq { value: AttrArgsEq::Hir(ll), .. }, Eq{ value: AttrArgsEq::Hir(rl), .. }) => ll.kind == rl.kind,
|
(Eq { expr: AttrArgsEq::Hir(ll), .. }, Eq{ expr: AttrArgsEq::Hir(rl), .. }) => ll.kind == rl.kind,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue