Skip to content

Commit 81b2565

Browse files
authored
Merge pull request #2443 from goodmanjonathan/fix-2438
Don't suggest eliding 'static on associated consts
2 parents b835877 + 73f2ba5 commit 81b2565

File tree

2 files changed

+2
-36
lines changed

2 files changed

+2
-36
lines changed

clippy_lints/src/const_static_lifetime.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,5 @@ impl EarlyLintPass for StaticConst {
8787
}
8888
}
8989

90-
fn check_trait_item(&mut self, cx: &EarlyContext, item: &TraitItem) {
91-
if !in_macro(item.span) {
92-
// Match only constants...
93-
if let TraitItemKind::Const(ref var_type, _) = item.node {
94-
self.visit_type(var_type, cx);
95-
}
96-
}
97-
}
98-
99-
fn check_impl_item(&mut self, cx: &EarlyContext, item: &ImplItem) {
100-
if !in_macro(item.span) {
101-
// Match only constants...
102-
if let ImplItemKind::Const(ref var_type, _) = item.node {
103-
self.visit_type(var_type, cx);
104-
}
105-
}
106-
}
90+
// Don't check associated consts because `'static` cannot be elided on those (issue #2438)
10791
}

tests/ui/const_static_lifetime.stderr

+1-19
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,5 @@ error: Constants have by default a `'static` lifetime
7878
24 | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
7979
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
8080

81-
error: Constants have by default a `'static` lifetime
82-
--> $DIR/const_static_lifetime.rs:40:23
83-
|
84-
40 | const TRAIT_VAR: &'static str;
85-
| -^^^^^^^---- help: consider removing `'static`: `&str`
86-
87-
error: Constants have by default a `'static` lifetime
88-
--> $DIR/const_static_lifetime.rs:44:22
89-
|
90-
44 | const IMPL_VAR: &'static str = "var";
91-
| -^^^^^^^---- help: consider removing `'static`: `&str`
92-
93-
error: Constants have by default a `'static` lifetime
94-
--> $DIR/const_static_lifetime.rs:48:23
95-
|
96-
48 | const TRAIT_VAR: &'static str = "foo";
97-
| -^^^^^^^---- help: consider removing `'static`: `&str`
98-
99-
error: aborting due to 16 previous errors
81+
error: aborting due to 13 previous errors
10082

0 commit comments

Comments
 (0)