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

+2-2
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

+1-1
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

+1-1
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

+1-1
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

+4-1
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

+1-1
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

+2-2
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

-6
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

+4-4
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

+5-5
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
})

src/libsyntax/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ impl<'a> StripUnconfigured<'a> {
9393
/// is in the original source file. Gives a compiler error if the syntax of
9494
/// the attribute is incorrect.
9595
fn process_cfg_attr(&mut self, attr: ast::Attribute) -> Vec<ast::Attribute> {
96-
if attr.path != sym::cfg_attr {
96+
if attr.item.path != sym::cfg_attr {
9797
return vec![attr];
9898
}
99-
if attr.tokens.is_empty() {
99+
if attr.item.tokens.is_empty() {
100100
self.sess.span_diagnostic
101101
.struct_span_err(
102102
attr.span,

src/libsyntax/feature_gate/check.rs

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

src/libsyntax/parse/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub fn parse_in_attr<'a, T>(
287287
) -> PResult<'a, T> {
288288
let mut parser = Parser::new(
289289
sess,
290-
attr.tokens.clone(),
290+
attr.item.tokens.clone(),
291291
None,
292292
false,
293293
false,
@@ -403,8 +403,8 @@ fn prepend_attrs(
403403
let mut brackets = tokenstream::TokenStreamBuilder::new();
404404

405405
// For simple paths, push the identifier directly
406-
if attr.path.segments.len() == 1 && attr.path.segments[0].args.is_none() {
407-
let ident = attr.path.segments[0].ident;
406+
if attr.item.path.segments.len() == 1 && attr.item.path.segments[0].args.is_none() {
407+
let ident = attr.item.path.segments[0].ident;
408408
let token = token::Ident(ident.name, ident.as_str().starts_with("r#"));
409409
brackets.push(tokenstream::TokenTree::token(token, ident.span));
410410

@@ -415,7 +415,7 @@ fn prepend_attrs(
415415
brackets.push(stream);
416416
}
417417

418-
brackets.push(attr.tokens.clone());
418+
brackets.push(attr.item.tokens.clone());
419419

420420
// The span we list here for `#` and for `[ ... ]` are both wrong in
421421
// that it encompasses more than each token, but it hopefully is "good

src/libsyntax/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
846846
}
847847

848848
pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) {
849-
visitor.visit_tts(attr.tokens.clone());
849+
visitor.visit_tts(attr.item.tokens.clone());
850850
}
851851

852852
pub fn walk_tt<'a, V: Visitor<'a>>(visitor: &mut V, tt: TokenTree) {

src/libsyntax_expand/expand.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
419419
}
420420

421421
let mut item = self.fully_configure(item);
422-
item.visit_attrs(|attrs| attrs.retain(|a| a.path != sym::derive));
422+
item.visit_attrs(|attrs| attrs.retain(|a| a.item.path != sym::derive));
423423
let mut helper_attrs = Vec::new();
424424
let mut has_copy = false;
425425
for ext in exts {
@@ -974,15 +974,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
974974
-> Option<ast::Attribute> {
975975
let attr = attrs.iter()
976976
.position(|a| {
977-
if a.path == sym::derive {
977+
if a.item.path == sym::derive {
978978
*after_derive = true;
979979
}
980980
!attr::is_known(a) && !is_builtin_attr(a)
981981
})
982982
.map(|i| attrs.remove(i));
983983
if let Some(attr) = &attr {
984984
if !self.cx.ecfg.custom_inner_attributes() &&
985-
attr.style == ast::AttrStyle::Inner && attr.path != sym::test {
985+
attr.style == ast::AttrStyle::Inner && attr.item.path != sym::test {
986986
emit_feature_err(&self.cx.parse_sess, sym::custom_inner_attributes,
987987
attr.span, GateIssue::Language,
988988
"non-builtin inner attributes are unstable");
@@ -1032,7 +1032,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10321032
feature_gate::check_attribute(attr, self.cx.parse_sess, features);
10331033

10341034
// macros are expanded before any lint passes so this warning has to be hardcoded
1035-
if attr.path == sym::derive {
1035+
if attr.item.path == sym::derive {
10361036
self.cx.struct_span_warn(attr.span, "`#[derive]` does nothing on macro invocations")
10371037
.note("this may become a hard error in a future release")
10381038
.emit();

src/libsyntax_expand/proc_macro.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a> Visitor<'a> for MarkAttrs<'a> {
181181
crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>) -> Vec<ast::Path> {
182182
let mut result = Vec::new();
183183
attrs.retain(|attr| {
184-
if attr.path != sym::derive {
184+
if attr.item.path != sym::derive {
185185
return true;
186186
}
187187
if !attr.is_meta_item_list() {
@@ -196,7 +196,7 @@ crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>)
196196
}
197197

198198
let parse_derive_paths = |attr: &ast::Attribute| {
199-
if attr.tokens.is_empty() {
199+
if attr.item.tokens.is_empty() {
200200
return Ok(Vec::new());
201201
}
202202
parse::parse_in_attr(cx.parse_sess, attr, |p| p.parse_derive_paths())

src/libsyntax_ext/proc_macro_harness.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
249249
for attr in &item.attrs {
250250
if is_proc_macro_attr(&attr) {
251251
if let Some(prev_attr) = found_attr {
252-
let path_str = pprust::path_to_string(&attr.path);
253-
let msg = if attr.path.segments[0].ident.name ==
254-
prev_attr.path.segments[0].ident.name {
252+
let path_str = pprust::path_to_string(&attr.item.path);
253+
let msg = if attr.item.path.segments[0].ident.name ==
254+
prev_attr.item.path.segments[0].ident.name {
255255
format!(
256256
"only one `#[{}]` attribute is allowed on any given function",
257257
path_str,
@@ -261,7 +261,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
261261
"`#[{}]` and `#[{}]` attributes cannot both be applied
262262
to the same function",
263263
path_str,
264-
pprust::path_to_string(&prev_attr.path),
264+
pprust::path_to_string(&prev_attr.item.path),
265265
)
266266
};
267267

@@ -290,7 +290,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
290290
if !is_fn {
291291
let msg = format!(
292292
"the `#[{}]` attribute may only be used on bare functions",
293-
pprust::path_to_string(&attr.path),
293+
pprust::path_to_string(&attr.item.path),
294294
);
295295

296296
self.handler.span_err(attr.span, &msg);
@@ -304,7 +304,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
304304
if !self.is_proc_macro_crate {
305305
let msg = format!(
306306
"the `#[{}]` attribute is only usable with crates of the `proc-macro` crate type",
307-
pprust::path_to_string(&attr.path),
307+
pprust::path_to_string(&attr.item.path),
308308
);
309309

310310
self.handler.span_err(attr.span, &msg);

0 commit comments

Comments
 (0)