about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjumbatm <jumbatm@gmail.com>2020-02-06 03:18:40 +1000
committerjumbatm <jumbatm@gmail.com>2020-02-11 19:50:26 +1000
commite45099619334bbf4413b40ff07a100ce72ace96a (patch)
treeb8419c96f84de0df8fa35c4669b17b790a0a829d
parent284982df6047ad8a259a3cb0698706ccdfd20946 (diff)
downloadrust-e45099619334bbf4413b40ff07a100ce72ace96a.tar.gz
rust-e45099619334bbf4413b40ff07a100ce72ace96a.zip
Avoid allocs in a few places.
- AnonymousParameters::check_trait_item
- TypeAliasBounds::check_item
- NonSnakeCase::check_snake_case
-rw-r--r--src/librustc_lint/builtin.rs22
-rw-r--r--src/librustc_lint/context.rs2
-rw-r--r--src/librustc_lint/nonstandard_style.rs3
3 files changed, 14 insertions, 13 deletions
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs
index 9cc3e39726b..c827a7f3d52 100644
--- a/src/librustc_lint/builtin.rs
+++ b/src/librustc_lint/builtin.rs
@@ -648,10 +648,10 @@ impl EarlyLintPass for AnonymousParameters {
                                 cx.struct_span_lint(ANONYMOUS_PARAMETERS, arg.pat.span, |lint| {
                                     let ty_snip = cx.sess.source_map().span_to_snippet(arg.ty.span);
 
-                                    let (ty_snip, appl) = if let Ok(snip) = ty_snip {
-                                        (snip, Applicability::MachineApplicable)
+                                    let (ty_snip, appl) = if let Ok(ref snip) = ty_snip {
+                                        (snip.as_str(), Applicability::MachineApplicable)
                                     } else {
-                                        ("<type>".to_owned(), Applicability::HasPlaceholders)
+                                        ("<type>", Applicability::HasPlaceholders)
                                     };
 
                                     lint.build(
@@ -1132,17 +1132,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
         let mut suggested_changing_assoc_types = false;
         // There must not be a where clause
         if !type_alias_generics.where_clause.predicates.is_empty() {
-            let spans: Vec<_> = type_alias_generics
-                .where_clause
-                .predicates
-                .iter()
-                .map(|pred| pred.span())
-                .collect();
-            cx.struct_span_lint(
+            cx.lint(
                 TYPE_ALIAS_BOUNDS,
-                spans,
                 |lint| {
                     let mut err = lint.build("where clauses are not enforced in type aliases");
+                    let spans: Vec<_> = type_alias_generics
+                        .where_clause
+                        .predicates
+                        .iter()
+                        .map(|pred| pred.span())
+                        .collect();
+                    err.set_span(spans);
                     err.span_suggestion(
                         type_alias_generics.where_clause.span_for_predicates_or_empty_place(),
                         "the clause will not be checked when the type alias is used, and should be removed",
diff --git a/src/librustc_lint/context.rs b/src/librustc_lint/context.rs
index f3cbd3f1c9e..8e8beefa72f 100644
--- a/src/librustc_lint/context.rs
+++ b/src/librustc_lint/context.rs
@@ -571,6 +571,8 @@ pub trait LintContext: Sized {
         });
     }
 
+    // FIXME: These methods should not take an Into<MultiSpan> -- instead, callers should need to
+    // set the span in their `decorate` function (preferably using set_span).
     fn lookup<S: Into<MultiSpan>>(
         &self,
         lint: &'static Lint,
diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs
index d45ea10dfbf..8c58f2ba4c0 100644
--- a/src/librustc_lint/nonstandard_style.rs
+++ b/src/librustc_lint/nonstandard_style.rs
@@ -225,9 +225,8 @@ impl NonSnakeCase {
         let name = &ident.name.as_str();
 
         if !is_snake_case(name) {
-            let sc = NonSnakeCase::to_snake_case(name);
-
             cx.struct_span_lint(NON_SNAKE_CASE, ident.span, |lint| {
+                let sc = NonSnakeCase::to_snake_case(name);
                 let msg = format!("{} `{}` should have a snake case name", sort, name);
                 let mut err = lint.build(&msg);
                 // We have a valid span in almost all cases, but we don't have one when linting a crate