Fix const_static_lifetime
This commit is contained in:
parent
ff83b3ecb9
commit
10d2feddba
@ -1,4 +1,4 @@
|
||||
use syntax::ast::{Item, ItemKind, Ty, TyKind};
|
||||
use syntax::ast::*;
|
||||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||
use utils::{in_macro, snippet, span_lint_and_then};
|
||||
|
||||
@ -86,4 +86,22 @@ impl EarlyLintPass for StaticConst {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &EarlyContext, item: &TraitItem) {
|
||||
if !in_macro(item.span) {
|
||||
// Match only constants...
|
||||
if let TraitItemKind::Const(ref var_type, _) = item.node {
|
||||
self.visit_type(var_type, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &EarlyContext, item: &ImplItem) {
|
||||
if !in_macro(item.span) {
|
||||
// Match only constants...
|
||||
if let ImplItemKind::Const(ref var_type, _) = item.node {
|
||||
self.visit_type(var_type, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,3 +35,15 @@ fn main() {
|
||||
println!("{:?}", VAR_HEIGHT);
|
||||
println!("{}", false_positive);
|
||||
}
|
||||
|
||||
trait Bar {
|
||||
const TRAIT_VAR: &'static str;
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
const IMPL_VAR: &'static str = "var";
|
||||
}
|
||||
|
||||
impl Bar for Foo {
|
||||
const TRAIT_VAR: &'static str = "foo";
|
||||
}
|
||||
|
@ -78,5 +78,23 @@ error: Constants have by default a `'static` lifetime
|
||||
24 | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
|
||||
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: Constants have by default a `'static` lifetime
|
||||
--> $DIR/const_static_lifetime.rs:40:23
|
||||
|
|
||||
40 | const TRAIT_VAR: &'static str;
|
||||
| -^^^^^^^---- help: consider removing `'static`: `&str`
|
||||
|
||||
error: Constants have by default a `'static` lifetime
|
||||
--> $DIR/const_static_lifetime.rs:44:22
|
||||
|
|
||||
44 | const IMPL_VAR: &'static str = "var";
|
||||
| -^^^^^^^---- help: consider removing `'static`: `&str`
|
||||
|
||||
error: Constants have by default a `'static` lifetime
|
||||
--> $DIR/const_static_lifetime.rs:48:23
|
||||
|
|
||||
48 | const TRAIT_VAR: &'static str = "foo";
|
||||
| -^^^^^^^---- help: consider removing `'static`: `&str`
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user