From fd1351f6e311b6c3e24a0b236bf2879501d4fd38 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 7 Feb 2017 21:05:30 +0100 Subject: [PATCH] rustup and compile-fail -> ui test move --- CHANGELOG.md | 4 + CONTRIBUTING.md | 5 + Cargo.toml | 4 +- clippy_lints/Cargo.toml | 2 +- clippy_lints/src/derive.rs | 2 +- clippy_lints/src/types.rs | 4 +- tests/compile-fail/non_expressive_names.rs | 4 + tests/compile-fail/strings.rs | 2 +- tests/compile-fail/swap.rs | 14 +- tests/compile-test.rs | 3 +- .../absurd-extreme-comparisons.rs | 0 tests/ui/absurd-extreme-comparisons.stderr | 151 +++ tests/{compile-fail => ui}/approx_const.rs | 0 tests/ui/approx_const.stderr | 122 +++ tests/{compile-fail => ui}/arithmetic.rs | 0 tests/ui/arithmetic.stderr | 82 ++ tests/{compile-fail => ui}/array_indexing.rs | 0 tests/ui/array_indexing.stderr | 152 +++ tests/{compile-fail => ui}/assign_ops.rs | 0 tests/ui/assign_ops.stderr | 201 ++++ tests/{compile-fail => ui}/assign_ops2.rs | 0 tests/ui/assign_ops2.stderr | 79 ++ tests/{compile-fail => ui}/attrs.rs | 0 tests/ui/attrs.stderr | 32 + tests/{compile-fail => ui}/bit_masks.rs | 0 tests/ui/bit_masks.stderr | 104 ++ .../{compile-fail => ui}/blacklisted_name.rs | 0 tests/ui/blacklisted_name.stderr | 50 + .../block_in_if_condition.rs | 0 tests/ui/block_in_if_condition.stderr | 68 ++ tests/{compile-fail => ui}/bool_comparison.rs | 0 tests/ui/bool_comparison.stderr | 43 + tests/{compile-fail => ui}/booleans.rs | 0 tests/ui/booleans.stderr | 160 +++ tests/{compile-fail => ui}/box_vec.rs | 0 tests/ui/box_vec.stderr | 16 + .../builtin-type-shadow.rs | 0 tests/ui/builtin-type-shadow.stderr | 23 + tests/{compile-fail => ui}/cast.rs | 0 tests/ui/cast.stderr | 278 +++++ tests/{compile-fail => ui}/char_lit_as_u8.rs | 0 tests/ui/char_lit_as_u8.stderr | 16 + tests/{compile-fail => ui}/cmp_nan.rs | 0 tests/ui/cmp_nan.stderr | 98 ++ tests/{compile-fail => ui}/cmp_null.rs | 0 tests/ui/cmp_null.stderr | 20 + tests/{compile-fail => ui}/cmp_owned.rs | 0 tests/ui/cmp_owned.stderr | 32 + tests/{compile-fail => ui}/collapsible_if.rs | 0 tests/ui/collapsible_if.stderr | 229 +++++ tests/{compile-fail => ui}/complex_types.rs | 0 tests/ui/complex_types.stderr | 127 +++ tests/{compile-fail => ui}/conf_bad_arg.rs | 0 tests/ui/conf_bad_arg.stderr | 14 + tests/{compile-fail => ui}/conf_bad_toml.rs | 0 tests/ui/conf_bad_toml.stderr | 4 + tests/{compile-fail => ui}/conf_bad_toml.toml | 0 tests/{compile-fail => ui}/conf_bad_type.rs | 0 tests/ui/conf_bad_type.stderr | 4 + tests/{compile-fail => ui}/conf_bad_type.toml | 0 .../conf_french_blacklisted_name.rs | 0 tests/ui/conf_french_blacklisted_name.stderr | 50 + .../{compile-fail => ui}/conf_non_existant.rs | 0 tests/ui/conf_non_existant.stderr | 4 + .../conf_path_non_string.rs | 0 tests/ui/conf_path_non_string.stderr | 14 + .../{compile-fail => ui}/conf_unknown_key.rs | 0 tests/ui/conf_unknown_key.stderr | 4 + tests/{compile-fail => ui}/copies.rs | 0 tests/ui/copies.stderr | 409 ++++++++ .../cyclomatic_complexity.rs | 0 tests/ui/cyclomatic_complexity.stderr | 232 +++++ .../cyclomatic_complexity_attr_used.rs | 0 .../ui/cyclomatic_complexity_attr_used.stderr | 22 + tests/{compile-fail => ui}/derive.rs | 0 tests/ui/derive.stderr | 103 ++ .../diverging_sub_expression.rs | 0 tests/ui/diverging_sub_expression.stderr | 44 + tests/{compile-fail => ui}/dlist.rs | 0 tests/ui/dlist.stderr | 61 ++ tests/{compile-fail => ui}/doc.rs | 0 tests/ui/doc.stderr | 182 ++++ tests/{compile-fail => ui}/double_neg.rs | 0 tests/ui/double_neg.stderr | 14 + tests/{compile-fail => ui}/double_parens.rs | 0 tests/ui/double_parens.stderr | 38 + tests/{compile-fail => ui}/drop_forget_ref.rs | 0 tests/ui/drop_forget_ref.stderr | 228 +++++ .../duplicate_underscore_argument.rs | 0 tests/ui/duplicate_underscore_argument.stderr | 14 + tests/{compile-fail => ui}/empty_enum.rs | 0 tests/ui/empty_enum.stderr | 19 + tests/{compile-fail => ui}/entry.rs | 0 tests/ui/entry.stderr | 70 ++ tests/{compile-fail => ui}/enum_glob_use.rs | 0 tests/ui/enum_glob_use.stderr | 23 + tests/{compile-fail => ui}/enum_variants.rs | 0 tests/ui/enum_variants.stderr | 127 +++ tests/{compile-fail => ui}/enums_clike.rs | 0 tests/ui/enums_clike.stderr | 71 ++ tests/{compile-fail => ui}/eq_op.rs | 0 tests/ui/eq_op.stderr | 223 ++++ tests/{compile-fail => ui}/escape_analysis.rs | 0 tests/ui/escape_analysis.stderr | 56 + tests/{compile-fail => ui}/eta.rs | 0 tests/ui/eta.stderr | 51 + .../eval_order_dependence.rs | 0 tests/ui/eval_order_dependence.stderr | 55 + tests/{compile-fail => ui}/filter_methods.rs | 0 tests/ui/filter_methods.stderr | 51 + tests/{compile-fail => ui}/float_cmp.rs | 0 tests/ui/float_cmp.stderr | 119 +++ tests/{compile-fail => ui}/for_loop.rs | 0 tests/ui/for_loop.stderr | 632 ++++++++++++ tests/{compile-fail => ui}/format.rs | 0 tests/ui/format.stderr | 26 + tests/{compile-fail => ui}/formatting.rs | 0 tests/ui/formatting.stderr | 116 +++ tests/{compile-fail => ui}/functions.rs | 0 tests/ui/functions.stderr | 111 ++ tests/{compile-fail => ui}/identity_op.rs | 0 tests/ui/identity_op.stderr | 50 + .../if_let_redundant_pattern_matching.rs | 0 .../if_let_redundant_pattern_matching.stderr | 47 + tests/{compile-fail => ui}/if_not_else.rs | 0 tests/ui/if_not_else.stderr | 33 + .../invalid_upcast_comparisons.rs | 0 tests/ui/invalid_upcast_comparisons.stderr | 62 ++ .../item_after_statement.rs | 0 tests/ui/item_after_statement.stderr | 20 + .../large_enum_variant.rs | 0 tests/ui/large_enum_variant.stderr | 84 ++ tests/{compile-fail => ui}/len_zero.rs | 0 tests/ui/len_zero.stderr | 100 ++ tests/{compile-fail => ui}/let_if_seq.rs | 0 tests/ui/let_if_seq.stderr | 60 ++ tests/{compile-fail => ui}/let_return.rs | 0 tests/ui/let_return.stderr | 31 + tests/{compile-fail => ui}/let_unit.rs | 0 tests/ui/let_unit.stderr | 20 + tests/{compile-fail => ui}/lifetimes.rs | 0 tests/ui/lifetimes.stderr | 95 ++ tests/{compile-fail => ui}/lint_pass.rs | 0 tests/ui/lint_pass.stderr | 14 + tests/{compile-fail => ui}/literals.rs | 0 tests/ui/literals.stderr | 78 ++ tests/{compile-fail => ui}/map_clone.rs | 0 tests/ui/map_clone.stderr | 106 ++ tests/{compile-fail => ui}/matches.rs | 0 tests/ui/matches.stderr | 392 +++++++ tests/{compile-fail => ui}/mem_forget.rs | 0 tests/ui/mem_forget.stderr | 26 + tests/ui/methods.rs | 691 +++++++++++++ tests/ui/methods.stderr | 954 ++++++++++++++++++ tests/{compile-fail => ui}/min_max.rs | 0 tests/ui/min_max.stderr | 63 ++ tests/{compile-fail => ui}/missing-doc.rs | 0 tests/ui/missing-doc.stderr | 279 +++++ .../{compile-fail => ui}/module_inception.rs | 0 tests/ui/module_inception.stderr | 26 + tests/{compile-fail => ui}/modulo_one.rs | 0 tests/ui/modulo_one.stderr | 14 + tests/{compile-fail => ui}/mut_mut.rs | 0 tests/ui/mut_mut.stderr | 89 ++ tests/{compile-fail => ui}/mut_reference.rs | 0 tests/ui/mut_reference.stderr | 26 + tests/{compile-fail => ui}/mutex_atomic.rs | 0 tests/ui/mutex_atomic.stderr | 65 ++ tests/{compile-fail => ui}/needless_bool.rs | 0 tests/ui/needless_bool.stderr | 95 ++ tests/{compile-fail => ui}/needless_borrow.rs | 0 tests/ui/needless_borrow.stderr | 31 + tests/{compile-fail => ui}/needless_return.rs | 0 tests/ui/needless_return.stderr | 79 ++ tests/{compile-fail => ui}/needless_update.rs | 0 tests/ui/needless_update.stderr | 14 + tests/{compile-fail => ui}/neg_multiply.rs | 0 tests/ui/neg_multiply.stderr | 20 + .../new_without_default.rs | 0 tests/ui/new_without_default.stderr | 47 + tests/{compile-fail => ui}/no_effect.rs | 0 tests/ui/no_effect.stderr | 334 ++++++ tests/ui/non_expressive_names.rs | 150 +++ tests/ui/non_expressive_names.stderr | 148 +++ tests/{compile-fail => ui}/ok_if_let.rs | 0 tests/ui/ok_if_let.stderr | 21 + tests/{compile-fail => ui}/open_options.rs | 0 tests/ui/open_options.stderr | 50 + .../overflow_check_conditional.rs | 0 tests/ui/overflow_check_conditional.stderr | 56 + tests/{compile-fail => ui}/panic.rs | 0 tests/ui/panic.stderr | 26 + .../{compile-fail => ui}/partialeq_ne_impl.rs | 0 tests/ui/partialeq_ne_impl.stderr | 15 + tests/{compile-fail => ui}/patterns.rs | 0 tests/ui/patterns.stderr | 15 + tests/{compile-fail => ui}/precedence.rs | 0 tests/ui/precedence.stderr | 88 ++ tests/{compile-fail => ui}/print.rs | 0 tests/ui/print.stderr | 62 ++ .../print_with_newline.rs | 0 tests/ui/print_with_newline.stderr | 32 + tests/{compile-fail => ui}/ptr_arg.rs | 0 tests/ui/ptr_arg.stderr | 26 + tests/{compile-fail => ui}/range.rs | 0 tests/ui/range.stderr | 44 + .../redundant_closure_call.rs | 0 tests/ui/redundant_closure_call.stderr | 41 + tests/{compile-fail => ui}/reference.rs | 0 tests/ui/reference.stderr | 106 ++ tests/{compile-fail => ui}/regex.rs | 0 tests/ui/regex.stderr | 175 ++++ tests/{compile-fail => ui}/serde.rs | 0 tests/ui/serde.stderr | 20 + tests/{compile-fail => ui}/shadow.rs | 0 tests/ui/shadow.stderr | 159 +++ .../short_circuit_statement.rs | 0 tests/ui/short_circuit_statement.stderr | 34 + tests/ui/strings.rs | 73 ++ tests/ui/strings.stderr | 80 ++ tests/{compile-fail => ui}/stutter.rs | 0 tests/ui/stutter.stderr | 32 + tests/ui/swap.rs | 84 ++ tests/ui/swap.stderr | 105 ++ .../temporary_assignment.rs | 0 tests/ui/temporary_assignment.stderr | 20 + .../{compile-fail => ui}/toplevel_ref_arg.rs | 0 tests/ui/toplevel_ref_arg.stderr | 55 + tests/{compile-fail => ui}/transmute.rs | 0 tests/ui/transmute.stderr | 225 +++++ tests/{compile-fail => ui}/transmute_32bit.rs | 0 tests/{compile-fail => ui}/transmute_64bit.rs | 0 tests/ui/transmute_64bit.stderr | 20 + tests/{compile-fail => ui}/unicode.rs | 0 tests/ui/unicode.stderr | 40 + tests/{compile-fail => ui}/unit_cmp.rs | 0 tests/ui/unit_cmp.stderr | 20 + .../unneeded_field_pattern.rs | 0 tests/ui/unneeded_field_pattern.stderr | 23 + .../unsafe_removed_from_name.rs | 0 tests/ui/unsafe_removed_from_name.stderr | 26 + .../{compile-fail => ui}/unused_io_amount.rs | 0 tests/ui/unused_io_amount.stderr | 52 + tests/{compile-fail => ui}/unused_labels.rs | 0 tests/ui/unused_labels.stderr | 32 + tests/{compile-fail => ui}/unused_lt.rs | 0 tests/ui/unused_lt.stderr | 26 + tests/ui/update-all-references.sh | 31 + tests/ui/update-references.sh | 50 + .../used_underscore_binding.rs | 0 tests/ui/used_underscore_binding.stderr | 38 + .../{compile-fail => ui}/useless_attribute.rs | 0 tests/ui/useless_attribute.stderr | 16 + tests/{compile-fail => ui}/vec.rs | 0 tests/ui/vec.stderr | 61 ++ tests/{compile-fail => ui}/while_loop.rs | 0 tests/ui/while_loop.stderr | 126 +++ tests/ui/wrong_macro_span.rs_ | 29 + .../wrong_self_convention.rs | 0 tests/ui/wrong_self_convention.stderr | 80 ++ tests/{compile-fail => ui}/zero_div_zero.rs | 0 tests/ui/zero_div_zero.stderr | 71 ++ 262 files changed, 12031 insertions(+), 15 deletions(-) rename tests/{compile-fail => ui}/absurd-extreme-comparisons.rs (100%) create mode 100644 tests/ui/absurd-extreme-comparisons.stderr rename tests/{compile-fail => ui}/approx_const.rs (100%) create mode 100644 tests/ui/approx_const.stderr rename tests/{compile-fail => ui}/arithmetic.rs (100%) create mode 100644 tests/ui/arithmetic.stderr rename tests/{compile-fail => ui}/array_indexing.rs (100%) create mode 100644 tests/ui/array_indexing.stderr rename tests/{compile-fail => ui}/assign_ops.rs (100%) create mode 100644 tests/ui/assign_ops.stderr rename tests/{compile-fail => ui}/assign_ops2.rs (100%) create mode 100644 tests/ui/assign_ops2.stderr rename tests/{compile-fail => ui}/attrs.rs (100%) create mode 100644 tests/ui/attrs.stderr rename tests/{compile-fail => ui}/bit_masks.rs (100%) create mode 100644 tests/ui/bit_masks.stderr rename tests/{compile-fail => ui}/blacklisted_name.rs (100%) create mode 100644 tests/ui/blacklisted_name.stderr rename tests/{compile-fail => ui}/block_in_if_condition.rs (100%) create mode 100644 tests/ui/block_in_if_condition.stderr rename tests/{compile-fail => ui}/bool_comparison.rs (100%) create mode 100644 tests/ui/bool_comparison.stderr rename tests/{compile-fail => ui}/booleans.rs (100%) create mode 100644 tests/ui/booleans.stderr rename tests/{compile-fail => ui}/box_vec.rs (100%) create mode 100644 tests/ui/box_vec.stderr rename tests/{compile-fail => ui}/builtin-type-shadow.rs (100%) create mode 100644 tests/ui/builtin-type-shadow.stderr rename tests/{compile-fail => ui}/cast.rs (100%) create mode 100644 tests/ui/cast.stderr rename tests/{compile-fail => ui}/char_lit_as_u8.rs (100%) create mode 100644 tests/ui/char_lit_as_u8.stderr rename tests/{compile-fail => ui}/cmp_nan.rs (100%) create mode 100644 tests/ui/cmp_nan.stderr rename tests/{compile-fail => ui}/cmp_null.rs (100%) create mode 100644 tests/ui/cmp_null.stderr rename tests/{compile-fail => ui}/cmp_owned.rs (100%) create mode 100644 tests/ui/cmp_owned.stderr rename tests/{compile-fail => ui}/collapsible_if.rs (100%) create mode 100644 tests/ui/collapsible_if.stderr rename tests/{compile-fail => ui}/complex_types.rs (100%) create mode 100644 tests/ui/complex_types.stderr rename tests/{compile-fail => ui}/conf_bad_arg.rs (100%) create mode 100644 tests/ui/conf_bad_arg.stderr rename tests/{compile-fail => ui}/conf_bad_toml.rs (100%) create mode 100644 tests/ui/conf_bad_toml.stderr rename tests/{compile-fail => ui}/conf_bad_toml.toml (100%) rename tests/{compile-fail => ui}/conf_bad_type.rs (100%) create mode 100644 tests/ui/conf_bad_type.stderr rename tests/{compile-fail => ui}/conf_bad_type.toml (100%) rename tests/{compile-fail => ui}/conf_french_blacklisted_name.rs (100%) create mode 100644 tests/ui/conf_french_blacklisted_name.stderr rename tests/{compile-fail => ui}/conf_non_existant.rs (100%) create mode 100644 tests/ui/conf_non_existant.stderr rename tests/{compile-fail => ui}/conf_path_non_string.rs (100%) create mode 100644 tests/ui/conf_path_non_string.stderr rename tests/{compile-fail => ui}/conf_unknown_key.rs (100%) create mode 100644 tests/ui/conf_unknown_key.stderr rename tests/{compile-fail => ui}/copies.rs (100%) create mode 100644 tests/ui/copies.stderr rename tests/{compile-fail => ui}/cyclomatic_complexity.rs (100%) create mode 100644 tests/ui/cyclomatic_complexity.stderr rename tests/{compile-fail => ui}/cyclomatic_complexity_attr_used.rs (100%) create mode 100644 tests/ui/cyclomatic_complexity_attr_used.stderr rename tests/{compile-fail => ui}/derive.rs (100%) create mode 100644 tests/ui/derive.stderr rename tests/{compile-fail => ui}/diverging_sub_expression.rs (100%) create mode 100644 tests/ui/diverging_sub_expression.stderr rename tests/{compile-fail => ui}/dlist.rs (100%) create mode 100644 tests/ui/dlist.stderr rename tests/{compile-fail => ui}/doc.rs (100%) create mode 100644 tests/ui/doc.stderr rename tests/{compile-fail => ui}/double_neg.rs (100%) create mode 100644 tests/ui/double_neg.stderr rename tests/{compile-fail => ui}/double_parens.rs (100%) create mode 100644 tests/ui/double_parens.stderr rename tests/{compile-fail => ui}/drop_forget_ref.rs (100%) create mode 100644 tests/ui/drop_forget_ref.stderr rename tests/{compile-fail => ui}/duplicate_underscore_argument.rs (100%) create mode 100644 tests/ui/duplicate_underscore_argument.stderr rename tests/{compile-fail => ui}/empty_enum.rs (100%) create mode 100644 tests/ui/empty_enum.stderr rename tests/{compile-fail => ui}/entry.rs (100%) create mode 100644 tests/ui/entry.stderr rename tests/{compile-fail => ui}/enum_glob_use.rs (100%) create mode 100644 tests/ui/enum_glob_use.stderr rename tests/{compile-fail => ui}/enum_variants.rs (100%) create mode 100644 tests/ui/enum_variants.stderr rename tests/{compile-fail => ui}/enums_clike.rs (100%) create mode 100644 tests/ui/enums_clike.stderr rename tests/{compile-fail => ui}/eq_op.rs (100%) create mode 100644 tests/ui/eq_op.stderr rename tests/{compile-fail => ui}/escape_analysis.rs (100%) create mode 100644 tests/ui/escape_analysis.stderr rename tests/{compile-fail => ui}/eta.rs (100%) create mode 100644 tests/ui/eta.stderr rename tests/{compile-fail => ui}/eval_order_dependence.rs (100%) create mode 100644 tests/ui/eval_order_dependence.stderr rename tests/{compile-fail => ui}/filter_methods.rs (100%) create mode 100644 tests/ui/filter_methods.stderr rename tests/{compile-fail => ui}/float_cmp.rs (100%) create mode 100644 tests/ui/float_cmp.stderr rename tests/{compile-fail => ui}/for_loop.rs (100%) create mode 100644 tests/ui/for_loop.stderr rename tests/{compile-fail => ui}/format.rs (100%) create mode 100644 tests/ui/format.stderr rename tests/{compile-fail => ui}/formatting.rs (100%) create mode 100644 tests/ui/formatting.stderr rename tests/{compile-fail => ui}/functions.rs (100%) create mode 100644 tests/ui/functions.stderr rename tests/{compile-fail => ui}/identity_op.rs (100%) create mode 100644 tests/ui/identity_op.stderr rename tests/{compile-fail => ui}/if_let_redundant_pattern_matching.rs (100%) create mode 100644 tests/ui/if_let_redundant_pattern_matching.stderr rename tests/{compile-fail => ui}/if_not_else.rs (100%) create mode 100644 tests/ui/if_not_else.stderr rename tests/{compile-fail => ui}/invalid_upcast_comparisons.rs (100%) create mode 100644 tests/ui/invalid_upcast_comparisons.stderr rename tests/{compile-fail => ui}/item_after_statement.rs (100%) create mode 100644 tests/ui/item_after_statement.stderr rename tests/{compile-fail => ui}/large_enum_variant.rs (100%) create mode 100644 tests/ui/large_enum_variant.stderr rename tests/{compile-fail => ui}/len_zero.rs (100%) create mode 100644 tests/ui/len_zero.stderr rename tests/{compile-fail => ui}/let_if_seq.rs (100%) create mode 100644 tests/ui/let_if_seq.stderr rename tests/{compile-fail => ui}/let_return.rs (100%) create mode 100644 tests/ui/let_return.stderr rename tests/{compile-fail => ui}/let_unit.rs (100%) create mode 100644 tests/ui/let_unit.stderr rename tests/{compile-fail => ui}/lifetimes.rs (100%) create mode 100644 tests/ui/lifetimes.stderr rename tests/{compile-fail => ui}/lint_pass.rs (100%) create mode 100644 tests/ui/lint_pass.stderr rename tests/{compile-fail => ui}/literals.rs (100%) create mode 100644 tests/ui/literals.stderr rename tests/{compile-fail => ui}/map_clone.rs (100%) create mode 100644 tests/ui/map_clone.stderr rename tests/{compile-fail => ui}/matches.rs (100%) create mode 100644 tests/ui/matches.stderr rename tests/{compile-fail => ui}/mem_forget.rs (100%) create mode 100644 tests/ui/mem_forget.stderr create mode 100644 tests/ui/methods.rs create mode 100644 tests/ui/methods.stderr rename tests/{compile-fail => ui}/min_max.rs (100%) create mode 100644 tests/ui/min_max.stderr rename tests/{compile-fail => ui}/missing-doc.rs (100%) create mode 100644 tests/ui/missing-doc.stderr rename tests/{compile-fail => ui}/module_inception.rs (100%) create mode 100644 tests/ui/module_inception.stderr rename tests/{compile-fail => ui}/modulo_one.rs (100%) create mode 100644 tests/ui/modulo_one.stderr rename tests/{compile-fail => ui}/mut_mut.rs (100%) create mode 100644 tests/ui/mut_mut.stderr rename tests/{compile-fail => ui}/mut_reference.rs (100%) create mode 100644 tests/ui/mut_reference.stderr rename tests/{compile-fail => ui}/mutex_atomic.rs (100%) create mode 100644 tests/ui/mutex_atomic.stderr rename tests/{compile-fail => ui}/needless_bool.rs (100%) create mode 100644 tests/ui/needless_bool.stderr rename tests/{compile-fail => ui}/needless_borrow.rs (100%) create mode 100644 tests/ui/needless_borrow.stderr rename tests/{compile-fail => ui}/needless_return.rs (100%) create mode 100644 tests/ui/needless_return.stderr rename tests/{compile-fail => ui}/needless_update.rs (100%) create mode 100644 tests/ui/needless_update.stderr rename tests/{compile-fail => ui}/neg_multiply.rs (100%) create mode 100644 tests/ui/neg_multiply.stderr rename tests/{compile-fail => ui}/new_without_default.rs (100%) create mode 100644 tests/ui/new_without_default.stderr rename tests/{compile-fail => ui}/no_effect.rs (100%) create mode 100644 tests/ui/no_effect.stderr create mode 100644 tests/ui/non_expressive_names.rs create mode 100644 tests/ui/non_expressive_names.stderr rename tests/{compile-fail => ui}/ok_if_let.rs (100%) create mode 100644 tests/ui/ok_if_let.stderr rename tests/{compile-fail => ui}/open_options.rs (100%) create mode 100644 tests/ui/open_options.stderr rename tests/{compile-fail => ui}/overflow_check_conditional.rs (100%) create mode 100644 tests/ui/overflow_check_conditional.stderr rename tests/{compile-fail => ui}/panic.rs (100%) create mode 100644 tests/ui/panic.stderr rename tests/{compile-fail => ui}/partialeq_ne_impl.rs (100%) create mode 100644 tests/ui/partialeq_ne_impl.stderr rename tests/{compile-fail => ui}/patterns.rs (100%) create mode 100644 tests/ui/patterns.stderr rename tests/{compile-fail => ui}/precedence.rs (100%) create mode 100644 tests/ui/precedence.stderr rename tests/{compile-fail => ui}/print.rs (100%) create mode 100644 tests/ui/print.stderr rename tests/{compile-fail => ui}/print_with_newline.rs (100%) create mode 100644 tests/ui/print_with_newline.stderr rename tests/{compile-fail => ui}/ptr_arg.rs (100%) create mode 100644 tests/ui/ptr_arg.stderr rename tests/{compile-fail => ui}/range.rs (100%) create mode 100644 tests/ui/range.stderr rename tests/{compile-fail => ui}/redundant_closure_call.rs (100%) create mode 100644 tests/ui/redundant_closure_call.stderr rename tests/{compile-fail => ui}/reference.rs (100%) create mode 100644 tests/ui/reference.stderr rename tests/{compile-fail => ui}/regex.rs (100%) create mode 100644 tests/ui/regex.stderr rename tests/{compile-fail => ui}/serde.rs (100%) create mode 100644 tests/ui/serde.stderr rename tests/{compile-fail => ui}/shadow.rs (100%) create mode 100644 tests/ui/shadow.stderr rename tests/{compile-fail => ui}/short_circuit_statement.rs (100%) create mode 100644 tests/ui/short_circuit_statement.stderr create mode 100644 tests/ui/strings.rs create mode 100644 tests/ui/strings.stderr rename tests/{compile-fail => ui}/stutter.rs (100%) create mode 100644 tests/ui/stutter.stderr create mode 100644 tests/ui/swap.rs create mode 100644 tests/ui/swap.stderr rename tests/{compile-fail => ui}/temporary_assignment.rs (100%) create mode 100644 tests/ui/temporary_assignment.stderr rename tests/{compile-fail => ui}/toplevel_ref_arg.rs (100%) create mode 100644 tests/ui/toplevel_ref_arg.stderr rename tests/{compile-fail => ui}/transmute.rs (100%) create mode 100644 tests/ui/transmute.stderr rename tests/{compile-fail => ui}/transmute_32bit.rs (100%) rename tests/{compile-fail => ui}/transmute_64bit.rs (100%) create mode 100644 tests/ui/transmute_64bit.stderr rename tests/{compile-fail => ui}/unicode.rs (100%) create mode 100644 tests/ui/unicode.stderr rename tests/{compile-fail => ui}/unit_cmp.rs (100%) create mode 100644 tests/ui/unit_cmp.stderr rename tests/{compile-fail => ui}/unneeded_field_pattern.rs (100%) create mode 100644 tests/ui/unneeded_field_pattern.stderr rename tests/{compile-fail => ui}/unsafe_removed_from_name.rs (100%) create mode 100644 tests/ui/unsafe_removed_from_name.stderr rename tests/{compile-fail => ui}/unused_io_amount.rs (100%) create mode 100644 tests/ui/unused_io_amount.stderr rename tests/{compile-fail => ui}/unused_labels.rs (100%) create mode 100644 tests/ui/unused_labels.stderr rename tests/{compile-fail => ui}/unused_lt.rs (100%) create mode 100644 tests/ui/unused_lt.stderr create mode 100755 tests/ui/update-all-references.sh create mode 100755 tests/ui/update-references.sh rename tests/{compile-fail => ui}/used_underscore_binding.rs (100%) create mode 100644 tests/ui/used_underscore_binding.stderr rename tests/{compile-fail => ui}/useless_attribute.rs (100%) create mode 100644 tests/ui/useless_attribute.stderr rename tests/{compile-fail => ui}/vec.rs (100%) create mode 100644 tests/ui/vec.stderr rename tests/{compile-fail => ui}/while_loop.rs (100%) create mode 100644 tests/ui/while_loop.stderr create mode 100644 tests/ui/wrong_macro_span.rs_ rename tests/{compile-fail => ui}/wrong_self_convention.rs (100%) create mode 100644 tests/ui/wrong_self_convention.stderr rename tests/{compile-fail => ui}/zero_div_zero.rs (100%) create mode 100644 tests/ui/zero_div_zero.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 42df561a6e1..1a8249aa563 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.114 — 2017-02-07 +* Rustup to rustc 1.17.0-nightly (c49d10207 2017-02-07) +* Tests are now ui tests (testing the exact output of rustc) + ## 0.0.113 — 2017-02-04 * Rustup to *rustc 1.16.0-nightly (eedaa94e3 2017-02-02)* * New lint: [`large_enum_variant`] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8734242c6c0..b7f68dc854d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,6 +40,11 @@ contains some questionable code itself! Also before making a pull request, pleas `util/update_lints.py`, which will update `lib.rs` and `README.md` with the lint declarations. Our travis build actually checks for this. +Clippy uses UI tests. UI tests check that the output of the compiler is exactly as expected. +Of course there's little sense in writing the output yourself or copying it around. +Therefore you can simply run `tests/ui/update-all-references.sh` and check whether +the output looks as you expect with `git diff`. Commit all `.stderr` files, too. + Also please document your lint with a doc comment akin to the following: ```rust /// **What it does:** Checks for ... (describe what the lint matches). diff --git a/Cargo.toml b/Cargo.toml index e46d3363a0d..a45a7edf0fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.113" +version = "0.0.114" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -30,7 +30,7 @@ test = false [dependencies] # begin automatic update -clippy_lints = { version = "0.0.113", path = "clippy_lints" } +clippy_lints = { version = "0.0.114", path = "clippy_lints" } # end automatic update cargo_metadata = "0.1.1" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 8a81dc75e97..d7a95ba04dd 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin automatic update -version = "0.0.113" +version = "0.0.114" # end automatic update authors = [ "Manish Goregaokar ", diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index b2a8d26000d..951dd51dec4 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -158,7 +158,7 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref TypeVariants::TyFnPtr(..) => { return; }, - TypeVariants::TyTuple(tys) if tys.len() > 12 => { + TypeVariants::TyTuple(tys, _) if tys.len() > 12 => { return; }, _ => (), diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index ccdcb94d212..b1581127c32 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -197,7 +197,7 @@ fn check_let_unit(cx: &LateContext, decl: &Decl) { if let DeclLocal(ref local) = decl.node { let bindtype = &cx.tables.pat_ty(&local.pat).sty; match *bindtype { - ty::TyTuple(slice) if slice.is_empty() => { + ty::TyTuple(slice, _) if slice.is_empty() => { if in_external_macro(cx, decl.span) || in_macro(cx, local.pat.span) { return; } @@ -268,7 +268,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp { if op.is_comparison() { let sty = &cx.tables.expr_ty(left).sty; match *sty { - ty::TyTuple(slice) if slice.is_empty() => { + ty::TyTuple(slice, _) if slice.is_empty() => { let result = match op { BiEq | BiLe | BiGe => "true", _ => "false", diff --git a/tests/compile-fail/non_expressive_names.rs b/tests/compile-fail/non_expressive_names.rs index 212dc2a96d5..778041f49b8 100644 --- a/tests/compile-fail/non_expressive_names.rs +++ b/tests/compile-fail/non_expressive_names.rs @@ -129,14 +129,18 @@ fn bla() { } { let e: i32; //~ ERROR: 5th binding whose name is just one char + //~^ NOTE implied by } { let e: i32; //~ ERROR: 5th binding whose name is just one char + //~^ NOTE implied by let f: i32; //~ ERROR: 6th binding whose name is just one char + //~^ NOTE implied by } match 5 { 1 => println!(""), e => panic!(), //~ ERROR: 5th binding whose name is just one char + //~^ NOTE implied by } match 5 { 1 => println!(""), diff --git a/tests/compile-fail/strings.rs b/tests/compile-fail/strings.rs index d08f8b891bc..7cfc8a41ea1 100644 --- a/tests/compile-fail/strings.rs +++ b/tests/compile-fail/strings.rs @@ -66,7 +66,7 @@ fn main() { // the add is only caught for `String` let mut x = 1; ; x = x + 1; - //~^ WARN assign_op_pattern + //~^ WARN manual implementation of an assign operation //~| HELP replace //~| SUGGESTION ; x += 1; assert_eq!(2, x); diff --git a/tests/compile-fail/swap.rs b/tests/compile-fail/swap.rs index c8ff2b610d0..0e56d5ca86e 100644 --- a/tests/compile-fail/swap.rs +++ b/tests/compile-fail/swap.rs @@ -8,7 +8,7 @@ struct Foo(u32); fn array() { let mut foo = [1, 2]; - let temp = foo[0]; + let temp = foo[0]; //~ NOTE implied by foo[0] = foo[1]; foo[1] = temp; //~^^^ ERROR this looks like you are swapping elements of `foo` manually @@ -20,7 +20,7 @@ fn array() { fn slice() { let foo = &mut [1, 2]; - let temp = foo[0]; + let temp = foo[0]; //~ NOTE implied by foo[0] = foo[1]; foo[1] = temp; //~^^^ ERROR this looks like you are swapping elements of `foo` manually @@ -32,7 +32,7 @@ fn slice() { fn vec() { let mut foo = vec![1, 2]; - let temp = foo[0]; + let temp = foo[0]; //~ NOTE implied by foo[0] = foo[1]; foo[1] = temp; //~^^^ ERROR this looks like you are swapping elements of `foo` manually @@ -50,14 +50,14 @@ fn main() { let mut a = 42; let mut b = 1337; - a = b; + a = b; //~ NOTE implied by b = a; //~^^ ERROR this looks like you are trying to swap `a` and `b` //~| HELP try //~| SUGGESTION std::mem::swap(&mut a, &mut b); //~| NOTE or maybe you should use `std::mem::replace`? - ; let t = a; + ; let t = a; //~ NOTE implied by a = b; b = t; //~^^^ ERROR this looks like you are swapping `a` and `b` manually @@ -67,14 +67,14 @@ fn main() { let mut c = Foo(42); - c.0 = a; + c.0 = a; //~ NOTE implied by a = c.0; //~^^ ERROR this looks like you are trying to swap `c.0` and `a` //~| HELP try //~| SUGGESTION std::mem::swap(&mut c.0, &mut a); //~| NOTE or maybe you should use `std::mem::replace`? - ; let t = c.0; + ; let t = c.0; //~ NOTE implied by c.0 = a; a = t; //~^^^ ERROR this looks like you are swapping `c.0` and `a` manually diff --git a/tests/compile-test.rs b/tests/compile-test.rs index deadd499192..bb60934d443 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -14,6 +14,7 @@ fn run_mode(dir: &'static str, mode: &'static str) { } config.mode = cfg_mode; + config.build_base = PathBuf::from("target/debug/test_build_base"); config.src_base = PathBuf::from(format!("tests/{}", dir)); compiletest::run_tests(&config); @@ -27,5 +28,5 @@ fn prepare_env() { fn compile_test() { prepare_env(); run_mode("run-pass", "run-pass"); - run_mode("compile-fail", "compile-fail"); + run_mode("ui", "ui"); } diff --git a/tests/compile-fail/absurd-extreme-comparisons.rs b/tests/ui/absurd-extreme-comparisons.rs similarity index 100% rename from tests/compile-fail/absurd-extreme-comparisons.rs rename to tests/ui/absurd-extreme-comparisons.rs diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr new file mode 100644 index 00000000000..ba3b6a24820 --- /dev/null +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -0,0 +1,151 @@ +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:12:5 + | +12 | u <= 0; + | ^^^^^^ + | +note: lint level defined here + --> $DIR/absurd-extreme-comparisons.rs:4:9 + | +4 | #![deny(absurd_extreme_comparisons)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: because 0 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == 0 instead + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:15:5 + | +15 | u <= Z; + | ^^^^^^ + | + = help: because Z is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == Z instead + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:18:5 + | +18 | u < Z; + | ^^^^^ + | + = help: because Z is the minimum value for this type, this comparison is always false + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:21:5 + | +21 | Z >= u; + | ^^^^^^ + | + = help: because Z is the minimum value for this type, the case where the two sides are not equal never occurs, consider using Z == u instead + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:24:5 + | +24 | Z > u; + | ^^^^^ + | + = help: because Z is the minimum value for this type, this comparison is always false + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:27:5 + | +27 | u > std::u32::MAX; + | ^^^^^^^^^^^^^^^^^ + | + = help: because std::u32::MAX is the maximum value for this type, this comparison is always false + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:30:5 + | +30 | u >= std::u32::MAX; + | ^^^^^^^^^^^^^^^^^^ + | + = help: because std::u32::MAX is the maximum value for this type, the case where the two sides are not equal never occurs, consider using u == std::u32::MAX instead + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:33:5 + | +33 | std::u32::MAX < u; + | ^^^^^^^^^^^^^^^^^ + | + = help: because std::u32::MAX is the maximum value for this type, this comparison is always false + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:36:5 + | +36 | std::u32::MAX <= u; + | ^^^^^^^^^^^^^^^^^^ + | + = help: because std::u32::MAX is the maximum value for this type, the case where the two sides are not equal never occurs, consider using std::u32::MAX == u instead + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:40:5 + | +40 | 1-1 > u; + | ^^^^^^^ + | + = help: because 1-1 is the minimum value for this type, this comparison is always false + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:43:5 + | +43 | u >= !0; + | ^^^^^^^ + | + = help: because !0 is the maximum value for this type, the case where the two sides are not equal never occurs, consider using u == !0 instead + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:46:5 + | +46 | u <= 12 - 2*6; + | ^^^^^^^^^^^^^ + | + = help: because 12 - 2*6 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == 12 - 2*6 instead + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:51:5 + | +51 | i < -127 - 1; + | ^^^^^^^^^^^^ + | + = help: because -127 - 1 is the minimum value for this type, this comparison is always false + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:54:5 + | +54 | std::i8::MAX >= i; + | ^^^^^^^^^^^^^^^^^ + | + = help: because std::i8::MAX is the maximum value for this type, this comparison is always true + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:57:5 + | +57 | 3-7 < std::i32::MIN; + | ^^^^^^^^^^^^^^^^^^^ + | + = help: because std::i32::MIN is the minimum value for this type, this comparison is always false + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:62:5 + | +62 | b >= true; + | ^^^^^^^^^ + | + = help: because true is the maximum value for this type, the case where the two sides are not equal never occurs, consider using b == true instead + +error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false + --> $DIR/absurd-extreme-comparisons.rs:65:5 + | +65 | false > b; + | ^^^^^^^^^ + | + = help: because false is the minimum value for this type, this comparison is always false + +warning: <-comparison of unit values detected. This will always be false + --> $DIR/absurd-extreme-comparisons.rs:72:5 + | +72 | () < {}; //~WARNING <-comparison of unit values detected. + | ^^^^^^^ + | + = note: #[warn(unit_cmp)] on by default + +error: aborting due to 17 previous errors + diff --git a/tests/compile-fail/approx_const.rs b/tests/ui/approx_const.rs similarity index 100% rename from tests/compile-fail/approx_const.rs rename to tests/ui/approx_const.rs diff --git a/tests/ui/approx_const.stderr b/tests/ui/approx_const.stderr new file mode 100644 index 00000000000..9f5a91074e5 --- /dev/null +++ b/tests/ui/approx_const.stderr @@ -0,0 +1,122 @@ +error: approximate value of `f{32, 64}::consts::E` found. Consider using it directly + --> $DIR/approx_const.rs:7:16 + | +7 | let my_e = 2.7182; //~ERROR approximate value of `f{32, 64}::consts::E` found + | ^^^^^^ + | +note: lint level defined here + --> $DIR/approx_const.rs:4:8 + | +4 | #[deny(approx_constant)] + | ^^^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::E` found. Consider using it directly + --> $DIR/approx_const.rs:8:20 + | +8 | let almost_e = 2.718; //~ERROR approximate value of `f{32, 64}::consts::E` found + | ^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_1_PI` found. Consider using it directly + --> $DIR/approx_const.rs:11:24 + | +11 | let my_1_frac_pi = 0.3183; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_PI` found + | ^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found. Consider using it directly + --> $DIR/approx_const.rs:14:28 + | +14 | let my_frac_1_sqrt_2 = 0.70710678; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found + | ^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found. Consider using it directly + --> $DIR/approx_const.rs:15:32 + | +15 | let almost_frac_1_sqrt_2 = 0.70711; //~ERROR approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found + | ^^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_2_PI` found. Consider using it directly + --> $DIR/approx_const.rs:18:24 + | +18 | let my_frac_2_pi = 0.63661977; //~ERROR approximate value of `f{32, 64}::consts::FRAC_2_PI` found + | ^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found. Consider using it directly + --> $DIR/approx_const.rs:21:27 + | +21 | let my_frac_2_sq_pi = 1.128379; //~ERROR approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found + | ^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_PI_2` found. Consider using it directly + --> $DIR/approx_const.rs:24:24 + | +24 | let my_frac_pi_2 = 1.57079632679; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_2` found + | ^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_PI_3` found. Consider using it directly + --> $DIR/approx_const.rs:27:24 + | +27 | let my_frac_pi_3 = 1.04719755119; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_3` found + | ^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_PI_4` found. Consider using it directly + --> $DIR/approx_const.rs:30:24 + | +30 | let my_frac_pi_4 = 0.785398163397; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_4` found + | ^^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_PI_6` found. Consider using it directly + --> $DIR/approx_const.rs:33:24 + | +33 | let my_frac_pi_6 = 0.523598775598; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_6` found + | ^^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::FRAC_PI_8` found. Consider using it directly + --> $DIR/approx_const.rs:36:24 + | +36 | let my_frac_pi_8 = 0.3926990816987; //~ERROR approximate value of `f{32, 64}::consts::FRAC_PI_8` found + | ^^^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::LN_10` found. Consider using it directly + --> $DIR/approx_const.rs:39:20 + | +39 | let my_ln_10 = 2.302585092994046; //~ERROR approximate value of `f{32, 64}::consts::LN_10` found + | ^^^^^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::LN_2` found. Consider using it directly + --> $DIR/approx_const.rs:42:19 + | +42 | let my_ln_2 = 0.6931471805599453; //~ERROR approximate value of `f{32, 64}::consts::LN_2` found + | ^^^^^^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::LOG10_E` found. Consider using it directly + --> $DIR/approx_const.rs:45:22 + | +45 | let my_log10_e = 0.43429448190325182; //~ERROR approximate value of `f{32, 64}::consts::LOG10_E` found + | ^^^^^^^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::LOG2_E` found. Consider using it directly + --> $DIR/approx_const.rs:48:21 + | +48 | let my_log2_e = 1.4426950408889634; //~ERROR approximate value of `f{32, 64}::consts::LOG2_E` found + | ^^^^^^^^^^^^^^^^^^ + +error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly + --> $DIR/approx_const.rs:51:17 + | +51 | let my_pi = 3.1415; //~ERROR approximate value of `f{32, 64}::consts::PI` found + | ^^^^^^ + +error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly + --> $DIR/approx_const.rs:52:21 + | +52 | let almost_pi = 3.14; //~ERROR approximate value of `f{32, 64}::consts::PI` found + | ^^^^ + +error: approximate value of `f{32, 64}::consts::SQRT_2` found. Consider using it directly + --> $DIR/approx_const.rs:55:18 + | +55 | let my_sq2 = 1.4142; //~ERROR approximate value of `f{32, 64}::consts::SQRT_2` found + | ^^^^^^ + +error: aborting due to 19 previous errors + diff --git a/tests/compile-fail/arithmetic.rs b/tests/ui/arithmetic.rs similarity index 100% rename from tests/compile-fail/arithmetic.rs rename to tests/ui/arithmetic.rs diff --git a/tests/ui/arithmetic.stderr b/tests/ui/arithmetic.stderr new file mode 100644 index 00000000000..1c333bfdcca --- /dev/null +++ b/tests/ui/arithmetic.stderr @@ -0,0 +1,82 @@ +error: integer arithmetic detected + --> $DIR/arithmetic.rs:8:5 + | +8 | 1 + i; //~ERROR integer arithmetic detected + | ^^^^^ + | +note: lint level defined here + --> $DIR/arithmetic.rs:4:9 + | +4 | #![deny(integer_arithmetic, float_arithmetic)] + | ^^^^^^^^^^^^^^^^^^ + +error: integer arithmetic detected + --> $DIR/arithmetic.rs:9:5 + | +9 | i * 2; //~ERROR integer arithmetic detected + | ^^^^^ + +error: integer arithmetic detected + --> $DIR/arithmetic.rs:10:5 + | +10 | 1 % //~ERROR integer arithmetic detected + | _____^ starting here... +11 | | i / 2; // no error, this is part of the expression in the preceding line + | |_________^ ...ending here + +error: integer arithmetic detected + --> $DIR/arithmetic.rs:12:5 + | +12 | i - 2 + 2 - i; //~ERROR integer arithmetic detected + | ^^^^^^^^^^^^^ + +error: integer arithmetic detected + --> $DIR/arithmetic.rs:13:5 + | +13 | -i; //~ERROR integer arithmetic detected + | ^^ + +error: floating-point arithmetic detected + --> $DIR/arithmetic.rs:23:5 + | +23 | f * 2.0; //~ERROR floating-point arithmetic detected + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/arithmetic.rs:4:29 + | +4 | #![deny(integer_arithmetic, float_arithmetic)] + | ^^^^^^^^^^^^^^^^ + +error: floating-point arithmetic detected + --> $DIR/arithmetic.rs:25:5 + | +25 | 1.0 + f; //~ERROR floating-point arithmetic detected + | ^^^^^^^ + +error: floating-point arithmetic detected + --> $DIR/arithmetic.rs:26:5 + | +26 | f * 2.0; //~ERROR floating-point arithmetic detected + | ^^^^^^^ + +error: floating-point arithmetic detected + --> $DIR/arithmetic.rs:27:5 + | +27 | f / 2.0; //~ERROR floating-point arithmetic detected + | ^^^^^^^ + +error: floating-point arithmetic detected + --> $DIR/arithmetic.rs:28:5 + | +28 | f - 2.0 * 4.2; //~ERROR floating-point arithmetic detected + | ^^^^^^^^^^^^^ + +error: floating-point arithmetic detected + --> $DIR/arithmetic.rs:29:5 + | +29 | -f; //~ERROR floating-point arithmetic detected + | ^^ + +error: aborting due to 11 previous errors + diff --git a/tests/compile-fail/array_indexing.rs b/tests/ui/array_indexing.rs similarity index 100% rename from tests/compile-fail/array_indexing.rs rename to tests/ui/array_indexing.rs diff --git a/tests/ui/array_indexing.stderr b/tests/ui/array_indexing.stderr new file mode 100644 index 00000000000..3eba56d35f8 --- /dev/null +++ b/tests/ui/array_indexing.stderr @@ -0,0 +1,152 @@ +error: const index is out of bounds + --> $DIR/array_indexing.rs:12:5 + | +12 | x[4]; //~ERROR: const index is out of bounds + | ^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: const index is out of bounds + --> $DIR/array_indexing.rs:13:5 + | +13 | x[1 << 3]; //~ERROR: const index is out of bounds + | ^^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:14:6 + | +14 | &x[1..5]; //~ERROR: range is out of bounds + | ^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:16:6 + | +16 | &x[0...4]; //~ERROR: range is out of bounds + | ^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:17:6 + | +17 | &x[...4]; //~ERROR: range is out of bounds + | ^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:21:6 + | +21 | &x[5..]; //~ERROR: range is out of bounds + | ^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:23:6 + | +23 | &x[..5]; //~ERROR: range is out of bounds + | ^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: indexing may panic + --> $DIR/array_indexing.rs:26:5 + | +26 | y[0]; //~ERROR: indexing may panic + | ^^^^ + | +note: lint level defined here + --> $DIR/array_indexing.rs:4:9 + | +4 | #![deny(indexing_slicing)] + | ^^^^^^^^^^^^^^^^ + +error: slicing may panic + --> $DIR/array_indexing.rs:27:6 + | +27 | &y[1..2]; //~ERROR: slicing may panic + | ^^^^^^^ + +error: slicing may panic + --> $DIR/array_indexing.rs:29:6 + | +29 | &y[0...4]; //~ERROR: slicing may panic + | ^^^^^^^^ + +error: slicing may panic + --> $DIR/array_indexing.rs:30:6 + | +30 | &y[...4]; //~ERROR: slicing may panic + | ^^^^^^^ + +error: const index is out of bounds + --> $DIR/array_indexing.rs:33:5 + | +33 | empty[0]; //~ERROR: const index is out of bounds + | ^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:34:6 + | +34 | &empty[1..5]; //~ERROR: range is out of bounds + | ^^^^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:35:6 + | +35 | &empty[0...4]; //~ERROR: range is out of bounds + | ^^^^^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:36:6 + | +36 | &empty[...4]; //~ERROR: range is out of bounds + | ^^^^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:40:6 + | +40 | &empty[0...0]; //~ERROR: range is out of bounds + | ^^^^^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:41:6 + | +41 | &empty[...0]; //~ERROR: range is out of bounds + | ^^^^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:43:6 + | +43 | &empty[1..]; //~ERROR: range is out of bounds + | ^^^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: range is out of bounds + --> $DIR/array_indexing.rs:44:6 + | +44 | &empty[..4]; //~ERROR: range is out of bounds + | ^^^^^^^^^^ + | + = note: #[deny(out_of_bounds_indexing)] on by default + +error: aborting due to 19 previous errors + diff --git a/tests/compile-fail/assign_ops.rs b/tests/ui/assign_ops.rs similarity index 100% rename from tests/compile-fail/assign_ops.rs rename to tests/ui/assign_ops.rs diff --git a/tests/ui/assign_ops.stderr b/tests/ui/assign_ops.stderr new file mode 100644 index 00000000000..61efd362a80 --- /dev/null +++ b/tests/ui/assign_ops.stderr @@ -0,0 +1,201 @@ +error: assign operation detected + --> $DIR/assign_ops.rs:8:5 + | +8 | i += 2; //~ ERROR assign operation detected + | ^^^^^^ + | +note: lint level defined here + --> $DIR/assign_ops.rs:4:8 + | +4 | #[deny(assign_ops)] + | ^^^^^^^^^^ +help: replace it with + | i = i + 2; //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:11:5 + | +11 | i += 2 + 17; //~ ERROR assign operation detected + | ^^^^^^^^^^^ + | +help: replace it with + | i = i + 2 + 17; //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:14:5 + | +14 | i -= 6; //~ ERROR assign operation detected + | ^^^^^^ + | +help: replace it with + | i = i - 6; //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:17:5 + | +17 | i -= 2 - 1; + | ^^^^^^^^^^ + | +help: replace it with + | i = i - (2 - 1); + +error: assign operation detected + --> $DIR/assign_ops.rs:21:5 + | +21 | i *= 5; //~ ERROR assign operation detected + | ^^^^^^ + | +help: replace it with + | i = i * 5; //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:24:5 + | +24 | i *= 1+5; //~ ERROR assign operation detected + | ^^^^^^^^ + | +help: replace it with + | i = i * (1+5); //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:27:5 + | +27 | i /= 32; //~ ERROR assign operation detected + | ^^^^^^^ + | +help: replace it with + | i = i / 32; //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:30:5 + | +30 | i /= 32 | 5; //~ ERROR assign operation detected + | ^^^^^^^^^^^ + | +help: replace it with + | i = i / (32 | 5); //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:33:5 + | +33 | i /= 32 / 5; //~ ERROR assign operation detected + | ^^^^^^^^^^^ + | +help: replace it with + | i = i / (32 / 5); //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:36:5 + | +36 | i %= 42; //~ ERROR assign operation detected + | ^^^^^^^ + | +help: replace it with + | i = i % 42; //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:39:5 + | +39 | i >>= i; //~ ERROR assign operation detected + | ^^^^^^^ + | +help: replace it with + | i = i >> i; //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:42:5 + | +42 | i <<= 9 + 6 - 7; //~ ERROR assign operation detected + | ^^^^^^^^^^^^^^^ + | +help: replace it with + | i = i << (9 + 6 - 7); //~ ERROR assign operation detected + +error: assign operation detected + --> $DIR/assign_ops.rs:45:5 + | +45 | i += 1 << 5; + | ^^^^^^^^^^^ + | +help: replace it with + | i = i + (1 << 5); + +error: manual implementation of an assign operation + --> $DIR/assign_ops.rs:55:5 + | +55 | a = a + 1; //~ ERROR manual implementation of an assign operation + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/assign_ops.rs:52:8 + | +52 | #[deny(assign_op_pattern)] + | ^^^^^^^^^^^^^^^^^ +help: replace it with + | a += 1; //~ ERROR manual implementation of an assign operation + +error: manual implementation of an assign operation + --> $DIR/assign_ops.rs:58:5 + | +58 | a = 1 + a; //~ ERROR manual implementation of an assign operation + | ^^^^^^^^^ + | +help: replace it with + | a += 1; //~ ERROR manual implementation of an assign operation + +error: manual implementation of an assign operation + --> $DIR/assign_ops.rs:61:5 + | +61 | a = a - 1; //~ ERROR manual implementation of an assign operation + | ^^^^^^^^^ + | +help: replace it with + | a -= 1; //~ ERROR manual implementation of an assign operation + +error: manual implementation of an assign operation + --> $DIR/assign_ops.rs:64:5 + | +64 | a = a * 99; //~ ERROR manual implementation of an assign operation + | ^^^^^^^^^^ + | +help: replace it with + | a *= 99; //~ ERROR manual implementation of an assign operation + +error: manual implementation of an assign operation + --> $DIR/assign_ops.rs:67:5 + | +67 | a = 42 * a; //~ ERROR manual implementation of an assign operation + | ^^^^^^^^^^ + | +help: replace it with + | a *= 42; //~ ERROR manual implementation of an assign operation + +error: manual implementation of an assign operation + --> $DIR/assign_ops.rs:70:5 + | +70 | a = a / 2; //~ ERROR manual implementation of an assign operation + | ^^^^^^^^^ + | +help: replace it with + | a /= 2; //~ ERROR manual implementation of an assign operation + +error: manual implementation of an assign operation + --> $DIR/assign_ops.rs:73:5 + | +73 | a = a % 5; //~ ERROR manual implementation of an assign operation + | ^^^^^^^^^ + | +help: replace it with + | a %= 5; //~ ERROR manual implementation of an assign operation + +error: manual implementation of an assign operation + --> $DIR/assign_ops.rs:76:5 + | +76 | a = a & 1; //~ ERROR manual implementation of an assign operation + | ^^^^^^^^^ + | +help: replace it with + | a &= 1; //~ ERROR manual implementation of an assign operation + +error: aborting due to 21 previous errors + diff --git a/tests/compile-fail/assign_ops2.rs b/tests/ui/assign_ops2.rs similarity index 100% rename from tests/compile-fail/assign_ops2.rs rename to tests/ui/assign_ops2.rs diff --git a/tests/ui/assign_ops2.stderr b/tests/ui/assign_ops2.stderr new file mode 100644 index 00000000000..98968fe8d2b --- /dev/null +++ b/tests/ui/assign_ops2.stderr @@ -0,0 +1,79 @@ +error: variable appears on both sides of an assignment operation + --> $DIR/assign_ops2.rs:8:5 + | +8 | a += a + 1; //~ ERROR variable appears on both sides of an assignment operation + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/assign_ops2.rs:5:8 + | +5 | #[deny(misrefactored_assign_op)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: replace it with + | a += 1; //~ ERROR variable appears on both sides of an assignment operation + +error: variable appears on both sides of an assignment operation + --> $DIR/assign_ops2.rs:11:5 + | +11 | a += 1 + a; //~ ERROR variable appears on both sides of an assignment operation + | ^^^^^^^^^^ + | +help: replace it with + | a += 1; //~ ERROR variable appears on both sides of an assignment operation + +error: variable appears on both sides of an assignment operation + --> $DIR/assign_ops2.rs:14:5 + | +14 | a -= a - 1; //~ ERROR variable appears on both sides of an assignment operation + | ^^^^^^^^^^ + | +help: replace it with + | a -= 1; //~ ERROR variable appears on both sides of an assignment operation + +error: variable appears on both sides of an assignment operation + --> $DIR/assign_ops2.rs:17:5 + | +17 | a *= a * 99; //~ ERROR variable appears on both sides of an assignment operation + | ^^^^^^^^^^^ + | +help: replace it with + | a *= 99; //~ ERROR variable appears on both sides of an assignment operation + +error: variable appears on both sides of an assignment operation + --> $DIR/assign_ops2.rs:20:5 + | +20 | a *= 42 * a; //~ ERROR variable appears on both sides of an assignment operation + | ^^^^^^^^^^^ + | +help: replace it with + | a *= 42; //~ ERROR variable appears on both sides of an assignment operation + +error: variable appears on both sides of an assignment operation + --> $DIR/assign_ops2.rs:23:5 + | +23 | a /= a / 2; //~ ERROR variable appears on both sides of an assignment operation + | ^^^^^^^^^^ + | +help: replace it with + | a /= 2; //~ ERROR variable appears on both sides of an assignment operation + +error: variable appears on both sides of an assignment operation + --> $DIR/assign_ops2.rs:26:5 + | +26 | a %= a % 5; //~ ERROR variable appears on both sides of an assignment operation + | ^^^^^^^^^^ + | +help: replace it with + | a %= 5; //~ ERROR variable appears on both sides of an assignment operation + +error: variable appears on both sides of an assignment operation + --> $DIR/assign_ops2.rs:29:5 + | +29 | a &= a & 1; //~ ERROR variable appears on both sides of an assignment operation + | ^^^^^^^^^^ + | +help: replace it with + | a &= 1; //~ ERROR variable appears on both sides of an assignment operation + +error: aborting due to 8 previous errors + diff --git a/tests/compile-fail/attrs.rs b/tests/ui/attrs.rs similarity index 100% rename from tests/compile-fail/attrs.rs rename to tests/ui/attrs.rs diff --git a/tests/ui/attrs.stderr b/tests/ui/attrs.stderr new file mode 100644 index 00000000000..411da0e22de --- /dev/null +++ b/tests/ui/attrs.stderr @@ -0,0 +1,32 @@ +error: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a bad idea + --> $DIR/attrs.rs:6:1 + | +6 | #[inline(always)] //~ERROR you have declared `#[inline(always)]` on `test_attr_lint`. + | ^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/attrs.rs:4:9 + | +4 | #![deny(inline_always, deprecated_semver)] + | ^^^^^^^^^^^^^ + +error: the since field must contain a semver-compliant version + --> $DIR/attrs.rs:27:14 + | +27 | #[deprecated(since = "forever")] //~ERROR the since field must contain a semver-compliant version + | ^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/attrs.rs:4:24 + | +4 | #![deny(inline_always, deprecated_semver)] + | ^^^^^^^^^^^^^^^^^ + +error: the since field must contain a semver-compliant version + --> $DIR/attrs.rs:30:14 + | +30 | #[deprecated(since = "1")] //~ERROR the since field must contain a semver-compliant version + | ^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/bit_masks.rs b/tests/ui/bit_masks.rs similarity index 100% rename from tests/compile-fail/bit_masks.rs rename to tests/ui/bit_masks.rs diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr new file mode 100644 index 00000000000..b8e63cef20a --- /dev/null +++ b/tests/ui/bit_masks.stderr @@ -0,0 +1,104 @@ +error: &-masking with zero + --> $DIR/bit_masks.rs:12:5 + | +12 | x & 0 == 0; //~ERROR &-masking with zero + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/bit_masks.rs:7:8 + | +7 | #[deny(bad_bit_mask)] + | ^^^^^^^^^^^^ + +error: incompatible bit mask: `_ & 2` can never be equal to `1` + --> $DIR/bit_masks.rs:15:5 + | +15 | x & 2 == 1; //~ERROR incompatible bit mask + | ^^^^^^^^^^ + +error: incompatible bit mask: `_ | 3` can never be equal to `2` + --> $DIR/bit_masks.rs:19:5 + | +19 | x | 3 == 2; //~ERROR incompatible bit mask + | ^^^^^^^^^^ + +error: incompatible bit mask: `_ & 1` will never be higher than `1` + --> $DIR/bit_masks.rs:21:5 + | +21 | x & 1 > 1; //~ERROR incompatible bit mask + | ^^^^^^^^^ + +error: incompatible bit mask: `_ | 2` will always be higher than `1` + --> $DIR/bit_masks.rs:25:5 + | +25 | x | 2 > 1; //~ERROR incompatible bit mask + | ^^^^^^^^^ + +error: incompatible bit mask: `_ & 7` can never be equal to `8` + --> $DIR/bit_masks.rs:32:5 + | +32 | x & THREE_BITS == 8; //~ERROR incompatible bit mask + | ^^^^^^^^^^^^^^^^^^^ + +error: incompatible bit mask: `_ | 7` will never be lower than `7` + --> $DIR/bit_masks.rs:33:5 + | +33 | x | EVEN_MORE_REDIRECTION < 7; //~ERROR incompatible bit mask + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: &-masking with zero + --> $DIR/bit_masks.rs:35:5 + | +35 | 0 & x == 0; //~ERROR &-masking with zero + | ^^^^^^^^^^ + +error: incompatible bit mask: `_ | 2` will always be higher than `1` + --> $DIR/bit_masks.rs:39:5 + | +39 | 1 < 2 | x; //~ERROR incompatible bit mask + | ^^^^^^^^^ + +error: incompatible bit mask: `_ | 3` can never be equal to `2` + --> $DIR/bit_masks.rs:40:5 + | +40 | 2 == 3 | x; //~ERROR incompatible bit mask + | ^^^^^^^^^^ + +error: incompatible bit mask: `_ & 2` can never be equal to `1` + --> $DIR/bit_masks.rs:41:5 + | +41 | 1 == x & 2; //~ERROR incompatible bit mask + | ^^^^^^^^^^ + +error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly + --> $DIR/bit_masks.rs:52:5 + | +52 | x | 1 > 3; //~ERROR ineffective bit mask + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/bit_masks.rs:47:8 + | +47 | #[deny(ineffective_bit_mask)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly + --> $DIR/bit_masks.rs:53:5 + | +53 | x | 1 < 4; //~ERROR ineffective bit mask + | ^^^^^^^^^ + +error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly + --> $DIR/bit_masks.rs:54:5 + | +54 | x | 1 <= 3; //~ERROR ineffective bit mask + | ^^^^^^^^^^ + +error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly + --> $DIR/bit_masks.rs:55:5 + | +55 | x | 1 >= 8; //~ERROR ineffective bit mask + | ^^^^^^^^^^ + +error: aborting due to 15 previous errors + diff --git a/tests/compile-fail/blacklisted_name.rs b/tests/ui/blacklisted_name.rs similarity index 100% rename from tests/compile-fail/blacklisted_name.rs rename to tests/ui/blacklisted_name.rs diff --git a/tests/ui/blacklisted_name.stderr b/tests/ui/blacklisted_name.stderr new file mode 100644 index 00000000000..055fb8836d7 --- /dev/null +++ b/tests/ui/blacklisted_name.stderr @@ -0,0 +1,50 @@ +error: use of a blacklisted/placeholder name `foo` + --> $DIR/blacklisted_name.rs:9:9 + | +9 | fn test(foo: ()) {} //~ERROR use of a blacklisted/placeholder name `foo` + | ^^^ + | +note: lint level defined here + --> $DIR/blacklisted_name.rs:7:9 + | +7 | #![deny(blacklisted_name)] + | ^^^^^^^^^^^^^^^^ + +error: use of a blacklisted/placeholder name `foo` + --> $DIR/blacklisted_name.rs:12:9 + | +12 | let foo = 42; //~ERROR use of a blacklisted/placeholder name `foo` + | ^^^ + +error: use of a blacklisted/placeholder name `bar` + --> $DIR/blacklisted_name.rs:13:9 + | +13 | let bar = 42; //~ERROR use of a blacklisted/placeholder name `bar` + | ^^^ + +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:14:9 + | +14 | let baz = 42; //~ERROR use of a blacklisted/placeholder name `baz` + | ^^^ + +error: use of a blacklisted/placeholder name `foo` + --> $DIR/blacklisted_name.rs:20:10 + | +20 | (foo, Some(bar), baz @ Some(_)) => (), + | ^^^ + +error: use of a blacklisted/placeholder name `bar` + --> $DIR/blacklisted_name.rs:20:20 + | +20 | (foo, Some(bar), baz @ Some(_)) => (), + | ^^^ + +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:20:26 + | +20 | (foo, Some(bar), baz @ Some(_)) => (), + | ^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/block_in_if_condition.rs b/tests/ui/block_in_if_condition.rs similarity index 100% rename from tests/compile-fail/block_in_if_condition.rs rename to tests/ui/block_in_if_condition.rs diff --git a/tests/ui/block_in_if_condition.stderr b/tests/ui/block_in_if_condition.stderr new file mode 100644 index 00000000000..be63b4a7430 --- /dev/null +++ b/tests/ui/block_in_if_condition.stderr @@ -0,0 +1,68 @@ +error: in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let' + --> $DIR/block_in_if_condition.rs:30:8 + | +30 | if { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks; + | ________^ starting here... +31 | | let x = 3; +32 | | x == 3 +33 | | } { + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/block_in_if_condition.rs:5:9 + | +5 | #![deny(block_in_if_condition_stmt)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: try + let res = { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks; + let x = 3; + x == 3 + }; + if res { + 6 + } ... + +error: omit braces around single expression condition + --> $DIR/block_in_if_condition.rs:41:8 + | +41 | if { true } { //~ERROR omit braces around single expression condition + | ^^^^^^^^ + | +note: lint level defined here + --> $DIR/block_in_if_condition.rs:4:9 + | +4 | #![deny(block_in_if_condition_expr)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: try + if true { //~ERROR omit braces around single expression condition + 6 + } ... + +error: in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let' + --> $DIR/block_in_if_condition.rs:58:49 + | +58 | if v == 3 && sky == "blue" && predicate(|x| { let target = 3; x == target }, v) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let' + --> $DIR/block_in_if_condition.rs:62:22 + | +62 | if predicate(|x| { let target = 3; x == target }, v) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: this boolean expression can be simplified + --> $DIR/block_in_if_condition.rs:70:8 + | +70 | if true && x == 3 { //~ WARN this boolean expression can be simplified + | ^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/block_in_if_condition.rs:7:9 + | +7 | #![warn(nonminimal_bool)] + | ^^^^^^^^^^^^^^^ +help: try + | if x == 3 { //~ WARN this boolean expression can be simplified + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/bool_comparison.rs b/tests/ui/bool_comparison.rs similarity index 100% rename from tests/compile-fail/bool_comparison.rs rename to tests/ui/bool_comparison.rs diff --git a/tests/ui/bool_comparison.stderr b/tests/ui/bool_comparison.stderr new file mode 100644 index 00000000000..9da1c76d07e --- /dev/null +++ b/tests/ui/bool_comparison.stderr @@ -0,0 +1,43 @@ +error: equality checks against true are unnecessary + --> $DIR/bool_comparison.rs:7:8 + | +7 | if x == true { "yes" } else { "no" }; + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/bool_comparison.rs:4:8 + | +4 | #[deny(bool_comparison)] + | ^^^^^^^^^^^^^^^ +help: try simplifying it as shown: + | if x { "yes" } else { "no" }; + +error: equality checks against false can be replaced by a negation + --> $DIR/bool_comparison.rs:11:8 + | +11 | if x == false { "yes" } else { "no" }; + | ^^^^^^^^^^ + | +help: try simplifying it as shown: + | if !x { "yes" } else { "no" }; + +error: equality checks against true are unnecessary + --> $DIR/bool_comparison.rs:15:8 + | +15 | if true == x { "yes" } else { "no" }; + | ^^^^^^^^^ + | +help: try simplifying it as shown: + | if x { "yes" } else { "no" }; + +error: equality checks against false can be replaced by a negation + --> $DIR/bool_comparison.rs:19:8 + | +19 | if false == x { "yes" } else { "no" }; + | ^^^^^^^^^^ + | +help: try simplifying it as shown: + | if !x { "yes" } else { "no" }; + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/booleans.rs b/tests/ui/booleans.rs similarity index 100% rename from tests/compile-fail/booleans.rs rename to tests/ui/booleans.rs diff --git a/tests/ui/booleans.stderr b/tests/ui/booleans.stderr new file mode 100644 index 00000000000..9be511928b8 --- /dev/null +++ b/tests/ui/booleans.stderr @@ -0,0 +1,160 @@ +error: this boolean expression contains a logic bug + --> $DIR/booleans.rs:12:13 + | +12 | let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug + | ^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/booleans.rs:3:26 + | +3 | #![deny(nonminimal_bool, logic_bug)] + | ^^^^^^^^^ +help: this expression can be optimized out by applying boolean operations to the outer expression + --> $DIR/booleans.rs:12:18 + | +12 | let _ = a && b || a; //~ ERROR this boolean expression contains a logic bug + | ^ +help: it would look like the following + | let _ = a; //~ ERROR this boolean expression contains a logic bug + +error: this boolean expression can be simplified + --> $DIR/booleans.rs:17:13 + | +17 | let _ = !true; //~ ERROR this boolean expression can be simplified + | ^^^^^ + | +note: lint level defined here + --> $DIR/booleans.rs:3:9 + | +3 | #![deny(nonminimal_bool, logic_bug)] + | ^^^^^^^^^^^^^^^ +help: try + | let _ = false; //~ ERROR this boolean expression can be simplified + +error: this boolean expression can be simplified + --> $DIR/booleans.rs:20:13 + | +20 | let _ = !false; //~ ERROR this boolean expression can be simplified + | ^^^^^^ + | +help: try + | let _ = true; //~ ERROR this boolean expression can be simplified + +error: this boolean expression can be simplified + --> $DIR/booleans.rs:23:13 + | +23 | let _ = !!a; //~ ERROR this boolean expression can be simplified + | ^^^ + | +help: try + | let _ = a; //~ ERROR this boolean expression can be simplified + +error: this boolean expression contains a logic bug + --> $DIR/booleans.rs:27:13 + | +27 | let _ = false && a; //~ ERROR this boolean expression contains a logic bug + | ^^^^^^^^^^ + | +help: this expression can be optimized out by applying boolean operations to the outer expression + --> $DIR/booleans.rs:27:22 + | +27 | let _ = false && a; //~ ERROR this boolean expression contains a logic bug + | ^ +help: it would look like the following + | let _ = false; //~ ERROR this boolean expression contains a logic bug + +error: this boolean expression can be simplified + --> $DIR/booleans.rs:32:13 + | +32 | let _ = false || a; //~ ERROR this boolean expression can be simplified + | ^^^^^^^^^^ + | +help: try + | let _ = a; //~ ERROR this boolean expression can be simplified + +error: this boolean expression can be simplified + --> $DIR/booleans.rs:43:13 + | +43 | let _ = !(!a && b); //~ ERROR this boolean expression can be simplified + | ^^^^^^^^^^ + | +help: try + | let _ = !b || a; //~ ERROR this boolean expression can be simplified + +error: this boolean expression contains a logic bug + --> $DIR/booleans.rs:55:13 + | +55 | let _ = a == b && a != b; + | ^^^^^^^^^^^^^^^^ + | +help: this expression can be optimized out by applying boolean operations to the outer expression + --> $DIR/booleans.rs:55:13 + | +55 | let _ = a == b && a != b; + | ^^^^^^ +help: it would look like the following + | let _ = false; + +error: this boolean expression can be simplified + --> $DIR/booleans.rs:60:13 + | +60 | let _ = a == b && c == 5 && a == b; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _ = a == b && c == 5; +help: try + | let _ = !(c != 5 || a != b); + +error: this boolean expression can be simplified + --> $DIR/booleans.rs:66:13 + | +66 | let _ = a == b && c == 5 && b == a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _ = a == b && c == 5; +help: try + | let _ = !(c != 5 || a != b); + +error: this boolean expression contains a logic bug + --> $DIR/booleans.rs:72:13 + | +72 | let _ = a < b && a >= b; + | ^^^^^^^^^^^^^^^ + | +help: this expression can be optimized out by applying boolean operations to the outer expression + --> $DIR/booleans.rs:72:13 + | +72 | let _ = a < b && a >= b; + | ^^^^^ +help: it would look like the following + | let _ = false; + +error: this boolean expression contains a logic bug + --> $DIR/booleans.rs:77:13 + | +77 | let _ = a > b && a <= b; + | ^^^^^^^^^^^^^^^ + | +help: this expression can be optimized out by applying boolean operations to the outer expression + --> $DIR/booleans.rs:77:13 + | +77 | let _ = a > b && a <= b; + | ^^^^^ +help: it would look like the following + | let _ = false; + +error: this boolean expression can be simplified + --> $DIR/booleans.rs:84:13 + | +84 | let _ = a != b || !(a != b || c == d); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _ = c != d || a != b; +help: try + | let _ = !(a == b && c == d); + +error: aborting due to 13 previous errors + diff --git a/tests/compile-fail/box_vec.rs b/tests/ui/box_vec.rs similarity index 100% rename from tests/compile-fail/box_vec.rs rename to tests/ui/box_vec.rs diff --git a/tests/ui/box_vec.stderr b/tests/ui/box_vec.stderr new file mode 100644 index 00000000000..b5cc66b60c9 --- /dev/null +++ b/tests/ui/box_vec.stderr @@ -0,0 +1,16 @@ +error: you seem to be trying to use `Box>`. Consider using just `Vec` + --> $DIR/box_vec.rs:17:18 + | +17 | pub fn test(foo: Box>) { //~ ERROR you seem to be trying to use `Box>` + | ^^^^^^^^^^^^^^ + | + = note: #[deny(box_vec)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/box_vec.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + = help: `Vec` is already on the heap, `Box>` makes an extra allocation. + +error: aborting due to previous error + diff --git a/tests/compile-fail/builtin-type-shadow.rs b/tests/ui/builtin-type-shadow.rs similarity index 100% rename from tests/compile-fail/builtin-type-shadow.rs rename to tests/ui/builtin-type-shadow.rs diff --git a/tests/ui/builtin-type-shadow.stderr b/tests/ui/builtin-type-shadow.stderr new file mode 100644 index 00000000000..e3b6c68e8c2 --- /dev/null +++ b/tests/ui/builtin-type-shadow.stderr @@ -0,0 +1,23 @@ +error: This generic shadows the built-in type `u32` + --> $DIR/builtin-type-shadow.rs:5:8 + | +5 | fn foo(a: u32) -> u32 { //~ERROR shadows the built-in type `u32` + | ^^^ + | +note: lint level defined here + --> $DIR/builtin-type-shadow.rs:3:9 + | +3 | #![deny(builtin_type_shadow)] + | ^^^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/builtin-type-shadow.rs:6:5 + | +6 | 42 //~ERROR E0308 + | ^^ expected type parameter, found integral variable + | + = note: expected type `u32` + found type `{integer}` + +error: aborting due to previous error + diff --git a/tests/compile-fail/cast.rs b/tests/ui/cast.rs similarity index 100% rename from tests/compile-fail/cast.rs rename to tests/ui/cast.rs diff --git a/tests/ui/cast.stderr b/tests/ui/cast.stderr new file mode 100644 index 00000000000..e5fbc8fe4da --- /dev/null +++ b/tests/ui/cast.stderr @@ -0,0 +1,278 @@ +error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast.rs:8:5 + | +8 | 1i32 as f32; //~ERROR casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide) + | ^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/cast.rs:4:8 + | +4 | #[deny(cast_precision_loss, cast_possible_truncation, cast_sign_loss, cast_possible_wrap)] + | ^^^^^^^^^^^^^^^^^^^ + +error: casting i64 to f32 causes a loss of precision (i64 is 64 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast.rs:9:5 + | +9 | 1i64 as f32; //~ERROR casting i64 to f32 causes a loss of precision (i64 is 64 bits wide, but f32's mantissa is only 23 bits wide) + | ^^^^^^^^^^^ + +error: casting i64 to f64 causes a loss of precision (i64 is 64 bits wide, but f64's mantissa is only 52 bits wide) + --> $DIR/cast.rs:10:5 + | +10 | 1i64 as f64; //~ERROR casting i64 to f64 causes a loss of precision (i64 is 64 bits wide, but f64's mantissa is only 52 bits wide) + | ^^^^^^^^^^^ + +error: casting u32 to f32 causes a loss of precision (u32 is 32 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast.rs:11:5 + | +11 | 1u32 as f32; //~ERROR casting u32 to f32 causes a loss of precision (u32 is 32 bits wide, but f32's mantissa is only 23 bits wide) + | ^^^^^^^^^^^ + +error: casting u64 to f32 causes a loss of precision (u64 is 64 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast.rs:12:5 + | +12 | 1u64 as f32; //~ERROR casting u64 to f32 causes a loss of precision (u64 is 64 bits wide, but f32's mantissa is only 23 bits wide) + | ^^^^^^^^^^^ + +error: casting u64 to f64 causes a loss of precision (u64 is 64 bits wide, but f64's mantissa is only 52 bits wide) + --> $DIR/cast.rs:13:5 + | +13 | 1u64 as f64; //~ERROR casting u64 to f64 causes a loss of precision (u64 is 64 bits wide, but f64's mantissa is only 52 bits wide) + | ^^^^^^^^^^^ + +error: casting f32 to i32 may truncate the value + --> $DIR/cast.rs:18:5 + | +18 | 1f32 as i32; //~ERROR casting f32 to i32 may truncate the value + | ^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/cast.rs:4:29 + | +4 | #[deny(cast_precision_loss, cast_possible_truncation, cast_sign_loss, cast_possible_wrap)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: casting f32 to u32 may truncate the value + --> $DIR/cast.rs:19:5 + | +19 | 1f32 as u32; //~ERROR casting f32 to u32 may truncate the value + | ^^^^^^^^^^^ + +error: casting f32 to u32 may lose the sign of the value + --> $DIR/cast.rs:19:5 + | +19 | 1f32 as u32; //~ERROR casting f32 to u32 may truncate the value + | ^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/cast.rs:4:55 + | +4 | #[deny(cast_precision_loss, cast_possible_truncation, cast_sign_loss, cast_possible_wrap)] + | ^^^^^^^^^^^^^^ + +error: casting f64 to f32 may truncate the value + --> $DIR/cast.rs:21:5 + | +21 | 1f64 as f32; //~ERROR casting f64 to f32 may truncate the value + | ^^^^^^^^^^^ + +error: casting i32 to i8 may truncate the value + --> $DIR/cast.rs:22:5 + | +22 | 1i32 as i8; //~ERROR casting i32 to i8 may truncate the value + | ^^^^^^^^^^ + +error: casting i32 to u8 may lose the sign of the value + --> $DIR/cast.rs:23:5 + | +23 | 1i32 as u8; //~ERROR casting i32 to u8 may truncate the value + | ^^^^^^^^^^ + +error: casting i32 to u8 may truncate the value + --> $DIR/cast.rs:23:5 + | +23 | 1i32 as u8; //~ERROR casting i32 to u8 may truncate the value + | ^^^^^^^^^^ + +error: casting f64 to isize may truncate the value + --> $DIR/cast.rs:25:5 + | +25 | 1f64 as isize; //~ERROR casting f64 to isize may truncate the value + | ^^^^^^^^^^^^^ + +error: casting f64 to usize may truncate the value + --> $DIR/cast.rs:26:5 + | +26 | 1f64 as usize; //~ERROR casting f64 to usize may truncate the value + | ^^^^^^^^^^^^^ + +error: casting f64 to usize may lose the sign of the value + --> $DIR/cast.rs:26:5 + | +26 | 1f64 as usize; //~ERROR casting f64 to usize may truncate the value + | ^^^^^^^^^^^^^ + +error: casting u8 to i8 may wrap around the value + --> $DIR/cast.rs:30:5 + | +30 | 1u8 as i8; //~ERROR casting u8 to i8 may wrap around the value + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/cast.rs:4:71 + | +4 | #[deny(cast_precision_loss, cast_possible_truncation, cast_sign_loss, cast_possible_wrap)] + | ^^^^^^^^^^^^^^^^^^ + +error: casting u16 to i16 may wrap around the value + --> $DIR/cast.rs:31:5 + | +31 | 1u16 as i16; //~ERROR casting u16 to i16 may wrap around the value + | ^^^^^^^^^^^ + +error: casting u32 to i32 may wrap around the value + --> $DIR/cast.rs:32:5 + | +32 | 1u32 as i32; //~ERROR casting u32 to i32 may wrap around the value + | ^^^^^^^^^^^ + +error: casting u64 to i64 may wrap around the value + --> $DIR/cast.rs:33:5 + | +33 | 1u64 as i64; //~ERROR casting u64 to i64 may wrap around the value + | ^^^^^^^^^^^ + +error: casting usize to isize may wrap around the value + --> $DIR/cast.rs:34:5 + | +34 | 1usize as isize; //~ERROR casting usize to isize may wrap around the value + | ^^^^^^^^^^^^^^^ + +error: casting i32 to u32 may lose the sign of the value + --> $DIR/cast.rs:37:5 + | +37 | 1i32 as u32; //~ERROR casting i32 to u32 may lose the sign of the value + | ^^^^^^^^^^^ + +error: casting isize to usize may lose the sign of the value + --> $DIR/cast.rs:38:5 + | +38 | 1isize as usize; //~ERROR casting isize to usize may lose the sign of the value + | ^^^^^^^^^^^^^^^ + +error: casting isize to i8 may truncate the value + --> $DIR/cast.rs:42:5 + | +42 | 1isize as i8; //~ERROR casting isize to i8 may truncate the value + | ^^^^^^^^^^^^ + +error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide) + --> $DIR/cast.rs:43:5 + | +43 | 1isize as f64; //~ERROR casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide) + | ^^^^^^^^^^^^^ + +error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) + --> $DIR/cast.rs:44:5 + | +44 | 1usize as f64; //~ERROR casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) + | ^^^^^^^^^^^^^ + +error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast.rs:45:5 + | +45 | 1isize as f32; //~ERROR casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) + | ^^^^^^^^^^^^^ + +error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) + --> $DIR/cast.rs:46:5 + | +46 | 1usize as f32; //~ERROR casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide) + | ^^^^^^^^^^^^^ + +error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast.rs:47:5 + | +47 | 1isize as i32; //~ERROR casting isize to i32 may truncate the value on targets with 64-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting isize to u32 may lose the sign of the value + --> $DIR/cast.rs:48:5 + | +48 | 1isize as u32; //~ERROR casting isize to u32 may lose the sign of the value + | ^^^^^^^^^^^^^ + +error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast.rs:48:5 + | +48 | 1isize as u32; //~ERROR casting isize to u32 may lose the sign of the value + | ^^^^^^^^^^^^^ + +error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast.rs:50:5 + | +50 | 1usize as u32; //~ERROR casting usize to u32 may truncate the value on targets with 64-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast.rs:51:5 + | +51 | 1usize as i32; //~ERROR casting usize to i32 may truncate the value on targets with 64-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers + --> $DIR/cast.rs:51:5 + | +51 | 1usize as i32; //~ERROR casting usize to i32 may truncate the value on targets with 64-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers + --> $DIR/cast.rs:54:5 + | +54 | 1i64 as isize; //~ERROR casting i64 to isize may truncate the value on targets with 32-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting i64 to usize may lose the sign of the value + --> $DIR/cast.rs:55:5 + | +55 | 1i64 as usize; //~ERROR casting i64 to usize may truncate the value on targets with 32-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers + --> $DIR/cast.rs:55:5 + | +55 | 1i64 as usize; //~ERROR casting i64 to usize may truncate the value on targets with 32-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers + --> $DIR/cast.rs:57:5 + | +57 | 1u64 as isize; //~ERROR casting u64 to isize may truncate the value on targets with 32-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers + --> $DIR/cast.rs:57:5 + | +57 | 1u64 as isize; //~ERROR casting u64 to isize may truncate the value on targets with 32-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers + --> $DIR/cast.rs:59:5 + | +59 | 1u64 as usize; //~ERROR casting u64 to usize may truncate the value on targets with 32-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers + --> $DIR/cast.rs:60:5 + | +60 | 1u32 as isize; //~ERROR casting u32 to isize may wrap around the value on targets with 32-bit wide pointers + | ^^^^^^^^^^^^^ + +error: casting i32 to usize may lose the sign of the value + --> $DIR/cast.rs:63:5 + | +63 | 1i32 as usize; //~ERROR casting i32 to usize may lose the sign of the value + | ^^^^^^^^^^^^^ + +error: aborting due to 42 previous errors + diff --git a/tests/compile-fail/char_lit_as_u8.rs b/tests/ui/char_lit_as_u8.rs similarity index 100% rename from tests/compile-fail/char_lit_as_u8.rs rename to tests/ui/char_lit_as_u8.rs diff --git a/tests/ui/char_lit_as_u8.stderr b/tests/ui/char_lit_as_u8.stderr new file mode 100644 index 00000000000..f297f692dbb --- /dev/null +++ b/tests/ui/char_lit_as_u8.stderr @@ -0,0 +1,16 @@ +error: casting character literal to u8. `char`s are 4 bytes wide in rust, so casting to u8 truncates them + --> $DIR/char_lit_as_u8.rs:7:13 + | +7 | let c = 'a' as u8; //~ERROR casting character literal + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/char_lit_as_u8.rs:4:9 + | +4 | #![deny(char_lit_as_u8)] + | ^^^^^^^^^^^^^^ + = help: Consider using a byte literal instead: + b'a' + +error: aborting due to previous error + diff --git a/tests/compile-fail/cmp_nan.rs b/tests/ui/cmp_nan.rs similarity index 100% rename from tests/compile-fail/cmp_nan.rs rename to tests/ui/cmp_nan.rs diff --git a/tests/ui/cmp_nan.stderr b/tests/ui/cmp_nan.stderr new file mode 100644 index 00000000000..9d76a076b4a --- /dev/null +++ b/tests/ui/cmp_nan.stderr @@ -0,0 +1,98 @@ +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:8:5 + | +8 | x == std::f32::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:9:5 + | +9 | x != std::f32::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:10:5 + | +10 | x < std::f32::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:11:5 + | +11 | x > std::f32::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:12:5 + | +12 | x <= std::f32::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:13:5 + | +13 | x >= std::f32::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:16:5 + | +16 | y == std::f64::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:17:5 + | +17 | y != std::f64::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:18:5 + | +18 | y < std::f64::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:19:5 + | +19 | y > std::f64::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:20:5 + | +20 | y <= std::f64::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead + --> $DIR/cmp_nan.rs:21:5 + | +21 | y >= std::f64::NAN; //~ERROR doomed comparison with NAN + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(cmp_nan)] on by default + +error: aborting due to 12 previous errors + diff --git a/tests/compile-fail/cmp_null.rs b/tests/ui/cmp_null.rs similarity index 100% rename from tests/compile-fail/cmp_null.rs rename to tests/ui/cmp_null.rs diff --git a/tests/ui/cmp_null.stderr b/tests/ui/cmp_null.stderr new file mode 100644 index 00000000000..45523cea39e --- /dev/null +++ b/tests/ui/cmp_null.stderr @@ -0,0 +1,20 @@ +error: Comparing with null is better expressed by the .is_null() method + --> $DIR/cmp_null.rs:11:8 + | +11 | if p == ptr::null() { //~ERROR: Comparing with null + | ^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/cmp_null.rs:3:9 + | +3 | #![deny(cmp_null)] + | ^^^^^^^^ + +error: Comparing with null is better expressed by the .is_null() method + --> $DIR/cmp_null.rs:16:8 + | +16 | if m == ptr::null_mut() { //~ERROR: Comparing with null + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/cmp_owned.rs b/tests/ui/cmp_owned.rs similarity index 100% rename from tests/compile-fail/cmp_owned.rs rename to tests/ui/cmp_owned.rs diff --git a/tests/ui/cmp_owned.stderr b/tests/ui/cmp_owned.stderr new file mode 100644 index 00000000000..5c4ff833849 --- /dev/null +++ b/tests/ui/cmp_owned.stderr @@ -0,0 +1,32 @@ +error: this creates an owned instance just for comparison. Consider using `x != "foo"` to compare without allocation + --> $DIR/cmp_owned.rs:8:14 + | +8 | x != "foo".to_string(); + | ^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/cmp_owned.rs:4:8 + | +4 | #[deny(cmp_owned)] + | ^^^^^^^^^ + +error: this creates an owned instance just for comparison. Consider using `"foo" != x` to compare without allocation + --> $DIR/cmp_owned.rs:11:9 + | +11 | "foo".to_string() != x; + | ^^^^^^^^^^^^^^^^^ + +error: this creates an owned instance just for comparison. Consider using `x != "foo"` to compare without allocation + --> $DIR/cmp_owned.rs:19:10 + | +19 | x != "foo".to_owned(); //~ERROR this creates an owned instance + | ^^^^^^^^^^^^^^^^ + +error: this creates an owned instance just for comparison. Consider using `x != "foo"` to compare without allocation + --> $DIR/cmp_owned.rs:24:10 + | +24 | x != String::from("foo"); //~ERROR this creates an owned instance + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/collapsible_if.rs b/tests/ui/collapsible_if.rs similarity index 100% rename from tests/compile-fail/collapsible_if.rs rename to tests/ui/collapsible_if.rs diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr new file mode 100644 index 00000000000..ed510f96229 --- /dev/null +++ b/tests/ui/collapsible_if.stderr @@ -0,0 +1,229 @@ +error: this if statement can be collapsed + --> $DIR/collapsible_if.rs:8:5 + | +8 | if x == "hello" { + | _____^ starting here... +9 | | //~^ ERROR this if statement can be collapsed +10 | | //~| HELP try +11 | | //~| SUGGESTION if x == "hello" && y == "world" { +12 | | if y == "world" { +13 | | println!("Hello world!"); +14 | | } +15 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/collapsible_if.rs:4:8 + | +4 | #[deny(collapsible_if)] + | ^^^^^^^^^^^^^^ +help: try + | if x == "hello" && y == "world" { + | println!("Hello world!"); + | } + +error: this if statement can be collapsed + --> $DIR/collapsible_if.rs:17:5 + | +17 | if x == "hello" || x == "world" { + | _____^ starting here... +18 | | //~^ ERROR this if statement can be collapsed +19 | | //~| HELP try +20 | | //~| SUGGESTION if (x == "hello" || x == "world") && (y == "world" || y == "hello") { +21 | | if y == "world" || y == "hello" { +22 | | println!("Hello world!"); +23 | | } +24 | | } + | |_____^ ...ending here + | +help: try + | if (x == "hello" || x == "world") && (y == "world" || y == "hello") { + | println!("Hello world!"); + | } + +error: this if statement can be collapsed + --> $DIR/collapsible_if.rs:26:5 + | +26 | if x == "hello" && x == "world" { + | _____^ starting here... +27 | | //~^ ERROR this if statement can be collapsed +28 | | //~| HELP try +29 | | //~| SUGGESTION if x == "hello" && x == "world" && (y == "world" || y == "hello") { +30 | | if y == "world" || y == "hello" { +31 | | println!("Hello world!"); +32 | | } +33 | | } + | |_____^ ...ending here + | +help: try + | if x == "hello" && x == "world" && (y == "world" || y == "hello") { + | println!("Hello world!"); + | } + +error: this if statement can be collapsed + --> $DIR/collapsible_if.rs:35:5 + | +35 | if x == "hello" || x == "world" { + | _____^ starting here... +36 | | //~^ ERROR this if statement can be collapsed +37 | | //~| HELP try +38 | | //~| SUGGESTION if (x == "hello" || x == "world") && y == "world" && y == "hello" { +39 | | if y == "world" && y == "hello" { +40 | | println!("Hello world!"); +41 | | } +42 | | } + | |_____^ ...ending here + | +help: try + | if (x == "hello" || x == "world") && y == "world" && y == "hello" { + | println!("Hello world!"); + | } + +error: this if statement can be collapsed + --> $DIR/collapsible_if.rs:44:5 + | +44 | if x == "hello" && x == "world" { + | _____^ starting here... +45 | | //~^ ERROR this if statement can be collapsed +46 | | //~| HELP try +47 | | //~| SUGGESTION if x == "hello" && x == "world" && y == "world" && y == "hello" { +48 | | if y == "world" && y == "hello" { +49 | | println!("Hello world!"); +50 | | } +51 | | } + | |_____^ ...ending here + | +help: try + | if x == "hello" && x == "world" && y == "world" && y == "hello" { + | println!("Hello world!"); + | } + +error: this if statement can be collapsed + --> $DIR/collapsible_if.rs:53:5 + | +53 | if 42 == 1337 { + | _____^ starting here... +54 | | //~^ ERROR this if statement can be collapsed +55 | | //~| HELP try +56 | | //~| SUGGESTION if 42 == 1337 && 'a' != 'A' { +57 | | if 'a' != 'A' { +58 | | println!("world!") +59 | | } +60 | | } + | |_____^ ...ending here + | +help: try + | if 42 == 1337 && 'a' != 'A' { + | println!("world!") + | } + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_if.rs:65:12 + | +65 | } else { + | ____________^ starting here... +66 | | //~^ ERROR: this `else { if .. }` +67 | | //~| HELP try +68 | | //~| SUGGESTION } else if y == "world" +69 | | if y == "world" { +70 | | println!("world!") +71 | | } +72 | | } + | |_____^ ...ending here + | +help: try + | } else if y == "world" { + | println!("world!") + | } + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_if.rs:76:12 + | +76 | } else { + | ____________^ starting here... +77 | | //~^ ERROR: this `else { if .. }` +78 | | //~| HELP try +79 | | //~| SUGGESTION } else if let Some(42) +80 | | if let Some(42) = Some(42) { +81 | | println!("world!") +82 | | } +83 | | } + | |_____^ ...ending here + | +help: try + | } else if let Some(42) = Some(42) { + | println!("world!") + | } + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_if.rs:87:12 + | +87 | } else { + | ^ + | +help: try + | } else if y == "world" { + | println!("world") + | } + | else { + | println!("!") + | } + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_if.rs:101:12 + | +101 | } else { + | ^ + | +help: try + | } else if let Some(42) = Some(42) { + | println!("world") + | } + | else { + | println!("!") + | } + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_if.rs:115:12 + | +115 | } else { + | ^ + | +help: try + | } else if let Some(42) = Some(42) { + | println!("world") + | } + | else { + | println!("!") + | } + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_if.rs:129:12 + | +129 | } else { + | ^ + | +help: try + | } else if x == "hello" { + | println!("world") + | } + | else { + | println!("!") + | } + +error: this `else { if .. }` block can be collapsed + --> $DIR/collapsible_if.rs:143:12 + | +143 | } else { + | ^ + | +help: try + | } else if let Some(42) = Some(42) { + | println!("world") + | } + | else { + | println!("!") + | } + +error: aborting due to 13 previous errors + diff --git a/tests/compile-fail/complex_types.rs b/tests/ui/complex_types.rs similarity index 100% rename from tests/compile-fail/complex_types.rs rename to tests/ui/complex_types.rs diff --git a/tests/ui/complex_types.stderr b/tests/ui/complex_types.stderr new file mode 100644 index 00000000000..b502a3fd5c1 --- /dev/null +++ b/tests/ui/complex_types.stderr @@ -0,0 +1,127 @@ +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:9:12 + | +9 | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/complex_types.rs:3:9 + | +3 | #![deny(clippy)] + | ^^^^^^ + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:10:12 + | +10 | static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:13:8 + | +13 | f: Vec>>, //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:16:11 + | +16 | struct TS(Vec>>); //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:19:11 + | +19 | Tuple(Vec>>), //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:20:17 + | +20 | Struct { f: Vec>> }, //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:24:14 + | +24 | const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:25:30 + | +25 | fn impl_method(&self, p: Vec>>) { } //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:29:14 + | +29 | const A: Vec>>; //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:30:14 + | +30 | type B = Vec>>; //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:31:25 + | +31 | fn method(&self, p: Vec>>); //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:32:29 + | +32 | fn def_method(&self, p: Vec>>) { } //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:35:15 + | +35 | fn test1() -> Vec>> { vec![] } //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:37:14 + | +37 | fn test2(_x: Vec>>) { } //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/complex_types.rs:40:13 + | +40 | let _y: Vec>> = vec![]; //~ERROR very complex type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(type_complexity)] implied by #[deny(clippy)] + +error: aborting due to 15 previous errors + diff --git a/tests/compile-fail/conf_bad_arg.rs b/tests/ui/conf_bad_arg.rs similarity index 100% rename from tests/compile-fail/conf_bad_arg.rs rename to tests/ui/conf_bad_arg.rs diff --git a/tests/ui/conf_bad_arg.stderr b/tests/ui/conf_bad_arg.stderr new file mode 100644 index 00000000000..92b3c82d458 --- /dev/null +++ b/tests/ui/conf_bad_arg.stderr @@ -0,0 +1,14 @@ +error: `conf_file` must be a named value + --> $DIR/conf_bad_arg.rs:4:18 + | +4 | #![plugin(clippy(conf_file))] + | ^^^^^^^^^ + | +note: Clippy will use default configuration + --> $DIR/conf_bad_arg.rs:4:18 + | +4 | #![plugin(clippy(conf_file))] + | ^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/conf_bad_toml.rs b/tests/ui/conf_bad_toml.rs similarity index 100% rename from tests/compile-fail/conf_bad_toml.rs rename to tests/ui/conf_bad_toml.rs diff --git a/tests/ui/conf_bad_toml.stderr b/tests/ui/conf_bad_toml.stderr new file mode 100644 index 00000000000..7920bd35589 --- /dev/null +++ b/tests/ui/conf_bad_toml.stderr @@ -0,0 +1,4 @@ +error: error reading Clippy's configuration file: No such file or directory (os error 2) + +error: aborting due to previous error + diff --git a/tests/compile-fail/conf_bad_toml.toml b/tests/ui/conf_bad_toml.toml similarity index 100% rename from tests/compile-fail/conf_bad_toml.toml rename to tests/ui/conf_bad_toml.toml diff --git a/tests/compile-fail/conf_bad_type.rs b/tests/ui/conf_bad_type.rs similarity index 100% rename from tests/compile-fail/conf_bad_type.rs rename to tests/ui/conf_bad_type.rs diff --git a/tests/ui/conf_bad_type.stderr b/tests/ui/conf_bad_type.stderr new file mode 100644 index 00000000000..7920bd35589 --- /dev/null +++ b/tests/ui/conf_bad_type.stderr @@ -0,0 +1,4 @@ +error: error reading Clippy's configuration file: No such file or directory (os error 2) + +error: aborting due to previous error + diff --git a/tests/compile-fail/conf_bad_type.toml b/tests/ui/conf_bad_type.toml similarity index 100% rename from tests/compile-fail/conf_bad_type.toml rename to tests/ui/conf_bad_type.toml diff --git a/tests/compile-fail/conf_french_blacklisted_name.rs b/tests/ui/conf_french_blacklisted_name.rs similarity index 100% rename from tests/compile-fail/conf_french_blacklisted_name.rs rename to tests/ui/conf_french_blacklisted_name.rs diff --git a/tests/ui/conf_french_blacklisted_name.stderr b/tests/ui/conf_french_blacklisted_name.stderr new file mode 100644 index 00000000000..0c4996c2c5f --- /dev/null +++ b/tests/ui/conf_french_blacklisted_name.stderr @@ -0,0 +1,50 @@ +error: use of a blacklisted/placeholder name `toto` + --> $DIR/conf_french_blacklisted_name.rs:9:9 + | +9 | fn test(toto: ()) {} //~ERROR use of a blacklisted/placeholder name `toto` + | ^^^^ + | +note: lint level defined here + --> $DIR/conf_french_blacklisted_name.rs:7:9 + | +7 | #![deny(blacklisted_name)] + | ^^^^^^^^^^^^^^^^ + +error: use of a blacklisted/placeholder name `toto` + --> $DIR/conf_french_blacklisted_name.rs:12:9 + | +12 | let toto = 42; //~ERROR use of a blacklisted/placeholder name `toto` + | ^^^^ + +error: use of a blacklisted/placeholder name `tata` + --> $DIR/conf_french_blacklisted_name.rs:13:9 + | +13 | let tata = 42; //~ERROR use of a blacklisted/placeholder name `tata` + | ^^^^ + +error: use of a blacklisted/placeholder name `titi` + --> $DIR/conf_french_blacklisted_name.rs:14:9 + | +14 | let titi = 42; //~ERROR use of a blacklisted/placeholder name `titi` + | ^^^^ + +error: use of a blacklisted/placeholder name `toto` + --> $DIR/conf_french_blacklisted_name.rs:20:10 + | +20 | (toto, Some(tata), titi @ Some(_)) => (), + | ^^^^ + +error: use of a blacklisted/placeholder name `tata` + --> $DIR/conf_french_blacklisted_name.rs:20:21 + | +20 | (toto, Some(tata), titi @ Some(_)) => (), + | ^^^^ + +error: use of a blacklisted/placeholder name `titi` + --> $DIR/conf_french_blacklisted_name.rs:20:28 + | +20 | (toto, Some(tata), titi @ Some(_)) => (), + | ^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/conf_non_existant.rs b/tests/ui/conf_non_existant.rs similarity index 100% rename from tests/compile-fail/conf_non_existant.rs rename to tests/ui/conf_non_existant.rs diff --git a/tests/ui/conf_non_existant.stderr b/tests/ui/conf_non_existant.stderr new file mode 100644 index 00000000000..7920bd35589 --- /dev/null +++ b/tests/ui/conf_non_existant.stderr @@ -0,0 +1,4 @@ +error: error reading Clippy's configuration file: No such file or directory (os error 2) + +error: aborting due to previous error + diff --git a/tests/compile-fail/conf_path_non_string.rs b/tests/ui/conf_path_non_string.rs similarity index 100% rename from tests/compile-fail/conf_path_non_string.rs rename to tests/ui/conf_path_non_string.rs diff --git a/tests/ui/conf_path_non_string.stderr b/tests/ui/conf_path_non_string.stderr new file mode 100644 index 00000000000..3bf53f10cce --- /dev/null +++ b/tests/ui/conf_path_non_string.stderr @@ -0,0 +1,14 @@ +error: `conf_file` value must be a string + --> $DIR/conf_path_non_string.rs:3:28 + | +3 | #![plugin(clippy(conf_file=42))] + | ^^ + | +note: Clippy will use default configuration + --> $DIR/conf_path_non_string.rs:3:28 + | +3 | #![plugin(clippy(conf_file=42))] + | ^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/conf_unknown_key.rs b/tests/ui/conf_unknown_key.rs similarity index 100% rename from tests/compile-fail/conf_unknown_key.rs rename to tests/ui/conf_unknown_key.rs diff --git a/tests/ui/conf_unknown_key.stderr b/tests/ui/conf_unknown_key.stderr new file mode 100644 index 00000000000..536950fec31 --- /dev/null +++ b/tests/ui/conf_unknown_key.stderr @@ -0,0 +1,4 @@ +error: error reading Clippy's configuration file: unknown key `foobar` + +error: aborting due to previous error + diff --git a/tests/compile-fail/copies.rs b/tests/ui/copies.rs similarity index 100% rename from tests/compile-fail/copies.rs rename to tests/ui/copies.rs diff --git a/tests/ui/copies.stderr b/tests/ui/copies.stderr new file mode 100644 index 00000000000..634eb5d546f --- /dev/null +++ b/tests/ui/copies.stderr @@ -0,0 +1,409 @@ +error: this `if` has identical blocks + --> $DIR/copies.rs:40:10 + | +40 | else { //~ERROR this `if` has identical blocks + | __________^ starting here... +41 | | Foo { bar: 42 }; +42 | | 0..10; +43 | | ..; +44 | | 0..; +45 | | ..10; +46 | | 0...10; +47 | | foo(); +48 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/copies.rs:27:8 + | +27 | #[deny(if_same_then_else)] + | ^^^^^^^^^^^^^^^^^ +note: same as this + --> $DIR/copies.rs:30:13 + | +30 | if true { + | ^ + +error: this `match` has identical arm bodies + --> $DIR/copies.rs:91:14 + | +91 | _ => { //~ERROR this `match` has identical arm bodies + | ______________^ starting here... +92 | | foo(); +93 | | let mut a = 42 + [23].len() as i32; +94 | | if true { +95 | | a += 7; +96 | | } +97 | | a = -31-a; +98 | | a +99 | | } + | |_________^ ...ending here + | +note: lint level defined here + --> $DIR/copies.rs:28:8 + | +28 | #[deny(match_same_arms)] + | ^^^^^^^^^^^^^^^ +note: same as this + --> $DIR/copies.rs:80:15 + | +80 | 42 => { + | ^ +note: `42` has the same arm body as the `_` wildcard, consider removing it` + --> $DIR/copies.rs:80:15 + | +80 | 42 => { + | ^ + +error: this `match` has identical arm bodies + --> $DIR/copies.rs:107:14 + | +107 | _ => 0, //~ERROR this `match` has identical arm bodies + | ^ + | +note: same as this + --> $DIR/copies.rs:103:19 + | +103 | Abc::A => 0, + | ^ +note: `Abc::A` has the same arm body as the `_` wildcard, consider removing it` + --> $DIR/copies.rs:103:19 + | +103 | Abc::A => 0, + | ^ + +error: this `if` has identical blocks + --> $DIR/copies.rs:118:10 + | +118 | else { //~ERROR this `if` has identical blocks + | __________^ starting here... +119 | | 42 +120 | | }; + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:114:21 + | +114 | let _ = if true { + | _____________________^ starting here... +115 | | //~^NOTE same as this +116 | | 42 +117 | | } + | |_____^ ...ending here + +error: this `if` has identical blocks + --> $DIR/copies.rs:133:10 + | +133 | else { //~ERROR this `if` has identical blocks + | ^ + | +note: same as this + --> $DIR/copies.rs:122:13 + | +122 | if true { + | ^ + +error: this `if` has identical blocks + --> $DIR/copies.rs:156:10 + | +156 | else { //~ERROR this `if` has identical blocks + | ^ + | +note: same as this + --> $DIR/copies.rs:144:13 + | +144 | if true { + | ^ + +error: this `if` has identical blocks + --> $DIR/copies.rs:180:19 + | +180 | else if foo() { //~ERROR this `if` has identical blocks + | ___________________^ starting here... +181 | | let _ = match 42 { +182 | | 42 => 1, +183 | | a if a > 0 => 2, +184 | | 10...15 => 3, +185 | | _ => 4, +186 | | }; +187 | | } + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:168:13 + | +168 | if true { + | _____________^ starting here... +169 | | //~^NOTE same as this +170 | | let _ = match 42 { +171 | | 42 => 1, +172 | | a if a > 0 => 2, +173 | | 10...15 => 3, +174 | | _ => 4, +175 | | }; +176 | | } + | |_____^ ...ending here + +error: this `if` has identical blocks + --> $DIR/copies.rs:193:10 + | +193 | else { //~ERROR this `if` has identical blocks + | __________^ starting here... +194 | | if let Some(a) = Some(42) {} +195 | | } + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:189:13 + | +189 | if true { + | _____________^ starting here... +190 | | //~^NOTE same as this +191 | | if let Some(a) = Some(42) {} +192 | | } + | |_____^ ...ending here + +error: this `if` has identical blocks + --> $DIR/copies.rs:201:10 + | +201 | else { //~ERROR this `if` has identical blocks + | __________^ starting here... +202 | | if let (1, .., 3) = (1, 2, 3) {} +203 | | } + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:197:13 + | +197 | if true { + | _____________^ starting here... +198 | | //~^NOTE same as this +199 | | if let (1, .., 3) = (1, 2, 3) {} +200 | | } + | |_____^ ...ending here + +error: this `match` has identical arm bodies + --> $DIR/copies.rs:258:15 + | +258 | 51 => foo(), //~ERROR this `match` has identical arm bodies + | ^^^^^ + | +note: same as this + --> $DIR/copies.rs:255:15 + | +255 | 42 => foo(), + | ^^^^^ +note: consider refactoring into `42 | 51` + --> $DIR/copies.rs:255:15 + | +255 | 42 => foo(), + | ^^^^^ + +error: this `match` has identical arm bodies + --> $DIR/copies.rs:266:17 + | +266 | None => 24, //~ERROR this `match` has identical arm bodies + | ^^ + | +note: same as this + --> $DIR/copies.rs:263:20 + | +263 | Some(_) => 24, + | ^^ +note: consider refactoring into `Some(_) | None` + --> $DIR/copies.rs:263:20 + | +263 | Some(_) => 24, + | ^^ + +error: this `match` has identical arm bodies + --> $DIR/copies.rs:290:28 + | +290 | (None, Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies + | ^^^^^^ + | +note: same as this + --> $DIR/copies.rs:287:28 + | +287 | (Some(a), None) => bar(a), + | ^^^^^^ +note: consider refactoring into `(Some(a), None) | (None, Some(a))` + --> $DIR/copies.rs:287:28 + | +287 | (Some(a), None) => bar(a), + | ^^^^^^ + +error: this `match` has identical arm bodies + --> $DIR/copies.rs:298:26 + | +298 | (.., Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies + | ^^^^^^ + | +note: same as this + --> $DIR/copies.rs:295:26 + | +295 | (Some(a), ..) => bar(a), + | ^^^^^^ +note: consider refactoring into `(Some(a), ..) | (.., Some(a))` + --> $DIR/copies.rs:295:26 + | +295 | (Some(a), ..) => bar(a), + | ^^^^^^ + +error: this `match` has identical arm bodies + --> $DIR/copies.rs:306:20 + | +306 | (.., 3) => 42, //~ERROR this `match` has identical arm bodies + | ^^ + | +note: same as this + --> $DIR/copies.rs:303:23 + | +303 | (1, .., 3) => 42, + | ^^ +note: consider refactoring into `(1, .., 3) | (.., 3)` + --> $DIR/copies.rs:303:23 + | +303 | (1, .., 3) => 42, + | ^^ + +error: this `if` has identical blocks + --> $DIR/copies.rs:313:12 + | +313 | } else { //~ERROR this `if` has identical blocks + | ____________^ starting here... +314 | | 0.0 +315 | | }; + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:310:21 + | +310 | let _ = if true { + | _____________________^ starting here... +311 | | //~^NOTE same as this +312 | | 0.0 +313 | | } else { //~ERROR this `if` has identical blocks + | |_____^ ...ending here + +error: this `if` has identical blocks + --> $DIR/copies.rs:320:12 + | +320 | } else { //~ERROR this `if` has identical blocks + | ____________^ starting here... +321 | | -0.0 +322 | | }; + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:317:21 + | +317 | let _ = if true { + | _____________________^ starting here... +318 | | //~^NOTE same as this +319 | | -0.0 +320 | | } else { //~ERROR this `if` has identical blocks + | |_____^ ...ending here + +error: this `if` has identical blocks + --> $DIR/copies.rs:341:12 + | +341 | } else { //~ERROR this `if` has identical blocks + | ____________^ starting here... +342 | | std::f32::NAN +343 | | }; + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:338:21 + | +338 | let _ = if true { + | _____________________^ starting here... +339 | | //~^NOTE same as this +340 | | std::f32::NAN +341 | | } else { //~ERROR this `if` has identical blocks + | |_____^ ...ending here + +error: this `if` has identical blocks + --> $DIR/copies.rs:360:10 + | +360 | else { //~ERROR this `if` has identical blocks + | __________^ starting here... +361 | | try!(Ok("foo")); +362 | | } + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:356:13 + | +356 | if true { + | _____________^ starting here... +357 | | //~^NOTE same as this +358 | | try!(Ok("foo")); +359 | | } + | |_____^ ...ending here + +error: this `if` has identical blocks + --> $DIR/copies.rs:373:10 + | +373 | else { //~ERROR this `if` has identical blocks + | __________^ starting here... +374 | | let foo = ""; +375 | | return Ok(&foo[0..]); +376 | | } + | |_____^ ...ending here + | +note: same as this + --> $DIR/copies.rs:364:13 + | +364 | if true { + | _____________^ starting here... +365 | | //~^NOTE same as this +366 | | let foo = ""; +367 | | return Ok(&foo[0..]); +368 | | } + | |_____^ ...ending here + +error: this `if` has the same condition as a previous if + --> $DIR/copies.rs:388:13 + | +388 | else if b { //~ERROR this `if` has the same condition as a previous if + | ^ + | +note: lint level defined here + --> $DIR/copies.rs:379:8 + | +379 | #[deny(ifs_same_cond)] + | ^^^^^^^^^^^^^ +note: same as this + --> $DIR/copies.rs:385:8 + | +385 | if b { + | ^ + +error: this `if` has the same condition as a previous if + --> $DIR/copies.rs:394:13 + | +394 | else if a == 1 { //~ERROR this `if` has the same condition as a previous if + | ^^^^^^ + | +note: same as this + --> $DIR/copies.rs:391:8 + | +391 | if a == 1 { + | ^^^^^^ + +error: this `if` has the same condition as a previous if + --> $DIR/copies.rs:402:13 + | +402 | else if 2*a == 1 { //~ERROR this `if` has the same condition as a previous if + | ^^^^^^^^ + | +note: same as this + --> $DIR/copies.rs:397:8 + | +397 | if 2*a == 1 { + | ^^^^^^^^ + +error: aborting due to 22 previous errors + diff --git a/tests/compile-fail/cyclomatic_complexity.rs b/tests/ui/cyclomatic_complexity.rs similarity index 100% rename from tests/compile-fail/cyclomatic_complexity.rs rename to tests/ui/cyclomatic_complexity.rs diff --git a/tests/ui/cyclomatic_complexity.stderr b/tests/ui/cyclomatic_complexity.stderr new file mode 100644 index 00000000000..45f258f9560 --- /dev/null +++ b/tests/ui/cyclomatic_complexity.stderr @@ -0,0 +1,232 @@ +error: the function has a cyclomatic complexity of 28 + --> $DIR/cyclomatic_complexity.rs:7:1 + | +7 | fn main() { //~ERROR the function has a cyclomatic complexity of 28 + | ^ + | +note: lint level defined here + --> $DIR/cyclomatic_complexity.rs:4:9 + | +4 | #![deny(cyclomatic_complexity)] + | ^^^^^^^^^^^^^^^^^^^^^ + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 7 + --> $DIR/cyclomatic_complexity.rs:92:1 + | +92 | fn kaboom() { //~ ERROR: the function has a cyclomatic complexity of 7 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 1 + --> $DIR/cyclomatic_complexity.rs:138:1 + | +138 | fn lots_of_short_circuits() -> bool { //~ ERROR: the function has a cyclomatic complexity of 1 + | _^ starting here... +139 | | true && false && true && false && true && false && true +140 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 1 + --> $DIR/cyclomatic_complexity.rs:143:1 + | +143 | fn lots_of_short_circuits2() -> bool { //~ ERROR: the function has a cyclomatic complexity of 1 + | _^ starting here... +144 | | true || false || true || false || true || false || true +145 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 2 + --> $DIR/cyclomatic_complexity.rs:148:1 + | +148 | fn baa() { //~ ERROR: the function has a cyclomatic complexity of 2 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 2 + --> $DIR/cyclomatic_complexity.rs:149:13 + | +149 | let x = || match 99 { //~ ERROR: the function has a cyclomatic complexity of 2 + | _____________^ starting here... +150 | | 0 => 0, +151 | | 1 => 1, +152 | | 2 => 2, +153 | | 4 => 4, +154 | | 6 => 6, +155 | | 9 => 9, +156 | | _ => 42, +157 | | }; + | |_____^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 2 + --> $DIR/cyclomatic_complexity.rs:166:1 + | +166 | fn bar() { //~ ERROR: the function has a cyclomatic complexity of 2 + | _^ starting here... +167 | | match 99 { +168 | | 0 => println!("hi"), +169 | | _ => println!("bye"), +170 | | } +171 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 2 + --> $DIR/cyclomatic_complexity.rs:185:1 + | +185 | fn barr() { //~ ERROR: the function has a cyclomatic complexity of 2 + | _^ starting here... +186 | | match 99 { +187 | | 0 => println!("hi"), +188 | | 1 => println!("bla"), +189 | | 2 | 3 => println!("blub"), +190 | | _ => println!("bye"), +191 | | } +192 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 3 + --> $DIR/cyclomatic_complexity.rs:195:1 + | +195 | fn barr2() { //~ ERROR: the function has a cyclomatic complexity of 3 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 2 + --> $DIR/cyclomatic_complexity.rs:211:1 + | +211 | fn barrr() { //~ ERROR: the function has a cyclomatic complexity of 2 + | _^ starting here... +212 | | match 99 { +213 | | 0 => println!("hi"), +214 | | 1 => panic!("bla"), +215 | | 2 | 3 => println!("blub"), +216 | | _ => println!("bye"), +217 | | } +218 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 3 + --> $DIR/cyclomatic_complexity.rs:221:1 + | +221 | fn barrr2() { //~ ERROR: the function has a cyclomatic complexity of 3 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 2 + --> $DIR/cyclomatic_complexity.rs:237:1 + | +237 | fn barrrr() { //~ ERROR: the function has a cyclomatic complexity of 2 + | _^ starting here... +238 | | match 99 { +239 | | 0 => println!("hi"), +240 | | 1 => println!("bla"), +241 | | 2 | 3 => panic!("blub"), +242 | | _ => println!("bye"), +243 | | } +244 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 3 + --> $DIR/cyclomatic_complexity.rs:247:1 + | +247 | fn barrrr2() { //~ ERROR: the function has a cyclomatic complexity of 3 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 2 + --> $DIR/cyclomatic_complexity.rs:263:1 + | +263 | fn cake() { //~ ERROR: the function has a cyclomatic complexity of 2 + | _^ starting here... +264 | | if 4 == 5 { +265 | | println!("yea"); +266 | | } else { +267 | | panic!("meh"); +268 | | } +269 | | println!("whee"); +270 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 4 + --> $DIR/cyclomatic_complexity.rs:274:1 + | +274 | pub fn read_file(input_path: &str) -> String { //~ ERROR: the function has a cyclomatic complexity of 4 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 1 + --> $DIR/cyclomatic_complexity.rs:305:1 + | +305 | fn void(void: Void) { //~ ERROR: the function has a cyclomatic complexity of 1 + | _^ starting here... +306 | | if true { +307 | | match void { +308 | | } +309 | | } +310 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 1 + --> $DIR/cyclomatic_complexity.rs:319:1 + | +319 | fn try() -> Result { //~ ERROR: cyclomatic complexity of 1 + | _^ starting here... +320 | | match 5 { +321 | | 5 => Ok(5), +322 | | _ => return Err("bla"), +323 | | } +324 | | } + | |_^ ...ending here + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 1 + --> $DIR/cyclomatic_complexity.rs:327:1 + | +327 | fn try_again() -> Result { //~ ERROR: cyclomatic complexity of 1 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 1 + --> $DIR/cyclomatic_complexity.rs:343:1 + | +343 | fn early() -> Result { //~ ERROR: cyclomatic complexity of 1 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: the function has a cyclomatic complexity of 8 + --> $DIR/cyclomatic_complexity.rs:356:1 + | +356 | fn early_ret() -> i32 { //~ ERROR: cyclomatic complexity of 8 + | ^ + | + = help: you could split it up into multiple smaller functions + +error: aborting due to 20 previous errors + diff --git a/tests/compile-fail/cyclomatic_complexity_attr_used.rs b/tests/ui/cyclomatic_complexity_attr_used.rs similarity index 100% rename from tests/compile-fail/cyclomatic_complexity_attr_used.rs rename to tests/ui/cyclomatic_complexity_attr_used.rs diff --git a/tests/ui/cyclomatic_complexity_attr_used.stderr b/tests/ui/cyclomatic_complexity_attr_used.stderr new file mode 100644 index 00000000000..aa87b75058c --- /dev/null +++ b/tests/ui/cyclomatic_complexity_attr_used.stderr @@ -0,0 +1,22 @@ +error: the function has a cyclomatic complexity of 3 + --> $DIR/cyclomatic_complexity_attr_used.rs:11:1 + | +11 | fn kaboom() { //~ ERROR: the function has a cyclomatic complexity of 3 + | _^ starting here... +12 | | if 42 == 43 { +13 | | panic!(); +14 | | } else if "cake" == "lie" { +15 | | println!("what?"); +16 | | } +17 | | } + | |_^ ...ending here + | +note: lint level defined here + --> $DIR/cyclomatic_complexity_attr_used.rs:3:9 + | +3 | #![deny(cyclomatic_complexity)] + | ^^^^^^^^^^^^^^^^^^^^^ + = help: you could split it up into multiple smaller functions + +error: aborting due to previous error + diff --git a/tests/compile-fail/derive.rs b/tests/ui/derive.rs similarity index 100% rename from tests/compile-fail/derive.rs rename to tests/ui/derive.rs diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr new file mode 100644 index 00000000000..97b5344ee7f --- /dev/null +++ b/tests/ui/derive.stderr @@ -0,0 +1,103 @@ +error: you are deriving `Hash` but have implemented `PartialEq` explicitly + --> $DIR/derive.rs:18:10 + | +18 | #[derive(Hash)] + | ^^^^ + | + = note: #[deny(derive_hash_xor_eq)] implied by #[deny(warnings)] +note: lint level defined here + --> $DIR/derive.rs:6:9 + | +6 | #![deny(warnings)] + | ^^^^^^^^ +note: `PartialEq` implemented here + --> $DIR/derive.rs:22:1 + | +22 | impl PartialEq for Bar { + | _^ starting here... +23 | | fn eq(&self, _: &Bar) -> bool { true } +24 | | } + | |_^ ...ending here + +error: you are deriving `Hash` but have implemented `PartialEq` explicitly + --> $DIR/derive.rs:26:10 + | +26 | #[derive(Hash)] + | ^^^^ + | + = note: #[deny(derive_hash_xor_eq)] implied by #[deny(warnings)] +note: `PartialEq` implemented here + --> $DIR/derive.rs:30:1 + | +30 | impl PartialEq for Baz { + | _^ starting here... +31 | | fn eq(&self, _: &Baz) -> bool { true } +32 | | } + | |_^ ...ending here + +error: you are implementing `Hash` explicitly but have derived `PartialEq` + --> $DIR/derive.rs:37:1 + | +37 | impl Hash for Bah { + | _^ starting here... +38 | | //~^ ERROR you are implementing `Hash` explicitly but have derived `PartialEq` +39 | | fn hash(&self, _: &mut H) {} +40 | | } + | |_^ ...ending here + | + = note: #[deny(derive_hash_xor_eq)] implied by #[deny(warnings)] +note: `PartialEq` implemented here + --> $DIR/derive.rs:34:10 + | +34 | #[derive(PartialEq)] + | ^^^^^^^^^ + +error: you are implementing `Clone` explicitly on a `Copy` type + --> $DIR/derive.rs:45:1 + | +45 | impl Clone for Qux { + | _^ starting here... +46 | | //~^ ERROR you are implementing `Clone` explicitly on a `Copy` type +47 | | fn clone(&self) -> Self { Qux } +48 | | } + | |_^ ...ending here + | + = note: #[deny(expl_impl_clone_on_copy)] implied by #[deny(warnings)] +note: lint level defined here + --> $DIR/derive.rs:6:9 + | +6 | #![deny(warnings)] + | ^^^^^^^^ +note: consider deriving `Clone` or removing `Copy` + --> $DIR/derive.rs:45:1 + | +45 | impl Clone for Qux { + | _^ starting here... +46 | | //~^ ERROR you are implementing `Clone` explicitly on a `Copy` type +47 | | fn clone(&self) -> Self { Qux } +48 | | } + | |_^ ...ending here + +error: you are implementing `Clone` explicitly on a `Copy` type + --> $DIR/derive.rs:70:1 + | +70 | impl<'a> Clone for Lt<'a> { + | _^ starting here... +71 | | //~^ ERROR you are implementing `Clone` explicitly on a `Copy` type +72 | | fn clone(&self) -> Self { unimplemented!() } +73 | | } + | |_^ ...ending here + | + = note: #[deny(expl_impl_clone_on_copy)] implied by #[deny(warnings)] +note: consider deriving `Clone` or removing `Copy` + --> $DIR/derive.rs:70:1 + | +70 | impl<'a> Clone for Lt<'a> { + | _^ starting here... +71 | | //~^ ERROR you are implementing `Clone` explicitly on a `Copy` type +72 | | fn clone(&self) -> Self { unimplemented!() } +73 | | } + | |_^ ...ending here + +error: aborting due to 5 previous errors + diff --git a/tests/compile-fail/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs similarity index 100% rename from tests/compile-fail/diverging_sub_expression.rs rename to tests/ui/diverging_sub_expression.rs diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr new file mode 100644 index 00000000000..805a01840de --- /dev/null +++ b/tests/ui/diverging_sub_expression.stderr @@ -0,0 +1,44 @@ +error: sub-expression diverges + --> $DIR/diverging_sub_expression.rs:18:10 + | +18 | b || diverge(); //~ ERROR sub-expression diverges + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/diverging_sub_expression.rs:3:9 + | +3 | #![deny(diverging_sub_expression)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: sub-expression diverges + --> $DIR/diverging_sub_expression.rs:19:10 + | +19 | b || A.foo(); //~ ERROR sub-expression diverges + | ^^^^^^^ + +error: sub-expression diverges + --> $DIR/diverging_sub_expression.rs:28:26 + | +28 | 6 => true || return, //~ ERROR sub-expression diverges + | ^^^^^^ + +error: sub-expression diverges + --> $DIR/diverging_sub_expression.rs:29:26 + | +29 | 7 => true || continue, //~ ERROR sub-expression diverges + | ^^^^^^^^ + +error: sub-expression diverges + --> $DIR/diverging_sub_expression.rs:32:26 + | +32 | 3 => true || diverge(), //~ ERROR sub-expression diverges + | ^^^^^^^^^ + +error: sub-expression diverges + --> $DIR/diverging_sub_expression.rs:37:26 + | +37 | _ => true || break, //~ ERROR sub-expression diverges + | ^^^^^ + +error: aborting due to 6 previous errors + diff --git a/tests/compile-fail/dlist.rs b/tests/ui/dlist.rs similarity index 100% rename from tests/compile-fail/dlist.rs rename to tests/ui/dlist.rs diff --git a/tests/ui/dlist.stderr b/tests/ui/dlist.stderr new file mode 100644 index 00000000000..1d0507d1e04 --- /dev/null +++ b/tests/ui/dlist.stderr @@ -0,0 +1,61 @@ +error: I see you're using a LinkedList! Perhaps you meant some other data structure? + --> $DIR/dlist.rs:13:16 + | +13 | type Baz = LinkedList; //~ ERROR I see you're using a LinkedList! + | ^^^^^^^^^^^^^^ + | + = note: #[deny(linkedlist)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/dlist.rs:6:9 + | +6 | #![deny(clippy)] + | ^^^^^^ + = help: a VecDeque might work + +error: I see you're using a LinkedList! Perhaps you meant some other data structure? + --> $DIR/dlist.rs:14:12 + | +14 | fn foo(LinkedList); //~ ERROR I see you're using a LinkedList! + | ^^^^^^^^^^^^^^ + | + = note: #[deny(linkedlist)] implied by #[deny(clippy)] + = help: a VecDeque might work + +error: I see you're using a LinkedList! Perhaps you meant some other data structure? + --> $DIR/dlist.rs:15:24 + | +15 | const BAR : Option>; //~ ERROR I see you're using a LinkedList! + | ^^^^^^^^^^^^^^ + | + = note: #[deny(linkedlist)] implied by #[deny(clippy)] + = help: a VecDeque might work + +error: I see you're using a LinkedList! Perhaps you meant some other data structure? + --> $DIR/dlist.rs:26:15 + | +26 | fn foo(_: LinkedList) {} //~ ERROR I see you're using a LinkedList! + | ^^^^^^^^^^^^^^ + | + = note: #[deny(linkedlist)] implied by #[deny(clippy)] + = help: a VecDeque might work + +error: I see you're using a LinkedList! Perhaps you meant some other data structure? + --> $DIR/dlist.rs:29:39 + | +29 | pub fn test(my_favourite_linked_list: LinkedList) { //~ ERROR I see you're using a LinkedList! + | ^^^^^^^^^^^^^^ + | + = note: #[deny(linkedlist)] implied by #[deny(clippy)] + = help: a VecDeque might work + +error: I see you're using a LinkedList! Perhaps you meant some other data structure? + --> $DIR/dlist.rs:33:29 + | +33 | pub fn test_ret() -> Option> { //~ ERROR I see you're using a LinkedList! + | ^^^^^^^^^^^^^^ + | + = note: #[deny(linkedlist)] implied by #[deny(clippy)] + = help: a VecDeque might work + +error: aborting due to 6 previous errors + diff --git a/tests/compile-fail/doc.rs b/tests/ui/doc.rs similarity index 100% rename from tests/compile-fail/doc.rs rename to tests/ui/doc.rs diff --git a/tests/ui/doc.stderr b/tests/ui/doc.stderr new file mode 100644 index 00000000000..90df4766fae --- /dev/null +++ b/tests/ui/doc.stderr @@ -0,0 +1,182 @@ +error: you should put `DOC_MARKDOWN` between ticks in the documentation + --> $DIR/doc.rs:1:29 + | +1 | //! This file tests for the DOC_MARKDOWN lint + | ^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/doc.rs:7:9 + | +7 | #![deny(doc_markdown)] + | ^^^^^^^^^^^^ + +error: you should put `foo_bar` between ticks in the documentation + --> $DIR/doc.rs:9:9 + | +9 | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) + | ^^^^^^^ + +error: you should put `foo::bar` between ticks in the documentation + --> $DIR/doc.rs:9:51 + | +9 | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) + | ^^^^^^^^ + +error: you should put `Foo::some_fun` between ticks in the documentation + --> $DIR/doc.rs:12:84 + | +12 | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not Foo::some_fun + | ^^^^^^^^^^^^^ + +error: you should put `is::a::global:path` between ticks in the documentation + --> $DIR/doc.rs:15:13 + | +15 | /// Here be ::is::a::global:path. + | ^^^^^^^^^^^^^^^^^^^^ + +error: you should put `NotInCodeBlock` between ticks in the documentation + --> $DIR/doc.rs:17:21 + | +17 | /// That's not code ~NotInCodeBlock~. + | ^^^^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:19:5 + | +19 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:34:5 + | +34 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:42:5 + | +42 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:57:5 + | +57 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `ß_foo` between ticks in the documentation + --> $DIR/doc.rs:67:5 + | +67 | /// ß_foo + | ^^^^^ + +error: you should put `ℝ_foo` between ticks in the documentation + --> $DIR/doc.rs:69:5 + | +69 | /// ℝ_foo + | ^^^^^ + +error: you should put `foo_ß` between ticks in the documentation + --> $DIR/doc.rs:73:5 + | +73 | /// foo_ß + | ^^^^^ + +error: you should put `foo_ℝ` between ticks in the documentation + --> $DIR/doc.rs:75:5 + | +75 | /// foo_ℝ + | ^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:91:5 + | +91 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `link_with_underscores` between ticks in the documentation + --> $DIR/doc.rs:96:22 + | +96 | /// This test has [a link_with_underscores][chunked-example] inside it. See #823. + | ^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `inline_link2` between ticks in the documentation + --> $DIR/doc.rs:100:21 + | +100 | /// It can also be [inline_link2]. + | ^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:112:5 + | +112 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `CamelCaseThing` between ticks in the documentation + --> $DIR/doc.rs:126:22 + | +126 | /// Not a title #897 CamelCaseThing + | ^^^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:128:5 + | +128 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:136:5 + | +136 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:150:5 + | +150 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `FooBar` between ticks in the documentation + --> $DIR/doc.rs:162:42 + | +162 | /** E.g. serialization of an empty list: FooBar + | ^^^^^^ + +error: you should put `BarQuz` between ticks in the documentation + --> $DIR/doc.rs:167:5 + | +167 | And BarQuz too. + | ^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:168:1 + | +168 | be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `FooBar` between ticks in the documentation + --> $DIR/doc.rs:176:42 + | +176 | /** E.g. serialization of an empty list: FooBar + | ^^^^^^ + +error: you should put `BarQuz` between ticks in the documentation + --> $DIR/doc.rs:181:5 + | +181 | And BarQuz too. + | ^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:182:1 + | +182 | be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation + --> $DIR/doc.rs:196:5 + | +196 | /// be_sure_we_got_to_the_end_of_it + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 29 previous errors + diff --git a/tests/compile-fail/double_neg.rs b/tests/ui/double_neg.rs similarity index 100% rename from tests/compile-fail/double_neg.rs rename to tests/ui/double_neg.rs diff --git a/tests/ui/double_neg.stderr b/tests/ui/double_neg.stderr new file mode 100644 index 00000000000..2964344029c --- /dev/null +++ b/tests/ui/double_neg.stderr @@ -0,0 +1,14 @@ +error: `--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op + --> $DIR/double_neg.rs:9:5 + | +9 | --x; //~ERROR: `--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op + | ^^^ + | +note: lint level defined here + --> $DIR/double_neg.rs:4:8 + | +4 | #[deny(double_neg)] + | ^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/double_parens.rs b/tests/ui/double_parens.rs similarity index 100% rename from tests/compile-fail/double_parens.rs rename to tests/ui/double_parens.rs diff --git a/tests/ui/double_parens.stderr b/tests/ui/double_parens.stderr new file mode 100644 index 00000000000..ba778c656ee --- /dev/null +++ b/tests/ui/double_parens.stderr @@ -0,0 +1,38 @@ +error: Consider removing unnecessary double parentheses + --> $DIR/double_parens.rs:16:5 + | +16 | ((0)) //~ERROR Consider removing unnecessary double parentheses + | ^^^^^ + | +note: lint level defined here + --> $DIR/double_parens.rs:4:9 + | +4 | #![deny(double_parens)] + | ^^^^^^^^^^^^^ + +error: Consider removing unnecessary double parentheses + --> $DIR/double_parens.rs:20:14 + | +20 | dummy_fn((0)); //~ERROR Consider removing unnecessary double parentheses + | ^^^ + +error: Consider removing unnecessary double parentheses + --> $DIR/double_parens.rs:24:20 + | +24 | x.dummy_method((0)); //~ERROR Consider removing unnecessary double parentheses + | ^^^ + +error: Consider removing unnecessary double parentheses + --> $DIR/double_parens.rs:28:5 + | +28 | ((1, 2)) //~ERROR Consider removing unnecessary double parentheses + | ^^^^^^^^ + +error: Consider removing unnecessary double parentheses + --> $DIR/double_parens.rs:32:5 + | +32 | (()) //~ERROR Consider removing unnecessary double parentheses + | ^^^^ + +error: aborting due to 5 previous errors + diff --git a/tests/compile-fail/drop_forget_ref.rs b/tests/ui/drop_forget_ref.rs similarity index 100% rename from tests/compile-fail/drop_forget_ref.rs rename to tests/ui/drop_forget_ref.rs diff --git a/tests/ui/drop_forget_ref.stderr b/tests/ui/drop_forget_ref.stderr new file mode 100644 index 00000000000..346426b7231 --- /dev/null +++ b/tests/ui/drop_forget_ref.stderr @@ -0,0 +1,228 @@ +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:12:5 + | +12 | drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/drop_forget_ref.rs:4:9 + | +4 | #![deny(drop_ref, forget_ref)] + | ^^^^^^^^ +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:12:10 + | +12 | drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:13:5 + | +13 | forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/drop_forget_ref.rs:4:19 + | +4 | #![deny(drop_ref, forget_ref)] + | ^^^^^^^^^^ +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:13:12 + | +13 | forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^ + +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:16:5 + | +16 | drop(&owned1); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^^^ + | +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:16:10 + | +16 | drop(&owned1); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^ + +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:17:5 + | +17 | drop(&&owned1); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^^^^ + | +note: argument has type &&SomeStruct + --> $DIR/drop_forget_ref.rs:17:10 + | +17 | drop(&&owned1); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^ + +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:18:5 + | +18 | drop(&mut owned1); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^^^^^^^ + | +note: argument has type &mut SomeStruct + --> $DIR/drop_forget_ref.rs:18:10 + | +18 | drop(&mut owned1); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:21:5 + | +21 | forget(&owned2); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^^^^ + | +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:21:12 + | +21 | forget(&owned2); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:22:5 + | +22 | forget(&&owned2); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^^^^^ + | +note: argument has type &&SomeStruct + --> $DIR/drop_forget_ref.rs:22:12 + | +22 | forget(&&owned2); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:23:5 + | +23 | forget(&mut owned2); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^^^^^^^^ + | +note: argument has type &mut SomeStruct + --> $DIR/drop_forget_ref.rs:23:12 + | +23 | forget(&mut owned2); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^ + +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:27:5 + | +27 | drop(reference1); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^^^^^^ + | +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:27:10 + | +27 | drop(reference1); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:28:5 + | +28 | forget(&*reference1); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:28:12 + | +28 | forget(&*reference1); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^ + +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:31:5 + | +31 | drop(reference2); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^^^^^^ + | +note: argument has type &mut SomeStruct + --> $DIR/drop_forget_ref.rs:31:10 + | +31 | drop(reference2); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:33:5 + | +33 | forget(reference3); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^^^^^^^ + | +note: argument has type &mut SomeStruct + --> $DIR/drop_forget_ref.rs:33:12 + | +33 | forget(reference3); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^ + +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:36:5 + | +36 | drop(reference4); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^^^^^^ + | +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:36:10 + | +36 | drop(reference4); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:37:5 + | +37 | forget(reference4); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^^^^^^^ + | +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:37:12 + | +37 | forget(reference4); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^ + +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:42:5 + | +42 | drop(&val); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^ + | +note: argument has type &T + --> $DIR/drop_forget_ref.rs:42:10 + | +42 | drop(&val); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:48:5 + | +48 | forget(&val); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^ + | +note: argument has type &T + --> $DIR/drop_forget_ref.rs:48:12 + | +48 | forget(&val); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^ + +error: call to `std::mem::drop` with a reference argument. Dropping a reference does nothing + --> $DIR/drop_forget_ref.rs:56:5 + | +56 | std::mem::drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:56:20 + | +56 | std::mem::drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument + | ^^^^^^^^^^^ + +error: call to `std::mem::forget` with a reference argument. Forgetting a reference does nothing + --> $DIR/drop_forget_ref.rs:59:5 + | +59 | std::mem::forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type &SomeStruct + --> $DIR/drop_forget_ref.rs:59:22 + | +59 | std::mem::forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument + | ^^^^^^^^^^^ + +error: aborting due to 18 previous errors + diff --git a/tests/compile-fail/duplicate_underscore_argument.rs b/tests/ui/duplicate_underscore_argument.rs similarity index 100% rename from tests/compile-fail/duplicate_underscore_argument.rs rename to tests/ui/duplicate_underscore_argument.rs diff --git a/tests/ui/duplicate_underscore_argument.stderr b/tests/ui/duplicate_underscore_argument.stderr new file mode 100644 index 00000000000..0550aaae566 --- /dev/null +++ b/tests/ui/duplicate_underscore_argument.stderr @@ -0,0 +1,14 @@ +error: `darth` already exists, having another argument having almost the same name makes code comprehension and documentation more difficult + --> $DIR/duplicate_underscore_argument.rs:7:23 + | +7 | fn join_the_dark_side(darth: i32, _darth: i32) {} //~ERROR `darth` already exists + | ^^^^^ + | +note: lint level defined here + --> $DIR/duplicate_underscore_argument.rs:4:9 + | +4 | #![deny(duplicate_underscore_argument)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/empty_enum.rs b/tests/ui/empty_enum.rs similarity index 100% rename from tests/compile-fail/empty_enum.rs rename to tests/ui/empty_enum.rs diff --git a/tests/ui/empty_enum.stderr b/tests/ui/empty_enum.stderr new file mode 100644 index 00000000000..93aeb2ddb9a --- /dev/null +++ b/tests/ui/empty_enum.stderr @@ -0,0 +1,19 @@ +error: enum with no variants + --> $DIR/empty_enum.rs:7:1 + | +7 | enum Empty {} //~ ERROR enum with no variants + | ^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/empty_enum.rs:5:9 + | +5 | #![deny(empty_enum)] + | ^^^^^^^^^^ +help: consider using the uninhabited type `!` or a wrapper around it + --> $DIR/empty_enum.rs:7:1 + | +7 | enum Empty {} //~ ERROR enum with no variants + | ^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/entry.rs b/tests/ui/entry.rs similarity index 100% rename from tests/compile-fail/entry.rs rename to tests/ui/entry.rs diff --git a/tests/ui/entry.stderr b/tests/ui/entry.stderr new file mode 100644 index 00000000000..b4e09d2671b --- /dev/null +++ b/tests/ui/entry.stderr @@ -0,0 +1,70 @@ +error: usage of `contains_key` followed by `insert` on a `HashMap` + --> $DIR/entry.rs:13:5 + | +13 | if !m.contains_key(&k) { m.insert(k, v); } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/entry.rs:5:9 + | +5 | #![deny(map_entry)] + | ^^^^^^^^^ +help: consider using + | m.entry(k).or_insert(v) + +error: usage of `contains_key` followed by `insert` on a `HashMap` + --> $DIR/entry.rs:20:5 + | +20 | if !m.contains_key(&k) { foo(); m.insert(k, v); } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using + | m.entry(k) + +error: usage of `contains_key` followed by `insert` on a `HashMap` + --> $DIR/entry.rs:27:5 + | +27 | if !m.contains_key(&k) { m.insert(k, v) } else { None }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using + | m.entry(k); + +error: usage of `contains_key` followed by `insert` on a `HashMap` + --> $DIR/entry.rs:34:5 + | +34 | if m.contains_key(&k) { None } else { m.insert(k, v) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using + | m.entry(k); + +error: usage of `contains_key` followed by `insert` on a `HashMap` + --> $DIR/entry.rs:41:5 + | +41 | if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using + | m.entry(k); + +error: usage of `contains_key` followed by `insert` on a `HashMap` + --> $DIR/entry.rs:48:5 + | +48 | if m.contains_key(&k) { None } else { foo(); m.insert(k, v) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using + | m.entry(k); + +error: usage of `contains_key` followed by `insert` on a `BTreeMap` + --> $DIR/entry.rs:55:5 + | +55 | if !m.contains_key(&k) { foo(); m.insert(k, v) } else { None }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using + | m.entry(k); + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/enum_glob_use.rs b/tests/ui/enum_glob_use.rs similarity index 100% rename from tests/compile-fail/enum_glob_use.rs rename to tests/ui/enum_glob_use.rs diff --git a/tests/ui/enum_glob_use.stderr b/tests/ui/enum_glob_use.stderr new file mode 100644 index 00000000000..e109269dc2f --- /dev/null +++ b/tests/ui/enum_glob_use.stderr @@ -0,0 +1,23 @@ +error: don't use glob imports for enum variants + --> $DIR/enum_glob_use.rs:6:1 + | +6 | use std::cmp::Ordering::*; //~ ERROR: don't use glob imports for enum variants + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_glob_use)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/enum_glob_use.rs:3:17 + | +3 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ + +error: don't use glob imports for enum variants + --> $DIR/enum_glob_use.rs:12:1 + | +12 | use self::Enum::*; //~ ERROR: don't use glob imports for enum variants + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_glob_use)] implied by #[deny(clippy_pedantic)] + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/enum_variants.rs b/tests/ui/enum_variants.rs similarity index 100% rename from tests/compile-fail/enum_variants.rs rename to tests/ui/enum_variants.rs diff --git a/tests/ui/enum_variants.stderr b/tests/ui/enum_variants.stderr new file mode 100644 index 00000000000..115fe8ea226 --- /dev/null +++ b/tests/ui/enum_variants.stderr @@ -0,0 +1,127 @@ +error: Variant name ends with the enum's name + --> $DIR/enum_variants.rs:14:5 + | +14 | cFoo, //~ ERROR: Variant name ends with the enum's name + | ^^^^ + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/enum_variants.rs:3:9 + | +3 | #![deny(clippy, pub_enum_variant_names)] + | ^^^^^^ + +error: Variant name starts with the enum's name + --> $DIR/enum_variants.rs:25:5 + | +25 | FoodGood, //~ ERROR: Variant name starts with the enum's name + | ^^^^^^^^ + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] + +error: Variant name starts with the enum's name + --> $DIR/enum_variants.rs:26:5 + | +26 | FoodMiddle, //~ ERROR: Variant name starts with the enum's name + | ^^^^^^^^^^ + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] + +error: Variant name starts with the enum's name + --> $DIR/enum_variants.rs:27:5 + | +27 | FoodBad, //~ ERROR: Variant name starts with the enum's name + | ^^^^^^^ + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] + +error: All variants have the same prefix: `Food` + --> $DIR/enum_variants.rs:24:1 + | +24 | enum Food { //~ ERROR: All variants have the same prefix: `Food` + | _^ starting here... +25 | | FoodGood, //~ ERROR: Variant name starts with the enum's name +26 | | FoodMiddle, //~ ERROR: Variant name starts with the enum's name +27 | | FoodBad, //~ ERROR: Variant name starts with the enum's name +28 | | } + | |_^ ...ending here + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] + = help: remove the prefixes and use full paths to the variants instead of glob imports + +error: All variants have the same prefix: `CallType` + --> $DIR/enum_variants.rs:34:1 + | +34 | enum BadCallType { //~ ERROR: All variants have the same prefix: `CallType` + | _^ starting here... +35 | | CallTypeCall, +36 | | CallTypeCreate, +37 | | CallTypeDestroy, +38 | | } + | |_^ ...ending here + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] + = help: remove the prefixes and use full paths to the variants instead of glob imports + +error: All variants have the same prefix: `Constant` + --> $DIR/enum_variants.rs:45:1 + | +45 | enum Consts { //~ ERROR: All variants have the same prefix: `Constant` + | _^ starting here... +46 | | ConstantInt, +47 | | ConstantCake, +48 | | ConstantLie, +49 | | } + | |_^ ...ending here + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] + = help: remove the prefixes and use full paths to the variants instead of glob imports + +error: All variants have the same prefix: `With` + --> $DIR/enum_variants.rs:78:1 + | +78 | enum Seallll { //~ ERROR: All variants have the same prefix: `With` + | _^ starting here... +79 | | WithOutCake, +80 | | WithOutTea, +81 | | WithOut, +82 | | } + | |_^ ...ending here + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] + = help: remove the prefixes and use full paths to the variants instead of glob imports + +error: All variants have the same prefix: `Prefix` + --> $DIR/enum_variants.rs:84:1 + | +84 | enum NonCaps { //~ ERROR: All variants have the same prefix: `Prefix` + | _^ starting here... +85 | | Prefix的, +86 | | PrefixTea, +87 | | PrefixCake, +88 | | } + | |_^ ...ending here + | + = note: #[deny(enum_variant_names)] implied by #[deny(clippy)] + = help: remove the prefixes and use full paths to the variants instead of glob imports + +error: All variants have the same prefix: `With` + --> $DIR/enum_variants.rs:90:1 + | +90 | pub enum PubSeall { //~ ERROR: All variants have the same prefix: + | _^ starting here... +91 | | WithOutCake, +92 | | WithOutTea, +93 | | WithOut, +94 | | } + | |_^ ...ending here + | +note: lint level defined here + --> $DIR/enum_variants.rs:3:17 + | +3 | #![deny(clippy, pub_enum_variant_names)] + | ^^^^^^^^^^^^^^^^^^^^^^ + = help: remove the prefixes and use full paths to the variants instead of glob imports + +error: aborting due to 10 previous errors + diff --git a/tests/compile-fail/enums_clike.rs b/tests/ui/enums_clike.rs similarity index 100% rename from tests/compile-fail/enums_clike.rs rename to tests/ui/enums_clike.rs diff --git a/tests/ui/enums_clike.stderr b/tests/ui/enums_clike.stderr new file mode 100644 index 00000000000..a3b7ba411df --- /dev/null +++ b/tests/ui/enums_clike.stderr @@ -0,0 +1,71 @@ +error: Clike enum variant discriminant is not portable to 32-bit targets + --> $DIR/enums_clike.rs:10:5 + | +10 | X = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/enums_clike.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + +error: Clike enum variant discriminant is not portable to 32-bit targets + --> $DIR/enums_clike.rs:17:5 + | +17 | X = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)] + +error: Clike enum variant discriminant is not portable to 32-bit targets + --> $DIR/enums_clike.rs:20:5 + | +20 | A = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets + | ^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)] + +error: Clike enum variant discriminant is not portable to 32-bit targets + --> $DIR/enums_clike.rs:27:5 + | +27 | Z = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets + | ^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)] + +error: Clike enum variant discriminant is not portable to 32-bit targets + --> $DIR/enums_clike.rs:28:5 + | +28 | A = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)] + +error: Clike enum variant discriminant is not portable to 32-bit targets + --> $DIR/enums_clike.rs:30:5 + | +30 | C = (std::i32::MIN as isize) - 1, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)] + +error: Clike enum variant discriminant is not portable to 32-bit targets + --> $DIR/enums_clike.rs:36:5 + | +36 | Z = 0xFFFF_FFFF, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets + | ^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)] + +error: Clike enum variant discriminant is not portable to 32-bit targets + --> $DIR/enums_clike.rs:37:5 + | +37 | A = 0x1_0000_0000, //~ ERROR: Clike enum variant discriminant is not portable to 32-bit targets + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(enum_clike_unportable_variant)] implied by #[deny(clippy)] + +error: aborting due to 8 previous errors + diff --git a/tests/compile-fail/eq_op.rs b/tests/ui/eq_op.rs similarity index 100% rename from tests/compile-fail/eq_op.rs rename to tests/ui/eq_op.rs diff --git a/tests/ui/eq_op.stderr b/tests/ui/eq_op.stderr new file mode 100644 index 00000000000..867156f6c59 --- /dev/null +++ b/tests/ui/eq_op.stderr @@ -0,0 +1,223 @@ +error: this boolean expression can be simplified + --> $DIR/eq_op.rs:41:5 + | +41 | true && true; //~ERROR equal expressions + | ^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/eq_op.rs:7:8 + | +7 | #[deny(nonminimal_bool)] + | ^^^^^^^^^^^^^^^ +help: try + | true; //~ERROR equal expressions + +error: this boolean expression can be simplified + --> $DIR/eq_op.rs:43:5 + | +43 | true || true; //~ERROR equal expressions + | ^^^^^^^^^^^^ + | +help: try + | true; //~ERROR equal expressions + +error: this boolean expression can be simplified + --> $DIR/eq_op.rs:49:5 + | +49 | a == b && b == a; //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^ + | +help: try + | a == b; //~ERROR equal expressions + +error: this boolean expression can be simplified + --> $DIR/eq_op.rs:51:5 + | +51 | a != b && b != a; //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^ + | +help: try + | a != b; //~ERROR equal expressions + +error: this boolean expression can be simplified + --> $DIR/eq_op.rs:53:5 + | +53 | a < b && b > a; //~ERROR equal expressions + | ^^^^^^^^^^^^^^ + | +help: try + | a < b; //~ERROR equal expressions + +error: this boolean expression can be simplified + --> $DIR/eq_op.rs:55:5 + | +55 | a <= b && b >= a; //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^ + | +help: try + | a <= b; //~ERROR equal expressions + +error: equal expressions as operands to `==` + --> $DIR/eq_op.rs:10:5 + | +10 | 1 == 1; //~ERROR equal expressions + | ^^^^^^ + | +note: lint level defined here + --> $DIR/eq_op.rs:4:8 + | +4 | #[deny(eq_op)] + | ^^^^^ + +error: equal expressions as operands to `==` + --> $DIR/eq_op.rs:11:5 + | +11 | "no" == "no"; //~ERROR equal expressions + | ^^^^^^^^^^^^ + +error: equal expressions as operands to `!=` + --> $DIR/eq_op.rs:13:5 + | +13 | false != false; //~ERROR equal expressions + | ^^^^^^^^^^^^^^ + +error: equal expressions as operands to `<` + --> $DIR/eq_op.rs:14:5 + | +14 | 1.5 < 1.5; //~ERROR equal expressions + | ^^^^^^^^^ + +error: equal expressions as operands to `>=` + --> $DIR/eq_op.rs:15:5 + | +15 | 1u64 >= 1u64; //~ERROR equal expressions + | ^^^^^^^^^^^^ + +error: equal expressions as operands to `&` + --> $DIR/eq_op.rs:18:5 + | +18 | (1 as u64) & (1 as u64); //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `^` + --> $DIR/eq_op.rs:19:5 + | +19 | 1 ^ ((((((1)))))); //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `<` + --> $DIR/eq_op.rs:22:5 + | +22 | (-(2) < -(2)); //~ERROR equal expressions + | ^^^^^^^^^^^^^ + +error: equal expressions as operands to `==` + --> $DIR/eq_op.rs:23:5 + | +23 | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `&` + --> $DIR/eq_op.rs:23:6 + | +23 | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); + | ^^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `&` + --> $DIR/eq_op.rs:23:27 + | +23 | ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); + | ^^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `==` + --> $DIR/eq_op.rs:27:5 + | +27 | (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `!=` + --> $DIR/eq_op.rs:30:5 + | +30 | ([1] != [1]); //~ERROR equal expressions + | ^^^^^^^^^^^^ + +error: equal expressions as operands to `!=` + --> $DIR/eq_op.rs:31:5 + | +31 | ((1, 2) != (1, 2)); //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `==` + --> $DIR/eq_op.rs:35:5 + | +35 | 1 + 1 == 2; //~ERROR equal expressions + | ^^^^^^^^^^ + +error: equal expressions as operands to `==` + --> $DIR/eq_op.rs:36:5 + | +36 | 1 - 1 == 0; //~ERROR equal expressions as operands to `==` + | ^^^^^^^^^^ + +error: equal expressions as operands to `-` + --> $DIR/eq_op.rs:36:5 + | +36 | 1 - 1 == 0; //~ERROR equal expressions as operands to `==` + | ^^^^^ + +error: equal expressions as operands to `-` + --> $DIR/eq_op.rs:39:5 + | +39 | 1 - 1; //~ERROR equal expressions + | ^^^^^ + +error: equal expressions as operands to `/` + --> $DIR/eq_op.rs:40:5 + | +40 | 1 / 1; //~ERROR equal expressions + | ^^^^^ + +error: equal expressions as operands to `&&` + --> $DIR/eq_op.rs:41:5 + | +41 | true && true; //~ERROR equal expressions + | ^^^^^^^^^^^^ + +error: equal expressions as operands to `||` + --> $DIR/eq_op.rs:43:5 + | +43 | true || true; //~ERROR equal expressions + | ^^^^^^^^^^^^ + +error: equal expressions as operands to `&&` + --> $DIR/eq_op.rs:49:5 + | +49 | a == b && b == a; //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `&&` + --> $DIR/eq_op.rs:51:5 + | +51 | a != b && b != a; //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `&&` + --> $DIR/eq_op.rs:53:5 + | +53 | a < b && b > a; //~ERROR equal expressions + | ^^^^^^^^^^^^^^ + +error: equal expressions as operands to `&&` + --> $DIR/eq_op.rs:55:5 + | +55 | a <= b && b >= a; //~ERROR equal expressions + | ^^^^^^^^^^^^^^^^ + +error: equal expressions as operands to `==` + --> $DIR/eq_op.rs:59:5 + | +59 | a == a; //~ERROR equal expressions + | ^^^^^^ + +error: aborting due to 32 previous errors + diff --git a/tests/compile-fail/escape_analysis.rs b/tests/ui/escape_analysis.rs similarity index 100% rename from tests/compile-fail/escape_analysis.rs rename to tests/ui/escape_analysis.rs diff --git a/tests/ui/escape_analysis.stderr b/tests/ui/escape_analysis.stderr new file mode 100644 index 00000000000..f05f1b32dcf --- /dev/null +++ b/tests/ui/escape_analysis.stderr @@ -0,0 +1,56 @@ +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:33:9 + | +33 | let x = box A; //~ ERROR local variable + | ^ + | +note: lint level defined here + --> $DIR/escape_analysis.rs:5:9 + | +5 | #![deny(boxed_local)] + | ^^^^^^^^^^^ + +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:37:13 + | +37 | fn warn_arg(x: Box) { //~ ERROR local variable + | ^ + +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:49:9 + | +49 | let y = x; //~ ERROR local variable + | ^ + +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:54:9 + | +54 | let bz = box A; //~ ERROR local variable + | ^^ + +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:58:9 + | +58 | let bz = box A; //~ ERROR local variable + | ^^ + +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:88:9 + | +88 | let x = box A; //~ ERROR local variable + | ^ + +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:101:9 + | +101 | let x = box A; //~ ERROR local variable + | ^ + +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:130:12 + | +130 | pub fn new(_needs_name: Box>) -> () { //~ ERROR local variable doesn't need + | ^^^^^^^^^^^ + +error: aborting due to 8 previous errors + diff --git a/tests/compile-fail/eta.rs b/tests/ui/eta.rs similarity index 100% rename from tests/compile-fail/eta.rs rename to tests/ui/eta.rs diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr new file mode 100644 index 00000000000..4683ae2708f --- /dev/null +++ b/tests/ui/eta.stderr @@ -0,0 +1,51 @@ +error: redundant closure found + --> $DIR/eta.rs:7:27 + | +7 | let a = Some(1u8).map(|a| foo(a)); + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/eta.rs:4:9 + | +4 | #![deny(redundant_closure)] + | ^^^^^^^^^^^^^^^^^ +help: remove closure as shown: + | let a = Some(1u8).map(foo); + +error: redundant closure found + --> $DIR/eta.rs:11:10 + | +11 | meta(|a| foo(a)); + | ^^^^^^^^^^ + | +help: remove closure as shown: + | meta(foo); + +error: redundant closure found + --> $DIR/eta.rs:15:27 + | +15 | let c = Some(1u8).map(|a| {1+2; foo}(a)); + | ^^^^^^^^^^^^^^^^^ + | +help: remove closure as shown: + | let c = Some(1u8).map({1+2; foo}); + +warning: this expression borrows a reference that is immediately dereferenced by the compiler + --> $DIR/eta.rs:20:21 + | +20 | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted + | ^^^ + | + = note: #[warn(needless_borrow)] on by default + +error: redundant closure found + --> $DIR/eta.rs:28:27 + | +28 | let e = Some(1u8).map(|a| generic(a)); + | ^^^^^^^^^^^^^^ + | +help: remove closure as shown: + | let e = Some(1u8).map(generic); + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/eval_order_dependence.rs b/tests/ui/eval_order_dependence.rs similarity index 100% rename from tests/compile-fail/eval_order_dependence.rs rename to tests/ui/eval_order_dependence.rs diff --git a/tests/ui/eval_order_dependence.stderr b/tests/ui/eval_order_dependence.stderr new file mode 100644 index 00000000000..d47e96862c2 --- /dev/null +++ b/tests/ui/eval_order_dependence.stderr @@ -0,0 +1,55 @@ +error: unsequenced read of a variable + --> $DIR/eval_order_dependence.rs:8:28 + | +8 | let a = { x = 1; 1 } + x; + | ^ + | +note: lint level defined here + --> $DIR/eval_order_dependence.rs:4:8 + | +4 | #[deny(eval_order_dependence)] + | ^^^^^^^^^^^^^^^^^^^^^ +note: whether read occurs before this write depends on evaluation order + --> $DIR/eval_order_dependence.rs:8:15 + | +8 | let a = { x = 1; 1 } + x; + | ^^^^^ + +error: unsequenced read of a variable + --> $DIR/eval_order_dependence.rs:12:5 + | +12 | x += { x = 20; 2 }; //~ERROR unsequenced read + | ^ + | +note: whether read occurs before this write depends on evaluation order + --> $DIR/eval_order_dependence.rs:12:12 + | +12 | x += { x = 20; 2 }; //~ERROR unsequenced read + | ^^^^^^ + +error: unsequenced read of a variable + --> $DIR/eval_order_dependence.rs:18:24 + | +18 | let foo = Foo { a: x, .. { x = 6; base } }; + | ^ + | +note: whether read occurs before this write depends on evaluation order + --> $DIR/eval_order_dependence.rs:18:32 + | +18 | let foo = Foo { a: x, .. { x = 6; base } }; + | ^^^^^ + +error: unsequenced read of a variable + --> $DIR/eval_order_dependence.rs:23:9 + | +23 | x += { x = 20; 2 }; //~ERROR unsequenced read + | ^ + | +note: whether read occurs before this write depends on evaluation order + --> $DIR/eval_order_dependence.rs:23:16 + | +23 | x += { x = 20; 2 }; //~ERROR unsequenced read + | ^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/filter_methods.rs b/tests/ui/filter_methods.rs similarity index 100% rename from tests/compile-fail/filter_methods.rs rename to tests/ui/filter_methods.rs diff --git a/tests/ui/filter_methods.stderr b/tests/ui/filter_methods.stderr new file mode 100644 index 00000000000..495e385d03c --- /dev/null +++ b/tests/ui/filter_methods.stderr @@ -0,0 +1,51 @@ +error: called `filter(p).map(q)` on an `Iterator`. This is more succinctly expressed by calling `.filter_map(..)` instead. + --> $DIR/filter_methods.rs:8:21 + | +8 | let _: Vec<_> = vec![5; 6].into_iter() //~ERROR called `filter(p).map(q)` on an `Iterator` + | _____________________^ starting here... +9 | | .filter(|&x| x == 0) +10 | | .map(|x| x * 2) + | |_____________________________________________^ ...ending here + | + = note: #[deny(filter_map)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/filter_methods.rs:4:17 + | +4 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ + +error: called `filter(p).flat_map(q)` on an `Iterator`. This is more succinctly expressed by calling `.flat_map(..)` and filtering by returning an empty Iterator. + --> $DIR/filter_methods.rs:13:21 + | +13 | let _: Vec<_> = vec![5_i8; 6].into_iter() //~ERROR called `filter(p).flat_map(q)` on an `Iterator` + | _____________________^ starting here... +14 | | .filter(|&x| x == 0) +15 | | .flat_map(|x| x.checked_mul(2)) + | |_______________________________________________________________^ ...ending here + | + = note: #[deny(filter_map)] implied by #[deny(clippy_pedantic)] + +error: called `filter_map(p).flat_map(q)` on an `Iterator`. This is more succinctly expressed by calling `.flat_map(..)` and filtering by returning an empty Iterator. + --> $DIR/filter_methods.rs:18:21 + | +18 | let _: Vec<_> = vec![5_i8; 6].into_iter() //~ERROR called `filter_map(p).flat_map(q)` on an `Iterator` + | _____________________^ starting here... +19 | | .filter_map(|x| x.checked_mul(2)) +20 | | .flat_map(|x| x.checked_mul(2)) + | |_______________________________________________________________^ ...ending here + | + = note: #[deny(filter_map)] implied by #[deny(clippy_pedantic)] + +error: called `filter_map(p).map(q)` on an `Iterator`. This is more succinctly expressed by only calling `.filter_map(..)` instead. + --> $DIR/filter_methods.rs:23:21 + | +23 | let _: Vec<_> = vec![5_i8; 6].into_iter() //~ERROR called `filter_map(p).map(q)` on an `Iterator` + | _____________________^ starting here... +24 | | .filter_map(|x| x.checked_mul(2)) +25 | | .map(|x| x.checked_mul(2)) + | |__________________________________________________________^ ...ending here + | + = note: #[deny(filter_map)] implied by #[deny(clippy_pedantic)] + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/float_cmp.rs b/tests/ui/float_cmp.rs similarity index 100% rename from tests/compile-fail/float_cmp.rs rename to tests/ui/float_cmp.rs diff --git a/tests/ui/float_cmp.stderr b/tests/ui/float_cmp.stderr new file mode 100644 index 00000000000..8c6abadadec --- /dev/null +++ b/tests/ui/float_cmp.stderr @@ -0,0 +1,119 @@ +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:43:5 + | +43 | ONE == 1f32; + | ^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/float_cmp.rs:4:9 + | +4 | #![deny(float_cmp)] + | ^^^^^^^^^ +help: consider comparing them within some error + | (ONE - 1f32).abs() < error; +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:43:5 + | +43 | ONE == 1f32; + | ^^^^^^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:47:5 + | +47 | ONE == 1.0 + 0.0; + | ^^^^^^^^^^^^^^^^ + | +help: consider comparing them within some error + | (ONE - (1.0 + 0.0)).abs() < error; +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:47:5 + | +47 | ONE == 1.0 + 0.0; + | ^^^^^^^^^^^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:52:5 + | +52 | ONE + ONE == ZERO + ONE + ONE; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider comparing them within some error + | (ONE + ONE - (ZERO + ONE + ONE)).abs() < error; +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:52:5 + | +52 | ONE + ONE == ZERO + ONE + ONE; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:57:5 + | +57 | ONE != 2.0; + | ^^^^^^^^^^ + | +help: consider comparing them within some error + | (ONE - 2.0).abs() < error; +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:57:5 + | +57 | ONE != 2.0; + | ^^^^^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:62:5 + | +62 | twice(ONE) != ONE; + | ^^^^^^^^^^^^^^^^^ + | +help: consider comparing them within some error + | (twice(ONE) - ONE).abs() < error; +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:62:5 + | +62 | twice(ONE) != ONE; + | ^^^^^^^^^^^^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:66:5 + | +66 | ONE as f64 != 2.0; + | ^^^^^^^^^^^^^^^^^ + | +help: consider comparing them within some error + | (ONE as f64 - 2.0).abs() < error; +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:66:5 + | +66 | ONE as f64 != 2.0; + | ^^^^^^^^^^^^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:74:5 + | +74 | x == 1.0; + | ^^^^^^^^ + | +help: consider comparing them within some error + | (x - 1.0).abs() < error; +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:74:5 + | +74 | x == 1.0; + | ^^^^^^^^ + +error: strict comparison of f32 or f64 + --> $DIR/float_cmp.rs:80:5 + | +80 | twice(x) != twice(ONE as f64); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider comparing them within some error + | (twice(x) - twice(ONE as f64)).abs() < error; +note: std::f32::EPSILON and std::f64::EPSILON are available. + --> $DIR/float_cmp.rs:80:5 + | +80 | twice(x) != twice(ONE as f64); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 8 previous errors + diff --git a/tests/compile-fail/for_loop.rs b/tests/ui/for_loop.rs similarity index 100% rename from tests/compile-fail/for_loop.rs rename to tests/ui/for_loop.rs diff --git a/tests/ui/for_loop.stderr b/tests/ui/for_loop.stderr new file mode 100644 index 00000000000..2e73a343817 --- /dev/null +++ b/tests/ui/for_loop.stderr @@ -0,0 +1,632 @@ +error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement. + --> $DIR/for_loop.rs:18:14 + | +18 | for x in option { + | ^^^^^^ + | + = note: #[deny(for_loop_over_option)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/for_loop.rs:10:8 + | +10 | #[deny(clippy)] + | ^^^^^^ + = help: consider replacing `for x in option` with `if let Some(x) = option` + +error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement. + --> $DIR/for_loop.rs:26:14 + | +26 | for x in result { + | ^^^^^^ + | + = note: #[deny(for_loop_over_result)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/for_loop.rs:10:8 + | +10 | #[deny(clippy)] + | ^^^^^^ + = help: consider replacing `for x in result` with `if let Ok(x) = result` + +error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement. + --> $DIR/for_loop.rs:32:14 + | +32 | for x in option.ok_or("x not found") { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(for_loop_over_result)] implied by #[deny(clippy)] + = help: consider replacing `for x in option.ok_or("x not found")` with `if let Ok(x) = option.ok_or("x not found")` + +error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want + --> $DIR/for_loop.rs:40:5 + | +40 | for x in v.iter().next() { + | _____^ starting here... +41 | | //~^ ERROR you are iterating over `Iterator::next()` which is an Option +42 | | println!("{}", x); +43 | | } + | |_____^ ...ending here + | + = note: #[deny(iter_next_loop)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/for_loop.rs:10:8 + | +10 | #[deny(clippy)] + | ^^^^^^ + +error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement. + --> $DIR/for_loop.rs:47:14 + | +47 | for x in v.iter().next().and(Some(0)) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(for_loop_over_option)] implied by #[deny(clippy)] + = help: consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))` + +error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement. + --> $DIR/for_loop.rs:53:14 + | +53 | for x in v.iter().next().ok_or("x not found") { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(for_loop_over_result)] implied by #[deny(clippy)] + = help: consider replacing `for x in v.iter().next().ok_or("x not found")` with `if let Ok(x) = v.iter().next().ok_or("x not found")` + +error: the loop variable `i` is only used to index `vec`. + --> $DIR/for_loop.rs:99:5 + | +99 | for i in 0..vec.len() { + | _____^ starting here... +100 | | //~^ ERROR `i` is only used to index `vec` +101 | | //~| HELP consider +102 | | //~| HELP consider +103 | | //~| SUGGESTION for in &vec { +104 | | println!("{}", vec[i]); +105 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/for_loop.rs:90:8 + | +90 | #[deny(needless_range_loop, explicit_iter_loop, explicit_into_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop, for_kv_map)] + | ^^^^^^^^^^^^^^^^^^^ +help: consider using an iterator + | for in &vec { + +warning: unused variable: `i` + --> $DIR/for_loop.rs:107:9 + | +107 | for i in 0..vec.len() { + | ^ + | + = note: #[warn(unused_variables)] on by default + +error: the loop variable `i` is only used to index `vec`. + --> $DIR/for_loop.rs:113:5 + | +113 | for i in 0..vec.len() { let _ = vec[i]; } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using an iterator + | for in &vec { let _ = vec[i]; } + +error: the loop variable `j` is only used to index `STATIC`. + --> $DIR/for_loop.rs:120:5 + | +120 | for j in 0..4 { + | _____^ starting here... +121 | | //~^ ERROR `j` is only used to index `STATIC` +122 | | //~| HELP consider +123 | | //~| HELP consider +124 | | //~| SUGGESTION for in STATIC.iter().take(4) { +125 | | println!("{:?}", STATIC[j]); +126 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for in STATIC.iter().take(4) { + +error: the loop variable `j` is only used to index `CONST`. + --> $DIR/for_loop.rs:128:5 + | +128 | for j in 0..4 { + | _____^ starting here... +129 | | //~^ ERROR `j` is only used to index `CONST` +130 | | //~| HELP consider +131 | | //~| HELP consider +132 | | //~| SUGGESTION for in CONST.iter().take(4) { +133 | | println!("{:?}", CONST[j]); +134 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for in CONST.iter().take(4) { + +error: the loop variable `i` is used to index `vec` + --> $DIR/for_loop.rs:136:5 + | +136 | for i in 0..vec.len() { + | _____^ starting here... +137 | | //~^ ERROR `i` is used to index `vec` +138 | | //~| HELP consider +139 | | //~| HELP consider +140 | | //~| SUGGESTION for (i, ) in vec.iter().enumerate() { +141 | | println!("{} {}", vec[i], i); +142 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for (i, ) in vec.iter().enumerate() { + +error: the loop variable `i` is only used to index `vec2`. + --> $DIR/for_loop.rs:147:5 + | +147 | for i in 0..vec.len() { + | _____^ starting here... +148 | | //~^ ERROR `i` is only used to index `vec2` +149 | | //~| HELP consider +150 | | //~| HELP consider +151 | | //~| SUGGESTION for in vec2.iter().take(vec.len()) { +152 | | println!("{}", vec2[i]); +153 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for in vec2.iter().take(vec.len()) { + +error: the loop variable `i` is only used to index `vec`. + --> $DIR/for_loop.rs:155:5 + | +155 | for i in 5..vec.len() { + | _____^ starting here... +156 | | //~^ ERROR `i` is only used to index `vec` +157 | | //~| HELP consider +158 | | //~| HELP consider +159 | | //~| SUGGESTION for in vec.iter().skip(5) { +160 | | println!("{}", vec[i]); +161 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for in vec.iter().skip(5) { + +error: the loop variable `i` is only used to index `vec`. + --> $DIR/for_loop.rs:163:5 + | +163 | for i in 0..MAX_LEN { + | _____^ starting here... +164 | | //~^ ERROR `i` is only used to index `vec` +165 | | //~| HELP consider +166 | | //~| HELP consider +167 | | //~| SUGGESTION for in vec.iter().take(MAX_LEN) { +168 | | println!("{}", vec[i]); +169 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for in vec.iter().take(MAX_LEN) { + +error: the loop variable `i` is only used to index `vec`. + --> $DIR/for_loop.rs:171:5 + | +171 | for i in 0...MAX_LEN { + | _____^ starting here... +172 | | //~^ ERROR `i` is only used to index `vec` +173 | | //~| HELP consider +174 | | //~| HELP consider +175 | | //~| SUGGESTION for in vec.iter().take(MAX_LEN + 1) { +176 | | println!("{}", vec[i]); +177 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for in vec.iter().take(MAX_LEN + 1) { + +error: the loop variable `i` is only used to index `vec`. + --> $DIR/for_loop.rs:179:5 + | +179 | for i in 5..10 { + | _____^ starting here... +180 | | //~^ ERROR `i` is only used to index `vec` +181 | | //~| HELP consider +182 | | //~| HELP consider +183 | | //~| SUGGESTION for in vec.iter().take(10).skip(5) { +184 | | println!("{}", vec[i]); +185 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for in vec.iter().take(10).skip(5) { + +error: the loop variable `i` is only used to index `vec`. + --> $DIR/for_loop.rs:187:5 + | +187 | for i in 5...10 { + | _____^ starting here... +188 | | //~^ ERROR `i` is only used to index `vec` +189 | | //~| HELP consider +190 | | //~| HELP consider +191 | | //~| SUGGESTION for in vec.iter().take(10 + 1).skip(5) { +192 | | println!("{}", vec[i]); +193 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for in vec.iter().take(10 + 1).skip(5) { + +error: the loop variable `i` is used to index `vec` + --> $DIR/for_loop.rs:195:5 + | +195 | for i in 5..vec.len() { + | _____^ starting here... +196 | | //~^ ERROR `i` is used to index `vec` +197 | | //~| HELP consider +198 | | //~| HELP consider +199 | | //~| SUGGESTION for (i, ) in vec.iter().enumerate().skip(5) { +200 | | println!("{} {}", vec[i], i); +201 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for (i, ) in vec.iter().enumerate().skip(5) { + +error: the loop variable `i` is used to index `vec` + --> $DIR/for_loop.rs:203:5 + | +203 | for i in 5..10 { + | _____^ starting here... +204 | | //~^ ERROR `i` is used to index `vec` +205 | | //~| HELP consider +206 | | //~| HELP consider +207 | | //~| SUGGESTION for (i, ) in vec.iter().enumerate().take(10).skip(5) { +208 | | println!("{} {}", vec[i], i); +209 | | } + | |_____^ ...ending here + | +help: consider using an iterator + | for (i, ) in vec.iter().enumerate().take(10).skip(5) { + +error: this range is empty so this for loop will never run + --> $DIR/for_loop.rs:211:5 + | +211 | for i in 10..0 { + | _____^ starting here... +212 | | //~^ERROR this range is empty so this for loop will never run +213 | | //~|HELP consider +214 | | //~|SUGGESTION (0..10).rev() +215 | | println!("{}", i); +216 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/for_loop.rs:90:90 + | +90 | #[deny(needless_range_loop, explicit_iter_loop, explicit_into_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop, for_kv_map)] + | ^^^^^^^^^^^^^^^^^^ +help: consider using the following if you are attempting to iterate over this range in reverse + | for i in (0..10).rev() { + +error: this range is empty so this for loop will never run + --> $DIR/for_loop.rs:218:5 + | +218 | for i in 10...0 { + | _____^ starting here... +219 | | //~^ERROR this range is empty so this for loop will never run +220 | | //~|HELP consider +221 | | //~|SUGGESTION (0...10).rev() +222 | | println!("{}", i); +223 | | } + | |_____^ ...ending here + | +help: consider using the following if you are attempting to iterate over this range in reverse + | for i in (0...10).rev() { + +error: this range is empty so this for loop will never run + --> $DIR/for_loop.rs:225:5 + | +225 | for i in MAX_LEN..0 { //~ERROR this range is empty so this for loop will never run + | _____^ starting here... +226 | | //~|HELP consider +227 | | //~|SUGGESTION (0..MAX_LEN).rev() +228 | | println!("{}", i); +229 | | } + | |_____^ ...ending here + | +help: consider using the following if you are attempting to iterate over this range in reverse + | for i in (0..MAX_LEN).rev() { //~ERROR this range is empty so this for loop will never run + +error: this range is empty so this for loop will never run + --> $DIR/for_loop.rs:231:5 + | +231 | for i in 5..5 { //~ERROR this range is empty so this for loop will never run + | _____^ starting here... +232 | | println!("{}", i); +233 | | } + | |_____^ ...ending here + +error: this range is empty so this for loop will never run + --> $DIR/for_loop.rs:252:5 + | +252 | for i in 10..5+4 { + | _____^ starting here... +253 | | //~^ ERROR this range is empty so this for loop will never run +254 | | //~| HELP if you are attempting to iterate over this range in reverse +255 | | //~| SUGGESTION for i in (5+4..10).rev() { +256 | | println!("{}", i); +257 | | } + | |_____^ ...ending here + | +help: consider using the following if you are attempting to iterate over this range in reverse + | for i in (5+4..10).rev() { + +error: this range is empty so this for loop will never run + --> $DIR/for_loop.rs:259:5 + | +259 | for i in (5+2)..(3-1) { + | _____^ starting here... +260 | | //~^ ERROR this range is empty so this for loop will never run +261 | | //~| HELP if you are attempting to iterate over this range in reverse +262 | | //~| SUGGESTION for i in ((3-1)..(5+2)).rev() { +263 | | println!("{}", i); +264 | | } + | |_____^ ...ending here + | +help: consider using the following if you are attempting to iterate over this range in reverse + | for i in ((3-1)..(5+2)).rev() { + +error: this range is empty so this for loop will never run + --> $DIR/for_loop.rs:266:5 + | +266 | for i in (5+2)..(8-1) { //~ERROR this range is empty so this for loop will never run + | _____^ starting here... +267 | | println!("{}", i); +268 | | } + | |_____^ ...ending here + +error: it is more idiomatic to loop over `&vec` instead of `vec.iter()` + --> $DIR/for_loop.rs:289:15 + | +289 | for _v in vec.iter() { } + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/for_loop.rs:90:29 + | +90 | #[deny(needless_range_loop, explicit_iter_loop, explicit_into_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop, for_kv_map)] + | ^^^^^^^^^^^^^^^^^^ +help: to write this more concisely, try looping over + | for _v in &vec { } + +error: it is more idiomatic to loop over `&mut vec` instead of `vec.iter_mut()` + --> $DIR/for_loop.rs:294:15 + | +294 | for _v in vec.iter_mut() { } + | ^^^^^^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &mut vec { } + +error: it is more idiomatic to loop over `out_vec` instead of `out_vec.into_iter()` + --> $DIR/for_loop.rs:300:15 + | +300 | for _v in out_vec.into_iter() { } + | ^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/for_loop.rs:90:49 + | +90 | #[deny(needless_range_loop, explicit_iter_loop, explicit_into_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop, for_kv_map)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: to write this more concisely, try looping over + | for _v in out_vec { } + +error: it is more idiomatic to loop over `&[1, 2, 3]` instead of `[1, 2, 3].iter()` + --> $DIR/for_loop.rs:308:15 + | +308 | for _v in [1, 2, 3].iter() { } + | ^^^^^^^^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &[1, 2, 3] { } + +error: it is more idiomatic to loop over `&[0; 32]` instead of `[0; 32].iter()` + --> $DIR/for_loop.rs:315:15 + | +315 | for _v in [0; 32].iter() {} + | ^^^^^^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &[0; 32] {} + +error: it is more idiomatic to loop over `&ll` instead of `ll.iter()` + --> $DIR/for_loop.rs:323:15 + | +323 | for _v in ll.iter() { } + | ^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &ll { } + +error: it is more idiomatic to loop over `&vd` instead of `vd.iter()` + --> $DIR/for_loop.rs:329:15 + | +329 | for _v in vd.iter() { } + | ^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &vd { } + +error: it is more idiomatic to loop over `&bh` instead of `bh.iter()` + --> $DIR/for_loop.rs:335:15 + | +335 | for _v in bh.iter() { } + | ^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &bh { } + +error: it is more idiomatic to loop over `&hm` instead of `hm.iter()` + --> $DIR/for_loop.rs:341:15 + | +341 | for _v in hm.iter() { } + | ^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &hm { } + +error: it is more idiomatic to loop over `&bt` instead of `bt.iter()` + --> $DIR/for_loop.rs:347:15 + | +347 | for _v in bt.iter() { } + | ^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &bt { } + +error: it is more idiomatic to loop over `&hs` instead of `hs.iter()` + --> $DIR/for_loop.rs:353:15 + | +353 | for _v in hs.iter() { } + | ^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &hs { } + +error: it is more idiomatic to loop over `&bs` instead of `bs.iter()` + --> $DIR/for_loop.rs:359:15 + | +359 | for _v in bs.iter() { } + | ^^^^^^^^^ + | +help: to write this more concisely, try looping over + | for _v in &bs { } + +error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want + --> $DIR/for_loop.rs:365:5 + | +365 | for _v in vec.iter().next() { } //~ERROR you are iterating over `Iterator::next()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/for_loop.rs:90:74 + | +90 | #[deny(needless_range_loop, explicit_iter_loop, explicit_into_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop, for_kv_map)] + | ^^^^^^^^^^^^^^ + +error: you are collect()ing an iterator and throwing away the result. Consider using an explicit for loop to exhaust the iterator + --> $DIR/for_loop.rs:372:5 + | +372 | vec.iter().map(|x| out.push(x)).collect::>(); //~ERROR you are collect()ing an iterator + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/for_loop.rs:91:8 + | +91 | #[deny(unused_collect)] + | ^^^^^^^^^^^^^^ + +error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators + --> $DIR/for_loop.rs:377:5 + | +377 | for _v in &vec { _index += 1 } //~ERROR the variable `_index` is used as a loop counter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/for_loop.rs:90:110 + | +90 | #[deny(needless_range_loop, explicit_iter_loop, explicit_into_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop, for_kv_map)] + | ^^^^^^^^^^^^^^^^^^^^^ + +error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators + --> $DIR/for_loop.rs:381:5 + | +381 | for _v in &vec { _index += 1 } //~ERROR the variable `_index` is used as a loop counter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: you seem to want to iterate on a map's values + --> $DIR/for_loop.rs:441:5 + | +441 | for (_, v) in &m { + | _____^ starting here... +442 | | //~^ you seem to want to iterate on a map's values +443 | | //~| HELP use the corresponding method +444 | | //~| HELP use the corresponding method +445 | | //~| SUGGESTION for v in m.values() { +446 | | let _v = v; +447 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/for_loop.rs:90:133 + | +90 | #[deny(needless_range_loop, explicit_iter_loop, explicit_into_iter_loop, iter_next_loop, reverse_range_loop, explicit_counter_loop, for_kv_map)] + | ^^^^^^^^^^ +help: use the corresponding method + | for v in m.values() { + +error: you seem to want to iterate on a map's values + --> $DIR/for_loop.rs:450:5 + | +450 | for (_, v) in &*m { + | _____^ starting here... +451 | | //~^ you seem to want to iterate on a map's values +452 | | //~| HELP use the corresponding method +453 | | //~| HELP use the corresponding method +454 | | //~| SUGGESTION for v in (*m).values() { +455 | | let _v = v; +456 | | // Here the `*` is not actually necesarry, but the test tests that we don't suggest +457 | | // `in *m.values()` as we used to +458 | | } + | |_____^ ...ending here + | +help: use the corresponding method + | for v in (*m).values() { + +error: you seem to want to iterate on a map's values + --> $DIR/for_loop.rs:461:5 + | +461 | for (_, v) in &mut m { + | _____^ starting here... +462 | | //~^ you seem to want to iterate on a map's values +463 | | //~| HELP use the corresponding method +464 | | //~| HELP use the corresponding method +465 | | //~| SUGGESTION for v in m.values_mut() +466 | | let _v = v; +467 | | } + | |_____^ ...ending here + | +help: use the corresponding method + | for v in m.values_mut() { + +error: you seem to want to iterate on a map's values + --> $DIR/for_loop.rs:470:5 + | +470 | for (_, v) in &mut *m { + | _____^ starting here... +471 | | //~^ you seem to want to iterate on a map's values +472 | | //~| HELP use the corresponding method +473 | | //~| HELP use the corresponding method +474 | | //~| SUGGESTION for v in (*m).values_mut() +475 | | let _v = v; +476 | | } + | |_____^ ...ending here + | +help: use the corresponding method + | for v in (*m).values_mut() { + +error: you seem to want to iterate on a map's keys + --> $DIR/for_loop.rs:480:5 + | +480 | for (k, _value) in rm { + | _____^ starting here... +481 | | //~^ you seem to want to iterate on a map's keys +482 | | //~| HELP use the corresponding method +483 | | //~| HELP use the corresponding method +484 | | //~| SUGGESTION for k in rm.keys() { +485 | | let _k = k; +486 | | } + | |_____^ ...ending here + | +help: use the corresponding method + | for k in rm.keys() { + +error: aborting due to 47 previous errors + diff --git a/tests/compile-fail/format.rs b/tests/ui/format.rs similarity index 100% rename from tests/compile-fail/format.rs rename to tests/ui/format.rs diff --git a/tests/ui/format.stderr b/tests/ui/format.stderr new file mode 100644 index 00000000000..a913ef24b25 --- /dev/null +++ b/tests/ui/format.stderr @@ -0,0 +1,26 @@ +error: useless use of `format!` + --> $DIR/format.rs:6:5 + | +6 | format!("foo"); //~ERROR useless use of `format!` + | ^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/format.rs:3:9 + | +3 | #![deny(useless_format)] + | ^^^^^^^^^^^^^^ + +error: useless use of `format!` + --> $DIR/format.rs:8:5 + | +8 | format!("{}", "foo"); //~ERROR useless use of `format!` + | ^^^^^^^^^^^^^^^^^^^^^ + +error: useless use of `format!` + --> $DIR/format.rs:15:5 + | +15 | format!("{}", arg); //~ERROR useless use of `format!` + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/formatting.rs b/tests/ui/formatting.rs similarity index 100% rename from tests/compile-fail/formatting.rs rename to tests/ui/formatting.rs diff --git a/tests/ui/formatting.stderr b/tests/ui/formatting.stderr new file mode 100644 index 00000000000..46ff2a45f48 --- /dev/null +++ b/tests/ui/formatting.stderr @@ -0,0 +1,116 @@ +error: this looks like an `else if` but the `else` is missing + --> $DIR/formatting.rs:15:6 + | +15 | } if foo() { + | ^ + | + = note: #[deny(suspicious_else_formatting)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/formatting.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + = note: to remove this lint, add the missing `else` or add a new line before the second `if` + +error: this looks like an `else if` but the `else` is missing + --> $DIR/formatting.rs:24:10 + | +24 | } if foo() { + | ^ + | + = note: #[deny(suspicious_else_formatting)] implied by #[deny(clippy)] + = note: to remove this lint, add the missing `else` or add a new line before the second `if` + +error: this looks like an `else if` but the `else` is missing + --> $DIR/formatting.rs:34:10 + | +34 | } if foo() { + | ^ + | + = note: #[deny(suspicious_else_formatting)] implied by #[deny(clippy)] + = note: to remove this lint, add the missing `else` or add a new line before the second `if` + +error: this is an `else if` but the formatting might hide it + --> $DIR/formatting.rs:45:6 + | +45 | } else + | ______^ starting here... +46 | | //~^ ERROR this is an `else if` but the formatting might hide it +47 | | //~| NOTE remove the `else` or +48 | | if foo() { // the span of the above error should continue here + | |____^ ...ending here + | + = note: #[deny(suspicious_else_formatting)] implied by #[deny(clippy)] + = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` + +error: this is an `else if` but the formatting might hide it + --> $DIR/formatting.rs:52:6 + | +52 | } + | ______^ starting here... +53 | | //~^ ERROR this is an `else if` but the formatting might hide it +54 | | //~| NOTE remove the `else` or +55 | | else +56 | | if foo() { // the span of the above error should continue here + | |____^ ...ending here + | + = note: #[deny(suspicious_else_formatting)] implied by #[deny(clippy)] + = note: to remove this lint, remove the `else` or remove the new line between `else` and `if` + +error: this looks like you are trying to use `.. -= ..`, but you really are doing `.. = (- ..)` + --> $DIR/formatting.rs:83:6 + | +83 | a =- 35; + | ^^^^ + | + = note: #[deny(suspicious_assignment_formatting)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/formatting.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + = note: to remove this lint, use either `-=` or `= -` + +error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` + --> $DIR/formatting.rs:86:6 + | +86 | a =* &191; + | ^^^^ + | + = note: #[deny(suspicious_assignment_formatting)] implied by #[deny(clippy)] + = note: to remove this lint, use either `*=` or `= *` + +error: this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)` + --> $DIR/formatting.rs:91:6 + | +91 | b =! false; + | ^^^^ + | + = note: #[deny(suspicious_assignment_formatting)] implied by #[deny(clippy)] + = note: to remove this lint, use either `!=` or `= !` + +error: possibly missing a comma here + --> $DIR/formatting.rs:102:19 + | +102 | -1, -2, -3 // <= no coma here + | ^ + | + = note: #[deny(possible_missing_comma)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/formatting.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + = note: to remove this lint, add a comma or write the expr in a single line + +error: possibly missing a comma here + --> $DIR/formatting.rs:108:19 + | +108 | -1, -2, -3 // <= no coma here + | ^ + | + = note: #[deny(possible_missing_comma)] implied by #[deny(clippy)] + = note: to remove this lint, add a comma or write the expr in a single line + +error: aborting due to 10 previous errors + diff --git a/tests/compile-fail/functions.rs b/tests/ui/functions.rs similarity index 100% rename from tests/compile-fail/functions.rs rename to tests/ui/functions.rs diff --git a/tests/ui/functions.stderr b/tests/ui/functions.stderr new file mode 100644 index 00000000000..a66ea4b8899 --- /dev/null +++ b/tests/ui/functions.stderr @@ -0,0 +1,111 @@ +error: this function has too many arguments (8/7) + --> $DIR/functions.rs:11:1 + | +11 | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) { + | _^ starting here... +12 | | //~^ ERROR: this function has too many arguments (8/7) +13 | | } + | |_^ ...ending here + | + = note: #[deny(too_many_arguments)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/functions.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + +error: this function has too many arguments (8/7) + --> $DIR/functions.rs:20:5 + | +20 | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(too_many_arguments)] implied by #[deny(clippy)] + +error: this function has too many arguments (8/7) + --> $DIR/functions.rs:30:5 + | +30 | fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(too_many_arguments)] implied by #[deny(clippy)] + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:40:34 + | +40 | println!("{}", unsafe { *p }); + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/functions.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:42:35 + | +42 | println!("{:?}", unsafe { p.as_ref() }); + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:44:33 + | +44 | unsafe { std::ptr::read(p) }; + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:56:30 + | +56 | println!("{}", unsafe { *p }); + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:58:31 + | +58 | println!("{:?}", unsafe { p.as_ref() }); + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:60:29 + | +60 | unsafe { std::ptr::read(p) }; + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:70:34 + | +70 | println!("{}", unsafe { *p }); + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:72:35 + | +72 | println!("{:?}", unsafe { p.as_ref() }); + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] + +error: this public function dereferences a raw pointer but is not marked `unsafe` + --> $DIR/functions.rs:74:33 + | +74 | unsafe { std::ptr::read(p) }; + | ^ + | + = note: #[deny(not_unsafe_ptr_arg_deref)] implied by #[deny(clippy)] + +error: aborting due to 12 previous errors + diff --git a/tests/compile-fail/identity_op.rs b/tests/ui/identity_op.rs similarity index 100% rename from tests/compile-fail/identity_op.rs rename to tests/ui/identity_op.rs diff --git a/tests/ui/identity_op.stderr b/tests/ui/identity_op.stderr new file mode 100644 index 00000000000..7590a99effe --- /dev/null +++ b/tests/ui/identity_op.stderr @@ -0,0 +1,50 @@ +error: the operation is ineffective. Consider reducing it to `x` + --> $DIR/identity_op.rs:13:5 + | +13 | x + 0; //~ERROR the operation is ineffective + | ^^^^^ + | +note: lint level defined here + --> $DIR/identity_op.rs:9:8 + | +9 | #[deny(identity_op)] + | ^^^^^^^^^^^ + +error: the operation is ineffective. Consider reducing it to `x` + --> $DIR/identity_op.rs:14:5 + | +14 | x + (1 - 1); //~ERROR the operation is ineffective + | ^^^^^^^^^^^ + +error: the operation is ineffective. Consider reducing it to `x` + --> $DIR/identity_op.rs:16:5 + | +16 | 0 + x; //~ERROR the operation is ineffective + | ^^^^^ + +error: the operation is ineffective. Consider reducing it to `x` + --> $DIR/identity_op.rs:19:5 + | +19 | x | (0); //~ERROR the operation is ineffective + | ^^^^^^^ + +error: the operation is ineffective. Consider reducing it to `x` + --> $DIR/identity_op.rs:22:5 + | +22 | x * 1; //~ERROR the operation is ineffective + | ^^^^^ + +error: the operation is ineffective. Consider reducing it to `x` + --> $DIR/identity_op.rs:23:5 + | +23 | 1 * x; //~ERROR the operation is ineffective + | ^^^^^ + +error: the operation is ineffective. Consider reducing it to `x` + --> $DIR/identity_op.rs:29:5 + | +29 | -1 & x; //~ERROR the operation is ineffective + | ^^^^^^ + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/if_let_redundant_pattern_matching.rs b/tests/ui/if_let_redundant_pattern_matching.rs similarity index 100% rename from tests/compile-fail/if_let_redundant_pattern_matching.rs rename to tests/ui/if_let_redundant_pattern_matching.rs diff --git a/tests/ui/if_let_redundant_pattern_matching.stderr b/tests/ui/if_let_redundant_pattern_matching.stderr new file mode 100644 index 00000000000..cc011b4a90c --- /dev/null +++ b/tests/ui/if_let_redundant_pattern_matching.stderr @@ -0,0 +1,47 @@ +error: redundant pattern matching, consider using `is_ok()` + --> $DIR/if_let_redundant_pattern_matching.rs:9:12 + | +9 | if let Ok(_) = Ok::(42) {} + | ^^^^^ + | + = note: #[deny(if_let_redundant_pattern_matching)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/if_let_redundant_pattern_matching.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ +help: try this + | if Ok::(42).is_ok() {} + +error: redundant pattern matching, consider using `is_err()` + --> $DIR/if_let_redundant_pattern_matching.rs:14:12 + | +14 | if let Err(_) = Err::(42) { + | ^^^^^^ + | + = note: #[deny(if_let_redundant_pattern_matching)] implied by #[deny(clippy)] +help: try this + | if Err::(42).is_err() { + +error: redundant pattern matching, consider using `is_none()` + --> $DIR/if_let_redundant_pattern_matching.rs:20:12 + | +20 | if let None = None::<()> { + | ^^^^ + | + = note: #[deny(if_let_redundant_pattern_matching)] implied by #[deny(clippy)] +help: try this + | if None::<()>.is_none() { + +error: redundant pattern matching, consider using `is_some()` + --> $DIR/if_let_redundant_pattern_matching.rs:26:12 + | +26 | if let Some(_) = Some(42) { + | ^^^^^^^ + | + = note: #[deny(if_let_redundant_pattern_matching)] implied by #[deny(clippy)] +help: try this + | if Some(42).is_some() { + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/if_not_else.rs b/tests/ui/if_not_else.rs similarity index 100% rename from tests/compile-fail/if_not_else.rs rename to tests/ui/if_not_else.rs diff --git a/tests/ui/if_not_else.stderr b/tests/ui/if_not_else.stderr new file mode 100644 index 00000000000..f31be63dd4c --- /dev/null +++ b/tests/ui/if_not_else.stderr @@ -0,0 +1,33 @@ +error: Unnecessary boolean `not` operation + --> $DIR/if_not_else.rs:9:5 + | +9 | if !bla() { //~ ERROR: Unnecessary boolean `not` operation + | _____^ starting here... +10 | | println!("Bugs"); +11 | | } else { +12 | | println!("Bunny"); +13 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/if_not_else.rs:4:9 + | +4 | #![deny(if_not_else)] + | ^^^^^^^^^^^ + = help: remove the `!` and swap the blocks of the if/else + +error: Unnecessary `!=` operation + --> $DIR/if_not_else.rs:14:5 + | +14 | if 4 != 5 { //~ ERROR: Unnecessary `!=` operation + | _____^ starting here... +15 | | println!("Bugs"); +16 | | } else { +17 | | println!("Bunny"); +18 | | } + | |_____^ ...ending here + | + = help: change to `==` and swap the blocks of the if/else + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs similarity index 100% rename from tests/compile-fail/invalid_upcast_comparisons.rs rename to tests/ui/invalid_upcast_comparisons.rs diff --git a/tests/ui/invalid_upcast_comparisons.stderr b/tests/ui/invalid_upcast_comparisons.stderr new file mode 100644 index 00000000000..1fd96e4de42 --- /dev/null +++ b/tests/ui/invalid_upcast_comparisons.stderr @@ -0,0 +1,62 @@ +error: because of the numeric bounds on `u8_max` prior to casting, this expression is always false + --> $DIR/invalid_upcast_comparisons.rs:10:5 + | +10 | (u8_max as u32) > 300; //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/invalid_upcast_comparisons.rs:4:9 + | +4 | #![deny(invalid_upcast_comparisons)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: because of the numeric bounds on `zero` prior to casting, this expression is always false + --> $DIR/invalid_upcast_comparisons.rs:13:5 + | +13 | (zero as i32) < -5; //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false + | ^^^^^^^^^^^^^^^^^^ + +error: because of the numeric bounds on `zero` prior to casting, this expression is always true + --> $DIR/invalid_upcast_comparisons.rs:16:5 + | +16 | -5 < (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always true + | ^^^^^^^^^^^^^^^^^^ + +error: because of the numeric bounds on `zero` prior to casting, this expression is always true + --> $DIR/invalid_upcast_comparisons.rs:17:5 + | +17 | 0 <= (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always true + | ^^^^^^^^^^^^^^^^^^ + +error: because of the numeric bounds on `zero` prior to casting, this expression is always false + --> $DIR/invalid_upcast_comparisons.rs:20:5 + | +20 | -5 > (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false + | ^^^^^^^^^^^^^^^^^^ + +error: because of the numeric bounds on `u8_max` prior to casting, this expression is always false + --> $DIR/invalid_upcast_comparisons.rs:21:5 + | +21 | -5 >= (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false + | ^^^^^^^^^^^^^^^^^^^^^ + +error: because of the numeric bounds on `u8_max` prior to casting, this expression is always false + --> $DIR/invalid_upcast_comparisons.rs:22:5 + | +22 | 1337 == (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always false + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: because of the numeric bounds on `zero` prior to casting, this expression is always false + --> $DIR/invalid_upcast_comparisons.rs:24:5 + | +24 | -5 == (zero as i32); //~ERROR because of the numeric bounds on `zero` prior to casting, this expression is always false + | ^^^^^^^^^^^^^^^^^^^ + +error: because of the numeric bounds on `u8_max` prior to casting, this expression is always true + --> $DIR/invalid_upcast_comparisons.rs:25:5 + | +25 | -5 != (u8_max as i32); //~ERROR because of the numeric bounds on `u8_max` prior to casting, this expression is always true + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 9 previous errors + diff --git a/tests/compile-fail/item_after_statement.rs b/tests/ui/item_after_statement.rs similarity index 100% rename from tests/compile-fail/item_after_statement.rs rename to tests/ui/item_after_statement.rs diff --git a/tests/ui/item_after_statement.stderr b/tests/ui/item_after_statement.stderr new file mode 100644 index 00000000000..be3455c2a71 --- /dev/null +++ b/tests/ui/item_after_statement.stderr @@ -0,0 +1,20 @@ +error: adding items after statements is confusing, since items exist from the start of the scope + --> $DIR/item_after_statement.rs:12:5 + | +12 | fn foo() { println!("foo"); } //~ ERROR adding items after statements is confusing + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/item_after_statement.rs:3:9 + | +3 | #![deny(items_after_statements)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: adding items after statements is confusing, since items exist from the start of the scope + --> $DIR/item_after_statement.rs:17:5 + | +17 | fn foo() { println!("foo"); } //~ ERROR adding items after statements is confusing + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/large_enum_variant.rs b/tests/ui/large_enum_variant.rs similarity index 100% rename from tests/compile-fail/large_enum_variant.rs rename to tests/ui/large_enum_variant.rs diff --git a/tests/ui/large_enum_variant.stderr b/tests/ui/large_enum_variant.stderr new file mode 100644 index 00000000000..8b7b3990260 --- /dev/null +++ b/tests/ui/large_enum_variant.stderr @@ -0,0 +1,84 @@ +error: large enum variant found + --> $DIR/large_enum_variant.rs:10:5 + | +10 | B([i32; 8000]), //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/large_enum_variant.rs:6:9 + | +6 | #![deny(large_enum_variant)] + | ^^^^^^^^^^^^^^^^^^ +help: consider boxing the large fields to reduce the total size of the enum + | B(Box<[i32; 8000]>), //~ ERROR large enum variant found + +error: large enum variant found + --> $DIR/large_enum_variant.rs:17:5 + | +17 | B([i32; 8000]), //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^ + | +help: consider boxing the large fields to reduce the total size of the enum + | B(Box<[i32; 8000]>), //~ ERROR large enum variant found + +error: large enum variant found + --> $DIR/large_enum_variant.rs:21:5 + | +21 | D(T, [i32; 8000]), //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^^^^ + | +help: consider boxing the large fields to reduce the total size of the enum + --> $DIR/large_enum_variant.rs:21:5 + | +21 | D(T, [i32; 8000]), //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^^^^ + +error: large enum variant found + --> $DIR/large_enum_variant.rs:35:5 + | +35 | ContainingLargeEnum(LargeEnum), //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider boxing the large fields to reduce the total size of the enum + | ContainingLargeEnum(Box), //~ ERROR large enum variant found + +error: large enum variant found + --> $DIR/large_enum_variant.rs:38:5 + | +38 | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider boxing the large fields to reduce the total size of the enum + --> $DIR/large_enum_variant.rs:38:5 + | +38 | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: large enum variant found + --> $DIR/large_enum_variant.rs:42:5 + | +42 | StructLikeLarge { x: [i32; 8000], y: i32 }, //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider boxing the large fields to reduce the total size of the enum + --> $DIR/large_enum_variant.rs:42:5 + | +42 | StructLikeLarge { x: [i32; 8000], y: i32 }, //~ ERROR large enum variant found + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: large enum variant found + --> $DIR/large_enum_variant.rs:44:5 + | +44 | StructLikeLarge2 { //~ ERROR large enum variant found + | _____^ starting here... +45 | | x: +46 | | [i32; 8000] //~ SUGGESTION Box<[i32; 8000]> +47 | | //~^ HELP consider boxing the large fields to reduce the total size of the enum +48 | | }, + | |_____^ ...ending here + | +help: consider boxing the large fields to reduce the total size of the enum + | Box<[i32; 8000]> //~ SUGGESTION Box<[i32; 8000]> + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/len_zero.rs b/tests/ui/len_zero.rs similarity index 100% rename from tests/compile-fail/len_zero.rs rename to tests/ui/len_zero.rs diff --git a/tests/ui/len_zero.stderr b/tests/ui/len_zero.stderr new file mode 100644 index 00000000000..48ee0a7ffd0 --- /dev/null +++ b/tests/ui/len_zero.stderr @@ -0,0 +1,100 @@ +error: item `PubOne` has a public `len` method but no corresponding `is_empty` method + --> $DIR/len_zero.rs:10:5 + | +10 | pub fn len(self: &Self) -> isize { //~ERROR item `PubOne` has a public `len` method but no corresponding `is_empty` + | _____^ starting here... +11 | | 1 +12 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/len_zero.rs:4:9 + | +4 | #![deny(len_without_is_empty, len_zero)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: trait `PubTraitsToo` has a `len` method but no `is_empty` method + --> $DIR/len_zero.rs:32:5 + | +32 | fn len(self: &Self) -> isize; //~ERROR trait `PubTraitsToo` has a `len` method but no `is_empty` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: item `HasIsEmpty` has a public `len` method but a private `is_empty` method + --> $DIR/len_zero.rs:66:5 + | +66 | pub fn len(self: &Self) -> isize { //~ERROR item `HasIsEmpty` has a public `len` method but a private `is_empty` + | _____^ starting here... +67 | | 1 +68 | | } + | |_____^ ...ending here + +error: item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty` method + --> $DIR/len_zero.rs:95:5 + | +95 | pub fn len(self: &Self) -> isize { //~ERROR item `HasWrongIsEmpty` has a public `len` method but no corresponding `is_empty` + | _____^ starting here... +96 | | 1 +97 | | } + | |_____^ ...ending here + +error: length comparison to zero + --> $DIR/len_zero.rs:106:8 + | +106 | if x.len() == 0 { + | ^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/len_zero.rs:4:31 + | +4 | #![deny(len_without_is_empty, len_zero)] + | ^^^^^^^^ +help: consider using `is_empty` + | if x.is_empty() { + +error: length comparison to zero + --> $DIR/len_zero.rs:113:8 + | +113 | if "".len() == 0 { + | ^^^^^^^^^^^^^ + | +help: consider using `is_empty` + | if "".is_empty() { + +error: length comparison to zero + --> $DIR/len_zero.rs:130:8 + | +130 | if has_is_empty.len() == 0 { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `is_empty` + | if has_is_empty.is_empty() { + +error: length comparison to zero + --> $DIR/len_zero.rs:136:8 + | +136 | if has_is_empty.len() != 0 { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `is_empty` + | if !has_is_empty.is_empty() { + +error: length comparison to zero + --> $DIR/len_zero.rs:142:8 + | +142 | if has_is_empty.len() > 0 { + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `is_empty` + | if !has_is_empty.is_empty() { + +error: length comparison to zero + --> $DIR/len_zero.rs:151:8 + | +151 | if with_is_empty.len() == 0 { + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `is_empty` + | if with_is_empty.is_empty() { + +error: aborting due to 10 previous errors + diff --git a/tests/compile-fail/let_if_seq.rs b/tests/ui/let_if_seq.rs similarity index 100% rename from tests/compile-fail/let_if_seq.rs rename to tests/ui/let_if_seq.rs diff --git a/tests/ui/let_if_seq.stderr b/tests/ui/let_if_seq.stderr new file mode 100644 index 00000000000..47ca7d2af16 --- /dev/null +++ b/tests/ui/let_if_seq.stderr @@ -0,0 +1,60 @@ +error: `if _ { .. } else { .. }` is an expression + --> $DIR/let_if_seq.rs:57:5 + | +57 | let mut foo = 0; + | _____^ starting here... +58 | | //~^ ERROR `if _ { .. } else { .. }` is an expression +59 | | //~| HELP more idiomatic +60 | | //~| SUGGESTION let foo = if f() { 42 } else { 0 }; +61 | | if f() { +62 | | foo = 42; +63 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/let_if_seq.rs:5:9 + | +5 | #![deny(useless_let_if_seq)] + | ^^^^^^^^^^^^^^^^^^ +help: it is more idiomatic to write + | let foo = if f() { 42 } else { 0 }; + = note: you might not need `mut` at all + +error: `if _ { .. } else { .. }` is an expression + --> $DIR/let_if_seq.rs:65:5 + | +65 | let mut bar = 0; + | ^ + | +help: it is more idiomatic to write + | let bar = if f() { ..; 42 } else { ..; 0 }; + = note: you might not need `mut` at all + +error: `if _ { .. } else { .. }` is an expression + --> $DIR/let_if_seq.rs:77:5 + | +77 | let quz; + | ^ + | +help: it is more idiomatic to write + | let quz = if f() { 42 } else { 0 }; + +error: `if _ { .. } else { .. }` is an expression + --> $DIR/let_if_seq.rs:111:5 + | +111 | let mut baz = 0; + | _____^ starting here... +112 | | //~^ ERROR `if _ { .. } else { .. }` is an expression +113 | | //~| HELP more idiomatic +114 | | //~| SUGGESTION let baz = if f() { 42 } else { 0 }; +115 | | if f() { +116 | | baz = 42; +117 | | } + | |_____^ ...ending here + | +help: it is more idiomatic to write + | let baz = if f() { 42 } else { 0 }; + = note: you might not need `mut` at all + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/let_return.rs b/tests/ui/let_return.rs similarity index 100% rename from tests/compile-fail/let_return.rs rename to tests/ui/let_return.rs diff --git a/tests/ui/let_return.stderr b/tests/ui/let_return.stderr new file mode 100644 index 00000000000..13197e5412c --- /dev/null +++ b/tests/ui/let_return.stderr @@ -0,0 +1,31 @@ +error: returning the result of a let binding from a block. Consider returning the expression directly. + --> $DIR/let_return.rs:10:5 + | +10 | x //~ERROR returning the result of a let binding + | ^ + | +note: lint level defined here + --> $DIR/let_return.rs:5:9 + | +5 | #![deny(let_and_return)] + | ^^^^^^^^^^^^^^ +note: this expression can be directly returned + --> $DIR/let_return.rs:9:13 + | +9 | let x = 5; //~NOTE this expression can be directly returned + | ^ + +error: returning the result of a let binding from a block. Consider returning the expression directly. + --> $DIR/let_return.rs:16:9 + | +16 | x //~ERROR returning the result of a let binding + | ^ + | +note: this expression can be directly returned + --> $DIR/let_return.rs:15:17 + | +15 | let x = 5; //~NOTE this expression can be directly returned + | ^ + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/let_unit.rs b/tests/ui/let_unit.rs similarity index 100% rename from tests/compile-fail/let_unit.rs rename to tests/ui/let_unit.rs diff --git a/tests/ui/let_unit.stderr b/tests/ui/let_unit.stderr new file mode 100644 index 00000000000..863b9dc59eb --- /dev/null +++ b/tests/ui/let_unit.stderr @@ -0,0 +1,20 @@ +error: this let-binding has unit value. Consider omitting `let _x =` + --> $DIR/let_unit.rs:14:5 + | +14 | let _x = println!("x"); //~ERROR this let-binding has unit value + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/let_unit.rs:4:9 + | +4 | #![deny(let_unit_value)] + | ^^^^^^^^^^^^^^ + +error: this let-binding has unit value. Consider omitting `let _a =` + --> $DIR/let_unit.rs:18:9 + | +18 | let _a = (); //~ERROR this let-binding has unit value + | ^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/lifetimes.rs b/tests/ui/lifetimes.rs similarity index 100% rename from tests/compile-fail/lifetimes.rs rename to tests/ui/lifetimes.rs diff --git a/tests/ui/lifetimes.stderr b/tests/ui/lifetimes.stderr new file mode 100644 index 00000000000..0d5f75c8930 --- /dev/null +++ b/tests/ui/lifetimes.stderr @@ -0,0 +1,95 @@ +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:7:1 + | +7 | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/lifetimes.rs:4:9 + | +4 | #![deny(needless_lifetimes, unused_lifetimes)] + | ^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:10:1 + | +10 | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:19:1 + | +19 | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { x } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:32:1 + | +32 | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { Ok(x) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:36:1 + | +36 | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> where T: Copy { Ok(x) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:43:1 + | +43 | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:58:1 + | +58 | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> //~ERROR explicit lifetimes given + | _^ starting here... +59 | | where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I> +60 | | { unreachable!() } + | |__________________^ ...ending here + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:67:5 + | +67 | fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:72:5 + | +72 | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:89:1 + | +89 | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:109:1 + | +109 | fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:113:1 + | +113 | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:124:1 + | +124 | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() } //~ERROR explicit lifetimes given + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit lifetimes given in parameter types where they could be elided + --> $DIR/lifetimes.rs:128:1 + | +128 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() } //~ERROR explicit lifetimes given + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 14 previous errors + diff --git a/tests/compile-fail/lint_pass.rs b/tests/ui/lint_pass.rs similarity index 100% rename from tests/compile-fail/lint_pass.rs rename to tests/ui/lint_pass.rs diff --git a/tests/ui/lint_pass.stderr b/tests/ui/lint_pass.stderr new file mode 100644 index 00000000000..2439007feac --- /dev/null +++ b/tests/ui/lint_pass.stderr @@ -0,0 +1,14 @@ +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: lint level defined here + --> $DIR/lint_pass.rs:5:9 + | +5 | #![deny(lint_without_lint_pass)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/literals.rs b/tests/ui/literals.rs similarity index 100% rename from tests/compile-fail/literals.rs rename to tests/ui/literals.rs diff --git a/tests/ui/literals.stderr b/tests/ui/literals.stderr new file mode 100644 index 00000000000..2806e688c82 --- /dev/null +++ b/tests/ui/literals.stderr @@ -0,0 +1,78 @@ +error: inconsistent casing in hexadecimal literal + --> $DIR/literals.rs:14:17 + | +14 | let fail1 = 0xabCD; //~ERROR inconsistent casing in hexadecimal literal + | ^^^^^^ + | +note: lint level defined here + --> $DIR/literals.rs:3:9 + | +3 | #![deny(mixed_case_hex_literals)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: inconsistent casing in hexadecimal literal + --> $DIR/literals.rs:15:17 + | +15 | let fail2 = 0xabCD_u32; //~ERROR inconsistent casing in hexadecimal literal + | ^^^^^^^^^^ + +error: inconsistent casing in hexadecimal literal + --> $DIR/literals.rs:16:17 + | +16 | let fail2 = 0xabCD_isize; //~ERROR inconsistent casing in hexadecimal literal + | ^^^^^^^^^^^^ + +error: integer type suffix should be separated by an underscore + --> $DIR/literals.rs:21:17 + | +21 | let fail3 = 1234i32; //~ERROR integer type suffix should be separated + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/literals.rs:4:9 + | +4 | #![deny(unseparated_literal_suffix)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: integer type suffix should be separated by an underscore + --> $DIR/literals.rs:22:17 + | +22 | let fail4 = 1234u32; //~ERROR integer type suffix should be separated + | ^^^^^^^ + +error: integer type suffix should be separated by an underscore + --> $DIR/literals.rs:23:17 + | +23 | let fail5 = 1234isize; //~ERROR integer type suffix should be separated + | ^^^^^^^^^ + +error: integer type suffix should be separated by an underscore + --> $DIR/literals.rs:24:17 + | +24 | let fail6 = 1234usize; //~ERROR integer type suffix should be separated + | ^^^^^^^^^ + +error: float type suffix should be separated by an underscore + --> $DIR/literals.rs:25:17 + | +25 | let fail7 = 1.5f32; //~ERROR float type suffix should be separated + | ^^^^^^ + +error: this is a decimal constant + --> $DIR/literals.rs:29:17 + | +29 | let fail8 = 0123; + | ^^^^ + | +note: lint level defined here + --> $DIR/literals.rs:5:9 + | +5 | #![deny(zero_prefixed_literal)] + | ^^^^^^^^^^^^^^^^^^^^^ +help: if you mean to use a decimal constant, remove the `0` to remove confusion: + | let fail8 = 123; +help: if you mean to use an octal constant, use `0o`: + | let fail8 = 0o123; + +error: aborting due to 9 previous errors + diff --git a/tests/compile-fail/map_clone.rs b/tests/ui/map_clone.rs similarity index 100% rename from tests/compile-fail/map_clone.rs rename to tests/ui/map_clone.rs diff --git a/tests/ui/map_clone.stderr b/tests/ui/map_clone.stderr new file mode 100644 index 00000000000..aa44340dca6 --- /dev/null +++ b/tests/ui/map_clone.stderr @@ -0,0 +1,106 @@ +error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()` + --> $DIR/map_clone.rs:12:5 + | +12 | x.iter().map(|y| y.clone()); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/map_clone.rs:4:9 + | +4 | #![deny(map_clone)] + | ^^^^^^^^^ + = help: try + x.iter().cloned() + +error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()` + --> $DIR/map_clone.rs:14:5 + | +14 | x.iter().map(|&y| y); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.iter().cloned() + +error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()` + --> $DIR/map_clone.rs:16:5 + | +16 | x.iter().map(|y| *y); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.iter().cloned() + +error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()` + --> $DIR/map_clone.rs:18:5 + | +18 | x.iter().map(|y| { y.clone() }); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.iter().cloned() + +error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()` + --> $DIR/map_clone.rs:20:5 + | +20 | x.iter().map(|&y| { y }); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.iter().cloned() + +error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()` + --> $DIR/map_clone.rs:22:5 + | +22 | x.iter().map(|y| { *y }); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.iter().cloned() + +error: you seem to be using .map() to clone the contents of an iterator, consider using `.cloned()` + --> $DIR/map_clone.rs:24:5 + | +24 | x.iter().map(Clone::clone); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.iter().cloned() + +error: you seem to be using .map() to clone the contents of an Option, consider using `.cloned()` + --> $DIR/map_clone.rs:30:5 + | +30 | x.as_ref().map(|y| y.clone()); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.as_ref().cloned() + +error: you seem to be using .map() to clone the contents of an Option, consider using `.cloned()` + --> $DIR/map_clone.rs:32:5 + | +32 | x.as_ref().map(|&y| y); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.as_ref().cloned() + +error: you seem to be using .map() to clone the contents of an Option, consider using `.cloned()` + --> $DIR/map_clone.rs:34:5 + | +34 | x.as_ref().map(|y| *y); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.as_ref().cloned() + +error: you seem to be using .map() to clone the contents of an Option, consider using `.cloned()` + --> $DIR/map_clone.rs:90:35 + | +90 | let _: Option = x.as_ref().map(|y| *y); //~ ERROR you seem to be using .map() + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try + x.as_ref().cloned() + +error: aborting due to 11 previous errors + diff --git a/tests/compile-fail/matches.rs b/tests/ui/matches.rs similarity index 100% rename from tests/compile-fail/matches.rs rename to tests/ui/matches.rs diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr new file mode 100644 index 00000000000..d24bb6cb1ff --- /dev/null +++ b/tests/ui/matches.stderr @@ -0,0 +1,392 @@ +error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` + --> $DIR/matches.rs:26:5 + | +26 | match ExprNode::Butterflies { + | _____^ starting here... +27 | | //~^ ERROR you seem to be trying to use match +28 | | //~| HELP try +29 | | //~| SUGGESTION if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None } +30 | | ExprNode::ExprAddrOf => Some(&NODE), +31 | | _ => { let x = 5; None }, +32 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/matches.rs:7:9 + | +7 | #![deny(single_match_else)] + | ^^^^^^^^^^^^^^^^^ +help: try this + | if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None } + +error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` + --> $DIR/matches.rs:38:5 + | +38 | match x { + | _____^ starting here... +39 | | //~^ ERROR you seem to be trying to use match +40 | | //~| HELP try +41 | | //~| SUGGESTION if let Some(y) = x { println!("{:?}", y); }; +42 | | Some(y) => { println!("{:?}", y); } +43 | | _ => () +44 | | }; + | |_____^ ...ending here + | + = note: #[deny(single_match)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/matches.rs:5:9 + | +5 | #![deny(clippy)] + | ^^^^^^ +help: try this + | if let Some(y) = x { println!("{:?}", y); }; + +error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` + --> $DIR/matches.rs:47:5 + | +47 | match z { + | _____^ starting here... +48 | | //~^ ERROR you seem to be trying to use match +49 | | //~| HELP try +50 | | //~| SUGGESTION if let (2...3, 7...9) = z { dummy() }; +51 | | (2...3, 7...9) => dummy(), +52 | | _ => {} +53 | | }; + | |_____^ ...ending here + | + = note: #[deny(single_match)] implied by #[deny(clippy)] +help: try this + | if let (2...3, 7...9) = z { dummy() }; + +error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` + --> $DIR/matches.rs:72:5 + | +72 | match x { + | _____^ starting here... +73 | | //~^ ERROR you seem to be trying to use match +74 | | //~| HELP try +75 | | //~| SUGGESTION if let Some(y) = x { dummy() }; +76 | | Some(y) => dummy(), +77 | | None => () +78 | | }; + | |_____^ ...ending here + | + = note: #[deny(single_match)] implied by #[deny(clippy)] +help: try this + | if let Some(y) = x { dummy() }; + +error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` + --> $DIR/matches.rs:80:5 + | +80 | match y { + | _____^ starting here... +81 | | //~^ ERROR you seem to be trying to use match +82 | | //~| HELP try +83 | | //~| SUGGESTION if let Ok(y) = y { dummy() }; +84 | | Ok(y) => dummy(), +85 | | Err(..) => () +86 | | }; + | |_____^ ...ending here + | + = note: #[deny(single_match)] implied by #[deny(clippy)] +help: try this + | if let Ok(y) = y { dummy() }; + +error: you seem to be trying to use match for destructuring a single pattern. Consider using `if let` + --> $DIR/matches.rs:90:5 + | +90 | match c { + | _____^ starting here... +91 | | //~^ ERROR you seem to be trying to use match +92 | | //~| HELP try +93 | | //~| SUGGESTION if let Cow::Borrowed(..) = c { dummy() }; +94 | | Cow::Borrowed(..) => dummy(), +95 | | Cow::Owned(..) => (), +96 | | }; + | |_____^ ...ending here + | + = note: #[deny(single_match)] implied by #[deny(clippy)] +help: try this + | if let Cow::Borrowed(..) = c { dummy() }; + +error: you seem to be trying to match on a boolean expression + --> $DIR/matches.rs:114:5 + | +114 | match test { + | _____^ starting here... +115 | | //~^ ERROR you seem to be trying to match on a boolean expression +116 | | //~| HELP consider +117 | | //~| SUGGESTION if test { 0 } else { 42 }; +118 | | true => 0, +119 | | false => 42, +120 | | }; + | |_____^ ...ending here + | + = note: #[deny(match_bool)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/matches.rs:5:9 + | +5 | #![deny(clippy)] + | ^^^^^^ +help: consider using an if/else expression + | if test { 0 } else { 42 }; + +error: you seem to be trying to match on a boolean expression + --> $DIR/matches.rs:123:5 + | +123 | match option == 1 { + | _____^ starting here... +124 | | //~^ ERROR you seem to be trying to match on a boolean expression +125 | | //~| HELP consider +126 | | //~| SUGGESTION if option == 1 { 1 } else { 0 }; +127 | | true => 1, +128 | | false => 0, +129 | | }; + | |_____^ ...ending here + | + = note: #[deny(match_bool)] implied by #[deny(clippy)] +help: consider using an if/else expression + | if option == 1 { 1 } else { 0 }; + +error: you seem to be trying to match on a boolean expression + --> $DIR/matches.rs:131:5 + | +131 | match test { + | _____^ starting here... +132 | | //~^ ERROR you seem to be trying to match on a boolean expression +133 | | //~| HELP consider +134 | | //~| SUGGESTION if !test { println!("Noooo!"); }; +135 | | true => (), +136 | | false => { println!("Noooo!"); } +137 | | }; + | |_____^ ...ending here + | + = note: #[deny(match_bool)] implied by #[deny(clippy)] +help: consider using an if/else expression + | if !test { println!("Noooo!"); }; + +error: you seem to be trying to match on a boolean expression + --> $DIR/matches.rs:139:5 + | +139 | match test { + | _____^ starting here... +140 | | //~^ ERROR you seem to be trying to match on a boolean expression +141 | | //~| HELP consider +142 | | //~| SUGGESTION if !test { println!("Noooo!"); }; +143 | | false => { println!("Noooo!"); } +144 | | _ => (), +145 | | }; + | |_____^ ...ending here + | + = note: #[deny(match_bool)] implied by #[deny(clippy)] +help: consider using an if/else expression + | if !test { println!("Noooo!"); }; + +error: you seem to be trying to match on a boolean expression + --> $DIR/matches.rs:147:5 + | +147 | match test && test { + | _____^ starting here... +148 | | //~^ ERROR you seem to be trying to match on a boolean expression +149 | | //~| HELP consider +150 | | //~| SUGGESTION if !(test && test) { println!("Noooo!"); }; +151 | | //~| ERROR equal expressions as operands +152 | | false => { println!("Noooo!"); } +153 | | _ => (), +154 | | }; + | |_____^ ...ending here + | + = note: #[deny(match_bool)] implied by #[deny(clippy)] +help: consider using an if/else expression + | if !(test && test) { println!("Noooo!"); }; + +error: equal expressions as operands to `&&` + --> $DIR/matches.rs:147:11 + | +147 | match test && test { + | ^^^^^^^^^^^^ + | + = note: #[deny(eq_op)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/matches.rs:5:9 + | +5 | #![deny(clippy)] + | ^^^^^^ + +error: you seem to be trying to match on a boolean expression + --> $DIR/matches.rs:156:5 + | +156 | match test { + | _____^ starting here... +157 | | //~^ ERROR you seem to be trying to match on a boolean expression +158 | | //~| HELP consider +159 | | //~| SUGGESTION if test { println!("Yes!"); } else { println!("Noooo!"); }; +160 | | false => { println!("Noooo!"); } +161 | | true => { println!("Yes!"); } +162 | | }; + | |_____^ ...ending here + | + = note: #[deny(match_bool)] implied by #[deny(clippy)] +help: consider using an if/else expression + | if test { println!("Yes!"); } else { println!("Noooo!"); }; + +error: you don't need to add `&` to all patterns + --> $DIR/matches.rs:175:9 + | +175 | match v { + | _________^ starting here... +176 | | //~^ERROR add `&` to all patterns +177 | | //~|HELP instead of +178 | | //~|SUGGESTION match *v { .. } +179 | | &Some(v) => println!("{:?}", v), +180 | | &None => println!("none"), +181 | | } + | |_________^ ...ending here + | + = note: #[deny(match_ref_pats)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/matches.rs:5:9 + | +5 | #![deny(clippy)] + | ^^^^^^ +help: instead of prefixing all patterns with `&`, you can dereference the expression + | match *v { .. } + +error: you don't need to add `&` to all patterns + --> $DIR/matches.rs:188:5 + | +188 | match tup { + | _____^ starting here... +189 | | //~^ERROR add `&` to all patterns +190 | | //~|HELP instead of +191 | | //~|SUGGESTION match *tup { .. } +192 | | &(v, 1) => println!("{}", v), +193 | | _ => println!("none"), +194 | | } + | |_____^ ...ending here + | + = note: #[deny(match_ref_pats)] implied by #[deny(clippy)] +help: instead of prefixing all patterns with `&`, you can dereference the expression + | match *tup { .. } + +error: you don't need to add `&` to both the expression and the patterns + --> $DIR/matches.rs:197:5 + | +197 | match &w { + | _____^ starting here... +198 | | //~^ERROR add `&` to both +199 | | //~|HELP try +200 | | //~|SUGGESTION match w { .. } +201 | | &Some(v) => println!("{:?}", v), +202 | | &None => println!("none"), +203 | | } + | |_____^ ...ending here + | + = note: #[deny(match_ref_pats)] implied by #[deny(clippy)] +help: try + | match w { .. } + +error: you don't need to add `&` to all patterns + --> $DIR/matches.rs:211:5 + | +211 | if let &None = a { + | _____^ starting here... +212 | | //~^ERROR add `&` to all patterns +213 | | //~|HELP instead of +214 | | //~|SUGGESTION if let .. = *a { .. } +215 | | println!("none"); +216 | | } + | |_____^ ...ending here + | + = note: #[deny(match_ref_pats)] implied by #[deny(clippy)] +help: instead of prefixing all patterns with `&`, you can dereference the expression + | if let .. = *a { .. } + +error: you don't need to add `&` to both the expression and the patterns + --> $DIR/matches.rs:219:5 + | +219 | if let &None = &b { + | _____^ starting here... +220 | | //~^ERROR add `&` to both +221 | | //~|HELP try +222 | | //~|SUGGESTION if let .. = b { .. } +223 | | println!("none"); +224 | | } + | |_____^ ...ending here + | + = note: #[deny(match_ref_pats)] implied by #[deny(clippy)] +help: try + | if let .. = b { .. } + +error: some ranges overlap + --> $DIR/matches.rs:231:9 + | +231 | 0 ... 10 => println!("0 ... 10"), //~ERROR: some ranges overlap + | ^^^^^^^^ + | + = note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/matches.rs:5:9 + | +5 | #![deny(clippy)] + | ^^^^^^ +note: overlaps with this + --> $DIR/matches.rs:232:9 + | +232 | 0 ... 11 => println!("0 ... 11"), //~NOTE overlaps with this + | ^^^^^^^^ + +error: some ranges overlap + --> $DIR/matches.rs:237:9 + | +237 | 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap + | ^^^^^^^ + | + = note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)] +note: overlaps with this + --> $DIR/matches.rs:239:9 + | +239 | FOO ... 11 => println!("0 ... 11"), //~NOTE overlaps with this + | ^^^^^^^^^^ + +error: some ranges overlap + --> $DIR/matches.rs:245:9 + | +245 | 0 ... 5 => println!("0 ... 5"), //~ERROR: some ranges overlap + | ^^^^^^^ + | + = note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)] +note: overlaps with this + --> $DIR/matches.rs:244:9 + | +244 | 2 => println!("2"), //~NOTE overlaps with this + | ^ + +error: some ranges overlap + --> $DIR/matches.rs:251:9 + | +251 | 0 ... 2 => println!("0 ... 2"), //~ERROR: some ranges overlap + | ^^^^^^^ + | + = note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)] +note: overlaps with this + --> $DIR/matches.rs:250:9 + | +250 | 2 => println!("2"), //~NOTE overlaps with this + | ^ + +error: some ranges overlap + --> $DIR/matches.rs:274:9 + | +274 | 0 .. 11 => println!("0 .. 11"), //~ERROR: some ranges overlap + | ^^^^^^^ + | + = note: #[deny(match_overlapping_arm)] implied by #[deny(clippy)] +note: overlaps with this + --> $DIR/matches.rs:275:9 + | +275 | 0 ... 11 => println!("0 ... 11"), //~NOTE overlaps with this + | ^^^^^^^^ + +error: aborting due to 23 previous errors + diff --git a/tests/compile-fail/mem_forget.rs b/tests/ui/mem_forget.rs similarity index 100% rename from tests/compile-fail/mem_forget.rs rename to tests/ui/mem_forget.rs diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr new file mode 100644 index 00000000000..47c61adfbbf --- /dev/null +++ b/tests/ui/mem_forget.stderr @@ -0,0 +1,26 @@ +error: usage of mem::forget on Drop type + --> $DIR/mem_forget.rs:16:5 + | +16 | memstuff::forget(six); + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/mem_forget.rs:10:8 + | +10 | #[deny(mem_forget)] + | ^^^^^^^^^^ + +error: usage of mem::forget on Drop type + --> $DIR/mem_forget.rs:20:5 + | +20 | std::mem::forget(seven); + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: usage of mem::forget on Drop type + --> $DIR/mem_forget.rs:24:5 + | +24 | forgetSomething(eight); + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs new file mode 100644 index 00000000000..43a4386886d --- /dev/null +++ b/tests/ui/methods.rs @@ -0,0 +1,691 @@ +#![feature(plugin)] +#![feature(const_fn)] +#![plugin(clippy)] + +#![deny(clippy, clippy_pedantic)] +#![allow(blacklisted_name, unused, print_stdout, non_ascii_literal, new_without_default, new_without_default_derive, missing_docs_in_private_items)] + +use std::collections::BTreeMap; +use std::collections::HashMap; +use std::collections::HashSet; +use std::collections::VecDeque; +use std::ops::Mul; +use std::iter::FromIterator; + +struct T; + +impl T { + fn add(self, other: T) -> T { self } //~ERROR defining a method called `add` + fn drop(&mut self) { } //~ERROR defining a method called `drop` + + fn sub(&self, other: T) -> &T { self } // no error, self is a ref + fn div(self) -> T { self } // no error, different #arguments + fn rem(self, other: T) { } // no error, wrong return type + + fn into_u32(self) -> u32 { 0 } // fine + fn into_u16(&self) -> u16 { 0 } //~ERROR methods called `into_*` usually take self by value + + fn to_something(self) -> u32 { 0 } //~ERROR methods called `to_*` usually take self by reference + + fn new(self) {} + //~^ ERROR methods called `new` usually take no self + //~| ERROR methods called `new` usually return `Self` +} + +struct Lt<'a> { + foo: &'a u32, +} + +impl<'a> Lt<'a> { + // The lifetime is different, but that’s irrelevant, see #734 + #[allow(needless_lifetimes)] + pub fn new<'b>(s: &'b str) -> Lt<'b> { unimplemented!() } +} + +struct Lt2<'a> { + foo: &'a u32, +} + +impl<'a> Lt2<'a> { + // The lifetime is different, but that’s irrelevant, see #734 + pub fn new(s: &str) -> Lt2 { unimplemented!() } +} + +struct Lt3<'a> { + foo: &'a u32, +} + +impl<'a> Lt3<'a> { + // The lifetime is different, but that’s irrelevant, see #734 + pub fn new() -> Lt3<'static> { unimplemented!() } +} + +#[derive(Clone,Copy)] +struct U; + +impl U { + fn new() -> Self { U } + fn to_something(self) -> u32 { 0 } // ok because U is Copy +} + +struct V { + _dummy: T +} + +impl V { + fn new() -> Option> { None } +} + +impl Mul for T { + type Output = T; + fn mul(self, other: T) -> T { self } // no error, obviously +} + +/// Utility macro to test linting behavior in `option_methods()` +/// The lints included in `option_methods()` should not lint if the call to map is partially +/// within a macro +macro_rules! opt_map { + ($opt:expr, $map:expr) => {($opt).map($map)}; +} + +/// Checks implementation of the following lints: +/// * `OPTION_MAP_UNWRAP_OR` +/// * `OPTION_MAP_UNWRAP_OR_ELSE` +fn option_methods() { + let opt = Some(1); + + // Check OPTION_MAP_UNWRAP_OR + // single line case + let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)` + //~| NOTE replace `map(|x| x + 1).unwrap_or(0)` + .unwrap_or(0); // should lint even though this call is on a separate line + // multi line cases + let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or(a)` + x + 1 + } + ).unwrap_or(0); + let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)` + .unwrap_or({ + 0 + }); + // macro case + let _ = opt_map!(opt, |x| x + 1).unwrap_or(0); // should not lint + + // Check OPTION_MAP_UNWRAP_OR_ELSE + // single line case + let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)` + //~| NOTE replace `map(|x| x + 1).unwrap_or_else(|| 0)` + .unwrap_or_else(|| 0); // should lint even though this call is on a separate line + // multi line cases + let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or_else(g)` + x + 1 + } + ).unwrap_or_else(|| 0); + let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)` + .unwrap_or_else(|| + 0 + ); + // macro case + let _ = opt_map!(opt, |x| x + 1).unwrap_or_else(|| 0); // should not lint +} + +/// Struct to generate false positives for things with .iter() +#[derive(Copy, Clone)] +struct HasIter; + +impl HasIter { + fn iter(self) -> IteratorFalsePositives { + IteratorFalsePositives { foo: 0 } + } + + fn iter_mut(self) -> IteratorFalsePositives { + IteratorFalsePositives { foo: 0 } + } +} + +/// Struct to generate false positive for Iterator-based lints +#[derive(Copy, Clone)] +struct IteratorFalsePositives { + foo: u32, +} + +impl IteratorFalsePositives { + fn filter(self) -> IteratorFalsePositives { + self + } + + fn next(self) -> IteratorFalsePositives { + self + } + + fn find(self) -> Option { + Some(self.foo) + } + + fn position(self) -> Option { + Some(self.foo) + } + + fn rposition(self) -> Option { + Some(self.foo) + } + + fn nth(self, n: usize) -> Option { + Some(self.foo) + } + + fn skip(self, _: usize) -> IteratorFalsePositives { + self + } +} + +#[derive(Copy, Clone)] +struct HasChars; + +impl HasChars { + fn chars(self) -> std::str::Chars<'static> { + "HasChars".chars() + } +} + +/// Checks implementation of `FILTER_NEXT` lint +fn filter_next() { + let v = vec![3, 2, 1, 0, -1, -2, -3]; + + // check single-line case + let _ = v.iter().filter(|&x| *x < 0).next(); + //~^ ERROR called `filter(p).next()` on an `Iterator`. + //~| NOTE replace `filter(|&x| *x < 0).next()` + + // check multi-line case + let _ = v.iter().filter(|&x| { //~ERROR called `filter(p).next()` on an `Iterator`. + *x < 0 + } + ).next(); + + // check that we don't lint if the caller is not an Iterator + let foo = IteratorFalsePositives { foo: 0 }; + let _ = foo.filter().next(); +} + +/// Checks implementation of `SEARCH_IS_SOME` lint +fn search_is_some() { + let v = vec![3, 2, 1, 0, -1, -2, -3]; + + // check `find().is_some()`, single-line + let _ = v.iter().find(|&x| *x < 0).is_some(); + //~^ ERROR called `is_some()` after searching + //~| NOTE replace `find(|&x| *x < 0).is_some()` + + // check `find().is_some()`, multi-line + let _ = v.iter().find(|&x| { //~ERROR called `is_some()` after searching + *x < 0 + } + ).is_some(); + + // check `position().is_some()`, single-line + let _ = v.iter().position(|&x| x < 0).is_some(); + //~^ ERROR called `is_some()` after searching + //~| NOTE replace `position(|&x| x < 0).is_some()` + + // check `position().is_some()`, multi-line + let _ = v.iter().position(|&x| { //~ERROR called `is_some()` after searching + x < 0 + } + ).is_some(); + + // check `rposition().is_some()`, single-line + let _ = v.iter().rposition(|&x| x < 0).is_some(); + //~^ ERROR called `is_some()` after searching + //~| NOTE replace `rposition(|&x| x < 0).is_some()` + + // check `rposition().is_some()`, multi-line + let _ = v.iter().rposition(|&x| { //~ERROR called `is_some()` after searching + x < 0 + } + ).is_some(); + + // check that we don't lint if the caller is not an Iterator + let foo = IteratorFalsePositives { foo: 0 }; + let _ = foo.find().is_some(); + let _ = foo.position().is_some(); + let _ = foo.rposition().is_some(); +} + +/// Checks implementation of the `OR_FUN_CALL` lint +fn or_fun_call() { + struct Foo; + + impl Foo { + fn new() -> Foo { Foo } + } + + enum Enum { + A(i32), + } + + const fn make_const(i: i32) -> i32 { i } + + fn make() -> T { unimplemented!(); } + + let with_enum = Some(Enum::A(1)); + with_enum.unwrap_or(Enum::A(5)); + + let with_const_fn = Some(1); + with_const_fn.unwrap_or(make_const(5)); + + let with_constructor = Some(vec![1]); + with_constructor.unwrap_or(make()); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION with_constructor.unwrap_or_else(make) + + let with_new = Some(vec![1]); + with_new.unwrap_or(Vec::new()); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION with_new.unwrap_or_default(); + + let with_const_args = Some(vec![1]); + with_const_args.unwrap_or(Vec::with_capacity(12)); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION with_const_args.unwrap_or_else(|| Vec::with_capacity(12)); + + let with_err : Result<_, ()> = Ok(vec![1]); + with_err.unwrap_or(make()); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION with_err.unwrap_or_else(|_| make()); + + let with_err_args : Result<_, ()> = Ok(vec![1]); + with_err_args.unwrap_or(Vec::with_capacity(12)); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION with_err_args.unwrap_or_else(|_| Vec::with_capacity(12)); + + let with_default_trait = Some(1); + with_default_trait.unwrap_or(Default::default()); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION with_default_trait.unwrap_or_default(); + + let with_default_type = Some(1); + with_default_type.unwrap_or(u64::default()); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION with_default_type.unwrap_or_default(); + + let with_vec = Some(vec![1]); + with_vec.unwrap_or(vec![]); + //~^ERROR use of `unwrap_or` + //~|HELP try this + // FIXME #944: ~|SUGGESTION with_vec.unwrap_or_else(|| vec![]); + + let without_default = Some(Foo); + without_default.unwrap_or(Foo::new()); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION without_default.unwrap_or_else(Foo::new); + + let mut map = HashMap::::new(); + map.entry(42).or_insert(String::new()); + //~^ERROR use of `or_insert` followed by a function call + //~|HELP try this + //~|SUGGESTION map.entry(42).or_insert_with(String::new); + + let mut btree = BTreeMap::::new(); + btree.entry(42).or_insert(String::new()); + //~^ERROR use of `or_insert` followed by a function call + //~|HELP try this + //~|SUGGESTION btree.entry(42).or_insert_with(String::new); + + let stringy = Some(String::from("")); + let _ = stringy.unwrap_or("".to_owned()); + //~^ERROR use of `unwrap_or` + //~|HELP try this + //~|SUGGESTION stringy.unwrap_or_else(|| "".to_owned()); +} + +/// Checks implementation of `ITER_NTH` lint +fn iter_nth() { + let mut some_vec = vec![0, 1, 2, 3]; + let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); + let mut some_vec_deque: VecDeque<_> = some_vec.iter().cloned().collect(); + + { + // Make sure we lint `.iter()` for relevant types + let bad_vec = some_vec.iter().nth(3); + //~^ERROR called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable + let bad_slice = &some_vec[..].iter().nth(3); + //~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable + let bad_boxed_slice = boxed_slice.iter().nth(3); + //~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable + let bad_vec_deque = some_vec_deque.iter().nth(3); + //~^ERROR called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable + } + + { + // Make sure we lint `.iter_mut()` for relevant types + let bad_vec = some_vec.iter_mut().nth(3); + //~^ERROR called `.iter_mut().nth()` on a Vec. Calling `.get_mut()` is both faster and more readable + } + { + let bad_slice = &some_vec[..].iter_mut().nth(3); + //~^ERROR called `.iter_mut().nth()` on a slice. Calling `.get_mut()` is both faster and more readable + } + { + let bad_vec_deque = some_vec_deque.iter_mut().nth(3); + //~^ERROR called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both faster and more readable + } + + // Make sure we don't lint for non-relevant types + let false_positive = HasIter; + let ok = false_positive.iter().nth(3); + let ok_mut = false_positive.iter_mut().nth(3); +} + +/// Checks implementation of `ITER_SKIP_NEXT` lint +fn iter_skip_next() { + let mut some_vec = vec![0, 1, 2, 3]; + + let _ = some_vec.iter().skip(42).next(); + //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` + + let _ = some_vec.iter().cycle().skip(42).next(); + //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` + + let _ = (1..10).skip(10).next(); + //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` + + let _ = &some_vec[..].iter().skip(3).next(); + //~^ERROR called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` + + let foo = IteratorFalsePositives { foo : 0 }; + let _ = foo.skip(42).next(); + let _ = foo.filter().skip(42).next(); +} + +struct GetFalsePositive { + arr: [u32; 3], +} + +impl GetFalsePositive { + fn get(&self, pos: usize) -> Option<&u32> { self.arr.get(pos) } + fn get_mut(&mut self, pos: usize) -> Option<&mut u32> { self.arr.get_mut(pos) } +} + +/// Checks implementation of `GET_UNWRAP` lint +fn get_unwrap() { + let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); + let mut some_slice = &mut [0, 1, 2, 3]; + let mut some_vec = vec![0, 1, 2, 3]; + let mut some_vecdeque: VecDeque<_> = some_vec.iter().cloned().collect(); + let mut some_hashmap: HashMap = HashMap::from_iter(vec![(1, 'a'), (2, 'b')]); + let mut some_btreemap: BTreeMap = BTreeMap::from_iter(vec![(1, 'a'), (2, 'b')]); + let mut false_positive = GetFalsePositive { arr: [0, 1, 2] }; + + { // Test `get().unwrap()` + let _ = boxed_slice.get(1).unwrap(); + //~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION boxed_slice[1] + let _ = some_slice.get(0).unwrap(); + //~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION some_slice[0] + let _ = some_vec.get(0).unwrap(); + //~^ERROR called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION some_vec[0] + let _ = some_vecdeque.get(0).unwrap(); + //~^ERROR called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION some_vecdeque[0] + let _ = some_hashmap.get(&1).unwrap(); + //~^ERROR called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION some_hashmap[&1] + let _ = some_btreemap.get(&1).unwrap(); + //~^ERROR called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION some_btreemap[&1] + + let _ = false_positive.get(0).unwrap(); + } + + { // Test `get_mut().unwrap()` + *boxed_slice.get_mut(0).unwrap() = 1; + //~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION &mut boxed_slice[0] + *some_slice.get_mut(0).unwrap() = 1; + //~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION &mut some_slice[0] + *some_vec.get_mut(0).unwrap() = 1; + //~^ERROR called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION &mut some_vec[0] + *some_vecdeque.get_mut(0).unwrap() = 1; + //~^ERROR called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise + //~|HELP try this + //~|SUGGESTION &mut some_vecdeque[0] + + // Check false positives + *some_hashmap.get_mut(&1).unwrap() = 'b'; + *some_btreemap.get_mut(&1).unwrap() = 'b'; + *false_positive.get_mut(0).unwrap() = 1; + } +} + + +#[allow(similar_names)] +fn main() { + use std::io; + + let opt = Some(0); + let _ = opt.unwrap(); //~ERROR used unwrap() on an Option + + let res: Result = Ok(0); + let _ = res.unwrap(); //~ERROR used unwrap() on a Result + + res.ok().expect("disaster!"); //~ERROR called `ok().expect()` + // the following should not warn, since `expect` isn't implemented unless + // the error type implements `Debug` + let res2: Result = Ok(0); + res2.ok().expect("oh noes!"); + let res3: Result>= Ok(0); + res3.ok().expect("whoof"); //~ERROR called `ok().expect()` + let res4: Result = Ok(0); + res4.ok().expect("argh"); //~ERROR called `ok().expect()` + let res5: io::Result = Ok(0); + res5.ok().expect("oops"); //~ERROR called `ok().expect()` + let res6: Result = Ok(0); + res6.ok().expect("meh"); //~ERROR called `ok().expect()` +} + +struct MyError(()); // doesn't implement Debug + +#[derive(Debug)] +struct MyErrorWithParam { + x: T +} + +#[allow(unnecessary_operation)] +fn starts_with() { + "".chars().next() == Some(' '); + //~^ ERROR starts_with + //~| HELP like this + //~| SUGGESTION "".starts_with(' ') + + Some(' ') != "".chars().next(); + //~^ ERROR starts_with + //~| HELP like this + //~| SUGGESTION !"".starts_with(' ') +} + +fn str_extend_chars() { + let abc = "abc"; + let def = String::from("def"); + let mut s = String::new(); + + s.push_str(abc); + s.extend(abc.chars()); + //~^ERROR calling `.extend(_.chars())` + //~|HELP try this + //~|SUGGESTION s.push_str(abc) + + s.push_str("abc"); + s.extend("abc".chars()); + //~^ERROR calling `.extend(_.chars())` + //~|HELP try this + //~|SUGGESTION s.push_str("abc") + + s.push_str(&def); + s.extend(def.chars()); + //~^ERROR calling `.extend(_.chars())` + //~|HELP try this + //~|SUGGESTION s.push_str(&def) + + s.extend(abc.chars().skip(1)); + s.extend("abc".chars().skip(1)); + s.extend(['a', 'b', 'c'].iter()); + + let f = HasChars; + s.extend(f.chars()); +} + +fn clone_on_copy() { + 42.clone(); //~ERROR using `clone` on a `Copy` type + //~| HELP try removing the `clone` call + //~| SUGGESTION 42 + vec![1].clone(); // ok, not a Copy type + Some(vec![1]).clone(); // ok, not a Copy type + (&42).clone(); //~ERROR using `clone` on a `Copy` type + //~| HELP try dereferencing it + //~| SUGGESTION *(&42) +} + +fn clone_on_copy_generic(t: T) { + t.clone(); //~ERROR using `clone` on a `Copy` type + //~| HELP try removing the `clone` call + //~| SUGGESTION t + Some(t).clone(); //~ERROR using `clone` on a `Copy` type + //~| HELP try removing the `clone` call + //~| SUGGESTION Some(t) +} + +fn clone_on_double_ref() { + let x = vec![1]; + let y = &&x; + let z: &Vec<_> = y.clone(); //~ERROR using `clone` on a double + //~| HELP try dereferencing it + //~| SUGGESTION let z: &Vec<_> = (*y).clone(); + println!("{:p} {:p}",*y, z); +} + +fn single_char_pattern() { + let x = "foo"; + x.split("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.split('x'); + + x.split("xx"); + + x.split('x'); + + let y = "x"; + x.split(y); + + // Not yet testing for multi-byte characters + // Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_single_char_pattern` + // should have done this but produced an ICE + // + // We may not want to suggest changing these anyway + // See: https://github.com/Manishearth/rust-clippy/issues/650#issuecomment-184328984 + x.split("ß"); + x.split("ℝ"); + x.split("💣"); + // Can't use this lint for unicode code points which don't fit in a char + x.split("❤️"); + + x.contains("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.contains('x'); + x.starts_with("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.starts_with('x'); + x.ends_with("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.ends_with('x'); + x.find("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.find('x'); + x.rfind("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.rfind('x'); + x.rsplit("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.rsplit('x'); + x.split_terminator("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.split_terminator('x'); + x.rsplit_terminator("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.rsplit_terminator('x'); + x.splitn(0, "x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.splitn(0, 'x'); + x.rsplitn(0, "x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.rsplitn(0, 'x'); + x.matches("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.matches('x'); + x.rmatches("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.rmatches('x'); + x.match_indices("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.match_indices('x'); + x.rmatch_indices("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.rmatch_indices('x'); + x.trim_left_matches("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.trim_left_matches('x'); + x.trim_right_matches("x"); + //~^ ERROR single-character string constant used as pattern + //~| HELP try using a char instead: + //~| SUGGESTION x.trim_right_matches('x'); + + let h = HashSet::::new(); + h.contains("X"); // should not warn +} + +#[allow(result_unwrap_used)] +fn temporary_cstring() { + use std::ffi::CString; + + CString::new("foo").unwrap().as_ptr(); + //~^ ERROR you are getting the inner pointer of a temporary `CString` + //~| NOTE that pointer will be invalid outside this expression + //~| HELP assign the `CString` to a variable to extend its lifetime +} diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr new file mode 100644 index 00000000000..6b3470f11dc --- /dev/null +++ b/tests/ui/methods.stderr @@ -0,0 +1,954 @@ +error: defining a method called `add` on this type; consider implementing the `std::ops::Add` trait or choosing a less ambiguous name + --> $DIR/methods.rs:18:5 + | +18 | fn add(self, other: T) -> T { self } //~ERROR defining a method called `add` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(should_implement_trait)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + +error: defining a method called `drop` on this type; consider implementing the `std::ops::Drop` trait or choosing a less ambiguous name + --> $DIR/methods.rs:19:5 + | +19 | fn drop(&mut self) { } //~ERROR defining a method called `drop` + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(should_implement_trait)] implied by #[deny(clippy)] + +error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name + --> $DIR/methods.rs:26:17 + | +26 | fn into_u16(&self) -> u16 { 0 } //~ERROR methods called `into_*` usually take self by value + | ^^^^^ + | + = note: #[deny(wrong_self_convention)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + +error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name + --> $DIR/methods.rs:28:21 + | +28 | fn to_something(self) -> u32 { 0 } //~ERROR methods called `to_*` usually take self by reference + | ^^^^ + | + = note: #[deny(wrong_self_convention)] implied by #[deny(clippy)] + +error: methods called `new` usually take no self; consider choosing a less ambiguous name + --> $DIR/methods.rs:30:12 + | +30 | fn new(self) {} + | ^^^^ + | + = note: #[deny(wrong_self_convention)] implied by #[deny(clippy)] + +error: methods called `new` usually return `Self` + --> $DIR/methods.rs:30:5 + | +30 | fn new(self) {} + | ^^^^^^^^^^^^^^^ + | + = note: #[deny(new_ret_no_self)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + +error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead + --> $DIR/methods.rs:99:13 + | +99 | let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)` + | _____________^ starting here... +100 | | //~| NOTE replace `map(|x| x + 1).unwrap_or(0)` +101 | | .unwrap_or(0); // should lint even though this call is on a separate line + | |____________________________^ ...ending here + | + = note: #[deny(option_map_unwrap_or)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/methods.rs:5:17 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ + = note: replace `map(|x| x + 1).unwrap_or(0)` with `map_or(0, |x| x + 1)` + +error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead + --> $DIR/methods.rs:103:13 + | +103 | let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or(a)` + | _____________^ starting here... +104 | | x + 1 +105 | | } +106 | | ).unwrap_or(0); + | |____________________________^ ...ending here + | + = note: #[deny(option_map_unwrap_or)] implied by #[deny(clippy_pedantic)] + +error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead + --> $DIR/methods.rs:107:13 + | +107 | let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)` + | _____________^ starting here... +108 | | .unwrap_or({ +109 | | 0 +110 | | }); + | |__________________^ ...ending here + | + = note: #[deny(option_map_unwrap_or)] implied by #[deny(clippy_pedantic)] + +error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead + --> $DIR/methods.rs:116:13 + | +116 | let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)` + | _____________^ starting here... +117 | | //~| NOTE replace `map(|x| x + 1).unwrap_or_else(|| 0)` +118 | | .unwrap_or_else(|| 0); // should lint even though this call is on a separate line + | |____________________________________^ ...ending here + | + = note: #[deny(option_map_unwrap_or_else)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/methods.rs:5:17 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ + = note: replace `map(|x| x + 1).unwrap_or_else(|| 0)` with `with map_or_else(|| 0, |x| x + 1)` + +error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead + --> $DIR/methods.rs:120:13 + | +120 | let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or_else(g)` + | _____________^ starting here... +121 | | x + 1 +122 | | } +123 | | ).unwrap_or_else(|| 0); + | |____________________________________^ ...ending here + | + = note: #[deny(option_map_unwrap_or_else)] implied by #[deny(clippy_pedantic)] + +error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead + --> $DIR/methods.rs:124:13 + | +124 | let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)` + | _____________^ starting here... +125 | | .unwrap_or_else(|| +126 | | 0 +127 | | ); + | |_________________^ ...ending here + | + = note: #[deny(option_map_unwrap_or_else)] implied by #[deny(clippy_pedantic)] + +error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead. + --> $DIR/methods.rs:196:13 + | +196 | let _ = v.iter().filter(|&x| *x < 0).next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(filter_next)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + = note: replace `filter(|&x| *x < 0).next()` with `find(|&x| *x < 0)` + +error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead. + --> $DIR/methods.rs:201:13 + | +201 | let _ = v.iter().filter(|&x| { //~ERROR called `filter(p).next()` on an `Iterator`. + | _____________^ starting here... +202 | | *x < 0 +203 | | } +204 | | ).next(); + | |___________________________^ ...ending here + | + = note: #[deny(filter_next)] implied by #[deny(clippy)] + +error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`. + --> $DIR/methods.rs:216:13 + | +216 | let _ = v.iter().find(|&x| *x < 0).is_some(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(search_is_some)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + = note: replace `find(|&x| *x < 0).is_some()` with `any(|&x| *x < 0)` + +error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`. + --> $DIR/methods.rs:221:13 + | +221 | let _ = v.iter().find(|&x| { //~ERROR called `is_some()` after searching + | _____________^ starting here... +222 | | *x < 0 +223 | | } +224 | | ).is_some(); + | |______________________________^ ...ending here + | + = note: #[deny(search_is_some)] implied by #[deny(clippy)] + +error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`. + --> $DIR/methods.rs:227:13 + | +227 | let _ = v.iter().position(|&x| x < 0).is_some(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(search_is_some)] implied by #[deny(clippy)] + = note: replace `position(|&x| x < 0).is_some()` with `any(|&x| x < 0)` + +error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`. + --> $DIR/methods.rs:232:13 + | +232 | let _ = v.iter().position(|&x| { //~ERROR called `is_some()` after searching + | _____________^ starting here... +233 | | x < 0 +234 | | } +235 | | ).is_some(); + | |______________________________^ ...ending here + | + = note: #[deny(search_is_some)] implied by #[deny(clippy)] + +error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`. + --> $DIR/methods.rs:238:13 + | +238 | let _ = v.iter().rposition(|&x| x < 0).is_some(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(search_is_some)] implied by #[deny(clippy)] + = note: replace `rposition(|&x| x < 0).is_some()` with `any(|&x| x < 0)` + +error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`. + --> $DIR/methods.rs:243:13 + | +243 | let _ = v.iter().rposition(|&x| { //~ERROR called `is_some()` after searching + | _____________^ starting here... +244 | | x < 0 +245 | | } +246 | | ).is_some(); + | |______________________________^ ...ending here + | + = note: #[deny(search_is_some)] implied by #[deny(clippy)] + +error: use of `unwrap_or` followed by a function call + --> $DIR/methods.rs:278:5 + | +278 | with_constructor.unwrap_or(make()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ +help: try this + | with_constructor.unwrap_or_else(make); + +error: use of `unwrap_or` followed by a call to `new` + --> $DIR/methods.rs:284:5 + | +284 | with_new.unwrap_or(Vec::new()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | with_new.unwrap_or_default(); + +error: use of `unwrap_or` followed by a function call + --> $DIR/methods.rs:290:5 + | +290 | with_const_args.unwrap_or(Vec::with_capacity(12)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | with_const_args.unwrap_or_else(|| Vec::with_capacity(12)); + +error: use of `unwrap_or` followed by a function call + --> $DIR/methods.rs:296:5 + | +296 | with_err.unwrap_or(make()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | with_err.unwrap_or_else(|_| make()); + +error: use of `unwrap_or` followed by a function call + --> $DIR/methods.rs:302:5 + | +302 | with_err_args.unwrap_or(Vec::with_capacity(12)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | with_err_args.unwrap_or_else(|_| Vec::with_capacity(12)); + +error: use of `unwrap_or` followed by a call to `default` + --> $DIR/methods.rs:308:5 + | +308 | with_default_trait.unwrap_or(Default::default()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | with_default_trait.unwrap_or_default(); + +error: use of `unwrap_or` followed by a call to `default` + --> $DIR/methods.rs:314:5 + | +314 | with_default_type.unwrap_or(u64::default()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | with_default_type.unwrap_or_default(); + +error: use of `unwrap_or` followed by a function call + --> $DIR/methods.rs:320:5 + | +320 | with_vec.unwrap_or(vec![]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | with_vec.unwrap_or_else(|| < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] )); + +error: use of `unwrap_or` followed by a function call + --> $DIR/methods.rs:326:5 + | +326 | without_default.unwrap_or(Foo::new()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | without_default.unwrap_or_else(Foo::new); + +error: use of `or_insert` followed by a function call + --> $DIR/methods.rs:332:5 + | +332 | map.entry(42).or_insert(String::new()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | map.entry(42).or_insert_with(String::new); + +error: use of `or_insert` followed by a function call + --> $DIR/methods.rs:338:5 + | +338 | btree.entry(42).or_insert(String::new()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | btree.entry(42).or_insert_with(String::new); + +error: use of `unwrap_or` followed by a function call + --> $DIR/methods.rs:344:13 + | +344 | let _ = stringy.unwrap_or("".to_owned()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(or_fun_call)] implied by #[deny(clippy)] +help: try this + | let _ = stringy.unwrap_or_else(|| "".to_owned()); + +error: called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable + --> $DIR/methods.rs:358:23 + | +358 | let bad_vec = some_vec.iter().nth(3); + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_nth)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + +error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable + --> $DIR/methods.rs:360:26 + | +360 | let bad_slice = &some_vec[..].iter().nth(3); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_nth)] implied by #[deny(clippy)] + +error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable + --> $DIR/methods.rs:362:31 + | +362 | let bad_boxed_slice = boxed_slice.iter().nth(3); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_nth)] implied by #[deny(clippy)] + +error: called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable + --> $DIR/methods.rs:364:29 + | +364 | let bad_vec_deque = some_vec_deque.iter().nth(3); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_nth)] implied by #[deny(clippy)] + +error: called `.iter_mut().nth()` on a Vec. Calling `.get_mut()` is both faster and more readable + --> $DIR/methods.rs:370:23 + | +370 | let bad_vec = some_vec.iter_mut().nth(3); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_nth)] implied by #[deny(clippy)] + +error: called `.iter_mut().nth()` on a slice. Calling `.get_mut()` is both faster and more readable + --> $DIR/methods.rs:374:26 + | +374 | let bad_slice = &some_vec[..].iter_mut().nth(3); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_nth)] implied by #[deny(clippy)] + +error: called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both faster and more readable + --> $DIR/methods.rs:378:29 + | +378 | let bad_vec_deque = some_vec_deque.iter_mut().nth(3); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_nth)] implied by #[deny(clippy)] + +error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` + --> $DIR/methods.rs:392:13 + | +392 | let _ = some_vec.iter().skip(42).next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_skip_next)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + +error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` + --> $DIR/methods.rs:395:13 + | +395 | let _ = some_vec.iter().cycle().skip(42).next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_skip_next)] implied by #[deny(clippy)] + +error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` + --> $DIR/methods.rs:398:13 + | +398 | let _ = (1..10).skip(10).next(); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_skip_next)] implied by #[deny(clippy)] + +error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)` + --> $DIR/methods.rs:401:14 + | +401 | let _ = &some_vec[..].iter().skip(3).next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(iter_skip_next)] implied by #[deny(clippy)] + +error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise + --> $DIR/methods.rs:429:17 + | +429 | let _ = boxed_slice.get(1).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ +help: try this + | let _ = &boxed_slice[1]; + +error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise + --> $DIR/methods.rs:433:17 + | +433 | let _ = some_slice.get(0).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | let _ = &some_slice[0]; + +error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise + --> $DIR/methods.rs:437:17 + | +437 | let _ = some_vec.get(0).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | let _ = &some_vec[0]; + +error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise + --> $DIR/methods.rs:441:17 + | +441 | let _ = some_vecdeque.get(0).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | let _ = &some_vecdeque[0]; + +error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise + --> $DIR/methods.rs:445:17 + | +445 | let _ = some_hashmap.get(&1).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | let _ = &some_hashmap[&1]; + +error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise + --> $DIR/methods.rs:449:17 + | +449 | let _ = some_btreemap.get(&1).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | let _ = &some_btreemap[&1]; + +error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise + --> $DIR/methods.rs:458:10 + | +458 | *boxed_slice.get_mut(0).unwrap() = 1; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | *&mut boxed_slice[0] = 1; + +error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise + --> $DIR/methods.rs:462:10 + | +462 | *some_slice.get_mut(0).unwrap() = 1; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | *&mut some_slice[0] = 1; + +error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise + --> $DIR/methods.rs:466:10 + | +466 | *some_vec.get_mut(0).unwrap() = 1; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | *&mut some_vec[0] = 1; + +error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise + --> $DIR/methods.rs:470:10 + | +470 | *some_vecdeque.get_mut(0).unwrap() = 1; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(get_unwrap)] implied by #[deny(clippy)] +help: try this + | *&mut some_vecdeque[0] = 1; + +error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message + --> $DIR/methods.rs:488:13 + | +488 | let _ = opt.unwrap(); //~ERROR used unwrap() on an Option + | ^^^^^^^^^^^^ + | + = note: #[deny(option_unwrap_used)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/methods.rs:5:17 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ + +error: used unwrap() on a Result value. If you don't want to handle the Err case gracefully, consider using expect() to provide a better panic message + --> $DIR/methods.rs:491:13 + | +491 | let _ = res.unwrap(); //~ERROR used unwrap() on a Result + | ^^^^^^^^^^^^ + | + = note: #[deny(result_unwrap_used)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/methods.rs:5:17 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ + +error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` + --> $DIR/methods.rs:493:5 + | +493 | res.ok().expect("disaster!"); //~ERROR called `ok().expect()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(ok_expect)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + +error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` + --> $DIR/methods.rs:499:5 + | +499 | res3.ok().expect("whoof"); //~ERROR called `ok().expect()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(ok_expect)] implied by #[deny(clippy)] + +error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` + --> $DIR/methods.rs:501:5 + | +501 | res4.ok().expect("argh"); //~ERROR called `ok().expect()` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(ok_expect)] implied by #[deny(clippy)] + +error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` + --> $DIR/methods.rs:503:5 + | +503 | res5.ok().expect("oops"); //~ERROR called `ok().expect()` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(ok_expect)] implied by #[deny(clippy)] + +error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result` + --> $DIR/methods.rs:505:5 + | +505 | res6.ok().expect("meh"); //~ERROR called `ok().expect()` + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(ok_expect)] implied by #[deny(clippy)] + +error: you should use the `starts_with` method + --> $DIR/methods.rs:517:5 + | +517 | "".chars().next() == Some(' '); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(chars_next_cmp)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ +help: like this + | "".starts_with(' '); + +error: you should use the `starts_with` method + --> $DIR/methods.rs:522:5 + | +522 | Some(' ') != "".chars().next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(chars_next_cmp)] implied by #[deny(clippy)] +help: like this + | !"".starts_with(' '); + +error: calling `.extend(_.chars())` + --> $DIR/methods.rs:534:5 + | +534 | s.extend(abc.chars()); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(string_extend_chars)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ +help: try this + | s.push_str(abc); + +error: calling `.extend(_.chars())` + --> $DIR/methods.rs:540:5 + | +540 | s.extend("abc".chars()); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(string_extend_chars)] implied by #[deny(clippy)] +help: try this + | s.push_str("abc"); + +error: calling `.extend(_.chars())` + --> $DIR/methods.rs:546:5 + | +546 | s.extend(def.chars()); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(string_extend_chars)] implied by #[deny(clippy)] +help: try this + | s.push_str(&def); + +error: using `clone` on a `Copy` type + --> $DIR/methods.rs:560:5 + | +560 | 42.clone(); //~ERROR using `clone` on a `Copy` type + | ^^^^^^^^^^ + | + = note: #[deny(clone_on_copy)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ +help: try removing the `clone` call + | 42; //~ERROR using `clone` on a `Copy` type + +error: using `clone` on a `Copy` type + --> $DIR/methods.rs:565:5 + | +565 | (&42).clone(); //~ERROR using `clone` on a `Copy` type + | ^^^^^^^^^^^^^ + | + = note: #[deny(clone_on_copy)] implied by #[deny(clippy)] +help: try dereferencing it + | *(&42); //~ERROR using `clone` on a `Copy` type + +error: using `clone` on a `Copy` type + --> $DIR/methods.rs:571:5 + | +571 | t.clone(); //~ERROR using `clone` on a `Copy` type + | ^^^^^^^^^ + | + = note: #[deny(clone_on_copy)] implied by #[deny(clippy)] +help: try removing the `clone` call + | t; //~ERROR using `clone` on a `Copy` type + +error: using `clone` on a `Copy` type + --> $DIR/methods.rs:574:5 + | +574 | Some(t).clone(); //~ERROR using `clone` on a `Copy` type + | ^^^^^^^^^^^^^^^ + | + = note: #[deny(clone_on_copy)] implied by #[deny(clippy)] +help: try removing the `clone` call + | Some(t); //~ERROR using `clone` on a `Copy` type + +error: using `clone` on a double-reference; this will copy the reference instead of cloning the inner type + --> $DIR/methods.rs:582:22 + | +582 | let z: &Vec<_> = y.clone(); //~ERROR using `clone` on a double + | ^^^^^^^^^ + | + = note: #[deny(clone_double_ref)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ +help: try dereferencing it + | let z: &Vec<_> = (*y).clone(); //~ERROR using `clone` on a double + +error: single-character string constant used as pattern + --> $DIR/methods.rs:590:13 + | +590 | x.split("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ +help: try using a char instead: + | x.split('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:614:16 + | +614 | x.contains("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.contains('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:618:19 + | +618 | x.starts_with("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.starts_with('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:622:17 + | +622 | x.ends_with("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.ends_with('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:626:12 + | +626 | x.find("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.find('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:630:13 + | +630 | x.rfind("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.rfind('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:634:14 + | +634 | x.rsplit("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.rsplit('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:638:24 + | +638 | x.split_terminator("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.split_terminator('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:642:25 + | +642 | x.rsplit_terminator("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.rsplit_terminator('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:646:17 + | +646 | x.splitn(0, "x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.splitn(0, 'x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:650:18 + | +650 | x.rsplitn(0, "x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.rsplitn(0, 'x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:654:15 + | +654 | x.matches("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.matches('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:658:16 + | +658 | x.rmatches("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.rmatches('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:662:21 + | +662 | x.match_indices("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.match_indices('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:666:22 + | +666 | x.rmatch_indices("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.rmatch_indices('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:670:25 + | +670 | x.trim_left_matches("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.trim_left_matches('x'); + +error: single-character string constant used as pattern + --> $DIR/methods.rs:674:26 + | +674 | x.trim_right_matches("x"); + | ^^^ + | + = note: #[deny(single_char_pattern)] implied by #[deny(clippy)] +help: try using a char instead: + | x.trim_right_matches('x'); + +error: you are getting the inner pointer of a temporary `CString` + --> $DIR/methods.rs:687:5 + | +687 | CString::new("foo").unwrap().as_ptr(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(temporary_cstring_as_ptr)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/methods.rs:5:9 + | +5 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^ + = note: that pointer will be invalid outside this expression +help: assign the `CString` to a variable to extend its lifetime + --> $DIR/methods.rs:687:5 + | +687 | CString::new("foo").unwrap().as_ptr(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 88 previous errors + diff --git a/tests/compile-fail/min_max.rs b/tests/ui/min_max.rs similarity index 100% rename from tests/compile-fail/min_max.rs rename to tests/ui/min_max.rs diff --git a/tests/ui/min_max.stderr b/tests/ui/min_max.stderr new file mode 100644 index 00000000000..3cb562e26df --- /dev/null +++ b/tests/ui/min_max.stderr @@ -0,0 +1,63 @@ +error: this min/max combination leads to constant result + --> $DIR/min_max.rs:15:5 + | +15 | min(1, max(3, x)); //~ERROR this min/max combination leads to constant result + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(min_max)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/min_max.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + +error: this min/max combination leads to constant result + --> $DIR/min_max.rs:16:5 + | +16 | min(max(3, x), 1); //~ERROR this min/max combination leads to constant result + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(min_max)] implied by #[deny(clippy)] + +error: this min/max combination leads to constant result + --> $DIR/min_max.rs:17:5 + | +17 | max(min(x, 1), 3); //~ERROR this min/max combination leads to constant result + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(min_max)] implied by #[deny(clippy)] + +error: this min/max combination leads to constant result + --> $DIR/min_max.rs:18:5 + | +18 | max(3, min(x, 1)); //~ERROR this min/max combination leads to constant result + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(min_max)] implied by #[deny(clippy)] + +error: this min/max combination leads to constant result + --> $DIR/min_max.rs:20:5 + | +20 | my_max(3, my_min(x, 1)); //~ERROR this min/max combination leads to constant result + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(min_max)] implied by #[deny(clippy)] + +error: this min/max combination leads to constant result + --> $DIR/min_max.rs:29:5 + | +29 | min("Apple", max("Zoo", s)); //~ERROR this min/max combination leads to constant result + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(min_max)] implied by #[deny(clippy)] + +error: this min/max combination leads to constant result + --> $DIR/min_max.rs:30:5 + | +30 | max(min(s, "Apple"), "Zoo"); //~ERROR this min/max combination leads to constant result + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(min_max)] implied by #[deny(clippy)] + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/missing-doc.rs b/tests/ui/missing-doc.rs similarity index 100% rename from tests/compile-fail/missing-doc.rs rename to tests/ui/missing-doc.rs diff --git a/tests/ui/missing-doc.stderr b/tests/ui/missing-doc.stderr new file mode 100644 index 00000000000..b81f46eaa1d --- /dev/null +++ b/tests/ui/missing-doc.stderr @@ -0,0 +1,279 @@ +error: missing documentation for a type alias + --> $DIR/missing-doc.rs:26:1 + | +26 | type Typedef = String; //~ ERROR: missing documentation for a type alias + | ^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/missing-doc.rs:16:9 + | +16 | #![deny(missing_docs_in_private_items)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a type alias + --> $DIR/missing-doc.rs:27:1 + | +27 | pub type PubTypedef = String; //~ ERROR: missing documentation for a type alias + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a struct + --> $DIR/missing-doc.rs:29:1 + | +29 | struct Foo { //~ ERROR: missing documentation for a struct + | _^ starting here... +30 | | a: isize, //~ ERROR: missing documentation for a struct field +31 | | b: isize, //~ ERROR: missing documentation for a struct field +32 | | } + | |_^ ...ending here + +error: missing documentation for a struct field + --> $DIR/missing-doc.rs:30:5 + | +30 | a: isize, //~ ERROR: missing documentation for a struct field + | ^^^^^^^^ + +error: missing documentation for a struct field + --> $DIR/missing-doc.rs:31:5 + | +31 | b: isize, //~ ERROR: missing documentation for a struct field + | ^^^^^^^^ + +error: missing documentation for a struct + --> $DIR/missing-doc.rs:34:1 + | +34 | pub struct PubFoo { //~ ERROR: missing documentation for a struct + | _^ starting here... +35 | | pub a: isize, //~ ERROR: missing documentation for a struct field +36 | | b: isize, //~ ERROR: missing documentation for a struct field +37 | | } + | |_^ ...ending here + +error: missing documentation for a struct field + --> $DIR/missing-doc.rs:35:5 + | +35 | pub a: isize, //~ ERROR: missing documentation for a struct field + | ^^^^^^^^^^^^ + +error: missing documentation for a struct field + --> $DIR/missing-doc.rs:36:5 + | +36 | b: isize, //~ ERROR: missing documentation for a struct field + | ^^^^^^^^ + +error: missing documentation for a module + --> $DIR/missing-doc.rs:45:1 + | +45 | mod module_no_dox {} //~ ERROR: missing documentation for a module + | ^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a module + --> $DIR/missing-doc.rs:46:1 + | +46 | pub mod pub_module_no_dox {} //~ ERROR: missing documentation for a module + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a function + --> $DIR/missing-doc.rs:50:1 + | +50 | pub fn foo2() {} //~ ERROR: missing documentation for a function + | ^^^^^^^^^^^^^^^^ + +error: missing documentation for a function + --> $DIR/missing-doc.rs:51:1 + | +51 | fn foo3() {} //~ ERROR: missing documentation for a function + | ^^^^^^^^^^^^ + +error: missing documentation for a trait + --> $DIR/missing-doc.rs:68:1 + | +68 | pub trait C { //~ ERROR: missing documentation for a trait + | _^ starting here... +69 | | fn foo(&self); //~ ERROR: missing documentation for a trait method +70 | | fn foo_with_impl(&self) {} //~ ERROR: missing documentation for a trait method +71 | | } + | |_^ ...ending here + +error: missing documentation for a trait method + --> $DIR/missing-doc.rs:69:5 + | +69 | fn foo(&self); //~ ERROR: missing documentation for a trait method + | ^^^^^^^^^^^^^^ + +error: missing documentation for a trait method + --> $DIR/missing-doc.rs:70:5 + | +70 | fn foo_with_impl(&self) {} //~ ERROR: missing documentation for a trait method + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for an associated type + --> $DIR/missing-doc.rs:80:5 + | +80 | type AssociatedType; //~ ERROR: missing documentation for an associated type + | ^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for an associated type + --> $DIR/missing-doc.rs:81:5 + | +81 | type AssociatedTypeDef = Self; //~ ERROR: missing documentation for an associated type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a method + --> $DIR/missing-doc.rs:92:5 + | +92 | pub fn foo() {} //~ ERROR: missing documentation for a method + | ^^^^^^^^^^^^^^^ + +error: missing documentation for a method + --> $DIR/missing-doc.rs:93:5 + | +93 | fn bar() {} //~ ERROR: missing documentation for a method + | ^^^^^^^^^^^ + +error: missing documentation for a method + --> $DIR/missing-doc.rs:97:5 + | +97 | pub fn foo() {} //~ ERROR: missing documentation for a method + | ^^^^^^^^^^^^^^^ + +error: missing documentation for a method + --> $DIR/missing-doc.rs:100:5 + | +100 | fn foo2() {} //~ ERROR: missing documentation for a method + | ^^^^^^^^^^^^ + +error: missing documentation for an enum + --> $DIR/missing-doc.rs:126:1 + | +126 | enum Baz { //~ ERROR: missing documentation for an enum + | _^ starting here... +127 | | BazA { //~ ERROR: missing documentation for a variant +128 | | a: isize, //~ ERROR: missing documentation for a struct field +129 | | b: isize //~ ERROR: missing documentation for a struct field +130 | | }, +131 | | BarB //~ ERROR: missing documentation for a variant +132 | | } + | |_^ ...ending here + +error: missing documentation for a variant + --> $DIR/missing-doc.rs:127:5 + | +127 | BazA { //~ ERROR: missing documentation for a variant + | _____^ starting here... +128 | | a: isize, //~ ERROR: missing documentation for a struct field +129 | | b: isize //~ ERROR: missing documentation for a struct field +130 | | }, + | |_____^ ...ending here + +error: missing documentation for a struct field + --> $DIR/missing-doc.rs:128:9 + | +128 | a: isize, //~ ERROR: missing documentation for a struct field + | ^^^^^^^^ + +error: missing documentation for a struct field + --> $DIR/missing-doc.rs:129:9 + | +129 | b: isize //~ ERROR: missing documentation for a struct field + | ^^^^^^^^ + +error: missing documentation for a variant + --> $DIR/missing-doc.rs:131:5 + | +131 | BarB //~ ERROR: missing documentation for a variant + | ^^^^ + +error: missing documentation for an enum + --> $DIR/missing-doc.rs:134:1 + | +134 | pub enum PubBaz { //~ ERROR: missing documentation for an enum + | _^ starting here... +135 | | PubBazA { //~ ERROR: missing documentation for a variant +136 | | a: isize, //~ ERROR: missing documentation for a struct field +137 | | }, +138 | | } + | |_^ ...ending here + +error: missing documentation for a variant + --> $DIR/missing-doc.rs:135:5 + | +135 | PubBazA { //~ ERROR: missing documentation for a variant + | _____^ starting here... +136 | | a: isize, //~ ERROR: missing documentation for a struct field +137 | | }, + | |_____^ ...ending here + +error: missing documentation for a struct field + --> $DIR/missing-doc.rs:136:9 + | +136 | a: isize, //~ ERROR: missing documentation for a struct field + | ^^^^^^^^ + +error: missing documentation for a constant + --> $DIR/missing-doc.rs:160:1 + | +160 | const FOO: u32 = 0; //~ ERROR: missing documentation for a const + | ^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a constant + --> $DIR/missing-doc.rs:167:1 + | +167 | pub const FOO4: u32 = 0; //~ ERROR: missing documentation for a const + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a static + --> $DIR/missing-doc.rs:170:1 + | +170 | static BAR: u32 = 0; //~ ERROR: missing documentation for a static + | ^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a static + --> $DIR/missing-doc.rs:177:1 + | +177 | pub static BAR4: u32 = 0; //~ ERROR: missing documentation for a static + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a module + --> $DIR/missing-doc.rs:180:1 + | +180 | mod internal_impl { //~ ERROR: missing documentation for a module + | ^ + +error: missing documentation for a function + --> $DIR/missing-doc.rs:183:5 + | +183 | pub fn undocumented1() {} //~ ERROR: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a function + --> $DIR/missing-doc.rs:184:5 + | +184 | pub fn undocumented2() {} //~ ERROR: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a function + --> $DIR/missing-doc.rs:185:5 + | +185 | fn undocumented3() {} //~ ERROR: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a function + --> $DIR/missing-doc.rs:190:9 + | +190 | pub fn also_undocumented1() {} //~ ERROR: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a function + --> $DIR/missing-doc.rs:191:9 + | +191 | fn also_undocumented2() {} //~ ERROR: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: missing documentation for a function + --> $DIR/missing-doc.rs:202:1 + | +202 | fn main() {} //~ ERROR: missing documentation for a function + | ^^^^^^^^^^^^ + +error: aborting due to 40 previous errors + diff --git a/tests/compile-fail/module_inception.rs b/tests/ui/module_inception.rs similarity index 100% rename from tests/compile-fail/module_inception.rs rename to tests/ui/module_inception.rs diff --git a/tests/ui/module_inception.stderr b/tests/ui/module_inception.stderr new file mode 100644 index 00000000000..de0ff78eb40 --- /dev/null +++ b/tests/ui/module_inception.stderr @@ -0,0 +1,26 @@ +error: module has the same name as its containing module + --> $DIR/module_inception.rs:7:9 + | +7 | mod bar { //~ ERROR module has the same name as its containing module + | _________^ starting here... +8 | | mod foo {} +9 | | } + | |_________^ ...ending here + | +note: lint level defined here + --> $DIR/module_inception.rs:3:9 + | +3 | #![deny(module_inception)] + | ^^^^^^^^^^^^^^^^ + +error: module has the same name as its containing module + --> $DIR/module_inception.rs:12:5 + | +12 | mod foo { //~ ERROR module has the same name as its containing module + | _____^ starting here... +13 | | mod bar {} +14 | | } + | |_____^ ...ending here + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/modulo_one.rs b/tests/ui/modulo_one.rs similarity index 100% rename from tests/compile-fail/modulo_one.rs rename to tests/ui/modulo_one.rs diff --git a/tests/ui/modulo_one.stderr b/tests/ui/modulo_one.stderr new file mode 100644 index 00000000000..c938afb0dc3 --- /dev/null +++ b/tests/ui/modulo_one.stderr @@ -0,0 +1,14 @@ +error: any number modulo 1 will be 0 + --> $DIR/modulo_one.rs:7:5 + | +7 | 10 % 1; //~ERROR any number modulo 1 will be 0 + | ^^^^^^ + | +note: lint level defined here + --> $DIR/modulo_one.rs:3:9 + | +3 | #![deny(modulo_one)] + | ^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/mut_mut.rs b/tests/ui/mut_mut.rs similarity index 100% rename from tests/compile-fail/mut_mut.rs rename to tests/ui/mut_mut.rs diff --git a/tests/ui/mut_mut.stderr b/tests/ui/mut_mut.stderr new file mode 100644 index 00000000000..55125f8d526 --- /dev/null +++ b/tests/ui/mut_mut.stderr @@ -0,0 +1,89 @@ +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:10:12 + | +10 | fn fun(x : &mut &mut u32) -> bool { //~ERROR generally you want to avoid `&mut &mut + | ^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/mut_mut.rs:5:9 + | +5 | #![deny(mut_mut)] + | ^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:25:17 + | +25 | let mut x = &mut &mut 1u32; //~ERROR generally you want to avoid `&mut &mut + | ^^^^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:19:20 + | +19 | ($p:expr) => { &mut $p } + | ^^^^^^^ +... +49 | let mut z = mut_ptr!(&mut 3u32); + | ------------------- in this macro invocation + +error: this expression mutably borrows a mutable reference. Consider reborrowing + --> $DIR/mut_mut.rs:27:21 + | +27 | let mut y = &mut x; //~ERROR this expression mutably borrows a mutable reference + | ^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:31:17 + | +31 | let y : &mut &mut u32 = &mut &mut 2; + | ^^^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:31:33 + | +31 | let y : &mut &mut u32 = &mut &mut 2; + | ^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:31:17 + | +31 | let y : &mut &mut u32 = &mut &mut 2; + | ^^^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:39:17 + | +39 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; + | ^^^^^^^^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:39:22 + | +39 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; + | ^^^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:39:38 + | +39 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; + | ^^^^^^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:39:17 + | +39 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; + | ^^^^^^^^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:39:22 + | +39 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; + | ^^^^^^^^^^^^^ + +error: generally you want to avoid `&mut &mut _` if possible + --> $DIR/mut_mut.rs:39:22 + | +39 | let y : &mut &mut &mut u32 = &mut &mut &mut 2; + | ^^^^^^^^^^^^^ + +error: aborting due to 13 previous errors + diff --git a/tests/compile-fail/mut_reference.rs b/tests/ui/mut_reference.rs similarity index 100% rename from tests/compile-fail/mut_reference.rs rename to tests/ui/mut_reference.rs diff --git a/tests/ui/mut_reference.stderr b/tests/ui/mut_reference.stderr new file mode 100644 index 00000000000..52e48347795 --- /dev/null +++ b/tests/ui/mut_reference.stderr @@ -0,0 +1,26 @@ +error: The function/method "takes_an_immutable_reference" doesn't need a mutable reference + --> $DIR/mut_reference.rs:22:34 + | +22 | takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/mut_reference.rs:19:8 + | +19 | #[deny(unnecessary_mut_passed)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: The function/method "as_ptr" doesn't need a mutable reference + --> $DIR/mut_reference.rs:24:12 + | +24 | as_ptr(&mut 42); //~ERROR The function/method "as_ptr" doesn't need a mutable reference + | ^^^^^^^ + +error: The function/method "takes_an_immutable_reference" doesn't need a mutable reference + --> $DIR/mut_reference.rs:28:44 + | +28 | my_struct.takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference + | ^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/mutex_atomic.rs b/tests/ui/mutex_atomic.rs similarity index 100% rename from tests/compile-fail/mutex_atomic.rs rename to tests/ui/mutex_atomic.rs diff --git a/tests/ui/mutex_atomic.stderr b/tests/ui/mutex_atomic.stderr new file mode 100644 index 00000000000..9554f42d225 --- /dev/null +++ b/tests/ui/mutex_atomic.stderr @@ -0,0 +1,65 @@ +error: Consider using an AtomicBool instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. + --> $DIR/mutex_atomic.rs:9:5 + | +9 | Mutex::new(true); //~ERROR Consider using an AtomicBool instead of a Mutex here. + | ^^^^^^^^^^^^^^^^ + | + = note: #[deny(mutex_atomic)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/mutex_atomic.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + +error: Consider using an AtomicUsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. + --> $DIR/mutex_atomic.rs:10:5 + | +10 | Mutex::new(5usize); //~ERROR Consider using an AtomicUsize instead of a Mutex here. + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(mutex_atomic)] implied by #[deny(clippy)] + +error: Consider using an AtomicIsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. + --> $DIR/mutex_atomic.rs:11:5 + | +11 | Mutex::new(9isize); //~ERROR Consider using an AtomicIsize instead of a Mutex here. + | ^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(mutex_atomic)] implied by #[deny(clippy)] + +error: Consider using an AtomicPtr instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. + --> $DIR/mutex_atomic.rs:13:5 + | +13 | Mutex::new(&x as *const u32); //~ERROR Consider using an AtomicPtr instead of a Mutex here. + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(mutex_atomic)] implied by #[deny(clippy)] + +error: Consider using an AtomicPtr instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. + --> $DIR/mutex_atomic.rs:14:5 + | +14 | Mutex::new(&mut x as *mut u32); //~ERROR Consider using an AtomicPtr instead of a Mutex here. + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(mutex_atomic)] implied by #[deny(clippy)] + +error: Consider using an AtomicUsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. + --> $DIR/mutex_atomic.rs:15:5 + | +15 | Mutex::new(0u32); //~ERROR Consider using an AtomicUsize instead of a Mutex here. + | ^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/mutex_atomic.rs:5:9 + | +5 | #![deny(mutex_integer)] + | ^^^^^^^^^^^^^ + +error: Consider using an AtomicIsize instead of a Mutex here. If you just want the locking behaviour and not the internal type, consider using Mutex<()>. + --> $DIR/mutex_atomic.rs:16:5 + | +16 | Mutex::new(0i32); //~ERROR Consider using an AtomicIsize instead of a Mutex here. + | ^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/needless_bool.rs b/tests/ui/needless_bool.rs similarity index 100% rename from tests/compile-fail/needless_bool.rs rename to tests/ui/needless_bool.rs diff --git a/tests/ui/needless_bool.stderr b/tests/ui/needless_bool.stderr new file mode 100644 index 00000000000..0042598e1cd --- /dev/null +++ b/tests/ui/needless_bool.stderr @@ -0,0 +1,95 @@ +error: this if-then-else expression will always return true + --> $DIR/needless_bool.rs:9:5 + | +9 | if x { true } else { true }; //~ERROR this if-then-else expression will always return true + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/needless_bool.rs:3:9 + | +3 | #![deny(needless_bool)] + | ^^^^^^^^^^^^^ + +error: this if-then-else expression will always return false + --> $DIR/needless_bool.rs:10:5 + | +10 | if x { false } else { false }; //~ERROR this if-then-else expression will always return false + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this if-then-else expression returns a bool literal + --> $DIR/needless_bool.rs:11:5 + | +11 | if x { true } else { false }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you can reduce it to + | x; + +error: this if-then-else expression returns a bool literal + --> $DIR/needless_bool.rs:15:5 + | +15 | if x { false } else { true }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you can reduce it to + | !x; + +error: this if-then-else expression returns a bool literal + --> $DIR/needless_bool.rs:19:5 + | +19 | if x && y { false } else { true }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you can reduce it to + | !(x && y); + +error: this if-then-else expression will always return true + --> $DIR/needless_bool.rs:34:5 + | +34 | if x { return true } else { return true }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this if-then-else expression will always return false + --> $DIR/needless_bool.rs:40:5 + | +40 | if x { return false } else { return false }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this if-then-else expression returns a bool literal + --> $DIR/needless_bool.rs:46:5 + | +46 | if x { return true } else { return false }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you can reduce it to + | return x; + +error: this if-then-else expression returns a bool literal + --> $DIR/needless_bool.rs:54:5 + | +54 | if x && y { return true } else { return false }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you can reduce it to + | return x && y; + +error: this if-then-else expression returns a bool literal + --> $DIR/needless_bool.rs:62:5 + | +62 | if x { return false } else { return true }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you can reduce it to + | return !x; + +error: this if-then-else expression returns a bool literal + --> $DIR/needless_bool.rs:70:5 + | +70 | if x && y { return false } else { return true }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you can reduce it to + | return !(x && y); + +error: aborting due to 11 previous errors + diff --git a/tests/compile-fail/needless_borrow.rs b/tests/ui/needless_borrow.rs similarity index 100% rename from tests/compile-fail/needless_borrow.rs rename to tests/ui/needless_borrow.rs diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr new file mode 100644 index 00000000000..e607185fe9b --- /dev/null +++ b/tests/ui/needless_borrow.stderr @@ -0,0 +1,31 @@ +error: this expression borrows a reference that is immediately dereferenced by the compiler + --> $DIR/needless_borrow.rs:13:15 + | +13 | let c = x(&&a); //~ ERROR: this expression borrows a reference that is immediately dereferenced by the compiler + | ^^^ + | + = note: #[deny(needless_borrow)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/needless_borrow.rs:8:8 + | +8 | #[deny(clippy)] + | ^^^^^^ + +error: this pattern creates a reference to a reference + --> $DIR/needless_borrow.rs:20:17 + | +20 | if let Some(ref cake) = Some(&5) {} //~ ERROR: this pattern creates a reference to a reference + | ^^^^^^^^ + | + = note: #[deny(needless_borrow)] implied by #[deny(clippy)] + +warning: this pattern creates a reference to a reference + --> $DIR/needless_borrow.rs:41:31 + | +41 | let _ = v.iter().filter(|&ref a| a.is_empty()); + | ^^^^^ + | + = note: #[warn(needless_borrow)] on by default + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/needless_return.rs b/tests/ui/needless_return.rs similarity index 100% rename from tests/compile-fail/needless_return.rs rename to tests/ui/needless_return.rs diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr new file mode 100644 index 00000000000..0d9f5f9a57d --- /dev/null +++ b/tests/ui/needless_return.stderr @@ -0,0 +1,79 @@ +error: unneeded return statement + --> $DIR/needless_return.rs:11:5 + | +11 | return true; + | ^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/needless_return.rs:4:9 + | +4 | #![deny(needless_return)] + | ^^^^^^^^^^^^^^^ +help: remove `return` as shown: + | true + +error: unneeded return statement + --> $DIR/needless_return.rs:18:5 + | +18 | return true + | ^^^^^^^^^^^ + | +help: remove `return` as shown: + | true + +error: unneeded return statement + --> $DIR/needless_return.rs:26:9 + | +26 | return true; + | ^^^^^^^^^^^^ + | +help: remove `return` as shown: + | true + +error: unneeded return statement + --> $DIR/needless_return.rs:31:9 + | +31 | return false; + | ^^^^^^^^^^^^^ + | +help: remove `return` as shown: + | false + +error: unneeded return statement + --> $DIR/needless_return.rs:40:17 + | +40 | true => return false, + | ^^^^^^^^^^^^ + | +help: remove `return` as shown: + | true => false, + +error: unneeded return statement + --> $DIR/needless_return.rs:46:13 + | +46 | return true; + | ^^^^^^^^^^^^ + | +help: remove `return` as shown: + | true + +error: unneeded return statement + --> $DIR/needless_return.rs:56:9 + | +56 | return true; + | ^^^^^^^^^^^^ + | +help: remove `return` as shown: + | true + +error: unneeded return statement + --> $DIR/needless_return.rs:61:16 + | +61 | let _ = || return true; + | ^^^^^^^^^^^ + | +help: remove `return` as shown: + | let _ = || true; + +error: aborting due to 8 previous errors + diff --git a/tests/compile-fail/needless_update.rs b/tests/ui/needless_update.rs similarity index 100% rename from tests/compile-fail/needless_update.rs rename to tests/ui/needless_update.rs diff --git a/tests/ui/needless_update.stderr b/tests/ui/needless_update.stderr new file mode 100644 index 00000000000..630d48331cc --- /dev/null +++ b/tests/ui/needless_update.stderr @@ -0,0 +1,14 @@ +error: struct update has no effect, all the fields in the struct have already been specified + --> $DIR/needless_update.rs:16:23 + | +16 | S { a: 1, b: 1, ..base }; //~ERROR struct update has no effect + | ^^^^ + | +note: lint level defined here + --> $DIR/needless_update.rs:4:9 + | +4 | #![deny(needless_update)] + | ^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/neg_multiply.rs b/tests/ui/neg_multiply.rs similarity index 100% rename from tests/compile-fail/neg_multiply.rs rename to tests/ui/neg_multiply.rs diff --git a/tests/ui/neg_multiply.stderr b/tests/ui/neg_multiply.stderr new file mode 100644 index 00000000000..11460a5583f --- /dev/null +++ b/tests/ui/neg_multiply.stderr @@ -0,0 +1,20 @@ +error: Negation by multiplying with -1 + --> $DIR/neg_multiply.rs:30:5 + | +30 | x * -1; + | ^^^^^^ + | +note: lint level defined here + --> $DIR/neg_multiply.rs:4:9 + | +4 | #![deny(neg_multiply)] + | ^^^^^^^^^^^^ + +error: Negation by multiplying with -1 + --> $DIR/neg_multiply.rs:33:5 + | +33 | -1 * x; + | ^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/new_without_default.rs b/tests/ui/new_without_default.rs similarity index 100% rename from tests/compile-fail/new_without_default.rs rename to tests/ui/new_without_default.rs diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr new file mode 100644 index 00000000000..e2b10894af8 --- /dev/null +++ b/tests/ui/new_without_default.stderr @@ -0,0 +1,47 @@ +error: you should consider deriving a `Default` implementation for `Foo` + --> $DIR/new_without_default.rs:13:5 + | +13 | pub fn new() -> Foo { Foo } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/new_without_default.rs:5:30 + | +5 | #![deny(new_without_default, new_without_default_derive)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: try this + | #[derive(Default)] + | pub struct Foo; + +error: you should consider deriving a `Default` implementation for `Bar` + --> $DIR/new_without_default.rs:23:5 + | +23 | pub fn new() -> Self { Bar } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try this + | #[derive(Default)] + | pub struct Bar; + +error: you should consider adding a `Default` implementation for `LtKo<'c>` + --> $DIR/new_without_default.rs:72:5 + | +72 | pub fn new() -> LtKo<'c> { unimplemented!() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/new_without_default.rs:5:9 + | +5 | #![deny(new_without_default, new_without_default_derive)] + | ^^^^^^^^^^^^^^^^^^^ +help: try this + | impl Default for LtKo<'c> { + | fn default() -> Self { + | Self::new() + | } + | } + | +... + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/no_effect.rs b/tests/ui/no_effect.rs similarity index 100% rename from tests/compile-fail/no_effect.rs rename to tests/ui/no_effect.rs diff --git a/tests/ui/no_effect.stderr b/tests/ui/no_effect.stderr new file mode 100644 index 00000000000..da65c5e8db8 --- /dev/null +++ b/tests/ui/no_effect.stderr @@ -0,0 +1,334 @@ +error: statement with no effect + --> $DIR/no_effect.rs:34:5 + | +34 | 0; //~ERROR statement with no effect + | ^^ + | +note: lint level defined here + --> $DIR/no_effect.rs:4:9 + | +4 | #![deny(no_effect, unnecessary_operation)] + | ^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:35:5 + | +35 | s2; //~ERROR statement with no effect + | ^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:36:5 + | +36 | Unit; //~ERROR statement with no effect + | ^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:37:5 + | +37 | Tuple(0); //~ERROR statement with no effect + | ^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:38:5 + | +38 | Struct { field: 0 }; //~ERROR statement with no effect + | ^^^^^^^^^^^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:39:5 + | +39 | Struct { ..s }; //~ERROR statement with no effect + | ^^^^^^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:40:5 + | +40 | Union { a: 0 }; //~ERROR statement with no effect + | ^^^^^^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:41:5 + | +41 | Enum::Tuple(0); //~ERROR statement with no effect + | ^^^^^^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:42:5 + | +42 | Enum::Struct { field: 0 }; //~ERROR statement with no effect + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:43:5 + | +43 | 5 + 6; //~ERROR statement with no effect + | ^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:44:5 + | +44 | *&42; //~ERROR statement with no effect + | ^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:45:5 + | +45 | &6; //~ERROR statement with no effect + | ^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:46:5 + | +46 | (5, 6, 7); //~ERROR statement with no effect + | ^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:47:5 + | +47 | box 42; //~ERROR statement with no effect + | ^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:48:5 + | +48 | ..; //~ERROR statement with no effect + | ^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:49:5 + | +49 | 5..; //~ERROR statement with no effect + | ^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:50:5 + | +50 | ..5; //~ERROR statement with no effect + | ^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:51:5 + | +51 | 5..6; //~ERROR statement with no effect + | ^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:52:5 + | +52 | 5...6; //~ERROR statement with no effect + | ^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:53:5 + | +53 | [42, 55]; //~ERROR statement with no effect + | ^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:54:5 + | +54 | [42, 55][1]; //~ERROR statement with no effect + | ^^^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:55:5 + | +55 | (42, 55).1; //~ERROR statement with no effect + | ^^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:56:5 + | +56 | [42; 55]; //~ERROR statement with no effect + | ^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:57:5 + | +57 | [42; 55][13]; //~ERROR statement with no effect + | ^^^^^^^^^^^^^ + +error: statement with no effect + --> $DIR/no_effect.rs:59:5 + | +59 | || x += 5; //~ERROR statement with no effect + | ^^^^^^^^^^ + +error: statement can be reduced + --> $DIR/no_effect.rs:65:5 + | +65 | Tuple(get_number()); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/no_effect.rs:4:20 + | +4 | #![deny(no_effect, unnecessary_operation)] + | ^^^^^^^^^^^^^^^^^^^^^ +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:68:5 + | +68 | Struct { field: get_number() }; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:71:5 + | +71 | Struct { ..get_struct() }; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | get_struct(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:74:5 + | +74 | Enum::Tuple(get_number()); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:77:5 + | +77 | Enum::Struct { field: get_number() }; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:80:5 + | +80 | 5 + get_number(); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^ + | +help: replace it with + | 5;get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:83:5 + | +83 | *&get_number(); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:86:5 + | +86 | &get_number(); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:89:5 + | +89 | (5, 6, get_number()); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | 5;6;get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:92:5 + | +92 | box get_number(); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:95:5 + | +95 | get_number()..; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:98:5 + | +98 | ..get_number(); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:101:5 + | +101 | 5..get_number(); //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^ + | +help: replace it with + | 5;get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:104:5 + | +104 | [42, get_number()]; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | 42;get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:107:5 + | +107 | [42, 55][get_number() as usize]; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | [42, 55];get_number() as usize; //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:110:5 + | +110 | (42, get_number()).1; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | 42;get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:113:5 + | +113 | [get_number(); 55]; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:116:5 + | +116 | [42; 55][get_number() as usize]; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with + | [42; 55];get_number() as usize; //~ERROR statement can be reduced + +error: statement can be reduced + --> $DIR/no_effect.rs:119:5 + | +119 | {get_number()}; //~ERROR statement can be reduced + | ^^^^^^^^^^^^^^^ + | +help: replace it with + | get_number(); //~ERROR statement can be reduced + +error: aborting due to 44 previous errors + diff --git a/tests/ui/non_expressive_names.rs b/tests/ui/non_expressive_names.rs new file mode 100644 index 00000000000..778041f49b8 --- /dev/null +++ b/tests/ui/non_expressive_names.rs @@ -0,0 +1,150 @@ +#![feature(plugin)] +#![plugin(clippy)] +#![deny(clippy,similar_names)] +//~^ NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +//~| NOTE: lint level defined here +#![allow(unused)] + + +struct Foo { + apple: i32, + bpple: i32, +} + +fn main() { + let specter: i32; + let spectre: i32; + + let apple: i32; //~ NOTE: existing binding defined here + //~^ NOTE: existing binding defined here + let bpple: i32; //~ ERROR: name is too similar + //~| HELP: separate the discriminating character by an underscore like: `b_pple` + let cpple: i32; //~ ERROR: name is too similar + //~| HELP: separate the discriminating character by an underscore like: `c_pple` + + let a_bar: i32; + let b_bar: i32; + let c_bar: i32; + + let items = [5]; + for item in &items { + loop {} + } + + let foo_x: i32; + let foo_y: i32; + + let rhs: i32; + let lhs: i32; + + let bla_rhs: i32; + let bla_lhs: i32; + + let blubrhs: i32; + let blublhs: i32; + + let blubx: i32; //~ NOTE: existing binding defined here + let bluby: i32; //~ ERROR: name is too similar + //~| HELP: separate the discriminating character by an underscore like: `blub_y` + + let cake: i32; //~ NOTE: existing binding defined here + let cakes: i32; + let coke: i32; //~ ERROR: name is too similar + + match 5 { + cheese @ 1 => {}, + rabbit => panic!(), + } + let cheese: i32; + match (42, 43) { + (cheese1, 1) => {}, + (cheese2, 2) => panic!(), + _ => println!(""), + } + let ipv4: i32; + let ipv6: i32; + let abcd1: i32; + let abdc2: i32; + let xyz1abc: i32; //~ NOTE: existing binding defined here + let xyz2abc: i32; + let xyzeabc: i32; //~ ERROR: name is too similar + + let parser: i32; //~ NOTE: existing binding defined here + let parsed: i32; + let parsee: i32; //~ ERROR: name is too similar + //~| HELP: separate the discriminating character by an underscore like: `parse_e` + + let setter: i32; + let getter: i32; + let tx1: i32; + let rx1: i32; + let tx_cake: i32; + let rx_cake: i32; +} + +fn foo() { + let Foo { apple, bpple } = unimplemented!(); + let Foo { apple: spring, //~NOTE existing binding defined here + bpple: sprang } = unimplemented!(); //~ ERROR: name is too similar +} + +#[derive(Clone, Debug)] +enum MaybeInst { + Split, + Split1(usize), + Split2(usize), +} + +struct InstSplit { + uiae: usize, +} + +impl MaybeInst { + fn fill(&mut self) { + let filled = match *self { + MaybeInst::Split1(goto1) => panic!(1), + MaybeInst::Split2(goto2) => panic!(2), + _ => unimplemented!(), + }; + unimplemented!() + } +} + +fn bla() { + let a: i32; + let (b, c, d): (i32, i64, i16); + { + { + let cdefg: i32; + let blar: i32; + } + { + let e: i32; //~ ERROR: 5th binding whose name is just one char + //~^ NOTE implied by + } + { + let e: i32; //~ ERROR: 5th binding whose name is just one char + //~^ NOTE implied by + let f: i32; //~ ERROR: 6th binding whose name is just one char + //~^ NOTE implied by + } + match 5 { + 1 => println!(""), + e => panic!(), //~ ERROR: 5th binding whose name is just one char + //~^ NOTE implied by + } + match 5 { + 1 => println!(""), + _ => panic!(), + } + } +} diff --git a/tests/ui/non_expressive_names.stderr b/tests/ui/non_expressive_names.stderr new file mode 100644 index 00000000000..4ddb5c84a64 --- /dev/null +++ b/tests/ui/non_expressive_names.stderr @@ -0,0 +1,148 @@ +error: binding's name is too similar to existing binding + --> $DIR/non_expressive_names.rs:29:9 + | +29 | let bpple: i32; //~ ERROR: name is too similar + | ^^^^^ + | +note: lint level defined here + --> $DIR/non_expressive_names.rs:3:16 + | +3 | #![deny(clippy,similar_names)] + | ^^^^^^^^^^^^^ +note: existing binding defined here + --> $DIR/non_expressive_names.rs:27:9 + | +27 | let apple: i32; //~ NOTE: existing binding defined here + | ^^^^^ +help: separate the discriminating character by an underscore like: `b_pple` + --> $DIR/non_expressive_names.rs:29:9 + | +29 | let bpple: i32; //~ ERROR: name is too similar + | ^^^^^ + +error: binding's name is too similar to existing binding + --> $DIR/non_expressive_names.rs:31:9 + | +31 | let cpple: i32; //~ ERROR: name is too similar + | ^^^^^ + | +note: existing binding defined here + --> $DIR/non_expressive_names.rs:27:9 + | +27 | let apple: i32; //~ NOTE: existing binding defined here + | ^^^^^ +help: separate the discriminating character by an underscore like: `c_pple` + --> $DIR/non_expressive_names.rs:31:9 + | +31 | let cpple: i32; //~ ERROR: name is too similar + | ^^^^^ + +error: binding's name is too similar to existing binding + --> $DIR/non_expressive_names.rs:56:9 + | +56 | let bluby: i32; //~ ERROR: name is too similar + | ^^^^^ + | +note: existing binding defined here + --> $DIR/non_expressive_names.rs:55:9 + | +55 | let blubx: i32; //~ NOTE: existing binding defined here + | ^^^^^ +help: separate the discriminating character by an underscore like: `blub_y` + --> $DIR/non_expressive_names.rs:56:9 + | +56 | let bluby: i32; //~ ERROR: name is too similar + | ^^^^^ + +error: binding's name is too similar to existing binding + --> $DIR/non_expressive_names.rs:61:9 + | +61 | let coke: i32; //~ ERROR: name is too similar + | ^^^^ + | +note: existing binding defined here + --> $DIR/non_expressive_names.rs:59:9 + | +59 | let cake: i32; //~ NOTE: existing binding defined here + | ^^^^ + +error: binding's name is too similar to existing binding + --> $DIR/non_expressive_names.rs:79:9 + | +79 | let xyzeabc: i32; //~ ERROR: name is too similar + | ^^^^^^^ + | +note: existing binding defined here + --> $DIR/non_expressive_names.rs:77:9 + | +77 | let xyz1abc: i32; //~ NOTE: existing binding defined here + | ^^^^^^^ + +error: binding's name is too similar to existing binding + --> $DIR/non_expressive_names.rs:83:9 + | +83 | let parsee: i32; //~ ERROR: name is too similar + | ^^^^^^ + | +note: existing binding defined here + --> $DIR/non_expressive_names.rs:81:9 + | +81 | let parser: i32; //~ NOTE: existing binding defined here + | ^^^^^^ +help: separate the discriminating character by an underscore like: `parse_e` + --> $DIR/non_expressive_names.rs:83:9 + | +83 | let parsee: i32; //~ ERROR: name is too similar + | ^^^^^^ + +error: binding's name is too similar to existing binding + --> $DIR/non_expressive_names.rs:97:16 + | +97 | bpple: sprang } = unimplemented!(); //~ ERROR: name is too similar + | ^^^^^^ + | +note: existing binding defined here + --> $DIR/non_expressive_names.rs:96:22 + | +96 | let Foo { apple: spring, //~NOTE existing binding defined here + | ^^^^^^ + +error: 5th binding whose name is just one char + --> $DIR/non_expressive_names.rs:131:17 + | +131 | let e: i32; //~ ERROR: 5th binding whose name is just one char + | ^ + | + = note: #[deny(many_single_char_names)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/non_expressive_names.rs:3:9 + | +3 | #![deny(clippy,similar_names)] + | ^^^^^^ + +error: 5th binding whose name is just one char + --> $DIR/non_expressive_names.rs:135:17 + | +135 | let e: i32; //~ ERROR: 5th binding whose name is just one char + | ^ + | + = note: #[deny(many_single_char_names)] implied by #[deny(clippy)] + +error: 6th binding whose name is just one char + --> $DIR/non_expressive_names.rs:137:17 + | +137 | let f: i32; //~ ERROR: 6th binding whose name is just one char + | ^ + | + = note: #[deny(many_single_char_names)] implied by #[deny(clippy)] + +error: 5th binding whose name is just one char + --> $DIR/non_expressive_names.rs:142:13 + | +142 | e => panic!(), //~ ERROR: 5th binding whose name is just one char + | ^ + | + = note: #[deny(many_single_char_names)] implied by #[deny(clippy)] + +error: aborting due to 11 previous errors + diff --git a/tests/compile-fail/ok_if_let.rs b/tests/ui/ok_if_let.rs similarity index 100% rename from tests/compile-fail/ok_if_let.rs rename to tests/ui/ok_if_let.rs diff --git a/tests/ui/ok_if_let.stderr b/tests/ui/ok_if_let.stderr new file mode 100644 index 00000000000..e39b5855435 --- /dev/null +++ b/tests/ui/ok_if_let.stderr @@ -0,0 +1,21 @@ +error: Matching on `Some` with `ok()` is redundant + --> $DIR/ok_if_let.rs:7:5 + | +7 | if let Some(y) = x.parse().ok() { + | _____^ starting here... +8 | | //~^ERROR Matching on `Some` with `ok()` is redundant +9 | | y +10 | | } else { +11 | | 0 +12 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/ok_if_let.rs:4:9 + | +4 | #![deny(if_let_some_result)] + | ^^^^^^^^^^^^^^^^^^ + = help: Consider matching on `Ok(y)` and removing the call to `ok` instead + +error: aborting due to previous error + diff --git a/tests/compile-fail/open_options.rs b/tests/ui/open_options.rs similarity index 100% rename from tests/compile-fail/open_options.rs rename to tests/ui/open_options.rs diff --git a/tests/ui/open_options.stderr b/tests/ui/open_options.stderr new file mode 100644 index 00000000000..f7d3d85edbd --- /dev/null +++ b/tests/ui/open_options.stderr @@ -0,0 +1,50 @@ +error: file opened with "truncate" and "read" + --> $DIR/open_options.rs:8:5 + | +8 | OpenOptions::new().read(true).truncate(true).open("foo.txt"); //~ERROR file opened with "truncate" and "read" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/open_options.rs:6:8 + | +6 | #[deny(nonsensical_open_options)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: file opened with "append" and "truncate" + --> $DIR/open_options.rs:9:5 + | +9 | OpenOptions::new().append(true).truncate(true).open("foo.txt"); //~ERROR file opened with "append" and "truncate" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: the method "read" is called more than once + --> $DIR/open_options.rs:11:5 + | +11 | OpenOptions::new().read(true).read(false).open("foo.txt"); //~ERROR the method "read" is called more than once + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: the method "create" is called more than once + --> $DIR/open_options.rs:12:5 + | +12 | OpenOptions::new().create(true).create(false).open("foo.txt"); //~ERROR the method "create" is called more than once + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: the method "write" is called more than once + --> $DIR/open_options.rs:13:5 + | +13 | OpenOptions::new().write(true).write(false).open("foo.txt"); //~ERROR the method "write" is called more than once + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: the method "append" is called more than once + --> $DIR/open_options.rs:14:5 + | +14 | OpenOptions::new().append(true).append(false).open("foo.txt"); //~ERROR the method "append" is called more than once + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: the method "truncate" is called more than once + --> $DIR/open_options.rs:15:5 + | +15 | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); //~ERROR the method "truncate" is called more than once + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/overflow_check_conditional.rs b/tests/ui/overflow_check_conditional.rs similarity index 100% rename from tests/compile-fail/overflow_check_conditional.rs rename to tests/ui/overflow_check_conditional.rs diff --git a/tests/ui/overflow_check_conditional.stderr b/tests/ui/overflow_check_conditional.stderr new file mode 100644 index 00000000000..f3c330b168a --- /dev/null +++ b/tests/ui/overflow_check_conditional.stderr @@ -0,0 +1,56 @@ +error: You are trying to use classic C overflow conditions that will fail in Rust. + --> $DIR/overflow_check_conditional.rs:11:5 + | +11 | \tif a + b < a { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust. + | \t ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/overflow_check_conditional.rs:5:9 + | +5 | #![deny(overflow_check_conditional)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: You are trying to use classic C overflow conditions that will fail in Rust. + --> $DIR/overflow_check_conditional.rs:14:5 + | +14 | \tif a > a + b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust. + | \t ^^^^^^^^^ + +error: You are trying to use classic C overflow conditions that will fail in Rust. + --> $DIR/overflow_check_conditional.rs:17:5 + | +17 | \tif a + b < b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust. + | \t ^^^^^^^^^ + +error: You are trying to use classic C overflow conditions that will fail in Rust. + --> $DIR/overflow_check_conditional.rs:20:5 + | +20 | \tif b > a + b { //~ERROR You are trying to use classic C overflow conditions that will fail in Rust. + | \t ^^^^^^^^^ + +error: You are trying to use classic C underflow conditions that will fail in Rust. + --> $DIR/overflow_check_conditional.rs:23:5 + | +23 | \tif a - b > b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust. + | \t ^^^^^^^^^ + +error: You are trying to use classic C underflow conditions that will fail in Rust. + --> $DIR/overflow_check_conditional.rs:26:5 + | +26 | \tif b < a - b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust. + | \t ^^^^^^^^^ + +error: You are trying to use classic C underflow conditions that will fail in Rust. + --> $DIR/overflow_check_conditional.rs:29:5 + | +29 | \tif a - b > a { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust. + | \t ^^^^^^^^^ + +error: You are trying to use classic C underflow conditions that will fail in Rust. + --> $DIR/overflow_check_conditional.rs:32:5 + | +32 | \tif a < a - b { //~ERROR You are trying to use classic C underflow conditions that will fail in Rust. + | \t ^^^^^^^^^ + +error: aborting due to 8 previous errors + diff --git a/tests/compile-fail/panic.rs b/tests/ui/panic.rs similarity index 100% rename from tests/compile-fail/panic.rs rename to tests/ui/panic.rs diff --git a/tests/ui/panic.stderr b/tests/ui/panic.stderr new file mode 100644 index 00000000000..41317288c3b --- /dev/null +++ b/tests/ui/panic.stderr @@ -0,0 +1,26 @@ +error: you probably are missing some parameter in your format string + --> $DIR/panic.rs:8:16 + | +8 | panic!("{}"); //~ERROR: you probably are missing some parameter + | ^^^^ + | +note: lint level defined here + --> $DIR/panic.rs:4:9 + | +4 | #![deny(panic_params)] + | ^^^^^^^^^^^^ + +error: you probably are missing some parameter in your format string + --> $DIR/panic.rs:10:16 + | +10 | panic!("{:?}"); //~ERROR: you probably are missing some parameter + | ^^^^^^ + +error: you probably are missing some parameter in your format string + --> $DIR/panic.rs:12:23 + | +12 | assert!(true, "here be missing values: {}"); //~ERROR you probably are missing some parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/partialeq_ne_impl.rs b/tests/ui/partialeq_ne_impl.rs similarity index 100% rename from tests/compile-fail/partialeq_ne_impl.rs rename to tests/ui/partialeq_ne_impl.rs diff --git a/tests/ui/partialeq_ne_impl.stderr b/tests/ui/partialeq_ne_impl.stderr new file mode 100644 index 00000000000..dd1e4099e4c --- /dev/null +++ b/tests/ui/partialeq_ne_impl.stderr @@ -0,0 +1,15 @@ +error: re-implementing `PartialEq::ne` is unnecessary + --> $DIR/partialeq_ne_impl.rs:11:5 + | +11 | fn ne(&self, _: &Foo) -> bool { false } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(partialeq_ne_impl)] implied by #[deny(warnings)] +note: lint level defined here + --> $DIR/partialeq_ne_impl.rs:4:9 + | +4 | #![deny(warnings)] + | ^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/patterns.rs b/tests/ui/patterns.rs similarity index 100% rename from tests/compile-fail/patterns.rs rename to tests/ui/patterns.rs diff --git a/tests/ui/patterns.stderr b/tests/ui/patterns.stderr new file mode 100644 index 00000000000..b55f9e477d4 --- /dev/null +++ b/tests/ui/patterns.stderr @@ -0,0 +1,15 @@ +error: the `y @ _` pattern can be written as just `y` + --> $DIR/patterns.rs:10:9 + | +10 | y @ _ => (), //~ERROR the `y @ _` pattern can be written as just `y` + | ^^^^^ + | + = note: #[deny(redundant_pattern)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/patterns.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/precedence.rs b/tests/ui/precedence.rs similarity index 100% rename from tests/compile-fail/precedence.rs rename to tests/ui/precedence.rs diff --git a/tests/ui/precedence.stderr b/tests/ui/precedence.stderr new file mode 100644 index 00000000000..5eb8d91ec21 --- /dev/null +++ b/tests/ui/precedence.stderr @@ -0,0 +1,88 @@ +error: operator precedence can trip the unwary + --> $DIR/precedence.rs:8:5 + | +8 | 1 << 2 + 3; + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/precedence.rs:4:8 + | +4 | #[deny(precedence)] + | ^^^^^^^^^^ +help: consider parenthesizing your expression + | 1 << (2 + 3); + +error: operator precedence can trip the unwary + --> $DIR/precedence.rs:11:5 + | +11 | 1 + 2 << 3; + | ^^^^^^^^^^ + | +help: consider parenthesizing your expression + | (1 + 2) << 3; + +error: operator precedence can trip the unwary + --> $DIR/precedence.rs:14:5 + | +14 | 4 >> 1 + 1; + | ^^^^^^^^^^ + | +help: consider parenthesizing your expression + | 4 >> (1 + 1); + +error: operator precedence can trip the unwary + --> $DIR/precedence.rs:17:5 + | +17 | 1 + 3 >> 2; + | ^^^^^^^^^^ + | +help: consider parenthesizing your expression + | (1 + 3) >> 2; + +error: operator precedence can trip the unwary + --> $DIR/precedence.rs:20:5 + | +20 | 1 ^ 1 - 1; + | ^^^^^^^^^ + | +help: consider parenthesizing your expression + | 1 ^ (1 - 1); + +error: operator precedence can trip the unwary + --> $DIR/precedence.rs:23:5 + | +23 | 3 | 2 - 1; + | ^^^^^^^^^ + | +help: consider parenthesizing your expression + | 3 | (2 - 1); + +error: operator precedence can trip the unwary + --> $DIR/precedence.rs:26:5 + | +26 | 3 & 5 - 2; + | ^^^^^^^^^ + | +help: consider parenthesizing your expression + | 3 & (5 - 2); + +error: unary minus has lower precedence than method call + --> $DIR/precedence.rs:30:5 + | +30 | -1i32.abs(); + | ^^^^^^^^^^^ + | +help: consider adding parentheses to clarify your intent + | -(1i32.abs()); + +error: unary minus has lower precedence than method call + --> $DIR/precedence.rs:33:5 + | +33 | -1f32.abs(); + | ^^^^^^^^^^^ + | +help: consider adding parentheses to clarify your intent + | -(1f32.abs()); + +error: aborting due to 9 previous errors + diff --git a/tests/compile-fail/print.rs b/tests/ui/print.rs similarity index 100% rename from tests/compile-fail/print.rs rename to tests/ui/print.rs diff --git a/tests/ui/print.stderr b/tests/ui/print.stderr new file mode 100644 index 00000000000..efa574f56e3 --- /dev/null +++ b/tests/ui/print.stderr @@ -0,0 +1,62 @@ +error: use of `Debug`-based formatting + --> $DIR/print.rs:12:27 + | +12 | write!(f, "{:?}", 43.1415) + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/print.rs:3:23 + | +3 | #![deny(print_stdout, use_debug)] + | ^^^^^^^^^ + +error: use of `println!` + --> $DIR/print.rs:25:5 + | +25 | println!("Hello"); //~ERROR use of `println!` + | ^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/print.rs:3:9 + | +3 | #![deny(print_stdout, use_debug)] + | ^^^^^^^^^^^^ + +error: use of `print!` + --> $DIR/print.rs:26:5 + | +26 | print!("Hello"); //~ERROR use of `print!` + | ^^^^^^^^^^^^^^^^ + +error: use of `print!` + --> $DIR/print.rs:28:5 + | +28 | print!("Hello {}", "World"); //~ERROR use of `print!` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: use of `print!` + --> $DIR/print.rs:30:5 + | +30 | print!("Hello {:?}", "World"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: use of `Debug`-based formatting + --> $DIR/print.rs:30:26 + | +30 | print!("Hello {:?}", "World"); + | ^^^^^^^ + +error: use of `print!` + --> $DIR/print.rs:34:5 + | +34 | print!("Hello {:#?}", "#orld"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: use of `Debug`-based formatting + --> $DIR/print.rs:34:27 + | +34 | print!("Hello {:#?}", "#orld"); + | ^^^^^^^ + +error: aborting due to 8 previous errors + diff --git a/tests/compile-fail/print_with_newline.rs b/tests/ui/print_with_newline.rs similarity index 100% rename from tests/compile-fail/print_with_newline.rs rename to tests/ui/print_with_newline.rs diff --git a/tests/ui/print_with_newline.stderr b/tests/ui/print_with_newline.stderr new file mode 100644 index 00000000000..94edc532593 --- /dev/null +++ b/tests/ui/print_with_newline.stderr @@ -0,0 +1,32 @@ +error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead + --> $DIR/print_with_newline.rs:6:5 + | +6 | print!("Hello/n"); //~ERROR using `print!()` with a format string + | ^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/print_with_newline.rs:3:9 + | +3 | #![deny(print_with_newline)] + | ^^^^^^^^^^^^^^^^^^ + +error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead + --> $DIR/print_with_newline.rs:7:5 + | +7 | print!("Hello {}/n", "world"); //~ERROR using `print!()` with a format string + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead + --> $DIR/print_with_newline.rs:8:5 + | +8 | print!("Hello {} {}/n/n", "world", "#2"); //~ERROR using `print!()` with a format string + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead + --> $DIR/print_with_newline.rs:9:5 + | +9 | print!("{}/n", 1265); //~ERROR using `print!()` with a format string + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/compile-fail/ptr_arg.rs b/tests/ui/ptr_arg.rs similarity index 100% rename from tests/compile-fail/ptr_arg.rs rename to tests/ui/ptr_arg.rs diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr new file mode 100644 index 00000000000..a022f0e5550 --- /dev/null +++ b/tests/ui/ptr_arg.stderr @@ -0,0 +1,26 @@ +error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices. Consider changing the type to `&[...]` + --> $DIR/ptr_arg.rs:6:14 + | +6 | fn do_vec(x: &Vec) { //~ERROR writing `&Vec<_>` instead of `&[_]` + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/ptr_arg.rs:4:9 + | +4 | #![deny(ptr_arg)] + | ^^^^^^^ + +error: writing `&String` instead of `&str` involves a new object where a slice will do. Consider changing the type to `&str` + --> $DIR/ptr_arg.rs:14:14 + | +14 | fn do_str(x: &String) { //~ERROR writing `&String` instead of `&str` + | ^^^^^^^ + +error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices. Consider changing the type to `&[...]` + --> $DIR/ptr_arg.rs:27:18 + | +27 | fn do_vec(x: &Vec); //~ERROR writing `&Vec<_>` + | ^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/range.rs b/tests/ui/range.rs similarity index 100% rename from tests/compile-fail/range.rs rename to tests/ui/range.rs diff --git a/tests/ui/range.stderr b/tests/ui/range.stderr new file mode 100644 index 00000000000..a7c4d4fcffd --- /dev/null +++ b/tests/ui/range.stderr @@ -0,0 +1,44 @@ +error: Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` instead + --> $DIR/range.rs:13:5 + | +13 | (0..1).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator + | ^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/range.rs:11:8 + | +11 | #[deny(range_step_by_zero, range_zip_with_len)] + | ^^^^^^^^^^^^^^^^^^ + +error: Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` instead + --> $DIR/range.rs:17:5 + | +17 | (1..).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator + | ^^^^^^^^^^^^^^^^ + +error: Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` instead + --> $DIR/range.rs:18:5 + | +18 | (1...2).step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator + | ^^^^^^^^^^^^^^^^^^ + +error: Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` instead + --> $DIR/range.rs:21:5 + | +21 | x.step_by(0); //~ERROR Range::step_by(0) produces an infinite iterator + | ^^^^^^^^^^^^ + +error: It is more idiomatic to use v1.iter().enumerate() + --> $DIR/range.rs:29:14 + | +29 | let _x = v1.iter().zip(0..v1.len()); //~ERROR It is more idiomatic to use v1.iter().enumerate() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/range.rs:11:28 + | +11 | #[deny(range_step_by_zero, range_zip_with_len)] + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/tests/compile-fail/redundant_closure_call.rs b/tests/ui/redundant_closure_call.rs similarity index 100% rename from tests/compile-fail/redundant_closure_call.rs rename to tests/ui/redundant_closure_call.rs diff --git a/tests/ui/redundant_closure_call.stderr b/tests/ui/redundant_closure_call.stderr new file mode 100644 index 00000000000..94facfa0fff --- /dev/null +++ b/tests/ui/redundant_closure_call.stderr @@ -0,0 +1,41 @@ +error: Closure called just once immediately after it was declared + --> $DIR/redundant_closure_call.rs:18:2 + | +18 | \ti = closure(); //~ERROR Closure called just once immediately after it was declared + | \t^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/redundant_closure_call.rs:4:9 + | +4 | #![deny(redundant_closure_call)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: Closure called just once immediately after it was declared + --> $DIR/redundant_closure_call.rs:21:2 + | +21 | \ti = closure(3); //~ERROR Closure called just once immediately after it was declared + | \t^^^^^^^^^^^^^^ + +error: Try not to call a closure in the expression where it is declared. + --> $DIR/redundant_closure_call.rs:7:10 + | +7 | \tlet a = (|| 42)(); + | \t ^^^^^^^^^ + | +help: Try doing something like: + | \tlet a = 42; + +error: Try not to call a closure in the expression where it is declared. + --> $DIR/redundant_closure_call.rs:13:10 + | +13 | \tlet k = (|m| m+1)(i); //~ERROR Try not to call a closure in the expression where it is declared. + | \t ^^^^^^^^^^^^ + +error: Try not to call a closure in the expression where it is declared. + --> $DIR/redundant_closure_call.rs:15:6 + | +15 | \tk = (|a,b| a*b)(1,5); //~ERROR Try not to call a closure in the expression where it is declared. + | \t ^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/tests/compile-fail/reference.rs b/tests/ui/reference.rs similarity index 100% rename from tests/compile-fail/reference.rs rename to tests/ui/reference.rs diff --git a/tests/ui/reference.stderr b/tests/ui/reference.stderr new file mode 100644 index 00000000000..6701016b3be --- /dev/null +++ b/tests/ui/reference.stderr @@ -0,0 +1,106 @@ +error: immediately dereferencing a reference + --> $DIR/reference.rs:19:13 + | +19 | let b = *&a; + | ^^^ + | +note: lint level defined here + --> $DIR/reference.rs:14:8 + | +14 | #[deny(deref_addrof)] + | ^^^^^^^^^^^^ +help: try this + | let b = a; + +error: immediately dereferencing a reference + --> $DIR/reference.rs:24:13 + | +24 | let b = *&get_number(); + | ^^^^^^^^^^^^^^ + | +help: try this + | let b = get_number(); + +error: immediately dereferencing a reference + --> $DIR/reference.rs:32:13 + | +32 | let b = *&bytes[1..2][0]; + | ^^^^^^^^^^^^^^^^ + | +help: try this + | let b = bytes[1..2][0]; + +error: immediately dereferencing a reference + --> $DIR/reference.rs:39:13 + | +39 | let b = *&(a); + | ^^^^^ + | +help: try this + | let b = (a); + +error: immediately dereferencing a reference + --> $DIR/reference.rs:44:13 + | +44 | let b = *(&a); + | ^^^^^ + | +help: try this + | let b = a; + +error: immediately dereferencing a reference + --> $DIR/reference.rs:49:13 + | +49 | let b = *((&a)); + | ^^^^^^^ + | +help: try this + | let b = a; + +error: immediately dereferencing a reference + --> $DIR/reference.rs:54:13 + | +54 | let b = *&&a; + | ^^^^ + | +help: try this + | let b = &a; + +error: immediately dereferencing a reference + --> $DIR/reference.rs:59:14 + | +59 | let b = **&aref; + | ^^^^^^ + | +help: try this + | let b = *aref; + +error: immediately dereferencing a reference + --> $DIR/reference.rs:66:14 + | +66 | let b = **&&a; + | ^^^^ + | +help: try this + | let b = *&a; + +error: immediately dereferencing a reference + --> $DIR/reference.rs:73:17 + | +73 | let y = *&mut x; + | ^^^^^^^ + | +help: try this + | let y = x; + +error: immediately dereferencing a reference + --> $DIR/reference.rs:83:18 + | +83 | let y = **&mut &mut x; + | ^^^^^^^^^^^^ + | +help: try this + | let y = *&mut x; + +error: aborting due to 11 previous errors + diff --git a/tests/compile-fail/regex.rs b/tests/ui/regex.rs similarity index 100% rename from tests/compile-fail/regex.rs rename to tests/ui/regex.rs diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr new file mode 100644 index 00000000000..f59d0c6b5dc --- /dev/null +++ b/tests/ui/regex.stderr @@ -0,0 +1,175 @@ +error: regex syntax error: empty alternate + --> $DIR/regex.rs:16:45 + | +16 | let pipe_in_wrong_position = Regex::new("|"); + | ^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error: empty alternate + --> $DIR/regex.rs:18:60 + | +18 | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); + | ^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error: invalid character class range + --> $DIR/regex.rs:20:40 + | +20 | let wrong_char_ranice = Regex::new("[z-a]"); + | ^^^^^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error: invalid character class range + --> $DIR/regex.rs:22:35 + | +22 | let some_unicode = Regex::new("[é-è]"); + | ^^^^^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error on position 0: unclosed parenthesis + --> $DIR/regex.rs:25:33 + | +25 | let some_regex = Regex::new(OPENING_PAREN); + | ^^^^^^^^^^^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error: empty alternate + --> $DIR/regex.rs:28:53 + | +28 | let binary_pipe_in_wrong_position = BRegex::new("|"); + | ^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error on position 0: unclosed parenthesis + --> $DIR/regex.rs:30:41 + | +30 | let some_binary_regex = BRegex::new(OPENING_PAREN); + | ^^^^^^^^^^^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error on position 0: unclosed parenthesis + --> $DIR/regex.rs:32:56 + | +32 | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); + | ^^^^^^^^^^^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error on position 0: unclosed parenthesis + --> $DIR/regex.rs:48:9 + | +48 | OPENING_PAREN, + | ^^^^^^^^^^^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: regex syntax error on position 0: unclosed parenthesis + --> $DIR/regex.rs:53:9 + | +53 | OPENING_PAREN, + | ^^^^^^^^^^^^^ + | + = note: #[deny(invalid_regex)] on by default + +error: trivial regex + --> $DIR/regex.rs:60:33 + | +60 | let trivial_eq = Regex::new("^foobar$"); + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/regex.rs:5:24 + | +5 | #![deny(invalid_regex, trivial_regex, regex_macro)] + | ^^^^^^^^^^^^^ + = help: consider using consider using `==` on `str`s + +error: trivial regex + --> $DIR/regex.rs:64:48 + | +64 | let trivial_eq_builder = RegexBuilder::new("^foobar$"); + | ^^^^^^^^^^ + | + = help: consider using consider using `==` on `str`s + +error: trivial regex + --> $DIR/regex.rs:68:42 + | +68 | let trivial_starts_with = Regex::new("^foobar"); + | ^^^^^^^^^ + | + = help: consider using consider using `str::starts_with` + +error: trivial regex + --> $DIR/regex.rs:72:40 + | +72 | let trivial_ends_with = Regex::new("foobar$"); + | ^^^^^^^^^ + | + = help: consider using consider using `str::ends_with` + +error: trivial regex + --> $DIR/regex.rs:76:39 + | +76 | let trivial_contains = Regex::new("foobar"); + | ^^^^^^^^ + | + = help: consider using consider using `str::contains` + +error: trivial regex + --> $DIR/regex.rs:80:39 + | +80 | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using consider using `str::contains` + +error: trivial regex + --> $DIR/regex.rs:84:40 + | +84 | let trivial_backslash = Regex::new("a//.b"); + | ^^^^^^^ + | + = help: consider using consider using `str::contains` + +error: trivial regex + --> $DIR/regex.rs:89:36 + | +89 | let trivial_empty = Regex::new(""); + | ^^ + | + = help: consider using the regex is unlikely to be useful as it is + +error: trivial regex + --> $DIR/regex.rs:93:36 + | +93 | let trivial_empty = Regex::new("^"); + | ^^^ + | + = help: consider using the regex is unlikely to be useful as it is + +error: trivial regex + --> $DIR/regex.rs:97:36 + | +97 | let trivial_empty = Regex::new("^$"); + | ^^^^ + | + = help: consider using consider using `str::is_empty` + +error: trivial regex + --> $DIR/regex.rs:101:44 + | +101 | let binary_trivial_empty = BRegex::new("^$"); + | ^^^^ + | + = help: consider using consider using `str::is_empty` + +error: aborting due to 21 previous errors + diff --git a/tests/compile-fail/serde.rs b/tests/ui/serde.rs similarity index 100% rename from tests/compile-fail/serde.rs rename to tests/ui/serde.rs diff --git a/tests/ui/serde.stderr b/tests/ui/serde.stderr new file mode 100644 index 00000000000..e7b493eb2ba --- /dev/null +++ b/tests/ui/serde.stderr @@ -0,0 +1,20 @@ +error: you should not implement `visit_string` without also implementing `visit_str` + --> $DIR/serde.rs:39:5 + | +39 | fn visit_string(self, _v: String) -> Result + | _____^ starting here... +40 | | //~^ ERROR you should not implement `visit_string` without also implementing `visit_str` +41 | | where E: serde::de::Error, +42 | | { +43 | | unimplemented!() +44 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/serde.rs:3:9 + | +3 | #![deny(serde_api_misuse)] + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/compile-fail/shadow.rs b/tests/ui/shadow.rs similarity index 100% rename from tests/compile-fail/shadow.rs rename to tests/ui/shadow.rs diff --git a/tests/ui/shadow.stderr b/tests/ui/shadow.stderr new file mode 100644 index 00000000000..e5ed3f18ce0 --- /dev/null +++ b/tests/ui/shadow.stderr @@ -0,0 +1,159 @@ +error: `x` is shadowed by itself in `&mut x` + --> $DIR/shadow.rs:13:9 + | +13 | let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x` + | ^^^^^^^^^^ + | + = note: #[deny(shadow_same)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/shadow.rs:4:17 + | +4 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ +note: previous binding is here + --> $DIR/shadow.rs:12:13 + | +12 | let mut x = 1; + | ^ + +error: `x` is shadowed by itself in `{ x }` + --> $DIR/shadow.rs:14:9 + | +14 | let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }` + | ^^^^^^^^^ + | + = note: #[deny(shadow_same)] implied by #[deny(clippy_pedantic)] +note: previous binding is here + --> $DIR/shadow.rs:13:9 + | +13 | let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x` + | ^ + +error: `x` is shadowed by itself in `(&*x)` + --> $DIR/shadow.rs:15:9 + | +15 | let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)` + | ^^^^^^^^^ + | + = note: #[deny(shadow_same)] implied by #[deny(clippy_pedantic)] +note: previous binding is here + --> $DIR/shadow.rs:14:9 + | +14 | let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }` + | ^ + +error: `x` is shadowed by `{ *x + 1 }` which reuses the original value + --> $DIR/shadow.rs:16:9 + | +16 | let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses + | ^ + | + = note: #[deny(shadow_reuse)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/shadow.rs:4:17 + | +4 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ +note: initialization happens here + --> $DIR/shadow.rs:16:13 + | +16 | let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses + | ^^^^^^^^^^ +note: previous binding is here + --> $DIR/shadow.rs:15:9 + | +15 | let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)` + | ^ + +error: `x` is shadowed by `id(x)` which reuses the original value + --> $DIR/shadow.rs:17:9 + | +17 | let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses + | ^ + | + = note: #[deny(shadow_reuse)] implied by #[deny(clippy_pedantic)] +note: initialization happens here + --> $DIR/shadow.rs:17:13 + | +17 | let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses + | ^^^^^ +note: previous binding is here + --> $DIR/shadow.rs:16:9 + | +16 | let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses + | ^ + +error: `x` is shadowed by `(1, x)` which reuses the original value + --> $DIR/shadow.rs:18:9 + | +18 | let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses + | ^ + | + = note: #[deny(shadow_reuse)] implied by #[deny(clippy_pedantic)] +note: initialization happens here + --> $DIR/shadow.rs:18:13 + | +18 | let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses + | ^^^^^^ +note: previous binding is here + --> $DIR/shadow.rs:17:9 + | +17 | let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses + | ^ + +error: `x` is shadowed by `first(x)` which reuses the original value + --> $DIR/shadow.rs:19:9 + | +19 | let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses + | ^ + | + = note: #[deny(shadow_reuse)] implied by #[deny(clippy_pedantic)] +note: initialization happens here + --> $DIR/shadow.rs:19:13 + | +19 | let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses + | ^^^^^^^^ +note: previous binding is here + --> $DIR/shadow.rs:18:9 + | +18 | let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses + | ^ + +error: `x` is shadowed by `y` + --> $DIR/shadow.rs:21:9 + | +21 | let x = y; //~ERROR `x` is shadowed by `y` + | ^ + | + = note: #[deny(shadow_unrelated)] implied by #[deny(clippy_pedantic)] +note: lint level defined here + --> $DIR/shadow.rs:4:17 + | +4 | #![deny(clippy, clippy_pedantic)] + | ^^^^^^^^^^^^^^^ +note: initialization happens here + --> $DIR/shadow.rs:21:13 + | +21 | let x = y; //~ERROR `x` is shadowed by `y` + | ^ +note: previous binding is here + --> $DIR/shadow.rs:19:9 + | +19 | let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses + | ^ + +error: `x` shadows a previous declaration + --> $DIR/shadow.rs:23:9 + | +23 | let x; //~ERROR `x` shadows a previous declaration + | ^ + | + = note: #[deny(shadow_unrelated)] implied by #[deny(clippy_pedantic)] +note: previous binding is here + --> $DIR/shadow.rs:21:9 + | +21 | let x = y; //~ERROR `x` is shadowed by `y` + | ^ + +error: aborting due to 9 previous errors + diff --git a/tests/compile-fail/short_circuit_statement.rs b/tests/ui/short_circuit_statement.rs similarity index 100% rename from tests/compile-fail/short_circuit_statement.rs rename to tests/ui/short_circuit_statement.rs diff --git a/tests/ui/short_circuit_statement.stderr b/tests/ui/short_circuit_statement.stderr new file mode 100644 index 00000000000..4c865ebeb19 --- /dev/null +++ b/tests/ui/short_circuit_statement.stderr @@ -0,0 +1,34 @@ +error: boolean short circuit operator in statement may be clearer using an explicit test + --> $DIR/short_circuit_statement.rs:7:5 + | +7 | f() && g(); + | ^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/short_circuit_statement.rs:4:9 + | +4 | #![deny(short_circuit_statement)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: replace it with + | if f() { g(); } + +error: boolean short circuit operator in statement may be clearer using an explicit test + --> $DIR/short_circuit_statement.rs:11:5 + | +11 | f() || g(); + | ^^^^^^^^^^^ + | +help: replace it with + | if !f() { g(); } + +error: boolean short circuit operator in statement may be clearer using an explicit test + --> $DIR/short_circuit_statement.rs:15:5 + | +15 | 1 == 2 || g(); + | ^^^^^^^^^^^^^^ + | +help: replace it with + | if !(1 == 2) { g(); } + +error: aborting due to 3 previous errors + diff --git a/tests/ui/strings.rs b/tests/ui/strings.rs new file mode 100644 index 00000000000..7cfc8a41ea1 --- /dev/null +++ b/tests/ui/strings.rs @@ -0,0 +1,73 @@ +#![feature(plugin)] +#![plugin(clippy)] + +#[deny(string_add)] +#[allow(string_add_assign)] +fn add_only() { // ignores assignment distinction + let mut x = "".to_owned(); + + for _ in 1..3 { + x = x + "."; //~ERROR you added something to a string. + } + + let y = "".to_owned(); + let z = y + "..."; //~ERROR you added something to a string. + + assert_eq!(&x, &z); +} + +#[deny(string_add_assign)] +fn add_assign_only() { + let mut x = "".to_owned(); + + for _ in 1..3 { + x = x + "."; //~ERROR you assigned the result of adding something to this string. + } + + let y = "".to_owned(); + let z = y + "..."; + + assert_eq!(&x, &z); +} + +#[deny(string_add, string_add_assign)] +fn both() { + let mut x = "".to_owned(); + + for _ in 1..3 { + x = x + "."; //~ERROR you assigned the result of adding something to this string. + } + + let y = "".to_owned(); + let z = y + "..."; //~ERROR you added something to a string. + + assert_eq!(&x, &z); +} + +#[allow(dead_code, unused_variables)] +#[deny(string_lit_as_bytes)] +fn str_lit_as_bytes() { + let bs = "hello there".as_bytes(); + //~^ERROR calling `as_bytes()` + //~|HELP byte string literal + //~|SUGGESTION b"hello there" + + // no warning, because this cannot be written as a byte string literal: + let ubs = "☃".as_bytes(); + + let strify = stringify!(foobar).as_bytes(); +} + +fn main() { + add_only(); + add_assign_only(); + both(); + + // the add is only caught for `String` + let mut x = 1; + ; x = x + 1; + //~^ WARN manual implementation of an assign operation + //~| HELP replace + //~| SUGGESTION ; x += 1; + assert_eq!(2, x); +} diff --git a/tests/ui/strings.stderr b/tests/ui/strings.stderr new file mode 100644 index 00000000000..892f04c7ea9 --- /dev/null +++ b/tests/ui/strings.stderr @@ -0,0 +1,80 @@ +error: you added something to a string. Consider using `String::push_str()` instead + --> $DIR/strings.rs:10:13 + | +10 | x = x + "."; //~ERROR you added something to a string. + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/strings.rs:4:8 + | +4 | #[deny(string_add)] + | ^^^^^^^^^^ + +error: you added something to a string. Consider using `String::push_str()` instead + --> $DIR/strings.rs:14:13 + | +14 | let z = y + "..."; //~ERROR you added something to a string. + | ^^^^^^^^^ + +error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead + --> $DIR/strings.rs:24:9 + | +24 | x = x + "."; //~ERROR you assigned the result of adding something to this string. + | ^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/strings.rs:19:8 + | +19 | #[deny(string_add_assign)] + | ^^^^^^^^^^^^^^^^^ + +error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead + --> $DIR/strings.rs:38:9 + | +38 | x = x + "."; //~ERROR you assigned the result of adding something to this string. + | ^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/strings.rs:33:20 + | +33 | #[deny(string_add, string_add_assign)] + | ^^^^^^^^^^^^^^^^^ + +error: you added something to a string. Consider using `String::push_str()` instead + --> $DIR/strings.rs:42:13 + | +42 | let z = y + "..."; //~ERROR you added something to a string. + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/strings.rs:33:8 + | +33 | #[deny(string_add, string_add_assign)] + | ^^^^^^^^^^ + +error: calling `as_bytes()` on a string literal + --> $DIR/strings.rs:50:14 + | +50 | let bs = "hello there".as_bytes(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/strings.rs:48:8 + | +48 | #[deny(string_lit_as_bytes)] + | ^^^^^^^^^^^^^^^^^^^ +help: consider using a byte string literal instead + | let bs = b"hello there"; + +warning: manual implementation of an assign operation + --> $DIR/strings.rs:68:7 + | +68 | ; x = x + 1; + | ^^^^^^^^^ + | + = note: #[warn(assign_op_pattern)] on by default +help: replace it with + | ; x += 1; + +error: aborting due to 6 previous errors + diff --git a/tests/compile-fail/stutter.rs b/tests/ui/stutter.rs similarity index 100% rename from tests/compile-fail/stutter.rs rename to tests/ui/stutter.rs diff --git a/tests/ui/stutter.stderr b/tests/ui/stutter.stderr new file mode 100644 index 00000000000..108fccb77f5 --- /dev/null +++ b/tests/ui/stutter.stderr @@ -0,0 +1,32 @@ +error: item name starts with its containing module's name + --> $DIR/stutter.rs:8:5 + | +8 | pub fn foo_bar() {} //~ ERROR: item name starts with its containing module's name + | ^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/stutter.rs:3:9 + | +3 | #![deny(stutter)] + | ^^^^^^^ + +error: item name ends with its containing module's name + --> $DIR/stutter.rs:9:5 + | +9 | pub fn bar_foo() {} //~ ERROR: item name ends with its containing module's name + | ^^^^^^^^^^^^^^^^^^^ + +error: item name starts with its containing module's name + --> $DIR/stutter.rs:10:5 + | +10 | pub struct FooCake {} //~ ERROR: item name starts with its containing module's name + | ^^^^^^^^^^^^^^^^^^^^^ + +error: item name ends with its containing module's name + --> $DIR/stutter.rs:11:5 + | +11 | pub enum CakeFoo {} //~ ERROR: item name ends with its containing module's name + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/swap.rs b/tests/ui/swap.rs new file mode 100644 index 00000000000..0e56d5ca86e --- /dev/null +++ b/tests/ui/swap.rs @@ -0,0 +1,84 @@ +#![feature(plugin)] +#![plugin(clippy)] + +#![deny(clippy)] +#![allow(blacklisted_name, unused_assignments)] + +struct Foo(u32); + +fn array() { + let mut foo = [1, 2]; + let temp = foo[0]; //~ NOTE implied by + foo[0] = foo[1]; + foo[1] = temp; + //~^^^ ERROR this looks like you are swapping elements of `foo` manually + //~| HELP try + //~| SUGGESTION foo.swap(0, 1); + + foo.swap(0, 1); +} + +fn slice() { + let foo = &mut [1, 2]; + let temp = foo[0]; //~ NOTE implied by + foo[0] = foo[1]; + foo[1] = temp; + //~^^^ ERROR this looks like you are swapping elements of `foo` manually + //~| HELP try + //~| SUGGESTION foo.swap(0, 1); + + foo.swap(0, 1); +} + +fn vec() { + let mut foo = vec![1, 2]; + let temp = foo[0]; //~ NOTE implied by + foo[0] = foo[1]; + foo[1] = temp; + //~^^^ ERROR this looks like you are swapping elements of `foo` manually + //~| HELP try + //~| SUGGESTION foo.swap(0, 1); + + foo.swap(0, 1); +} + +fn main() { + array(); + slice(); + vec(); + + let mut a = 42; + let mut b = 1337; + + a = b; //~ NOTE implied by + b = a; + //~^^ ERROR this looks like you are trying to swap `a` and `b` + //~| HELP try + //~| SUGGESTION std::mem::swap(&mut a, &mut b); + //~| NOTE or maybe you should use `std::mem::replace`? + + ; let t = a; //~ NOTE implied by + a = b; + b = t; + //~^^^ ERROR this looks like you are swapping `a` and `b` manually + //~| HELP try + //~| SUGGESTION ; std::mem::swap(&mut a, &mut b); + //~| NOTE or maybe you should use `std::mem::replace`? + + let mut c = Foo(42); + + c.0 = a; //~ NOTE implied by + a = c.0; + //~^^ ERROR this looks like you are trying to swap `c.0` and `a` + //~| HELP try + //~| SUGGESTION std::mem::swap(&mut c.0, &mut a); + //~| NOTE or maybe you should use `std::mem::replace`? + + ; let t = c.0; //~ NOTE implied by + c.0 = a; + a = t; + //~^^^ ERROR this looks like you are swapping `c.0` and `a` manually + //~| HELP try + //~| SUGGESTION ; std::mem::swap(&mut c.0, &mut a); + //~| NOTE or maybe you should use `std::mem::replace`? +} diff --git a/tests/ui/swap.stderr b/tests/ui/swap.stderr new file mode 100644 index 00000000000..f4fd80ec9ca --- /dev/null +++ b/tests/ui/swap.stderr @@ -0,0 +1,105 @@ +error: this looks like you are swapping elements of `foo` manually + --> $DIR/swap.rs:11:5 + | +11 | let temp = foo[0]; //~ NOTE implied by + | _____^ starting here... +12 | | foo[0] = foo[1]; +13 | | foo[1] = temp; + | |_________________^ ...ending here + | + = note: #[deny(manual_swap)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/swap.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ +help: try + | foo.swap(0, 1); + +error: this looks like you are swapping elements of `foo` manually + --> $DIR/swap.rs:23:5 + | +23 | let temp = foo[0]; //~ NOTE implied by + | _____^ starting here... +24 | | foo[0] = foo[1]; +25 | | foo[1] = temp; + | |_________________^ ...ending here + | + = note: #[deny(manual_swap)] implied by #[deny(clippy)] +help: try + | foo.swap(0, 1); + +error: this looks like you are swapping elements of `foo` manually + --> $DIR/swap.rs:35:5 + | +35 | let temp = foo[0]; //~ NOTE implied by + | _____^ starting here... +36 | | foo[0] = foo[1]; +37 | | foo[1] = temp; + | |_________________^ ...ending here + | + = note: #[deny(manual_swap)] implied by #[deny(clippy)] +help: try + | foo.swap(0, 1); + +error: this looks like you are swapping `a` and `b` manually + --> $DIR/swap.rs:60:7 + | +60 | ; let t = a; //~ NOTE implied by + | _______^ starting here... +61 | | a = b; +62 | | b = t; + | |_________^ ...ending here + | + = note: #[deny(manual_swap)] implied by #[deny(clippy)] +help: try + | ; std::mem::swap(&mut a, &mut b); + = note: or maybe you should use `std::mem::replace`? + +error: this looks like you are swapping `c.0` and `a` manually + --> $DIR/swap.rs:77:7 + | +77 | ; let t = c.0; //~ NOTE implied by + | _______^ starting here... +78 | | c.0 = a; +79 | | a = t; + | |_________^ ...ending here + | + = note: #[deny(manual_swap)] implied by #[deny(clippy)] +help: try + | ; std::mem::swap(&mut c.0, &mut a); + = note: or maybe you should use `std::mem::replace`? + +error: this looks like you are trying to swap `a` and `b` + --> $DIR/swap.rs:53:5 + | +53 | a = b; //~ NOTE implied by + | _____^ starting here... +54 | | b = a; + | |_________^ ...ending here + | + = note: #[deny(almost_swapped)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/swap.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ +help: try + | std::mem::swap(&mut a, &mut b); + = note: or maybe you should use `std::mem::replace`? + +error: this looks like you are trying to swap `c.0` and `a` + --> $DIR/swap.rs:70:5 + | +70 | c.0 = a; //~ NOTE implied by + | _____^ starting here... +71 | | a = c.0; + | |___________^ ...ending here + | + = note: #[deny(almost_swapped)] implied by #[deny(clippy)] +help: try + | std::mem::swap(&mut c.0, &mut a); + = note: or maybe you should use `std::mem::replace`? + +error: aborting due to 7 previous errors + diff --git a/tests/compile-fail/temporary_assignment.rs b/tests/ui/temporary_assignment.rs similarity index 100% rename from tests/compile-fail/temporary_assignment.rs rename to tests/ui/temporary_assignment.rs diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr new file mode 100644 index 00000000000..953fd4e772a --- /dev/null +++ b/tests/ui/temporary_assignment.stderr @@ -0,0 +1,20 @@ +error: assignment to temporary + --> $DIR/temporary_assignment.rs:29:5 + | +29 | Struct { field: 0 }.field = 1; //~ERROR assignment to temporary + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/temporary_assignment.rs:4:9 + | +4 | #![deny(temporary_assignment)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: assignment to temporary + --> $DIR/temporary_assignment.rs:30:5 + | +30 | (0, 0).0 = 1; //~ERROR assignment to temporary + | ^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs similarity index 100% rename from tests/compile-fail/toplevel_ref_arg.rs rename to tests/ui/toplevel_ref_arg.rs diff --git a/tests/ui/toplevel_ref_arg.stderr b/tests/ui/toplevel_ref_arg.stderr new file mode 100644 index 00000000000..3e3ec712cd3 --- /dev/null +++ b/tests/ui/toplevel_ref_arg.stderr @@ -0,0 +1,55 @@ +error: `ref` directly on a function argument is ignored. Consider using a reference type instead. + --> $DIR/toplevel_ref_arg.rs:7:15 + | +7 | fn the_answer(ref mut x: u8) { //~ ERROR `ref` directly on a function argument is ignored + | ^^^^^^^^^ + | + = note: #[deny(toplevel_ref_arg)] implied by #[deny(clippy)] +note: lint level defined here + --> $DIR/toplevel_ref_arg.rs:4:9 + | +4 | #![deny(clippy)] + | ^^^^^^ + +error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead + --> $DIR/toplevel_ref_arg.rs:18:7 + | +18 | let ref x = 1; + | ^^^^^ + | + = note: #[deny(toplevel_ref_arg)] implied by #[deny(clippy)] +help: try + | let x = &1; + +error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead + --> $DIR/toplevel_ref_arg.rs:23:7 + | +23 | let ref y: (&_, u8) = (&1, 2); + | ^^^^^ + | + = note: #[deny(toplevel_ref_arg)] implied by #[deny(clippy)] +help: try + | let y: &(&_, u8) = &(&1, 2); + +error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead + --> $DIR/toplevel_ref_arg.rs:28:7 + | +28 | let ref z = 1 + 2; + | ^^^^^ + | + = note: #[deny(toplevel_ref_arg)] implied by #[deny(clippy)] +help: try + | let z = &(1 + 2); + +error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead + --> $DIR/toplevel_ref_arg.rs:33:7 + | +33 | let ref mut z = 1 + 2; + | ^^^^^^^^^ + | + = note: #[deny(toplevel_ref_arg)] implied by #[deny(clippy)] +help: try + | let z = &mut (1 + 2); + +error: aborting due to 5 previous errors + diff --git a/tests/compile-fail/transmute.rs b/tests/ui/transmute.rs similarity index 100% rename from tests/compile-fail/transmute.rs rename to tests/ui/transmute.rs diff --git a/tests/ui/transmute.stderr b/tests/ui/transmute.stderr new file mode 100644 index 00000000000..ec9e7941855 --- /dev/null +++ b/tests/ui/transmute.stderr @@ -0,0 +1,225 @@ +error: transmute from a type (`&'a T`) to itself + --> $DIR/transmute.rs:22:20 + | +22 | let _: &'a T = core::intrinsics::transmute(t); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/transmute.rs:20:8 + | +20 | #[deny(useless_transmute)] + | ^^^^^^^^^^^^^^^^^ + +error: transmute from a reference to a pointer + --> $DIR/transmute.rs:27:23 + | +27 | let _: *const T = core::intrinsics::transmute(t); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: *const T = t as *const T; + +error: transmute from a reference to a pointer + --> $DIR/transmute.rs:32:21 + | +32 | let _: *mut T = core::intrinsics::transmute(t); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: *mut T = t as *const T as *mut T; + +error: transmute from a reference to a pointer + --> $DIR/transmute.rs:37:23 + | +37 | let _: *const U = core::intrinsics::transmute(t); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: *const U = t as *const T as *const U; + +error: transmute from a pointer type (`*const T`) to a reference type (`&T`) + --> $DIR/transmute.rs:45:17 + | +45 | let _: &T = std::mem::transmute(p); + | ^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/transmute.rs:43:8 + | +43 | #[deny(transmute_ptr_to_ref)] + | ^^^^^^^^^^^^^^^^^^^^ +help: try + | let _: &T = &*p; + +error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) + --> $DIR/transmute.rs:51:21 + | +51 | let _: &mut T = std::mem::transmute(m); + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: &mut T = &mut *m; + +error: transmute from a pointer type (`*mut T`) to a reference type (`&T`) + --> $DIR/transmute.rs:57:17 + | +57 | let _: &T = std::mem::transmute(m); + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: &T = &*m; + +error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) + --> $DIR/transmute.rs:63:21 + | +63 | let _: &mut T = std::mem::transmute(p as *mut T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: &mut T = &mut *(p as *mut T); + +error: transmute from a pointer type (`*const U`) to a reference type (`&T`) + --> $DIR/transmute.rs:69:17 + | +69 | let _: &T = std::mem::transmute(o); + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: &T = &*(o as *const T); + +error: transmute from a pointer type (`*mut U`) to a reference type (`&mut T`) + --> $DIR/transmute.rs:75:21 + | +75 | let _: &mut T = std::mem::transmute(om); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: &mut T = &mut *(om as *mut T); + +error: transmute from a pointer type (`*mut U`) to a reference type (`&T`) + --> $DIR/transmute.rs:81:17 + | +81 | let _: &T = std::mem::transmute(om); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: &T = &*(om as *const T); + +error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<'_, u8>`) + --> $DIR/transmute.rs:95:32 + | +95 | let _: &Foo = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/transmute.rs:88:8 + | +88 | #[deny(transmute_ptr_to_ref)] + | ^^^^^^^^^^^^^^^^^^^^ +help: try + | let _: &Foo = unsafe { &*(raw as *const Foo<_>) }; + +error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<'_, &u8>`) + --> $DIR/transmute.rs:100:33 + | +100 | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: &Foo<&u8> = unsafe { &*(raw as *const Foo<&_>) }; + +error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`) + --> $DIR/transmute.rs:107:14 + | +107 | unsafe { std::mem::transmute::<_, Bar>(raw) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | unsafe { &*(raw as *const u8) }; + +error: transmute from a type (`std::vec::Vec`) to itself + --> $DIR/transmute.rs:116:27 + | +116 | let _: Vec = core::intrinsics::transmute(my_vec()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/transmute.rs:113:8 + | +113 | #[deny(useless_transmute)] + | ^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`std::vec::Vec`) to itself + --> $DIR/transmute.rs:119:27 + | +119 | let _: Vec = core::mem::transmute(my_vec()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`std::vec::Vec`) to itself + --> $DIR/transmute.rs:122:27 + | +122 | let _: Vec = std::intrinsics::transmute(my_vec()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`std::vec::Vec`) to itself + --> $DIR/transmute.rs:125:27 + | +125 | let _: Vec = std::mem::transmute(my_vec()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`std::vec::Vec`) to itself + --> $DIR/transmute.rs:128:27 + | +128 | let _: Vec = my_transmute(my_vec()); + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from an integer to a pointer + --> $DIR/transmute.rs:137:31 + | +137 | let _: *const usize = std::mem::transmute(5_isize); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: *const usize = 5_isize as *const usize; + +error: transmute from an integer to a pointer + --> $DIR/transmute.rs:143:31 + | +143 | let _: *const usize = std::mem::transmute(1+1usize); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | let _: *const usize = (1+1usize) as *const usize; + +error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) + --> $DIR/transmute.rs:160:24 + | +160 | let _: Usize = core::intrinsics::transmute(int_const_ptr); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/transmute.rs:153:8 + | +153 | #[deny(crosspointer_transmute)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) + --> $DIR/transmute.rs:163:24 + | +163 | let _: Usize = core::intrinsics::transmute(int_mut_ptr); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) + --> $DIR/transmute.rs:166:31 + | +166 | let _: *const Usize = core::intrinsics::transmute(my_int()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) + --> $DIR/transmute.rs:169:29 + | +169 | let _: *mut Usize = core::intrinsics::transmute(my_int()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 25 previous errors + diff --git a/tests/compile-fail/transmute_32bit.rs b/tests/ui/transmute_32bit.rs similarity index 100% rename from tests/compile-fail/transmute_32bit.rs rename to tests/ui/transmute_32bit.rs diff --git a/tests/compile-fail/transmute_64bit.rs b/tests/ui/transmute_64bit.rs similarity index 100% rename from tests/compile-fail/transmute_64bit.rs rename to tests/ui/transmute_64bit.rs diff --git a/tests/ui/transmute_64bit.stderr b/tests/ui/transmute_64bit.stderr new file mode 100644 index 00000000000..1559809eb83 --- /dev/null +++ b/tests/ui/transmute_64bit.stderr @@ -0,0 +1,20 @@ +error: transmute from a `f64` to a pointer + --> $DIR/transmute_64bit.rs:9:31 + | +9 | let _: *const usize = std::mem::transmute(6.0f64); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/transmute_64bit.rs:6:8 + | +6 | #[deny(wrong_transmute)] + | ^^^^^^^^^^^^^^^ + +error: transmute from a `f64` to a pointer + --> $DIR/transmute_64bit.rs:12:29 + | +12 | let _: *mut usize = std::mem::transmute(6.0f64); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/unicode.rs b/tests/ui/unicode.rs similarity index 100% rename from tests/compile-fail/unicode.rs rename to tests/ui/unicode.rs diff --git a/tests/ui/unicode.stderr b/tests/ui/unicode.stderr new file mode 100644 index 00000000000..b8ecb7c460f --- /dev/null +++ b/tests/ui/unicode.stderr @@ -0,0 +1,40 @@ +error: zero-width space detected + --> $DIR/unicode.rs:6:12 + | +6 | print!("Here >​< is a ZWS, and ​another"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(zero_width_space)] on by default + = help: Consider replacing the string with: + ""Here >/u{200B}< is a ZWS, and /u{200B}another"" + +error: non-nfc unicode sequence detected + --> $DIR/unicode.rs:13:12 + | +13 | print!("̀àh?"); //~ERROR non-nfc unicode sequence detected + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/unicode.rs:11:8 + | +11 | #[deny(unicode_not_nfc)] + | ^^^^^^^^^^^^^^^ + = help: Consider replacing the string with: + ""̀àh?"" + +error: literal non-ASCII character detected + --> $DIR/unicode.rs:19:12 + | +19 | print!("Üben!"); //~ERROR literal non-ASCII character detected + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/unicode.rs:17:8 + | +17 | #[deny(non_ascii_literal)] + | ^^^^^^^^^^^^^^^^^ + = help: Consider replacing the string with: + ""/u{dc}ben!"" + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/unit_cmp.rs b/tests/ui/unit_cmp.rs similarity index 100% rename from tests/compile-fail/unit_cmp.rs rename to tests/ui/unit_cmp.rs diff --git a/tests/ui/unit_cmp.stderr b/tests/ui/unit_cmp.stderr new file mode 100644 index 00000000000..a35c04b4998 --- /dev/null +++ b/tests/ui/unit_cmp.stderr @@ -0,0 +1,20 @@ +error: ==-comparison of unit values detected. This will always be true + --> $DIR/unit_cmp.rs:16:8 + | +16 | if { true; } == { false; } { //~ERROR ==-comparison of unit values detected. This will always be true + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/unit_cmp.rs:4:9 + | +4 | #![deny(unit_cmp)] + | ^^^^^^^^ + +error: >-comparison of unit values detected. This will always be false + --> $DIR/unit_cmp.rs:19:8 + | +19 | if { true; } > { false; } { //~ERROR >-comparison of unit values detected. This will always be false + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/unneeded_field_pattern.rs b/tests/ui/unneeded_field_pattern.rs similarity index 100% rename from tests/compile-fail/unneeded_field_pattern.rs rename to tests/ui/unneeded_field_pattern.rs diff --git a/tests/ui/unneeded_field_pattern.stderr b/tests/ui/unneeded_field_pattern.stderr new file mode 100644 index 00000000000..cb721a2d694 --- /dev/null +++ b/tests/ui/unneeded_field_pattern.stderr @@ -0,0 +1,23 @@ +error: You matched a field with a wildcard pattern. Consider using `..` instead + --> $DIR/unneeded_field_pattern.rs:17:15 + | +17 | Foo { a: _, b: 0, .. } => {} //~ERROR You matched a field with a wildcard pattern + | ^^^^ + | +note: lint level defined here + --> $DIR/unneeded_field_pattern.rs:4:9 + | +4 | #![deny(unneeded_field_pattern)] + | ^^^^^^^^^^^^^^^^^^^^^^ + = help: Try with `Foo { b: 0, .. }` + +error: All the struct fields are matched to a wildcard pattern, consider using `..`. + --> $DIR/unneeded_field_pattern.rs:19:9 + | +19 | Foo { a: _, b: _, c: _ } => {} //~ERROR All the struct fields are matched to a + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: Try with `Foo { .. }` instead + +error: aborting due to 2 previous errors + diff --git a/tests/compile-fail/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs similarity index 100% rename from tests/compile-fail/unsafe_removed_from_name.rs rename to tests/ui/unsafe_removed_from_name.rs diff --git a/tests/ui/unsafe_removed_from_name.stderr b/tests/ui/unsafe_removed_from_name.stderr new file mode 100644 index 00000000000..4080353efbd --- /dev/null +++ b/tests/ui/unsafe_removed_from_name.stderr @@ -0,0 +1,26 @@ +error: removed "unsafe" from the name of `UnsafeCell` in use as `TotallySafeCell` + --> $DIR/unsafe_removed_from_name.rs:7:1 + | +7 | use std::cell::{UnsafeCell as TotallySafeCell}; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/unsafe_removed_from_name.rs:5:9 + | +5 | #![deny(unsafe_removed_from_name)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: removed "unsafe" from the name of `UnsafeCell` in use as `TotallySafeCellAgain` + --> $DIR/unsafe_removed_from_name.rs:10:1 + | +10 | use std::cell::UnsafeCell as TotallySafeCellAgain; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: removed "unsafe" from the name of `Unsafe` in use as `LieAboutModSafety` + --> $DIR/unsafe_removed_from_name.rs:25:1 + | +25 | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/unused_io_amount.rs b/tests/ui/unused_io_amount.rs similarity index 100% rename from tests/compile-fail/unused_io_amount.rs rename to tests/ui/unused_io_amount.rs diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr new file mode 100644 index 00000000000..54d8158908f --- /dev/null +++ b/tests/ui/unused_io_amount.stderr @@ -0,0 +1,52 @@ +error: handle written amount returned or use `Write::write_all` instead + --> $DIR/unused_io_amount.rs:10:5 + | +10 | try!(s.write(b"test")); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(unused_io_amount)] on by default + = note: this error originates in a macro outside of the current crate + +error: handle read amount returned or use `Read::read_exact` instead + --> $DIR/unused_io_amount.rs:12:5 + | +12 | try!(s.read(&mut buf)); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(unused_io_amount)] on by default + = note: this error originates in a macro outside of the current crate + +error: handle written amount returned or use `Write::write_all` instead + --> $DIR/unused_io_amount.rs:17:5 + | +17 | s.write(b"test")?; + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(unused_io_amount)] on by default + +error: handle read amount returned or use `Read::read_exact` instead + --> $DIR/unused_io_amount.rs:20:5 + | +20 | s.read(&mut buf)?; + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(unused_io_amount)] on by default + +error: handle written amount returned or use `Write::write_all` instead + --> $DIR/unused_io_amount.rs:26:5 + | +26 | s.write(b"test").unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(unused_io_amount)] on by default + +error: handle read amount returned or use `Read::read_exact` instead + --> $DIR/unused_io_amount.rs:29:5 + | +29 | s.read(&mut buf).unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: #[deny(unused_io_amount)] on by default + +error: aborting due to 6 previous errors + diff --git a/tests/compile-fail/unused_labels.rs b/tests/ui/unused_labels.rs similarity index 100% rename from tests/compile-fail/unused_labels.rs rename to tests/ui/unused_labels.rs diff --git a/tests/ui/unused_labels.stderr b/tests/ui/unused_labels.stderr new file mode 100644 index 00000000000..280ea148cf2 --- /dev/null +++ b/tests/ui/unused_labels.stderr @@ -0,0 +1,32 @@ +error: unused label `'label` + --> $DIR/unused_labels.rs:8:5 + | +8 | 'label: for i in 1..2 { //~ERROR: unused label `'label` + | _____^ starting here... +9 | | if i > 4 { continue } +10 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/unused_labels.rs:5:9 + | +5 | #![deny(unused_label)] + | ^^^^^^^^^^^^ + +error: unused label `'a` + --> $DIR/unused_labels.rs:21:5 + | +21 | 'a: loop { break } //~ERROR: unused label `'a` + | ^^^^^^^^^^^^^^^^^^ + +error: unused label `'same_label_in_two_fns` + --> $DIR/unused_labels.rs:32:5 + | +32 | 'same_label_in_two_fns: loop { //~ERROR: unused label `'same_label_in_two_fns` + | _____^ starting here... +33 | | let _ = 1; +34 | | } + | |_____^ ...ending here + +error: aborting due to 3 previous errors + diff --git a/tests/compile-fail/unused_lt.rs b/tests/ui/unused_lt.rs similarity index 100% rename from tests/compile-fail/unused_lt.rs rename to tests/ui/unused_lt.rs diff --git a/tests/ui/unused_lt.stderr b/tests/ui/unused_lt.stderr new file mode 100644 index 00000000000..1df4e285f7a --- /dev/null +++ b/tests/ui/unused_lt.stderr @@ -0,0 +1,26 @@ +error: this lifetime isn't used in the function definition + --> $DIR/unused_lt.rs:16:14 + | +16 | fn unused_lt<'a>(x: u8) { //~ ERROR this lifetime + | ^^ + | +note: lint level defined here + --> $DIR/unused_lt.rs:4:9 + | +4 | #![deny(unused_lifetimes)] + | ^^^^^^^^^^^^^^^^ + +error: this lifetime isn't used in the function definition + --> $DIR/unused_lt.rs:20:25 + | +20 | fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) { //~ ERROR this lifetime + | ^^ + +error: this lifetime isn't used in the function definition + --> $DIR/unused_lt.rs:50:10 + | +50 | fn x<'a>(&self) {} //~ ERROR this lifetime + | ^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/update-all-references.sh b/tests/ui/update-all-references.sh new file mode 100755 index 00000000000..ddd69c399a5 --- /dev/null +++ b/tests/ui/update-all-references.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Copyright 2015 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +# A script to update the references for all tests. The idea is that +# you do a run, which will generate files in the build directory +# containing the (normalized) actual output of the compiler. You then +# run this script, which will copy those files over. If you find +# yourself manually editing a foo.stderr file, you're doing it wrong. +# +# See all `update-references.sh`, if you just want to update a single test. + +if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" != "" ]]; then + echo "usage: $0 " + echo "" + echo "For example:" + echo " $0 ../../../build/x86_64-apple-darwin/test/ui" +fi + +BUILD_DIR=$PWD/$1 +MY_DIR=$(dirname $0) +cd $MY_DIR +find . -name '*.rs' | xargs ./update-references.sh $BUILD_DIR diff --git a/tests/ui/update-references.sh b/tests/ui/update-references.sh new file mode 100755 index 00000000000..aa99d35f7aa --- /dev/null +++ b/tests/ui/update-references.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# +# Copyright 2015 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +# A script to update the references for particular tests. The idea is +# that you do a run, which will generate files in the build directory +# containing the (normalized) actual output of the compiler. This +# script will then copy that output and replace the "expected output" +# files. You can then commit the changes. +# +# If you find yourself manually editing a foo.stderr file, you're +# doing it wrong. + +if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then + echo "usage: $0 " + echo "" + echo "For example:" + echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs" +fi + +MYDIR=$(dirname $0) + +BUILD_DIR="$1" +shift + +while [[ "$1" != "" ]]; do + STDERR_NAME="${1/%.rs/.stderr}" + STDOUT_NAME="${1/%.rs/.stdout}" + shift + if [ -f $BUILD_DIR/$STDOUT_NAME ] && \ + ! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then + echo updating $MYDIR/$STDOUT_NAME + cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME + fi + if [ -f $BUILD_DIR/$STDERR_NAME ] && \ + ! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then + echo updating $MYDIR/$STDERR_NAME + cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME + fi +done + + diff --git a/tests/compile-fail/used_underscore_binding.rs b/tests/ui/used_underscore_binding.rs similarity index 100% rename from tests/compile-fail/used_underscore_binding.rs rename to tests/ui/used_underscore_binding.rs diff --git a/tests/ui/used_underscore_binding.stderr b/tests/ui/used_underscore_binding.stderr new file mode 100644 index 00000000000..5377698a6b8 --- /dev/null +++ b/tests/ui/used_underscore_binding.stderr @@ -0,0 +1,38 @@ +error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. + --> $DIR/used_underscore_binding.rs:17:5 + | +17 | _foo + 1 //~ ERROR used binding `_foo` which is prefixed with an underscore + | ^^^^ + | +note: lint level defined here + --> $DIR/used_underscore_binding.rs:6:9 + | +6 | #![deny(used_underscore_binding)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. + --> $DIR/used_underscore_binding.rs:22:20 + | +22 | println!("{}", _foo); + | ^^^^ + +error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. + --> $DIR/used_underscore_binding.rs:24:16 + | +24 | assert_eq!(_foo, _foo); + | ^^^^ + +error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. + --> $DIR/used_underscore_binding.rs:24:22 + | +24 | assert_eq!(_foo, _foo); + | ^^^^ + +error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used. + --> $DIR/used_underscore_binding.rs:39:5 + | +39 | s._underscore_field += 1; //~ Error used binding `_underscore_field` which is prefixed with an underscore + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/tests/compile-fail/useless_attribute.rs b/tests/ui/useless_attribute.rs similarity index 100% rename from tests/compile-fail/useless_attribute.rs rename to tests/ui/useless_attribute.rs diff --git a/tests/ui/useless_attribute.stderr b/tests/ui/useless_attribute.stderr new file mode 100644 index 00000000000..a0a7936dc0b --- /dev/null +++ b/tests/ui/useless_attribute.stderr @@ -0,0 +1,16 @@ +error: useless lint attribute + --> $DIR/useless_attribute.rs:5:1 + | +5 | #[allow(dead_code)] //~ ERROR useless lint attribute + | ^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/useless_attribute.rs:3:9 + | +3 | #![deny(useless_attribute)] + | ^^^^^^^^^^^^^^^^^ +help: if you just forgot a `!`, use + | #![allow(dead_code)] //~ ERROR useless lint attribute + +error: aborting due to previous error + diff --git a/tests/compile-fail/vec.rs b/tests/ui/vec.rs similarity index 100% rename from tests/compile-fail/vec.rs rename to tests/ui/vec.rs diff --git a/tests/ui/vec.stderr b/tests/ui/vec.stderr new file mode 100644 index 00000000000..c42b156fced --- /dev/null +++ b/tests/ui/vec.stderr @@ -0,0 +1,61 @@ +error: useless use of `vec!` + --> $DIR/vec.rs:24:14 + | +24 | on_slice(&vec![]); + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/vec.rs:4:9 + | +4 | #![deny(useless_vec)] + | ^^^^^^^^^^^ +help: you can use a slice directly + | on_slice(&[]); + +error: useless use of `vec!` + --> $DIR/vec.rs:30:14 + | +30 | on_slice(&vec![1, 2]); + | ^^^^^^^^^^^ + | +help: you can use a slice directly + | on_slice(&[1, 2]); + +error: useless use of `vec!` + --> $DIR/vec.rs:36:14 + | +36 | on_slice(&vec ![1, 2]); + | ^^^^^^^^^^^^ + | +help: you can use a slice directly + | on_slice(&[1, 2]); + +error: useless use of `vec!` + --> $DIR/vec.rs:42:14 + | +42 | on_slice(&vec!(1, 2)); + | ^^^^^^^^^^^ + | +help: you can use a slice directly + | on_slice(&[1, 2]); + +error: useless use of `vec!` + --> $DIR/vec.rs:48:14 + | +48 | on_slice(&vec![1; 2]); + | ^^^^^^^^^^^ + | +help: you can use a slice directly + | on_slice(&[1; 2]); + +error: useless use of `vec!` + --> $DIR/vec.rs:64:14 + | +64 | for a in vec![1, 2, 3] { + | ^^^^^^^^^^^^^ + | +help: you can use a slice directly + | for a in &[1, 2, 3] { + +error: aborting due to 6 previous errors + diff --git a/tests/compile-fail/while_loop.rs b/tests/ui/while_loop.rs similarity index 100% rename from tests/compile-fail/while_loop.rs rename to tests/ui/while_loop.rs diff --git a/tests/ui/while_loop.stderr b/tests/ui/while_loop.stderr new file mode 100644 index 00000000000..46f0260879a --- /dev/null +++ b/tests/ui/while_loop.stderr @@ -0,0 +1,126 @@ +error: this loop could be written as a `while let` loop + --> $DIR/while_loop.rs:9:5 + | +9 | loop { + | ^ + | +note: lint level defined here + --> $DIR/while_loop.rs:4:9 + | +4 | #![deny(while_let_loop, empty_loop, while_let_on_iterator)] + | ^^^^^^^^^^^^^^ +help: try + | while let Some(_x) = y { .. } + +error: this loop could be written as a `while let` loop + --> $DIR/while_loop.rs:25:5 + | +25 | loop { + | _____^ starting here... +26 | | //~^ERROR this loop could be written as a `while let` loop +27 | | //~|HELP try +28 | | //~|SUGGESTION while let Some(_x) = y { +29 | | match y { +30 | | Some(_x) => true, +31 | | None => break +32 | | }; +33 | | } + | |_____^ ...ending here + | +help: try + | while let Some(_x) = y { .. } + +error: this loop could be written as a `while let` loop + --> $DIR/while_loop.rs:34:5 + | +34 | loop { + | ^ + | +help: try + | while let Some(x) = y { .. } + +error: this loop could be written as a `while let` loop + --> $DIR/while_loop.rs:45:5 + | +45 | loop { + | ^ + | +help: try + | while let Some(x) = y { .. } + +error: this loop could be written as a `while let` loop + --> $DIR/while_loop.rs:70:5 + | +70 | loop { + | ^ + | +help: try + | while let Some(word) = "".split_whitespace().next() { .. } + +error: this loop could be written as a `for` loop + --> $DIR/while_loop.rs:83:5 + | +83 | while let Option::Some(x) = iter.next() { + | _____^ starting here... +84 | | //~^ ERROR this loop could be written as a `for` loop +85 | | //~| HELP try +86 | | //~| SUGGESTION for x in iter { +87 | | println!("{}", x); +88 | | } + | |_____^ ...ending here + | +note: lint level defined here + --> $DIR/while_loop.rs:4:37 + | +4 | #![deny(while_let_loop, empty_loop, while_let_on_iterator)] + | ^^^^^^^^^^^^^^^^^^^^^ +help: try + | for x in iter { .. } + +error: this loop could be written as a `for` loop + --> $DIR/while_loop.rs:91:5 + | +91 | while let Some(x) = iter.next() { + | _____^ starting here... +92 | | //~^ ERROR this loop could be written as a `for` loop +93 | | //~| HELP try +94 | | //~| SUGGESTION for x in iter { +95 | | println!("{}", x); +96 | | } + | |_____^ ...ending here + | +help: try + | for x in iter { .. } + +error: this loop could be written as a `for` loop + --> $DIR/while_loop.rs:99:5 + | +99 | while let Some(_) = iter.next() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try + | for _ in iter { .. } + +error: this loop could be written as a `while let` loop + --> $DIR/while_loop.rs:142:5 + | +142 | loop { + | ^ + | +help: try + | while let Some(ele) = iter.next() { .. } + +error: empty `loop {}` detected. You may want to either use `panic!()` or add `std::thread::sleep(..);` to the loop body. + --> $DIR/while_loop.rs:150:9 + | +150 | loop {} //~ERROR empty `loop {}` detected. + | ^^^^^^^ + | +note: lint level defined here + --> $DIR/while_loop.rs:4:25 + | +4 | #![deny(while_let_loop, empty_loop, while_let_on_iterator)] + | ^^^^^^^^^^ + +error: aborting due to 10 previous errors + diff --git a/tests/ui/wrong_macro_span.rs_ b/tests/ui/wrong_macro_span.rs_ new file mode 100644 index 00000000000..f22efd810f8 --- /dev/null +++ b/tests/ui/wrong_macro_span.rs_ @@ -0,0 +1,29 @@ +#![feature(plugin)] + +#![plugin(clippy)] +#![deny(clippy)] +#![allow(unused, if_let_redundant_pattern_matching)] + +fn main() { + #[derive(Debug)] + enum Foo { + A(String), + B, + } + + struct Thingy(Foo); + + macro_rules! issue_1404 { + ($idx:tt) => {{ + let thingy = Thingy(Foo::A("Foo".into())); + let t = &thingy; + + match t.$idx { Foo::A(ref val) => { println!("42"); }, _ => {} } + //~^ ERROR you seem to be trying to use match + //~| HELP try this + //~| SUGGESTION if let Foo::A(ref val) = t.$idx { println!("42"); } + }} + } + + issue_1404!(0) +} diff --git a/tests/compile-fail/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs similarity index 100% rename from tests/compile-fail/wrong_self_convention.rs rename to tests/ui/wrong_self_convention.rs diff --git a/tests/ui/wrong_self_convention.stderr b/tests/ui/wrong_self_convention.stderr new file mode 100644 index 00000000000..06781411b9e --- /dev/null +++ b/tests/ui/wrong_self_convention.stderr @@ -0,0 +1,80 @@ +error: methods called `from_*` usually take no self; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:21:17 + | +21 | fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self + | ^^^^ + | +note: lint level defined here + --> $DIR/wrong_self_convention.rs:4:9 + | +4 | #![deny(wrong_self_convention)] + | ^^^^^^^^^^^^^^^^^^^^^ + +error: methods called `from_*` usually take no self; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:27:21 + | +27 | pub fn from_i64(self) {} //~ERROR: methods called `from_*` usually take no self + | ^^^^ + +error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:38:15 + | +38 | fn as_i32(self) {} //~ERROR: methods called `as_*` usually take self by reference + | ^^^^ + +error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:40:17 + | +40 | fn into_i32(&self) {} //~ERROR: methods called `into_*` usually take self by value + | ^^^^^ + +error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:42:15 + | +42 | fn is_i32(self) {} //~ERROR: methods called `is_*` usually take self by reference + | ^^^^ + +error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:44:15 + | +44 | fn to_i32(self) {} //~ERROR: methods called `to_*` usually take self by reference + | ^^^^ + +error: methods called `from_*` usually take no self; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:46:17 + | +46 | fn from_i32(self) {} //~ERROR: methods called `from_*` usually take no self + | ^^^^ + +error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:48:19 + | +48 | pub fn as_i64(self) {} //~ERROR: methods called `as_*` usually take self by reference + | ^^^^ + +error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:49:21 + | +49 | pub fn into_i64(&self) {} //~ERROR: methods called `into_*` usually take self by value + | ^^^^^ + +error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:50:19 + | +50 | pub fn is_i64(self) {} //~ERROR: methods called `is_*` usually take self by reference + | ^^^^ + +error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:51:19 + | +51 | pub fn to_i64(self) {} //~ERROR: methods called `to_*` usually take self by reference + | ^^^^ + +error: methods called `from_*` usually take no self; consider choosing a less ambiguous name + --> $DIR/wrong_self_convention.rs:52:21 + | +52 | pub fn from_i64(self) {} //~ERROR: methods called `from_*` usually take no self + | ^^^^ + +error: aborting due to 12 previous errors + diff --git a/tests/compile-fail/zero_div_zero.rs b/tests/ui/zero_div_zero.rs similarity index 100% rename from tests/compile-fail/zero_div_zero.rs rename to tests/ui/zero_div_zero.rs diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr new file mode 100644 index 00000000000..a28d47257a1 --- /dev/null +++ b/tests/ui/zero_div_zero.stderr @@ -0,0 +1,71 @@ +warning: equal expressions as operands to `/` + --> $DIR/zero_div_zero.rs:7:15 + | +7 | let nan = 0.0 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN + | ^^^^^^^^^ + | + = note: #[warn(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 + | +7 | let nan = 0.0 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN + | ^^^^^^^^^ + | +note: lint level defined here + --> $DIR/zero_div_zero.rs:5:8 + | +5 | #[deny(zero_divided_by_zero)] + | ^^^^^^^^^^^^^^^^^^^^ + = help: Consider using `std::f32::NAN` if you would like a constant representing NaN + +warning: equal expressions as operands to `/` + --> $DIR/zero_div_zero.rs:9:19 + | +9 | let f64_nan = 0.0 / 0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN + | ^^^^^^^^^^^^ + | + = note: #[warn(eq_op)] on by default + +error: constant division of 0.0 with 0.0 will always result in NaN + --> $DIR/zero_div_zero.rs:9:19 + | +9 | let f64_nan = 0.0 / 0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN + | ^^^^^^^^^^^^ + | + = help: Consider using `std::f64::NAN` if you would like a constant representing NaN + +warning: equal expressions as operands to `/` + --> $DIR/zero_div_zero.rs:11:25 + | +11 | let other_f64_nan = 0.0f64 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN + | ^^^^^^^^^^^^ + | + = note: #[warn(eq_op)] on by default + +error: constant division of 0.0 with 0.0 will always result in NaN + --> $DIR/zero_div_zero.rs:11:25 + | +11 | let other_f64_nan = 0.0f64 / 0.0; //~ERROR constant division of 0.0 with 0.0 will always result in NaN + | ^^^^^^^^^^^^ + | + = help: Consider using `std::f64::NAN` if you would like a constant representing NaN + +warning: equal expressions as operands to `/` + --> $DIR/zero_div_zero.rs:13:28 + | +13 | let one_more_f64_nan = 0.0f64/0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN + | ^^^^^^^^^^^^^ + | + = note: #[warn(eq_op)] on by default + +error: constant division of 0.0 with 0.0 will always result in NaN + --> $DIR/zero_div_zero.rs:13:28 + | +13 | let one_more_f64_nan = 0.0f64/0.0f64; //~ERROR constant division of 0.0 with 0.0 will always result in NaN + | ^^^^^^^^^^^^^ + | + = help: Consider using `std::f64::NAN` if you would like a constant representing NaN + +error: aborting due to 4 previous errors +