]> git.lizzy.rs Git - rust.git/commitdiff
Better linting : use of span_lint_and_then.
authorPaul Florence <florencepaul@hotmail.fr>
Fri, 20 Oct 2017 14:00:44 +0000 (10:00 -0400)
committerPaul Florence <florencepaul@hotmail.fr>
Fri, 20 Oct 2017 14:17:41 +0000 (10:17 -0400)
clippy_lints/src/const_static_lifetime.rs
tests/ui/const_static_lifetime.stderr

index a56e73e2c50d2b735b1ec019ca433dd71cca2f66..4f2d86565329acedf1cde55d1525948d969e3277 100644 (file)
@@ -1,16 +1,18 @@
 use syntax::ast::{Item, ItemKind, TyKind, Ty};
 use rustc::lint::{LintPass, EarlyLintPass, LintArray, EarlyContext};
-use utils::{span_help_and_lint, in_macro};
+use utils::{span_lint_and_then, in_macro};
 
 /// **What it does:** Checks for constants with an explicit `'static` lifetime.
 ///
-/// **Why is this bad?** Adding `'static` to every reference can create very complicated types.
+/// **Why is this bad?** Adding `'static` to every reference can create very
+/// complicated types.
 ///
 /// **Known problems:** None.
 ///
 /// **Example:**
 /// ```rust
-///  const FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] = &[..]
+/// const FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] =
+/// &[...]
 /// ```
 /// This code can be rewritten as
 /// ```rust
@@ -52,11 +54,12 @@ fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext) {
                     if let TyKind::Path(_, _) = borrow_type.ty.node {
                         // Verify that the path is a str
                         if lifetime.ident.name == "'static" {
-                            span_help_and_lint(cx,
+                            let mut sug: String = String::new();
+                            span_lint_and_then(cx,
                                                CONST_STATIC_LIFETIME,
                                                lifetime.span,
                                                "Constants have by default a `'static` lifetime",
-                                               "consider removing `'static`");
+                                               |db| {db.span_suggestion(lifetime.span,"consider removing `'static`",sug);});
                         }
                     }
                 }
index 30b6165d1f3d4c621b0919e87a29878c643a63b1..a6fed5f58d29670a2f7d3177b6b17359d864aa57 100644 (file)
@@ -1,65 +1,52 @@
+warning: running cargo clippy on a crate that also imports the clippy plugin
+
 error: Constants have by default a `'static` lifetime
- --> $DIR/const_static_lifetime.rs:6:17
+ --> $DIR/const_static_lifetime.rs:7:17
   |
-6 | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
-  |                 ^^^^^^^
+7 | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
+  |                 ^^^^^^^ help: consider removing `'static`: `&str`
   |
   = note: `-D const-static-lifetime` implied by `-D warnings`
-  = help: consider removing `'static`
 
 error: Constants have by default a `'static` lifetime
-  --> $DIR/const_static_lifetime.rs:10:21
-   |
-10 | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
-   |                     ^^^^^^^
+  --> $DIR/const_static_lifetime.rs:11:21
    |
-   = help: consider removing `'static`
+11 | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
+   |                     ^^^^^^^ help: consider removing `'static`: `&str`
 
 error: Constants have by default a `'static` lifetime
-  --> $DIR/const_static_lifetime.rs:12:32
+  --> $DIR/const_static_lifetime.rs:13:32
    |
-12 | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
-   |                                ^^^^^^^
-   |
-   = help: consider removing `'static`
+13 | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+   |                                ^^^^^^^ help: consider removing `'static`: `&str`
 
 error: Constants have by default a `'static` lifetime
-  --> $DIR/const_static_lifetime.rs:12:47
-   |
-12 | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
-   |                                               ^^^^^^^
+  --> $DIR/const_static_lifetime.rs:13:47
    |
-   = help: consider removing `'static`
+13 | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+   |                                               ^^^^^^^ help: consider removing `'static`: `&str`
 
 error: Constants have by default a `'static` lifetime
-  --> $DIR/const_static_lifetime.rs:14:30
+  --> $DIR/const_static_lifetime.rs:15:30
    |
-14 | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
-   |                              ^^^^^^^
-   |
-   = help: consider removing `'static`
+15 | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
+   |                              ^^^^^^^ help: consider removing `'static`: `&str`
 
 error: Constants have by default a `'static` lifetime
-  --> $DIR/const_static_lifetime.rs:16:17
-   |
-16 | const VAR_SIX: &'static u8 = &5;
-   |                 ^^^^^^^
+  --> $DIR/const_static_lifetime.rs:17:17
    |
-   = help: consider removing `'static`
+17 | const VAR_SIX: &'static u8 = &5;
+   |                 ^^^^^^^ help: consider removing `'static`: `&u8`
 
 error: Constants have by default a `'static` lifetime
-  --> $DIR/const_static_lifetime.rs:18:39
+  --> $DIR/const_static_lifetime.rs:19:39
    |
-18 | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
-   |                                       ^^^^^^^
-   |
-   = help: consider removing `'static`
+19 | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
+   |                                       ^^^^^^^ help: consider removing `'static`: `&str`
 
 error: Constants have by default a `'static` lifetime
-  --> $DIR/const_static_lifetime.rs:20:20
-   |
-20 | const VAR_HEIGHT: &'static Foo = &Foo {};
-   |                    ^^^^^^^
+  --> $DIR/const_static_lifetime.rs:21:20
    |
-   = help: consider removing `'static`
+21 | const VAR_HEIGHT: &'static Foo = &Foo {};
+   |                    ^^^^^^^ help: consider removing `'static`: `&Foo`