Rust-clippy: Run clippy::pedantic on clippy codebase

Created on 13 Sep 2018  路  5Comments  路  Source: rust-lang/rust-clippy

As discovered by @mikerite, we currently don't run the pedantic lints over the clippy codebase.
There were about 70 warnings on Travis when it was enabled.

L-enhancement P-help-wanted

Most helpful comment

I have a wip branch for some of these, should get PR done soonish.

All 5 comments

List of warnings to fix:

  • [x] warning: you seem to be trying to use match for destructuring a single pattern. Consider using if let
    --> rustc_tools_util/src/lib.rs:43:9
  • [x] warning: you seem to be trying to use match for destructuring a single pattern. Consider using if let
    --> rustc_tools_util/src/lib.rs:71:9
  • [x] warning: unnecessary structure name repetition
    --> clippy_dev/src/lib.rs:41:97
  • [x] warning: unnecessary structure name repetition
    --> clippy_dev/src/lib.rs:42:9
  • [x] warning: unnecessary structure name repetition
    --> clippy_dev/src/lib.rs:52:34
  • [x] warning: unnecessary structure name repetition
    --> clippy_dev/src/lib.rs:57:35
  • [x] warning: unnecessary structure name repetition
    --> clippy_dev/src/lib.rs:57:65
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/hir_utils.rs:111:92
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/hir_utils.rs:123:82
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/hir_utils.rs:203:73
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/hir_utils.rs:206:80
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/hir_utils.rs:206:89
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/hir_utils.rs:258:76
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/inspector.rs:273:37
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/inspector.rs:422:44
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/utils/usage.rs:58:39
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/double_comparison.rs:50:33
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/enum_clike.rs:59:25
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/enum_variants.rs:268:29
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/eq_op.rs:93:29
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/eq_op.rs:95:29
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/eq_op.rs:105:41
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/if_let_redundant_pattern_matching.rs:52:56
  • [x] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/transmute.rs:291:42
  • [x] warning: adding items after statements is confusing, since items exist from the start of the scope
    --> clippy_lints/src/consts.rs:282:17
  • [x] warning: item name starts with its containing module's name
    --> clippy_lints/src/utils/camel_case.rs:3:1
  • [x] warning: item name starts with its containing module's name
    --> clippy_lints/src/utils/camel_case.rs:36:1
  • [x] warning: adding items after statements is confusing, since items exist from the start of the scope
    --> clippy_lints/src/utils/higher.rs:80:5
  • [x] warning: item name starts with its containing module's name
    --> clippy_lints/src/double_comparison.rs:33:1
  • [x] warning: you should put 1_000_000_000.0 between ticks in the documentation
    --> clippy_lints/src/excessive_precision.rs:102:8
  • [x] warning: you should put var_arg between ticks in the documentation
    --> clippy_lints/src/map_unit_fn.rs:172:49
  • [x] warning: adding items after statements is confusing, since items exist from the start of the scope
    --> clippy_lints/src/methods.rs:1050:9
  • [x] warning: adding items after statements is confusing, since items exist from the start of the scope
    --> clippy_lints/src/methods.rs:1288:5
  • [x] warning: item name starts with its containing module's name
    --> clippy_lints/src/question_mark.rs:37:1
  • [x] warning: adding items after statements is confusing, since items exist from the start of the scope
    --> clippy_lints/src/write.rs:267:5
  • [x] warning: adding items after statements is confusing, since items exist from the start of the scope
    --> clippy_lints/src/write.rs:293:9
  • [x] warning: unnecessary structure name repetition
    --> clippy_lints/src/consts.rs:126:33
  • [x] warning: unnecessary structure name repetition
    --> clippy_lints/src/consts.rs:130:23
  • [x] warning: casting u128 to i128 may wrap around the value
    --> clippy_lints/src/consts.rs:229:63
  • [x] warning: casting u128 to u32 may truncate the value
    --> clippy_lints/src/consts.rs:332:61
  • [x] warning: casting i128 to u128 may lose the sign of the value
    --> clippy_lints/src/consts.rs:332:61
  • [x] warning: casting u128 to u32 may truncate the value
    --> clippy_lints/src/consts.rs:333:61
  • [x] warning: casting i128 to u128 may lose the sign of the value
    --> clippy_lints/src/consts.rs:333:61
  • [x] warning: casting u128 to u32 may truncate the value
    --> clippy_lints/src/consts.rs:353:61
  • [x] warning: casting u128 to u32 may truncate the value
    --> clippy_lints/src/consts.rs:354:61
  • [x] warning: casting u128 to u32 may truncate the value
    --> clippy_lints/src/consts.rs:417:74
  • [x] warning: casting u128 to u64 may truncate the value
    --> clippy_lints/src/consts.rs:418:74
  • [x] warning: casting u64 to usize may truncate the value on targets with 32-bit wide pointers
    --> clippy_lints/src/consts.rs:431:34
  • [x] warning: unnecessary structure name repetition
    --> clippy_lints/src/utils/conf.rs:151:21
  • [x] warning: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
    --> clippy_lints/src/utils/sugg.rs:533:78
  • [x] warning: casting u128 to i128 may wrap around the value
    --> clippy_lints/src/utils/mod.rs:976:6
  • [x] warning: casting i128 to u128 may lose the sign of the value
    --> clippy_lints/src/utils/mod.rs:982:6
  • [x] warning: this match has identical arm bodies
    --> clippy_lints/src/duration_subsec.rs:51:52
  • [x] warning: casting u128 to i128 may wrap around the value
    --> clippy_lints/src/enum_clike.rs:73:44
  • [x] warning: unnecessary structure name repetition
    --> clippy_lints/src/inherent_impl.rs:49:9
  • [x] warning: called filter(p).map(q) on an Iterator. This is more succinctly expressed by calling .filter_map(..) instead.
    --> clippy_lints/src/inherent_impl.rs:78:38
  • [x] warning: you seem to be trying to use match for destructuring a single pattern. Consider using if let
    --> clippy_lints/src/multiple_crate_versions.rs:44:24
  • [x] warning: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
    --> clippy_lints/src/regex.rs:136:35
  • [x] warning: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
    --> clippy_lints/src/regex.rs:137:37
  • [x] warning: casting isize to i32 may truncate the value on targets with 64-bit wide pointers
    --> src/driver.rs:18:10
  • [x] warning: called filter(p).map(q) on an Iterator. This is more succinctly expressed by calling .filter_map(..) instead.
    --> src/driver.rs:79:21
  • [x] warning: casting isize to i32 may truncate the value on targets with 64-bit wide pointers
    --> src/driver.rs:18:10

So I was taking a look at fixing the various casting warnings, and I was wondering what the "right" way to address them is. For cast_possible_truncation, the casts can be replaced with a try_into().expect(...), which is easy enough. But for cast_sign_loss / cast_possible_wrap, the situation is a little trickier, because often we are doing something clever with the bits and it's fine for it to wrap. So what's the right way to express that it's okay to e.g. cast a i128 to a u128 and back in utils::{sext, unsext}? Should I just #[allow] these lints in these cases?

Yeah, pedantic lints typically have a healthy helping of allow. If the "fix" isn't really improving things, just allow it.

Just tried again running clippy with -W clippy::pedantic on the clippy code base. Now it produces new warnings:

  • [ ] warning: called filter(p).map(q) on an Iterator. This is more succinctly expressed by calling .filter_map(..) instead.
    --> clippy_dev/src/lib.rs:78:5
  • [ ] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/redundant_pattern_matching.rs:86:48
  • [ ] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/redundant_pattern_matching.rs:138:57
  • [ ] warning: binding's name is too similar to existing binding
    --> clippy_lints/src/redundant_pattern_matching.rs:139:58
  • [ ] warning: it is more concise to loop over references to containers instead of using explicit iteration methods
    --> clippy_lints/src/methods/mod.rs:943:34
  • [ ] warning: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
    --> clippy_lints/src/returns.rs:203:64

I have a wip branch for some of these, should get PR done soonish.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jyn514 picture jyn514  路  3Comments

matthiaskrgr picture matthiaskrgr  路  3Comments

0e4ef622 picture 0e4ef622  路  3Comments

phansch picture phansch  路  3Comments

taiki-e picture taiki-e  路  3Comments