Skip to content

Commit 1e916c4

Browse files
committed
submodules: update clippy from 7b2a7a2 to be5d17f
Changes: ```` Fix wrong lifetime of TyCtxt Use replace_region_in_file for creating the lint list Restructure rename tests Register rename to the LintStore. Rename REDUNDANT_STATIC_LIFETIME to REDUNDANT_STATIC_LIFETIMES. Remove pub from RedundantStaticLifetime.visit_type function. Rename const_static_lifetime to redundant_static_lifetime. Merge StaticConst and StaticStatic lints into StaticConst. Use RedundantStaticLifetime in StaticStatic. Move type-checking logic in StaticConst to RedundantStaticLifetime. Add lint for statics with explicit static lifetime. minor fix make it pass dogfood run rustfmt fix padding and put clippy someplaces show default lint levels group printing prelim arg parse move Lint static def into its own module switch to sorted usable lints Update clippy_dev/src/main.rs initial commit for help improvements on clippy-driver ````
1 parent 4b45e73 commit 1e916c4

File tree

15 files changed

+2602
-145
lines changed

15 files changed

+2602
-145
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,6 @@ All notable changes to this project will be documented in this file.
881881
[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
882882
[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity
883883
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
884-
[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
885884
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
886885
[`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute
887886
[`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro
@@ -1068,6 +1067,7 @@ All notable changes to this project will be documented in this file.
10681067
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
10691068
[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
10701069
[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
1070+
[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes
10711071
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
10721072
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
10731073
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts

clippy_dev/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,33 @@ fn print_lints() {
8787

8888
fn update_lints(update_mode: &UpdateMode) {
8989
let lint_list: Vec<Lint> = gather_all().collect();
90+
9091
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
9192
let lint_count = usable_lints.len();
9293

94+
let mut sorted_usable_lints = usable_lints.clone();
95+
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
96+
9397
let mut file_change = replace_region_in_file(
98+
"../src/lintlist/mod.rs",
99+
"begin lint list",
100+
"end lint list",
101+
false,
102+
update_mode == &UpdateMode::Change,
103+
|| {
104+
format!(
105+
"pub const ALL_LINTS: [Lint; {}] = {:#?};",
106+
sorted_usable_lints.len(),
107+
sorted_usable_lints
108+
)
109+
.lines()
110+
.map(ToString::to_string)
111+
.collect::<Vec<_>>()
112+
},
113+
)
114+
.changed;
115+
116+
file_change |= replace_region_in_file(
94117
"../README.md",
95118
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
96119
"",

clippy_lints/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Hash for Constant {
121121
}
122122

123123
impl Constant {
124-
pub fn partial_cmp(tcx: TyCtxt<'_, '_>, cmp_type: Ty<'_>, left: &Self, right: &Self) -> Option<Ordering> {
124+
pub fn partial_cmp(tcx: TyCtxt<'_>, cmp_type: Ty<'_>, left: &Self, right: &Self) -> Option<Ordering> {
125125
match (left, right) {
126126
(&Constant::Str(ref ls), &Constant::Str(ref rs)) => Some(ls.cmp(rs)),
127127
(&Constant::Char(ref l), &Constant::Char(ref r)) => Some(l.cmp(r)),

clippy_lints/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ pub mod cargo_common_metadata;
157157
pub mod checked_conversions;
158158
pub mod cognitive_complexity;
159159
pub mod collapsible_if;
160-
pub mod const_static_lifetime;
161160
pub mod copies;
162161
pub mod copy_iterator;
163162
pub mod dbg_macro;
@@ -249,6 +248,7 @@ pub mod ranges;
249248
pub mod redundant_clone;
250249
pub mod redundant_field_names;
251250
pub mod redundant_pattern_matching;
251+
pub mod redundant_static_lifetimes;
252252
pub mod reference;
253253
pub mod regex;
254254
pub mod replace_consts;
@@ -553,7 +553,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
553553
reg.register_late_lint_pass(box invalid_ref::InvalidRef);
554554
reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default());
555555
reg.register_late_lint_pass(box types::ImplicitHasher);
556-
reg.register_early_lint_pass(box const_static_lifetime::StaticConst);
556+
reg.register_early_lint_pass(box redundant_static_lifetimes::RedundantStaticLifetimes);
557557
reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom);
558558
reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
559559
reg.register_late_lint_pass(box types::UnitArg);
@@ -686,7 +686,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
686686
bytecount::NAIVE_BYTECOUNT,
687687
cognitive_complexity::COGNITIVE_COMPLEXITY,
688688
collapsible_if::COLLAPSIBLE_IF,
689-
const_static_lifetime::CONST_STATIC_LIFETIME,
690689
copies::IFS_SAME_COND,
691690
copies::IF_SAME_THEN_ELSE,
692691
derive::DERIVE_HASH_XOR_EQ,
@@ -834,6 +833,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
834833
ranges::RANGE_ZIP_WITH_LEN,
835834
redundant_field_names::REDUNDANT_FIELD_NAMES,
836835
redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
836+
redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
837837
reference::DEREF_ADDROF,
838838
reference::REF_IN_DEREF,
839839
regex::INVALID_REGEX,
@@ -901,7 +901,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
901901
block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
902902
block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
903903
collapsible_if::COLLAPSIBLE_IF,
904-
const_static_lifetime::CONST_STATIC_LIFETIME,
905904
enum_variants::ENUM_VARIANT_NAMES,
906905
enum_variants::MODULE_INCEPTION,
907906
eq_op::OP_REF,
@@ -957,6 +956,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
957956
question_mark::QUESTION_MARK,
958957
redundant_field_names::REDUNDANT_FIELD_NAMES,
959958
redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
959+
redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
960960
regex::REGEX_MACRO,
961961
regex::TRIVIAL_REGEX,
962962
returns::LET_AND_RETURN,
@@ -1153,6 +1153,7 @@ pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
11531153
ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
11541154
ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");
11551155
ls.register_renamed("clippy::cyclomatic_complexity", "clippy::cognitive_complexity");
1156+
ls.register_renamed("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes");
11561157
}
11571158

11581159
// only exists to let the dogfood integration test works.

clippy_lints/src/const_static_lifetime.rs renamed to clippy_lints/src/redundant_static_lifetimes.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_errors::Applicability;
55
use syntax::ast::*;
66

77
declare_clippy_lint! {
8-
/// **What it does:** Checks for constants with an explicit `'static` lifetime.
8+
/// **What it does:** Checks for constants and statics with an explicit `'static` lifetime.
99
///
1010
/// **Why is this bad?** Adding `'static` to every reference can create very
1111
/// complicated types.
@@ -16,29 +16,32 @@ declare_clippy_lint! {
1616
/// ```ignore
1717
/// const FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] =
1818
/// &[...]
19+
/// static FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] =
20+
/// &[...]
1921
/// ```
2022
/// This code can be rewritten as
2123
/// ```ignore
2224
/// const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...]
25+
/// static FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...]
2326
/// ```
24-
pub CONST_STATIC_LIFETIME,
27+
pub REDUNDANT_STATIC_LIFETIMES,
2528
style,
26-
"Using explicit `'static` lifetime for constants when elision rules would allow omitting them."
29+
"Using explicit `'static` lifetime for constants or statics when elision rules would allow omitting them."
2730
}
2831

29-
declare_lint_pass!(StaticConst => [CONST_STATIC_LIFETIME]);
32+
declare_lint_pass!(RedundantStaticLifetimes => [REDUNDANT_STATIC_LIFETIMES]);
3033

31-
impl StaticConst {
34+
impl RedundantStaticLifetimes {
3235
// Recursively visit types
33-
fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext<'_>) {
36+
fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext<'_>, reason: &str) {
3437
match ty.node {
3538
// Be careful of nested structures (arrays and tuples)
3639
TyKind::Array(ref ty, _) => {
37-
self.visit_type(&*ty, cx);
40+
self.visit_type(&*ty, cx, reason);
3841
},
3942
TyKind::Tup(ref tup) => {
4043
for tup_ty in tup {
41-
self.visit_type(&*tup_ty, cx);
44+
self.visit_type(&*tup_ty, cx, reason);
4245
}
4346
},
4447
// This is what we are looking for !
@@ -50,44 +53,40 @@ impl StaticConst {
5053
if lifetime.ident.name == syntax::symbol::kw::StaticLifetime {
5154
let snip = snippet(cx, borrow_type.ty.span, "<type>");
5255
let sugg = format!("&{}", snip);
53-
span_lint_and_then(
54-
cx,
55-
CONST_STATIC_LIFETIME,
56-
lifetime.ident.span,
57-
"Constants have by default a `'static` lifetime",
58-
|db| {
59-
db.span_suggestion(
60-
ty.span,
61-
"consider removing `'static`",
62-
sugg,
63-
Applicability::MachineApplicable, //snippet
64-
);
65-
},
66-
);
56+
span_lint_and_then(cx, REDUNDANT_STATIC_LIFETIMES, lifetime.ident.span, reason, |db| {
57+
db.span_suggestion(
58+
ty.span,
59+
"consider removing `'static`",
60+
sugg,
61+
Applicability::MachineApplicable, //snippet
62+
);
63+
});
6764
}
6865
},
6966
_ => {},
7067
}
7168
}
72-
self.visit_type(&*borrow_type.ty, cx);
69+
self.visit_type(&*borrow_type.ty, cx, reason);
7370
},
7471
TyKind::Slice(ref ty) => {
75-
self.visit_type(ty, cx);
72+
self.visit_type(ty, cx, reason);
7673
},
7774
_ => {},
7875
}
7976
}
8077
}
8178

82-
impl EarlyLintPass for StaticConst {
79+
impl EarlyLintPass for RedundantStaticLifetimes {
8380
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
8481
if !in_macro_or_desugar(item.span) {
85-
// Match only constants...
8682
if let ItemKind::Const(ref var_type, _) = item.node {
87-
self.visit_type(var_type, cx);
83+
self.visit_type(var_type, cx, "Constants have by default a `'static` lifetime");
84+
// Don't check associated consts because `'static` cannot be elided on those (issue #2438)
85+
}
86+
87+
if let ItemKind::Static(ref var_type, _, _) = item.node {
88+
self.visit_type(var_type, cx, "Statics have by default a `'static` lifetime");
8889
}
8990
}
9091
}
91-
92-
// Don't check associated consts because `'static` cannot be elided on those (issue #2438)
9392
}

clippy_lints/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ declare_clippy_lint! {
860860

861861
/// Returns the size in bits of an integral type.
862862
/// Will return 0 if the type is not an int or uint variant
863-
fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_, '_>) -> u64 {
863+
fn int_ty_to_nbits(typ: Ty<'_>, tcx: TyCtxt<'_>) -> u64 {
864864
match typ.sty {
865865
ty::Int(i) => match i {
866866
IntTy::Isize => tcx.data_layout.pointer_size.bits(),

clippy_lints/src/utils/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,28 +911,28 @@ pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
911911
}
912912
}
913913

914-
pub fn int_bits(tcx: TyCtxt<'_, '_>, ity: ast::IntTy) -> u64 {
914+
pub fn int_bits(tcx: TyCtxt<'_>, ity: ast::IntTy) -> u64 {
915915
layout::Integer::from_attr(&tcx, attr::IntType::SignedInt(ity))
916916
.size()
917917
.bits()
918918
}
919919

920920
#[allow(clippy::cast_possible_wrap)]
921921
/// Turn a constant int byte representation into an i128
922-
pub fn sext(tcx: TyCtxt<'_, '_>, u: u128, ity: ast::IntTy) -> i128 {
922+
pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ast::IntTy) -> i128 {
923923
let amt = 128 - int_bits(tcx, ity);
924924
((u as i128) << amt) >> amt
925925
}
926926

927927
#[allow(clippy::cast_sign_loss)]
928928
/// clip unused bytes
929-
pub fn unsext(tcx: TyCtxt<'_, '_>, u: i128, ity: ast::IntTy) -> u128 {
929+
pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ast::IntTy) -> u128 {
930930
let amt = 128 - int_bits(tcx, ity);
931931
((u as u128) << amt) >> amt
932932
}
933933

934934
/// clip unused bytes
935-
pub fn clip(tcx: TyCtxt<'_, '_>, u: u128, ity: ast::UintTy) -> u128 {
935+
pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ast::UintTy) -> u128 {
936936
let bits = layout::Integer::from_attr(&tcx, attr::IntType::UnsignedInt(ity))
937937
.size()
938938
.bits();
@@ -973,7 +973,7 @@ pub fn without_block_comments(lines: Vec<&str>) -> Vec<&str> {
973973
without
974974
}
975975

976-
pub fn any_parent_is_automatically_derived(tcx: TyCtxt<'_, '_>, node: HirId) -> bool {
976+
pub fn any_parent_is_automatically_derived(tcx: TyCtxt<'_>, node: HirId) -> bool {
977977
let map = &tcx.hir();
978978
let mut prev_enclosing_node = None;
979979
let mut enclosing_node = node;

0 commit comments

Comments
 (0)