Remove unnecessary Deref impl for Attribute.

This kind of thing just makes the code harder to read.
This commit is contained in:
Nicholas Nethercote 2019-10-24 06:40:35 +11:00
parent e8b190ac4a
commit 69bc4aba78
17 changed files with 41 additions and 44 deletions

View file

@ -999,8 +999,8 @@ impl<'a> LoweringContext<'a> {
// the `HirId`s. We don't actually need HIR version of attributes anyway.
Attribute {
item: AttrItem {
path: attr.path.clone(),
tokens: self.lower_token_stream(attr.tokens.clone()),
path: attr.item.path.clone(),
tokens: self.lower_token_stream(attr.item.tokens.clone()),
},
id: attr.id,
style: attr.style,

View file

@ -706,7 +706,7 @@ impl EarlyLintPass for DeprecatedAttr {
}
}
if attr.check_name(sym::no_start) || attr.check_name(sym::crate_id) {
let path_str = pprust::path_to_string(&attr.path);
let path_str = pprust::path_to_string(&attr.item.path);
let msg = format!("use of deprecated attribute `{}`: no longer used.", path_str);
lint_deprecated_attr(cx, attr, &msg, None);
}

View file

@ -11,7 +11,7 @@ crate fn collect(tcx: TyCtxt<'_>) -> Vec<String> {
tcx.hir().krate().visit_all_item_likes(&mut collector);
for attr in tcx.hir().krate().attrs.iter() {
if attr.path == sym::link_args {
if attr.item.path == sym::link_args {
if let Some(linkarg) = attr.value_str() {
collector.add_link_args(&linkarg.as_str());
}

View file

@ -1230,7 +1230,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
fn visit_attribute(&mut self, attr: &'b ast::Attribute) {
if !attr.is_sugared_doc && is_builtin_attr(attr) {
self.r.builtin_attrs.push((attr.path.segments[0].ident, self.parent_scope));
self.r.builtin_attrs.push((attr.item.path.segments[0].ident, self.parent_scope));
}
visit::walk_attribute(self, attr);
}

View file

@ -179,7 +179,10 @@ impl<'a> base::Resolver for Resolver<'a> {
let (path, kind, derives, after_derive) = match invoc.kind {
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
(&attr.path, MacroKind::Attr, self.arenas.alloc_ast_paths(derives), after_derive),
(&attr.item.path,
MacroKind::Attr,
self.arenas.alloc_ast_paths(derives),
after_derive),
InvocationKind::Bang { ref mac, .. } =>
(&mac.path, MacroKind::Bang, &[][..], false),
InvocationKind::Derive { ref path, .. } =>

View file

@ -1195,7 +1195,7 @@ fn null_id() -> rls_data::Id {
fn lower_attributes(attrs: Vec<Attribute>, scx: &SaveContext<'_, '_>) -> Vec<rls_data::Attribute> {
attrs.into_iter()
// Only retain real attributes. Doc comments are lowered separately.
.filter(|attr| attr.path != sym::doc)
.filter(|attr| attr.item.path != sym::doc)
.map(|mut attr| {
// Remove the surrounding '#[..]' or '#![..]' of the pretty printed
// attribute. First normalize all inner attribute (#![..]) to outer

View file

@ -2706,7 +2706,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
}
codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
if attr.path != sym::inline {
if attr.item.path != sym::inline {
return ia;
}
match attr.meta().map(|i| i.kind) {
@ -2746,7 +2746,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
});
codegen_fn_attrs.optimize = attrs.iter().fold(OptimizeAttr::None, |ia, attr| {
if attr.path != sym::optimize {
if attr.item.path != sym::optimize {
return ia;
}
let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s);

View file

@ -2202,12 +2202,6 @@ pub struct Attribute {
pub span: Span,
}
// Compatibility impl to avoid churn, consider removing.
impl std::ops::Deref for Attribute {
type Target = AttrItem;
fn deref(&self) -> &Self::Target { &self.item }
}
/// `TraitRef`s appear in impls.
///
/// Resolution maps each `TraitRef`'s `ref_id` to its defining trait; that's all

View file

@ -228,7 +228,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
sym::stable,
sym::rustc_promotable,
sym::rustc_allow_const_fn_ptr,
].iter().any(|&s| attr.path == s) {
].iter().any(|&s| attr.item.path == s) {
continue // not a stability level
}
@ -236,10 +236,10 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
let meta = attr.meta();
if attr.path == sym::rustc_promotable {
if attr.item.path == sym::rustc_promotable {
promotable = true;
}
if attr.path == sym::rustc_allow_const_fn_ptr {
if attr.item.path == sym::rustc_allow_const_fn_ptr {
allow_const_fn_ptr = true;
}
// attributes with data
@ -778,7 +778,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
let mut acc = Vec::new();
let diagnostic = &sess.span_diagnostic;
if attr.path == sym::repr {
if attr.item.path == sym::repr {
if let Some(items) = attr.meta_item_list() {
mark_used(attr);
for item in items {

View file

@ -150,7 +150,7 @@ impl Attribute {
///
/// To check the attribute name without marking it used, use the `path` field directly.
pub fn check_name(&self, name: Symbol) -> bool {
let matches = self.path == name;
let matches = self.item.path == name;
if matches {
mark_used(self);
}
@ -159,8 +159,8 @@ impl Attribute {
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
pub fn ident(&self) -> Option<Ident> {
if self.path.segments.len() == 1 {
Some(self.path.segments[0].ident)
if self.item.path.segments.len() == 1 {
Some(self.item.path.segments[0].ident)
} else {
None
}
@ -181,7 +181,7 @@ impl Attribute {
}
pub fn is_word(&self) -> bool {
self.tokens.is_empty()
self.item.tokens.is_empty()
}
pub fn is_meta_item_list(&self) -> bool {
@ -282,7 +282,7 @@ impl Attribute {
pub fn parse_meta<'a>(&self, sess: &'a ParseSess) -> PResult<'a, MetaItem> {
Ok(MetaItem {
path: self.path.clone(),
path: self.item.path.clone(),
kind: parse::parse_in_attr(sess, self, |p| p.parse_meta_item_kind())?,
span: self.span,
})

View file

@ -93,10 +93,10 @@ impl<'a> StripUnconfigured<'a> {
/// is in the original source file. Gives a compiler error if the syntax of
/// the attribute is incorrect.
fn process_cfg_attr(&mut self, attr: ast::Attribute) -> Vec<ast::Attribute> {
if attr.path != sym::cfg_attr {
if attr.item.path != sym::cfg_attr {
return vec![attr];
}
if attr.tokens.is_empty() {
if attr.item.tokens.is_empty() {
self.sess.span_diagnostic
.struct_span_err(
attr.span,

View file

@ -329,7 +329,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
Some((name, _, template, _)) if name != sym::rustc_dummy =>
check_builtin_attribute(self.parse_sess, attr, name, template),
_ => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() {
_ => if let Some(TokenTree::Token(token)) = attr.item.tokens.trees().next() {
if token == token::Eq {
// All key-value attributes are restricted to meta-item syntax.
attr.parse_meta(self.parse_sess).map_err(|mut err| err.emit()).ok();

View file

@ -287,7 +287,7 @@ pub fn parse_in_attr<'a, T>(
) -> PResult<'a, T> {
let mut parser = Parser::new(
sess,
attr.tokens.clone(),
attr.item.tokens.clone(),
None,
false,
false,
@ -403,8 +403,8 @@ fn prepend_attrs(
let mut brackets = tokenstream::TokenStreamBuilder::new();
// For simple paths, push the identifier directly
if attr.path.segments.len() == 1 && attr.path.segments[0].args.is_none() {
let ident = attr.path.segments[0].ident;
if attr.item.path.segments.len() == 1 && attr.item.path.segments[0].args.is_none() {
let ident = attr.item.path.segments[0].ident;
let token = token::Ident(ident.name, ident.as_str().starts_with("r#"));
brackets.push(tokenstream::TokenTree::token(token, ident.span));
@ -415,7 +415,7 @@ fn prepend_attrs(
brackets.push(stream);
}
brackets.push(attr.tokens.clone());
brackets.push(attr.item.tokens.clone());
// The span we list here for `#` and for `[ ... ]` are both wrong in
// that it encompasses more than each token, but it hopefully is "good

View file

@ -846,7 +846,7 @@ pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
}
pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) {
visitor.visit_tts(attr.tokens.clone());
visitor.visit_tts(attr.item.tokens.clone());
}
pub fn walk_tt<'a, V: Visitor<'a>>(visitor: &mut V, tt: TokenTree) {

View file

@ -419,7 +419,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
let mut item = self.fully_configure(item);
item.visit_attrs(|attrs| attrs.retain(|a| a.path != sym::derive));
item.visit_attrs(|attrs| attrs.retain(|a| a.item.path != sym::derive));
let mut helper_attrs = Vec::new();
let mut has_copy = false;
for ext in exts {
@ -974,7 +974,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
-> Option<ast::Attribute> {
let attr = attrs.iter()
.position(|a| {
if a.path == sym::derive {
if a.item.path == sym::derive {
*after_derive = true;
}
!attr::is_known(a) && !is_builtin_attr(a)
@ -982,7 +982,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
.map(|i| attrs.remove(i));
if let Some(attr) = &attr {
if !self.cx.ecfg.custom_inner_attributes() &&
attr.style == ast::AttrStyle::Inner && attr.path != sym::test {
attr.style == ast::AttrStyle::Inner && attr.item.path != sym::test {
emit_feature_err(&self.cx.parse_sess, sym::custom_inner_attributes,
attr.span, GateIssue::Language,
"non-builtin inner attributes are unstable");
@ -1032,7 +1032,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
feature_gate::check_attribute(attr, self.cx.parse_sess, features);
// macros are expanded before any lint passes so this warning has to be hardcoded
if attr.path == sym::derive {
if attr.item.path == sym::derive {
self.cx.struct_span_warn(attr.span, "`#[derive]` does nothing on macro invocations")
.note("this may become a hard error in a future release")
.emit();

View file

@ -181,7 +181,7 @@ impl<'a> Visitor<'a> for MarkAttrs<'a> {
crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>) -> Vec<ast::Path> {
let mut result = Vec::new();
attrs.retain(|attr| {
if attr.path != sym::derive {
if attr.item.path != sym::derive {
return true;
}
if !attr.is_meta_item_list() {
@ -196,7 +196,7 @@ crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>)
}
let parse_derive_paths = |attr: &ast::Attribute| {
if attr.tokens.is_empty() {
if attr.item.tokens.is_empty() {
return Ok(Vec::new());
}
parse::parse_in_attr(cx.parse_sess, attr, |p| p.parse_derive_paths())

View file

@ -249,9 +249,9 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
for attr in &item.attrs {
if is_proc_macro_attr(&attr) {
if let Some(prev_attr) = found_attr {
let path_str = pprust::path_to_string(&attr.path);
let msg = if attr.path.segments[0].ident.name ==
prev_attr.path.segments[0].ident.name {
let path_str = pprust::path_to_string(&attr.item.path);
let msg = if attr.item.path.segments[0].ident.name ==
prev_attr.item.path.segments[0].ident.name {
format!(
"only one `#[{}]` attribute is allowed on any given function",
path_str,
@ -261,7 +261,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
"`#[{}]` and `#[{}]` attributes cannot both be applied
to the same function",
path_str,
pprust::path_to_string(&prev_attr.path),
pprust::path_to_string(&prev_attr.item.path),
)
};
@ -290,7 +290,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
if !is_fn {
let msg = format!(
"the `#[{}]` attribute may only be used on bare functions",
pprust::path_to_string(&attr.path),
pprust::path_to_string(&attr.item.path),
);
self.handler.span_err(attr.span, &msg);
@ -304,7 +304,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
if !self.is_proc_macro_crate {
let msg = format!(
"the `#[{}]` attribute is only usable with crates of the `proc-macro` crate type",
pprust::path_to_string(&attr.path),
pprust::path_to_string(&attr.item.path),
);
self.handler.span_err(attr.span, &msg);