Skip to content

Commit 69bc4ab

Browse files
committed
Remove unnecessary Deref impl for Attribute.
This kind of thing just makes the code harder to read.
1 parent e8b190a commit 69bc4ab

File tree

17 files changed

+41
-44
lines changed

17 files changed

+41
-44
lines changed

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,8 @@ impl<'a> LoweringContext<'a> {
999999
// the `HirId`s. We don't actually need HIR version of attributes anyway.
10001000
Attribute {
10011001
item: AttrItem {
1002-
path: attr.path.clone(),
1003-
tokens: self.lower_token_stream(attr.tokens.clone()),
1002+
path: attr.item.path.clone(),
1003+
tokens: self.lower_token_stream(attr.item.tokens.clone()),
10041004
},
10051005
id: attr.id,
10061006
style: attr.style,

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ impl EarlyLintPass for DeprecatedAttr {
706706
}
707707
}
708708
if attr.check_name(sym::no_start) || attr.check_name(sym::crate_id) {
709-
let path_str = pprust::path_to_string(&attr.path);
709+
let path_str = pprust::path_to_string(&attr.item.path);
710710
let msg = format!("use of deprecated attribute `{}`: no longer used.", path_str);
711711
lint_deprecated_attr(cx, attr, &msg, None);
712712
}

src/librustc_metadata/link_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate fn collect(tcx: TyCtxt<'_>) -> Vec<String> {
1111
tcx.hir().krate().visit_all_item_likes(&mut collector);
1212

1313
for attr in tcx.hir().krate().attrs.iter() {
14-
if attr.path == sym::link_args {
14+
if attr.item.path == sym::link_args {
1515
if let Some(linkarg) = attr.value_str() {
1616
collector.add_link_args(&linkarg.as_str());
1717
}

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
12301230

12311231
fn visit_attribute(&mut self, attr: &'b ast::Attribute) {
12321232
if !attr.is_sugared_doc && is_builtin_attr(attr) {
1233-
self.r.builtin_attrs.push((attr.path.segments[0].ident, self.parent_scope));
1233+
self.r.builtin_attrs.push((attr.item.path.segments[0].ident, self.parent_scope));
12341234
}
12351235
visit::walk_attribute(self, attr);
12361236
}

src/librustc_resolve/macros.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ impl<'a> base::Resolver for Resolver<'a> {
179179

180180
let (path, kind, derives, after_derive) = match invoc.kind {
181181
InvocationKind::Attr { ref attr, ref derives, after_derive, .. } =>
182-
(&attr.path, MacroKind::Attr, self.arenas.alloc_ast_paths(derives), after_derive),
182+
(&attr.item.path,
183+
MacroKind::Attr,
184+
self.arenas.alloc_ast_paths(derives),
185+
after_derive),
183186
InvocationKind::Bang { ref mac, .. } =>
184187
(&mac.path, MacroKind::Bang, &[][..], false),
185188
InvocationKind::Derive { ref path, .. } =>

src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ fn null_id() -> rls_data::Id {
11951195
fn lower_attributes(attrs: Vec<Attribute>, scx: &SaveContext<'_, '_>) -> Vec<rls_data::Attribute> {
11961196
attrs.into_iter()
11971197
// Only retain real attributes. Doc comments are lowered separately.
1198-
.filter(|attr| attr.path != sym::doc)
1198+
.filter(|attr| attr.item.path != sym::doc)
11991199
.map(|mut attr| {
12001200
// Remove the surrounding '#[..]' or '#![..]' of the pretty printed
12011201
// attribute. First normalize all inner attribute (#![..]) to outer

src/librustc_typeck/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,7 +2706,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27062706
}
27072707

27082708
codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
2709-
if attr.path != sym::inline {
2709+
if attr.item.path != sym::inline {
27102710
return ia;
27112711
}
27122712
match attr.meta().map(|i| i.kind) {
@@ -2746,7 +2746,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27462746
});
27472747

27482748
codegen_fn_attrs.optimize = attrs.iter().fold(OptimizeAttr::None, |ia, attr| {
2749-
if attr.path != sym::optimize {
2749+
if attr.item.path != sym::optimize {
27502750
return ia;
27512751
}
27522752
let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s);

src/libsyntax/ast.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,12 +2202,6 @@ pub struct Attribute {
22022202
pub span: Span,
22032203
}
22042204

2205-
// Compatibility impl to avoid churn, consider removing.
2206-
impl std::ops::Deref for Attribute {
2207-
type Target = AttrItem;
2208-
fn deref(&self) -> &Self::Target { &self.item }
2209-
}
2210-
22112205
/// `TraitRef`s appear in impls.
22122206
///
22132207
/// Resolution maps each `TraitRef`'s `ref_id` to its defining trait; that's all

src/libsyntax/attr/builtin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,18 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
228228
sym::stable,
229229
sym::rustc_promotable,
230230
sym::rustc_allow_const_fn_ptr,
231-
].iter().any(|&s| attr.path == s) {
231+
].iter().any(|&s| attr.item.path == s) {
232232
continue // not a stability level
233233
}
234234

235235
mark_used(attr);
236236

237237
let meta = attr.meta();
238238

239-
if attr.path == sym::rustc_promotable {
239+
if attr.item.path == sym::rustc_promotable {
240240
promotable = true;
241241
}
242-
if attr.path == sym::rustc_allow_const_fn_ptr {
242+
if attr.item.path == sym::rustc_allow_const_fn_ptr {
243243
allow_const_fn_ptr = true;
244244
}
245245
// attributes with data
@@ -778,7 +778,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
778778

779779
let mut acc = Vec::new();
780780
let diagnostic = &sess.span_diagnostic;
781-
if attr.path == sym::repr {
781+
if attr.item.path == sym::repr {
782782
if let Some(items) = attr.meta_item_list() {
783783
mark_used(attr);
784784
for item in items {

src/libsyntax/attr/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Attribute {
150150
///
151151
/// To check the attribute name without marking it used, use the `path` field directly.
152152
pub fn check_name(&self, name: Symbol) -> bool {
153-
let matches = self.path == name;
153+
let matches = self.item.path == name;
154154
if matches {
155155
mark_used(self);
156156
}
@@ -159,8 +159,8 @@ impl Attribute {
159159

160160
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
161161
pub fn ident(&self) -> Option<Ident> {
162-
if self.path.segments.len() == 1 {
163-
Some(self.path.segments[0].ident)
162+
if self.item.path.segments.len() == 1 {
163+
Some(self.item.path.segments[0].ident)
164164
} else {
165165
None
166166
}
@@ -181,7 +181,7 @@ impl Attribute {
181181
}
182182

183183
pub fn is_word(&self) -> bool {
184-
self.tokens.is_empty()
184+
self.item.tokens.is_empty()
185185
}
186186

187187
pub fn is_meta_item_list(&self) -> bool {
@@ -282,7 +282,7 @@ impl Attribute {
282282

283283
pub fn parse_meta<'a>(&self, sess: &'a ParseSess) -> PResult<'a, MetaItem> {
284284
Ok(MetaItem {
285-
path: self.path.clone(),
285+
path: self.item.path.clone(),
286286
kind: parse::parse_in_attr(sess, self, |p| p.parse_meta_item_kind())?,
287287
span: self.span,
288288
})

0 commit comments

Comments
 (0)