Update test suite

This commit is contained in:
Oliver Schneider 2018-03-28 23:49:32 +02:00
parent d6344c47e3
commit eafb9fe8df
No known key found for this signature in database
GPG key ID: 1D5CB4FC597C3004
21 changed files with 253 additions and 60 deletions

View file

@ -7,7 +7,7 @@
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
[There are 208 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
[There are 248 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
More to come, please [file an issue](https://github.com/rust-lang-nursery/rust-clippy/issues) if you have ideas!

View file

@ -401,15 +401,26 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
reg.register_late_lint_pass(box redundant_field_names::RedundantFieldNames);
reg.register_lint_group("clippy_restrictions", vec![
reg.register_lint_group("clippy_restriction", vec![
arithmetic::FLOAT_ARITHMETIC,
arithmetic::INTEGER_ARITHMETIC,
array_indexing::INDEXING_SLICING,
assign_ops::ASSIGN_OPS,
else_if_without_else::ELSE_IF_WITHOUT_ELSE,
literal_representation::DECIMAL_LITERAL_REPRESENTATION,
mem_forget::MEM_FORGET,
methods::CLONE_ON_REF_PTR,
methods::OPTION_UNWRAP_USED,
methods::RESULT_UNWRAP_USED,
methods::WRONG_PUB_SELF_CONVENTION,
misc::FLOAT_CMP_CONST,
missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
print::PRINT_STDOUT,
print::USE_DEBUG,
shadow::SHADOW_REUSE,
shadow::SHADOW_SAME,
shadow::SHADOW_UNRELATED,
strings::STRING_ADD,
]);
reg.register_lint_group("clippy_pedantic", vec![
@ -454,6 +465,200 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
]);
reg.register_lint_group("clippy", vec![
approx_const::APPROX_CONSTANT,
array_indexing::OUT_OF_BOUNDS_INDEXING,
assign_ops::ASSIGN_OP_PATTERN,
assign_ops::MISREFACTORED_ASSIGN_OP,
attrs::DEPRECATED_SEMVER,
attrs::EMPTY_LINE_AFTER_OUTER_ATTR,
attrs::USELESS_ATTRIBUTE,
bit_mask::BAD_BIT_MASK,
bit_mask::INEFFECTIVE_BIT_MASK,
bit_mask::VERBOSE_BIT_MASK,
blacklisted_name::BLACKLISTED_NAME,
block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR,
block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT,
booleans::LOGIC_BUG,
booleans::NONMINIMAL_BOOL,
bytecount::NAIVE_BYTECOUNT,
collapsible_if::COLLAPSIBLE_IF,
const_static_lifetime::CONST_STATIC_LIFETIME,
copies::IF_SAME_THEN_ELSE,
copies::IFS_SAME_COND,
cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
derive::DERIVE_HASH_XOR_EQ,
double_comparison::DOUBLE_COMPARISONS,
double_parens::DOUBLE_PARENS,
drop_forget_ref::DROP_COPY,
drop_forget_ref::DROP_REF,
drop_forget_ref::FORGET_COPY,
drop_forget_ref::FORGET_REF,
entry::MAP_ENTRY,
enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT,
enum_variants::ENUM_VARIANT_NAMES,
enum_variants::MODULE_INCEPTION,
eq_op::EQ_OP,
eq_op::OP_REF,
erasing_op::ERASING_OP,
escape::BOXED_LOCAL,
eta_reduction::REDUNDANT_CLOSURE,
eval_order_dependence::DIVERGING_SUB_EXPRESSION,
eval_order_dependence::EVAL_ORDER_DEPENDENCE,
explicit_write::EXPLICIT_WRITE,
format::USELESS_FORMAT,
formatting::POSSIBLE_MISSING_COMMA,
formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
formatting::SUSPICIOUS_ELSE_FORMATTING,
functions::NOT_UNSAFE_PTR_ARG_DEREF,
functions::TOO_MANY_ARGUMENTS,
identity_conversion::IDENTITY_CONVERSION,
identity_op::IDENTITY_OP,
if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING,
infinite_iter::INFINITE_ITER,
inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
int_plus_one::INT_PLUS_ONE,
invalid_ref::INVALID_REF,
large_enum_variant::LARGE_ENUM_VARIANT,
len_zero::LEN_WITHOUT_IS_EMPTY,
len_zero::LEN_ZERO,
let_if_seq::USELESS_LET_IF_SEQ,
lifetimes::NEEDLESS_LIFETIMES,
lifetimes::UNUSED_LIFETIMES,
literal_representation::INCONSISTENT_DIGIT_GROUPING,
literal_representation::LARGE_DIGIT_GROUPS,
literal_representation::UNREADABLE_LITERAL,
loops::EMPTY_LOOP,
loops::EXPLICIT_COUNTER_LOOP,
loops::EXPLICIT_INTO_ITER_LOOP,
loops::EXPLICIT_ITER_LOOP,
loops::FOR_KV_MAP,
loops::FOR_LOOP_OVER_OPTION,
loops::FOR_LOOP_OVER_RESULT,
loops::ITER_NEXT_LOOP,
loops::MANUAL_MEMCPY,
loops::MUT_RANGE_BOUND,
loops::NEEDLESS_RANGE_LOOP,
loops::NEVER_LOOP,
loops::REVERSE_RANGE_LOOP,
loops::UNUSED_COLLECT,
loops::WHILE_IMMUTABLE_CONDITION,
loops::WHILE_LET_LOOP,
loops::WHILE_LET_ON_ITERATOR,
map_clone::MAP_CLONE,
matches::MATCH_AS_REF,
matches::MATCH_BOOL,
matches::MATCH_OVERLAPPING_ARM,
matches::MATCH_REF_PATS,
matches::MATCH_WILD_ERR_ARM,
matches::SINGLE_MATCH,
methods::CHARS_LAST_CMP,
methods::CHARS_NEXT_CMP,
methods::CLONE_DOUBLE_REF,
methods::CLONE_ON_COPY,
methods::FILTER_NEXT,
methods::GET_UNWRAP,
methods::ITER_CLONED_COLLECT,
methods::ITER_NTH,
methods::ITER_SKIP_NEXT,
methods::NEW_RET_NO_SELF,
methods::OK_EXPECT,
methods::OPTION_MAP_OR_NONE,
methods::OR_FUN_CALL,
methods::SEARCH_IS_SOME,
methods::SHOULD_IMPLEMENT_TRAIT,
methods::SINGLE_CHAR_PATTERN,
methods::STRING_EXTEND_CHARS,
methods::TEMPORARY_CSTRING_AS_PTR,
methods::UNNECESSARY_FOLD,
methods::USELESS_ASREF,
methods::WRONG_SELF_CONVENTION,
minmax::MIN_MAX,
misc::CMP_NAN,
misc::CMP_OWNED,
misc::FLOAT_CMP,
misc::MODULO_ONE,
misc::REDUNDANT_PATTERN,
misc::SHORT_CIRCUIT_STATEMENT,
misc::TOPLEVEL_REF_ARG,
misc::ZERO_PTR,
misc_early::BUILTIN_TYPE_SHADOW,
misc_early::DOUBLE_NEG,
misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
misc_early::MIXED_CASE_HEX_LITERALS,
misc_early::REDUNDANT_CLOSURE_CALL,
misc_early::UNNEEDED_FIELD_PATTERN,
misc_early::ZERO_PREFIXED_LITERAL,
mut_reference::UNNECESSARY_MUT_PASSED,
mutex_atomic::MUTEX_ATOMIC,
needless_bool::BOOL_COMPARISON,
needless_bool::NEEDLESS_BOOL,
needless_borrow::NEEDLESS_BORROW,
needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
needless_update::NEEDLESS_UPDATE,
neg_multiply::NEG_MULTIPLY,
new_without_default::NEW_WITHOUT_DEFAULT,
new_without_default::NEW_WITHOUT_DEFAULT_DERIVE,
no_effect::NO_EFFECT,
no_effect::UNNECESSARY_OPERATION,
non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
non_expressive_names::MANY_SINGLE_CHAR_NAMES,
ok_if_let::IF_LET_SOME_RESULT,
open_options::NONSENSICAL_OPEN_OPTIONS,
overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
panic::PANIC_PARAMS,
partialeq_ne_impl::PARTIALEQ_NE_IMPL,
precedence::PRECEDENCE,
print::PRINT_WITH_NEWLINE,
print::PRINTLN_EMPTY_STRING,
ptr::CMP_NULL,
ptr::MUT_FROM_REF,
ptr::PTR_ARG,
question_mark::QUESTION_MARK,
ranges::ITERATOR_STEP_BY_ZERO,
ranges::RANGE_MINUS_ONE,
ranges::RANGE_ZIP_WITH_LEN,
redundant_field_names::REDUNDANT_FIELD_NAMES,
reference::DEREF_ADDROF,
regex::INVALID_REGEX,
regex::REGEX_MACRO,
regex::TRIVIAL_REGEX,
returns::LET_AND_RETURN,
returns::NEEDLESS_RETURN,
serde_api::SERDE_API_MISUSE,
strings::STRING_LIT_AS_BYTES,
suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
swap::ALMOST_SWAPPED,
swap::MANUAL_SWAP,
temporary_assignment::TEMPORARY_ASSIGNMENT,
transmute::CROSSPOINTER_TRANSMUTE,
transmute::MISALIGNED_TRANSMUTE,
transmute::TRANSMUTE_BYTES_TO_STR,
transmute::TRANSMUTE_INT_TO_BOOL,
transmute::TRANSMUTE_INT_TO_CHAR,
transmute::TRANSMUTE_INT_TO_FLOAT,
transmute::TRANSMUTE_PTR_TO_REF,
transmute::USELESS_TRANSMUTE,
transmute::WRONG_TRANSMUTE,
types::ABSURD_EXTREME_COMPARISONS,
types::BORROWED_BOX,
types::BOX_VEC,
types::CAST_LOSSLESS,
types::CHAR_LIT_AS_U8,
types::IMPLICIT_HASHER,
types::LET_UNIT_VALUE,
types::OPTION_OPTION,
types::TYPE_COMPLEXITY,
types::UNIT_ARG,
types::UNIT_CMP,
types::UNNECESSARY_CAST,
unicode::ZERO_WIDTH_SPACE,
unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
unused_io_amount::UNUSED_IO_AMOUNT,
unused_label::UNUSED_LABEL,
vec::USELESS_VEC,
zero_div_zero::ZERO_DIVIDED_BY_ZERO,
]);
reg.register_lint_group("clippy_style", vec![

View file

@ -141,7 +141,7 @@ error: <-comparison of unit values detected. This will always be false
31 | () < {};
| ^^^^^^^
|
= note: `-D unit-cmp` implied by `-D warnings`
= note: #[deny(unit_cmp)] on by default
error: aborting due to 18 previous errors

View file

@ -12,7 +12,7 @@ error: this operation will always return zero. This is likely not the intended o
12 | x & 0 == 0;
| ^^^^^
|
= note: `-D erasing-op` implied by `-D warnings`
= note: #[deny(erasing_op)] on by default
error: incompatible bit mask: `_ & 2` can never be equal to `1`
--> $DIR/bit_masks.rs:15:5

View file

@ -4,7 +4,7 @@ error: you are getting the inner pointer of a temporary `CString`
7 | CString::new("foo").unwrap().as_ptr();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D temporary-cstring-as-ptr` implied by `-D warnings`
= note: #[deny(temporary_cstring_as_ptr)] on by default
= note: that pointer will be invalid outside this expression
help: assign the `CString` to a variable to extend its lifetime
--> $DIR/cstring.rs:7:5

View file

@ -1,9 +1,9 @@
#![feature(untagged_unions)]
#![allow(dead_code)]
#![warn(expl_impl_clone_on_copy)]
use std::hash::{Hash, Hasher};

View file

@ -4,7 +4,7 @@ error: you are deriving `Hash` but have implemented `PartialEq` explicitly
17 | #[derive(Hash)]
| ^^^^
|
= note: `-D derive-hash-xor-eq` implied by `-D warnings`
= note: #[deny(derive_hash_xor_eq)] on by default
note: `PartialEq` implemented here
--> $DIR/derive.rs:20:1
|

View file

@ -2,7 +2,7 @@
#![feature(associated_type_defaults)]
#![warn(clippy)]
#![warn(linkedlist)]
#![allow(dead_code, needless_pass_by_value)]
extern crate alloc;

View file

@ -4,7 +4,7 @@ error: This binary expression can be simplified
4 | if x == y || x < y {
| ^^^^^^^^^^^^^^^ help: try: `x <= y`
|
= note: #[deny(double_comparisons)] on by default
= note: `-D double-comparisons` implied by `-D warnings`
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:7:8

View file

@ -4,7 +4,7 @@ error: Variable in the condition are not mutated in the loop body. This either l
14 | while y < 10 {
| ^^^^^^
|
= note: `-D while-immutable-condition` implied by `-D warnings`
= note: #[deny(while_immutable_condition)] on by default
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
--> $DIR/infinite_loop.rs:19:11

View file

@ -4,7 +4,7 @@ error: reference to zeroed memory
27 | let ref_zero: &T = std::mem::zeroed(); // warning
| ^^^^^^^^^^^^^^^^^^
|
= note: `-D invalid-ref` implied by `-D warnings`
= note: #[deny(invalid_ref)] on by default
= help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
error: reference to zeroed memory

View file

@ -1,24 +0,0 @@
#![feature(rustc_private)]
#![feature(macro_vis_matcher)]
#![warn(lint_without_lint_pass)]
#[macro_use] extern crate rustc;
use rustc::lint::{LintPass, LintArray};
declare_clippy_lint! { GOOD_LINT, style, "good lint" }
declare_clippy_lint! { MISSING_LINT, style, "missing lint" }
pub struct Pass;
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array![GOOD_LINT]
}
}
fn main() {
let _ = MISSING_LINT;
}

View file

@ -1,10 +0,0 @@
error: the lint `MISSING_LINT` is not added to any `LintPass`
--> $DIR/lint_pass.rs:12:1
|
12 | declare_lint! { MISSING_LINT, Warn, "missing lint" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D lint-without-lint-pass` implied by `-D warnings`
error: aborting due to previous error

View file

@ -4,7 +4,7 @@
#![warn(clippy)]
#![allow(unused, if_let_redundant_pattern_matching)]
#![warn(single_match_else)]
#![warn(single_match_else, match_same_arms)]
use std::borrow::Cow;

View file

@ -56,6 +56,14 @@ error: you seem to be trying to use match for destructuring a single pattern. Co
78 | | };
| |_____^ help: try this: `if let Cow::Borrowed(..) = c { dummy() }`
error: this boolean expression can be simplified
--> $DIR/matches.rs:117:11
|
117 | match test && test {
| ^^^^^^^^^^^^ help: try: `test`
|
= note: `-D nonminimal-bool` implied by `-D warnings`
error: you seem to be trying to match on a boolean expression
--> $DIR/matches.rs:96:5
|
@ -461,5 +469,5 @@ error: use as_mut() instead
329 | | };
| |_____^ help: try this: `mut_owned.as_mut()`
error: aborting due to 37 previous errors
error: aborting due to 38 previous errors

View file

@ -1,7 +1,7 @@
#![feature(const_fn)]
#![warn(clippy, clippy_pedantic)]
#![warn(clippy, clippy_pedantic, option_unwrap_used)]
#![allow(blacklisted_name, unused, print_stdout, non_ascii_literal, new_without_default,
new_without_default_derive, missing_docs_in_private_items, needless_pass_by_value)]

View file

@ -1,7 +1,7 @@
#![warn(clippy, clippy_pedantic)]
#![warn(clippy, clippy_pedantic, shadow_same, shadow_reuse, shadow_unrelated)]
#![allow(unused_parens, unused_variables, missing_docs_in_private_items)]
fn id<T>(x: T) -> T { x }

View file

@ -12,7 +12,7 @@ error: Suspicious use of binary operator in `AddAssign` impl
20 | *self = *self - other;
| ^
|
= note: `-D suspicious-op-assign-impl` implied by `-D warnings`
= note: #[deny(suspicious_op_assign_impl)] on by default
error: aborting due to 2 previous errors

View file

@ -62,7 +62,7 @@ error: using `clone` on a double-reference; this will copy the reference instead
55 | let z: &Vec<_> = y.clone();
| ^^^^^^^^^
|
= note: `-D clone-double-ref` implied by `-D warnings`
= note: #[deny(clone_double_ref)] on by default
help: try dereferencing it
|
55 | let z: &Vec<_> = &(*y).clone();

View file

@ -4,7 +4,7 @@ error: equal expressions as operands to `/`
7 | let nan = 0.0 / 0.0;
| ^^^^^^^^^
|
= note: `-D eq-op` implied by `-D warnings`
= note: #[deny(eq_op)] on by default
error: constant division of 0.0 with 0.0 will always result in NaN
--> $DIR/zero_div_zero.rs:7:15

View file

@ -26,7 +26,7 @@ nl_escape_re = re.compile(r'\\\n\s*')
docs_link = 'https://rust-lang-nursery.github.io/rust-clippy/master/index.html'
def collect(lints, deprecated_lints, clippy_lints, fn):
def collect(deprecated_lints, clippy_lints, fn):
"""Collect all lints from a file.
Adds entries to the lints list as `(module, name, level, desc)`.
@ -88,6 +88,8 @@ def replace_region(fn, region_start, region_end, callback,
with open(fn) as fp:
lines = list(fp)
found = False
# replace old region with new region
new_lines = []
in_old_region = False
@ -102,9 +104,13 @@ def replace_region(fn, region_start, region_end, callback,
new_lines.append(line)
# old region starts here
in_old_region = True
found = True
else:
new_lines.append(line)
if not found:
print "regex " + region_start + " not found"
# write back to file
if write_back:
with open(fn, 'w') as fp:
@ -115,7 +121,6 @@ def replace_region(fn, region_start, region_end, callback,
def main(print_only=False, check=False):
lints = []
deprecated_lints = []
clippy_lints = {
"correctness": [],
@ -135,7 +140,7 @@ def main(print_only=False, check=False):
# collect all lints from source files
for fn in os.listdir('clippy_lints/src'):
if fn.endswith('.rs'):
collect(lints, deprecated_lints, clippy_lints,
collect(deprecated_lints, clippy_lints,
os.path.join('clippy_lints', 'src', fn))
# determine version
@ -148,7 +153,16 @@ def main(print_only=False, check=False):
print('Error: version not found in Cargo.toml!')
return
all_lints = lints
all_lints = []
clippy_lint_groups = [
"correctness",
"style",
"complexity",
"perf",
]
clippy_lint_list = []
for x in clippy_lint_groups:
clippy_lint_list += clippy_lints[x]
for _, value in clippy_lints.iteritems():
all_lints += value
@ -159,8 +173,8 @@ def main(print_only=False, check=False):
# update the lint counter in README.md
changed = replace_region(
'README.md',
r'^\[There are \d+ lints included in this crate\]\(https://rust-lang-nursery.github.io/rust-clippy/master/index.html\)$', "",
lambda: ['[There are %d lints included in this crate](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)\n' %
r'^\[There are \d+ lints included in this crate!\]\(https://rust-lang-nursery.github.io/rust-clippy/master/index.html\)$', "",
lambda: ['[There are %d lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)\n' %
(len(all_lints))],
write_back=not check)
@ -193,10 +207,10 @@ def main(print_only=False, check=False):
lambda: gen_mods(all_lints),
replace_start=False, write_back=not check)
# same for "clippy" lint collection
# same for "clippy_*" lint collections
changed |= replace_region(
'clippy_lints/src/lib.rs', r'reg.register_lint_group\("clippy"', r'\]\);',
lambda: gen_group(lints, levels=('warn', 'deny')),
lambda: gen_group(clippy_lint_list),
replace_start=False, write_back=not check)
for key, value in clippy_lints.iteritems():