Skip to content

Commit bd2ff65

Browse files
Rollup merge of rust-lang#156065 - mejrs:spanculler, r=JonathanBrouwer
Remove unused spans from AttributeKind Recently I noticed some spans in diagnostic attributes were never used. I went through and checked the other variants too.
2 parents 84b7305 + 4a13f36 commit bd2ff65

49 files changed

Lines changed: 191 additions & 248 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
10631063
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
10641064

10651065
let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
1066-
let mut coroutine_kind = find_attr!(attrs, Coroutine(_) => hir::CoroutineKind::Coroutine(Movability::Movable));
1066+
let mut coroutine_kind =
1067+
find_attr!(attrs, Coroutine => hir::CoroutineKind::Coroutine(Movability::Movable));
10671068

10681069
// FIXME(contracts): Support contracts on closures?
10691070
let body_id = this.lower_fn_body(decl, None, |this| {

compiler/rustc_attr_parsing/src/attributes/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ pub(crate) struct CoroutineParser;
77
impl NoArgsAttributeParser for CoroutineParser {
88
const PATH: &[Symbol] = &[sym::coroutine];
99
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Closure)]);
10-
const CREATE: fn(rustc_span::Span) -> AttributeKind = |span| AttributeKind::Coroutine(span);
10+
const CREATE: fn(rustc_span::Span) -> AttributeKind = |_| AttributeKind::Coroutine;
1111
}

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl NoArgsAttributeParser for ColdParser {
5454
Allow(Target::ForeignFn),
5555
Allow(Target::Closure),
5656
]);
57-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
57+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::Cold;
5858
}
5959

6060
pub(crate) struct CoverageParser;
@@ -94,7 +94,7 @@ impl SingleAttributeParser for CoverageParser {
9494
}
9595
};
9696

97-
Some(AttributeKind::Coverage(cx.attr_span, kind))
97+
Some(AttributeKind::Coverage(kind))
9898
}
9999
}
100100

@@ -156,7 +156,7 @@ impl SingleAttributeParser for RustcObjcClassParser {
156156
cx.emit_err(NullOnObjcClass { span: nv.value_span });
157157
return None;
158158
}
159-
Some(AttributeKind::RustcObjcClass { classname, span: cx.attr_span })
159+
Some(AttributeKind::RustcObjcClass { classname })
160160
}
161161
}
162162

@@ -183,7 +183,7 @@ impl SingleAttributeParser for RustcObjcSelectorParser {
183183
cx.emit_err(NullOnObjcSelector { span: nv.value_span });
184184
return None;
185185
}
186-
Some(AttributeKind::RustcObjcSelector { methname, span: cx.attr_span })
186+
Some(AttributeKind::RustcObjcSelector { methname })
187187
}
188188
}
189189

@@ -436,9 +436,9 @@ impl AttributeParser for UsedParser {
436436
// If a specific form of `used` is specified, it takes precedence over generic `#[used]`.
437437
// If both `linker` and `compiler` are specified, use `linker`.
438438
Some(match (self.first_compiler, self.first_linker, self.first_default) {
439-
(_, Some(span), _) => AttributeKind::Used { used_by: UsedBy::Linker, span },
440-
(Some(span), _, _) => AttributeKind::Used { used_by: UsedBy::Compiler, span },
441-
(_, _, Some(span)) => AttributeKind::Used { used_by: UsedBy::Default, span },
439+
(_, Some(_), _) => AttributeKind::Used { used_by: UsedBy::Linker },
440+
(Some(_), _, _) => AttributeKind::Used { used_by: UsedBy::Compiler },
441+
(_, _, Some(_)) => AttributeKind::Used { used_by: UsedBy::Default },
442442
(None, None, None) => return None,
443443
})
444444
}

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ impl SingleAttributeParser for RecursionLimitParser {
8484
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
8585
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
8686

87-
Some(AttributeKind::RecursionLimit {
88-
limit: cx.parse_limit_int(nv)?,
89-
attr_span: cx.attr_span,
90-
limit_span: nv.value_span,
91-
})
87+
Some(AttributeKind::RecursionLimit { limit: cx.parse_limit_int(nv)? })
9288
}
9389
}
9490

@@ -102,11 +98,7 @@ impl SingleAttributeParser for MoveSizeLimitParser {
10298
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
10399
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
104100

105-
Some(AttributeKind::MoveSizeLimit {
106-
limit: cx.parse_limit_int(nv)?,
107-
attr_span: cx.attr_span,
108-
limit_span: nv.value_span,
109-
})
101+
Some(AttributeKind::MoveSizeLimit { limit: cx.parse_limit_int(nv)? })
110102
}
111103
}
112104

@@ -121,11 +113,7 @@ impl SingleAttributeParser for TypeLengthLimitParser {
121113
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
122114
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
123115

124-
Some(AttributeKind::TypeLengthLimit {
125-
limit: cx.parse_limit_int(nv)?,
126-
attr_span: cx.attr_span,
127-
limit_span: nv.value_span,
128-
})
116+
Some(AttributeKind::TypeLengthLimit { limit: cx.parse_limit_int(nv)? })
129117
}
130118
}
131119

@@ -139,11 +127,7 @@ impl SingleAttributeParser for PatternComplexityLimitParser {
139127
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
140128
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
141129

142-
Some(AttributeKind::PatternComplexityLimit {
143-
limit: cx.parse_limit_int(nv)?,
144-
attr_span: cx.attr_span,
145-
limit_span: nv.value_span,
146-
})
130+
Some(AttributeKind::PatternComplexityLimit { limit: cx.parse_limit_int(nv)? })
147131
}
148132
}
149133

@@ -152,7 +136,7 @@ pub(crate) struct NoCoreParser;
152136
impl NoArgsAttributeParser for NoCoreParser {
153137
const PATH: &[Symbol] = &[sym::no_core];
154138
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
155-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoCore;
139+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoCore;
156140
}
157141

158142
pub(crate) struct NoStdParser;
@@ -161,7 +145,7 @@ impl NoArgsAttributeParser for NoStdParser {
161145
const PATH: &[Symbol] = &[sym::no_std];
162146
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
163147
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
164-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoStd;
148+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoStd;
165149
}
166150

167151
pub(crate) struct NoMainParser;
@@ -178,7 +162,7 @@ pub(crate) struct RustcCoherenceIsCoreParser;
178162
impl NoArgsAttributeParser for RustcCoherenceIsCoreParser {
179163
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
180164
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
181-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcCoherenceIsCore;
165+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcCoherenceIsCore;
182166
}
183167

184168
pub(crate) struct WindowsSubsystemParser;
@@ -204,7 +188,7 @@ impl SingleAttributeParser for WindowsSubsystemParser {
204188
}
205189
};
206190

207-
Some(AttributeKind::WindowsSubsystem(kind, cx.attr_span))
191+
Some(AttributeKind::WindowsSubsystem(kind))
208192
}
209193
}
210194

@@ -314,7 +298,7 @@ pub(crate) struct RegisterToolParser;
314298
impl CombineAttributeParser for RegisterToolParser {
315299
const PATH: &[Symbol] = &[sym::register_tool];
316300
type Item = Ident;
317-
const CONVERT: ConvertFn<Self::Item> = AttributeKind::RegisterTool;
301+
const CONVERT: ConvertFn<Self::Item> = |tools, _span| AttributeKind::RegisterTool(tools);
318302
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
319303
const TEMPLATE: AttributeTemplate = template!(List: &["tool1, tool2, ..."]);
320304

compiler/rustc_attr_parsing/src/attributes/diagnostic/do_not_recommend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ impl SingleAttributeParser for DoNotRecommendParser {
4040
return None;
4141
}
4242

43-
Some(AttributeKind::DoNotRecommend { attr_span })
43+
Some(AttributeKind::DoNotRecommend)
4444
}
4545
}

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_move.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl AttributeParser for OnMoveParser {
5151
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
5252

5353
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
54-
if let Some(span) = self.span {
55-
Some(AttributeKind::OnMove { span, directive: self.directive.map(|d| Box::new(d.1)) })
54+
if let Some(_span) = self.span {
55+
Some(AttributeKind::OnMove { directive: self.directive.map(|d| Box::new(d.1)) })
5656
} else {
5757
None
5858
}

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unimplemented.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ impl AttributeParser for OnUnimplementedParser {
5454
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
5555

5656
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
57-
if let Some(span) = self.span {
57+
if let Some(_span) = self.span {
5858
Some(AttributeKind::OnUnimplemented {
59-
span,
6059
directive: self.directive.map(|d| Box::new(d.1)),
6160
})
6261
} else {

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ impl AttributeParser for OnUnknownParser {
5757
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
5858

5959
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
60-
if let Some(span) = self.span {
61-
Some(AttributeKind::OnUnknown {
62-
span,
63-
directive: self.directive.map(|d| Box::new(d.1)),
64-
})
60+
if let Some(_span) = self.span {
61+
Some(AttributeKind::OnUnknown { directive: self.directive.map(|d| Box::new(d.1)) })
6562
} else {
6663
None
6764
}

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatch_args.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ impl AttributeParser for OnUnmatchArgsParser {
4545
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
4646

4747
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
48-
if let Some(span) = self.span {
49-
Some(AttributeKind::OnUnmatchArgs {
50-
span,
51-
directive: self.directive.map(|d| Box::new(d.1)),
52-
})
48+
if let Some(_span) = self.span {
49+
Some(AttributeKind::OnUnmatchArgs { directive: self.directive.map(|d| Box::new(d.1)) })
5350
} else {
5451
None
5552
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl SingleAttributeParser for LinkSectionParser {
521521
BinaryFormat::Coff | BinaryFormat::Elf | BinaryFormat::Wasm | BinaryFormat::Xcoff => {}
522522
}
523523

524-
Some(LinkSection { name, span: cx.attr_span })
524+
Some(LinkSection { name })
525525
}
526526
}
527527

@@ -537,7 +537,7 @@ impl NoArgsAttributeParser for FfiConstParser {
537537
const PATH: &[Symbol] = &[sym::ffi_const];
538538
const SAFETY: AttributeSafety = AttributeSafety::Unsafe { unsafe_since: None };
539539
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::ForeignFn)]);
540-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::FfiConst;
540+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::FfiConst;
541541
}
542542

543543
pub(crate) struct FfiPureParser;
@@ -557,7 +557,7 @@ impl NoArgsAttributeParser for RustcStdInternalSymbolParser {
557557
Allow(Target::Static),
558558
Allow(Target::ForeignStatic),
559559
]);
560-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcStdInternalSymbol;
560+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcStdInternalSymbol;
561561
}
562562

563563
pub(crate) struct LinkOrdinalParser;

0 commit comments

Comments
 (0)