Skip to content

Commit e450996

Browse files
committed
Avoid allocs in a few places.
- AnonymousParameters::check_trait_item - TypeAliasBounds::check_item - NonSnakeCase::check_snake_case
1 parent 284982d commit e450996

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/librustc_lint/builtin.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,10 @@ impl EarlyLintPass for AnonymousParameters {
648648
cx.struct_span_lint(ANONYMOUS_PARAMETERS, arg.pat.span, |lint| {
649649
let ty_snip = cx.sess.source_map().span_to_snippet(arg.ty.span);
650650

651-
let (ty_snip, appl) = if let Ok(snip) = ty_snip {
652-
(snip, Applicability::MachineApplicable)
651+
let (ty_snip, appl) = if let Ok(ref snip) = ty_snip {
652+
(snip.as_str(), Applicability::MachineApplicable)
653653
} else {
654-
("<type>".to_owned(), Applicability::HasPlaceholders)
654+
("<type>", Applicability::HasPlaceholders)
655655
};
656656

657657
lint.build(
@@ -1132,17 +1132,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
11321132
let mut suggested_changing_assoc_types = false;
11331133
// There must not be a where clause
11341134
if !type_alias_generics.where_clause.predicates.is_empty() {
1135-
let spans: Vec<_> = type_alias_generics
1136-
.where_clause
1137-
.predicates
1138-
.iter()
1139-
.map(|pred| pred.span())
1140-
.collect();
1141-
cx.struct_span_lint(
1135+
cx.lint(
11421136
TYPE_ALIAS_BOUNDS,
1143-
spans,
11441137
|lint| {
11451138
let mut err = lint.build("where clauses are not enforced in type aliases");
1139+
let spans: Vec<_> = type_alias_generics
1140+
.where_clause
1141+
.predicates
1142+
.iter()
1143+
.map(|pred| pred.span())
1144+
.collect();
1145+
err.set_span(spans);
11461146
err.span_suggestion(
11471147
type_alias_generics.where_clause.span_for_predicates_or_empty_place(),
11481148
"the clause will not be checked when the type alias is used, and should be removed",

src/librustc_lint/context.rs

+2
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ pub trait LintContext: Sized {
571571
});
572572
}
573573

574+
// FIXME: These methods should not take an Into<MultiSpan> -- instead, callers should need to
575+
// set the span in their `decorate` function (preferably using set_span).
574576
fn lookup<S: Into<MultiSpan>>(
575577
&self,
576578
lint: &'static Lint,

src/librustc_lint/nonstandard_style.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ impl NonSnakeCase {
225225
let name = &ident.name.as_str();
226226

227227
if !is_snake_case(name) {
228-
let sc = NonSnakeCase::to_snake_case(name);
229-
230228
cx.struct_span_lint(NON_SNAKE_CASE, ident.span, |lint| {
229+
let sc = NonSnakeCase::to_snake_case(name);
231230
let msg = format!("{} `{}` should have a snake case name", sort, name);
232231
let mut err = lint.build(&msg);
233232
// We have a valid span in almost all cases, but we don't have one when linting a crate

0 commit comments

Comments
 (0)