From 69bc4aba785e071740d2d46f109623b9951aae5d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 24 Oct 2019 06:40:35 +1100 Subject: Remove unnecessary `Deref` impl for `Attribute`. This kind of thing just makes the code harder to read. --- src/libsyntax/ast.rs | 6 ------ src/libsyntax/attr/builtin.rs | 8 ++++---- src/libsyntax/attr/mod.rs | 10 +++++----- src/libsyntax/config.rs | 4 ++-- src/libsyntax/feature_gate/check.rs | 2 +- src/libsyntax/parse/mod.rs | 8 ++++---- src/libsyntax/visit.rs | 2 +- 7 files changed, 17 insertions(+), 23 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 8af38507b48..df1fb5d97d7 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -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 diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 84c86c9651f..e77d9ef326a 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -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 { 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 { diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 3e240a855e2..0c46c501be9 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -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 { - 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, }) diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 6003fd1d286..682c8f71dc8 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -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 { - 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, diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index d9cc5f6c169..c19ed774507 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -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(); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 6d8ecdf805b..6cfa0dfad82 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -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 diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index a36783e2b64..64393a295de 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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) { -- cgit 1.4.1-3-g733a5