Auto merge of #5438 - flip1995:rollup-pi762oy, r=flip1995

Rollup of 11 pull requests

Successful merges:

 - #5406 (Fix update_lints)
 - #5409 (Downgrade let_unit_value to pedantic)
 - #5410 (Downgrade trivially_copy_pass_by_ref to pedantic)
 - #5412 (Downgrade inefficient_to_string to pedantic)
 - #5415 (Add new lint for `Result<T, E>.map_or(None, Some(T))`)
 - #5417 (Update doc links and mentioned names in docs)
 - #5419 (Downgrade unreadable_literal to pedantic)
 - #5420 (Downgrade new_ret_no_self to pedantic)
 - #5422 (CONTRIBUTING.md: fix broken triage link)
 - #5424 (Incorrect suspicious_op_assign_impl)
 - #5425 (Ehance opt_as_ref_deref lint.)

Failed merges:

 - #5345 (Add lint for float in array comparison)
 - #5411 (Downgrade implicit_hasher to pedantic)
 - #5428 (Move cognitive_complexity to nursery)

r? @ghost

changelog: rollup
This commit is contained in:
bors 2020-04-08 14:17:47 +00:00
commit f8308c811f
62 changed files with 687 additions and 532 deletions

View file

@ -1448,6 +1448,7 @@ Released 2018-09-13
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used
[`result_map_or_into_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_or_into_option
[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn
[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
[`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used

View file

@ -36,7 +36,8 @@ High level approach:
### Finding something to fix/improve
All issues on Clippy are mentored, if you want help with a bug just ask @Manishearth, @llogiq, @mcarton or @oli-obk.
All issues on Clippy are mentored, if you want help with a bug just ask
@Manishearth, @flip1995, @phansch or @yaahc.
Some issues are easier than others. The [`good first issue`] label can be used to find the easy issues.
If you want to work on an issue, please leave a comment so that we can assign it to you!
@ -70,7 +71,7 @@ an AST expression). `match_def_path()` in Clippy's `utils` module can also be us
[`T-AST`]: https://github.com/rust-lang/rust-clippy/labels/T-AST
[`T-middle`]: https://github.com/rust-lang/rust-clippy/labels/T-middle
[`E-medium`]: https://github.com/rust-lang/rust-clippy/labels/E-medium
[`ty`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty
[`ty`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty
[nodes in the AST docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/
[deep-nesting]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/mem_forget.rs#L29-L43
[if_chain]: https://docs.rs/if_chain/*/if_chain
@ -78,8 +79,7 @@ an AST expression). `match_def_path()` in Clippy's `utils` module can also be us
## Writing code
Have a look at the [docs for writing lints][adding_lints] for more details. [Llogiq's blog post on lints]
is also a nice primer to lint-writing, though it does get into advanced stuff and may be a bit outdated.
Have a look at the [docs for writing lints][adding_lints] for more details.
If you want to add a new lint or change existing ones apart from bugfixing, it's
also a good idea to give the [stability guarantees][rfc_stability] and
@ -87,7 +87,6 @@ also a good idea to give the [stability guarantees][rfc_stability] and
quick read.
[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
[Llogiq's blog post on lints]: https://llogiq.github.io/2015/06/04/workflows.html
[clippy_rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md
[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories
@ -223,7 +222,7 @@ You can find the Clippy bors queue [here][homu_queue].
If you have @bors permissions, you can find an overview of the available
commands [here][homu_instructions].
[triage]: https://forge.rust-lang.org/triage-procedure.html
[triage]: https://forge.rust-lang.org/release/triage-procedure.html
[l-crash]: https://github.com/rust-lang/rust-clippy/labels/L-crash%20%3Aboom%3A
[l-bug]: https://github.com/rust-lang/rust-clippy/labels/L-bug%20%3Abeetle%3A
[homu]: https://github.com/rust-lang/homu

View file

@ -62,13 +62,25 @@ impl Lint {
}
/// Returns all non-deprecated lints and non-internal lints
pub fn usable_lints(lints: impl Iterator<Item = Self>) -> impl Iterator<Item = Self> {
lints.filter(|l| l.deprecation.is_none() && !l.is_internal())
#[must_use]
pub fn usable_lints(lints: &[Self]) -> Vec<Self> {
lints
.iter()
.filter(|l| l.deprecation.is_none() && !l.group.starts_with("internal"))
.cloned()
.collect()
}
/// Returns all internal lints (not `internal_warn` lints)
pub fn internal_lints(lints: impl Iterator<Item = Self>) -> impl Iterator<Item = Self> {
lints.filter(|l| l.group == "internal")
#[must_use]
pub fn internal_lints(lints: &[Self]) -> Vec<Self> {
lints.iter().filter(|l| l.group == "internal").cloned().collect()
}
/// Returns all deprecated lints
#[must_use]
pub fn deprecated_lints(lints: &[Self]) -> Vec<Self> {
lints.iter().filter(|l| l.deprecation.is_some()).cloned().collect()
}
/// Returns the lints in a `HashMap`, grouped by the different lint groups
@ -76,96 +88,63 @@ impl Lint {
pub fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
lints.map(|lint| (lint.group.to_string(), lint)).into_group_map()
}
#[must_use]
pub fn is_internal(&self) -> bool {
self.group.starts_with("internal")
}
}
/// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`.
#[must_use]
pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
pub fn gen_lint_group_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
lints
.into_iter()
.filter_map(|l| {
if l.deprecation.is_some() {
None
} else {
Some(format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
}
})
.map(|l| format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
.sorted()
.collect::<Vec<String>>()
}
/// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
#[must_use]
pub fn gen_modules_list(lints: Vec<Lint>) -> Vec<String> {
pub fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
lints
.into_iter()
.filter_map(|l| {
if l.is_internal() || l.deprecation.is_some() {
None
} else {
Some(l.module)
}
})
.map(|l| &l.module)
.unique()
.map(|module| format!("pub mod {};", module))
.map(|module| format!("mod {};", module))
.sorted()
.collect::<Vec<String>>()
}
/// Generates the list of lint links at the bottom of the README
#[must_use]
pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
let mut lint_list_sorted: Vec<Lint> = lints;
lint_list_sorted.sort_by_key(|l| l.name.clone());
lint_list_sorted
.iter()
.filter_map(|l| {
if l.is_internal() {
None
} else {
Some(format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name))
}
})
pub fn gen_changelog_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
lints
.sorted_by_key(|l| &l.name)
.map(|l| format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name))
.collect()
}
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
#[must_use]
pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
pub fn gen_deprecated<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
lints
.iter()
.filter_map(|l| {
l.clone().deprecation.map(|depr_text| {
vec![
" store.register_removed(".to_string(),
format!(" \"clippy::{}\",", l.name),
format!(" \"{}\",", depr_text),
" );".to_string(),
]
})
.flat_map(|l| {
l.deprecation
.clone()
.map(|depr_text| {
vec![
" store.register_removed(".to_string(),
format!(" \"clippy::{}\",", l.name),
format!(" \"{}\",", depr_text),
" );".to_string(),
]
})
.expect("only deprecated lints should be passed")
})
.flatten()
.collect::<Vec<String>>()
}
#[must_use]
pub fn gen_register_lint_list(lints: &[Lint]) -> Vec<String> {
pub fn gen_register_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
let pre = " store.register_lints(&[".to_string();
let post = " ]);".to_string();
let mut inner = lints
.iter()
.filter_map(|l| {
if !l.is_internal() && l.deprecation.is_none() {
Some(format!(" &{}::{},", l.module, l.name.to_uppercase()))
} else {
None
}
})
.map(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
.sorted()
.collect::<Vec<String>>();
inner.insert(0, pre);
@ -439,7 +418,7 @@ fn test_usable_lints() {
None,
"module_name",
)];
assert_eq!(expected, Lint::usable_lints(lints.into_iter()).collect::<Vec<Lint>>());
assert_eq!(expected, Lint::usable_lints(&lints));
}
#[test]
@ -469,13 +448,12 @@ fn test_gen_changelog_lint_list() {
let lints = vec![
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
];
let expected = vec![
format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()),
format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string()),
];
assert_eq!(expected, gen_changelog_lint_list(lints));
assert_eq!(expected, gen_changelog_lint_list(lints.iter()));
}
#[test]
@ -495,7 +473,6 @@ fn test_gen_deprecated() {
Some("will be removed"),
"module_name",
),
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
];
let expected: Vec<String> = vec![
" store.register_removed(",
@ -510,22 +487,24 @@ fn test_gen_deprecated() {
.into_iter()
.map(String::from)
.collect();
assert_eq!(expected, gen_deprecated(&lints));
assert_eq!(expected, gen_deprecated(lints.iter()));
}
#[test]
#[should_panic]
fn test_gen_deprecated_fail() {
let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")];
let _ = gen_deprecated(lints.iter());
}
#[test]
fn test_gen_modules_list() {
let lints = vec![
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
Lint::new("should_assert_eq2", "group2", "abc", Some("abc"), "deprecated"),
Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"),
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
];
let expected = vec![
"pub mod another_module;".to_string(),
"pub mod module_name;".to_string(),
];
assert_eq!(expected, gen_modules_list(lints));
let expected = vec!["mod another_module;".to_string(), "mod module_name;".to_string()];
assert_eq!(expected, gen_modules_list(lints.iter()));
}
#[test]
@ -533,7 +512,6 @@ fn test_gen_lint_group_list() {
let lints = vec![
Lint::new("abc", "group1", "abc", None, "module_name"),
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
Lint::new("should_assert_eq2", "group2", "abc", Some("abc"), "deprecated"),
Lint::new("internal", "internal_style", "abc", None, "module_name"),
];
let expected = vec![
@ -541,5 +519,5 @@ fn test_gen_lint_group_list() {
" LintId::of(&module_name::INTERNAL),".to_string(),
" LintId::of(&module_name::SHOULD_ASSERT_EQ),".to_string(),
];
assert_eq!(expected, gen_lint_group_list(lints));
assert_eq!(expected, gen_lint_group_list(lints.iter()));
}

View file

@ -14,14 +14,14 @@ pub enum UpdateMode {
pub fn run(update_mode: UpdateMode) {
let lint_list: Vec<Lint> = gather_all().collect();
let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
let usable_lint_count = round_to_fifty(usable_lints.len());
let internal_lints = Lint::internal_lints(&lint_list);
let deprecated_lints = Lint::deprecated_lints(&lint_list);
let usable_lints = Lint::usable_lints(&lint_list);
let mut sorted_usable_lints = usable_lints.clone();
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
let usable_lint_count = round_to_fifty(usable_lints.len());
let mut file_change = replace_region_in_file(
Path::new("src/lintlist/mod.rs"),
"begin lint list",
@ -61,7 +61,7 @@ pub fn run(update_mode: UpdateMode) {
"<!-- end autogenerated links to lint list -->",
false,
update_mode == UpdateMode::Change,
|| gen_changelog_lint_list(lint_list.clone()),
|| gen_changelog_lint_list(usable_lints.iter().chain(deprecated_lints.iter())),
)
.changed;
@ -71,7 +71,7 @@ pub fn run(update_mode: UpdateMode) {
"end deprecated lints",
false,
update_mode == UpdateMode::Change,
|| gen_deprecated(&lint_list),
|| gen_deprecated(deprecated_lints.iter()),
)
.changed;
@ -81,7 +81,7 @@ pub fn run(update_mode: UpdateMode) {
"end register lints",
false,
update_mode == UpdateMode::Change,
|| gen_register_lint_list(&lint_list),
|| gen_register_lint_list(usable_lints.iter().chain(internal_lints.iter())),
)
.changed;
@ -91,7 +91,7 @@ pub fn run(update_mode: UpdateMode) {
"end lints modules",
false,
update_mode == UpdateMode::Change,
|| gen_modules_list(lint_list.clone()),
|| gen_modules_list(usable_lints.iter()),
)
.changed;
@ -104,13 +104,9 @@ pub fn run(update_mode: UpdateMode) {
update_mode == UpdateMode::Change,
|| {
// clippy::all should only include the following lint groups:
let all_group_lints = usable_lints
.clone()
.into_iter()
.filter(|l| {
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
})
.collect();
let all_group_lints = usable_lints.iter().filter(|l| {
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
});
gen_lint_group_list(all_group_lints)
},
@ -125,7 +121,7 @@ pub fn run(update_mode: UpdateMode) {
r#"\]\);"#,
false,
update_mode == UpdateMode::Change,
|| gen_lint_group_list(lints.clone()),
|| gen_lint_group_list(lints.iter()),
)
.changed;
}
@ -140,8 +136,8 @@ pub fn run(update_mode: UpdateMode) {
}
pub fn print_lints() {
let lint_list = gather_all();
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
let lint_list: Vec<Lint> = gather_all().collect();
let usable_lints = Lint::usable_lints(&lint_list);
let usable_lint_count = usable_lints.len();
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());

View file

@ -170,157 +170,157 @@ mod consts;
mod utils;
// begin lints modules, do not remove this comment, its used in `update_lints`
pub mod approx_const;
pub mod arithmetic;
pub mod as_conversions;
pub mod assertions_on_constants;
pub mod assign_ops;
pub mod atomic_ordering;
pub mod attrs;
pub mod bit_mask;
pub mod blacklisted_name;
pub mod block_in_if_condition;
pub mod booleans;
pub mod bytecount;
pub mod cargo_common_metadata;
pub mod checked_conversions;
pub mod cognitive_complexity;
pub mod collapsible_if;
pub mod comparison_chain;
pub mod copies;
pub mod copy_iterator;
pub mod dbg_macro;
pub mod default_trait_access;
pub mod derive;
pub mod doc;
pub mod double_comparison;
pub mod double_parens;
pub mod drop_bounds;
pub mod drop_forget_ref;
pub mod duration_subsec;
pub mod else_if_without_else;
pub mod empty_enum;
pub mod entry;
pub mod enum_clike;
pub mod enum_variants;
pub mod eq_op;
pub mod erasing_op;
pub mod escape;
pub mod eta_reduction;
pub mod eval_order_dependence;
pub mod excessive_bools;
pub mod exit;
pub mod explicit_write;
pub mod fallible_impl_from;
pub mod float_literal;
pub mod floating_point_arithmetic;
pub mod format;
pub mod formatting;
pub mod functions;
pub mod get_last_with_len;
pub mod identity_conversion;
pub mod identity_op;
pub mod if_let_some_result;
pub mod if_not_else;
pub mod implicit_return;
pub mod indexing_slicing;
pub mod infinite_iter;
pub mod inherent_impl;
pub mod inherent_to_string;
pub mod inline_fn_without_body;
pub mod int_plus_one;
pub mod integer_division;
pub mod items_after_statements;
pub mod large_enum_variant;
pub mod large_stack_arrays;
pub mod len_zero;
pub mod let_if_seq;
pub mod let_underscore;
pub mod lifetimes;
pub mod literal_representation;
pub mod loops;
pub mod macro_use;
pub mod main_recursion;
pub mod map_clone;
pub mod map_unit_fn;
pub mod matches;
pub mod mem_discriminant;
pub mod mem_forget;
pub mod mem_replace;
pub mod methods;
pub mod minmax;
pub mod misc;
pub mod misc_early;
pub mod missing_const_for_fn;
pub mod missing_doc;
pub mod missing_inline;
pub mod modulo_arithmetic;
pub mod multiple_crate_versions;
pub mod mut_key;
pub mod mut_mut;
pub mod mut_reference;
pub mod mutable_debug_assertion;
pub mod mutex_atomic;
pub mod needless_bool;
pub mod needless_borrow;
pub mod needless_borrowed_ref;
pub mod needless_continue;
pub mod needless_pass_by_value;
pub mod needless_update;
pub mod neg_cmp_op_on_partial_ord;
pub mod neg_multiply;
pub mod new_without_default;
pub mod no_effect;
pub mod non_copy_const;
pub mod non_expressive_names;
pub mod open_options;
pub mod option_env_unwrap;
pub mod overflow_check_conditional;
pub mod panic_unimplemented;
pub mod partialeq_ne_impl;
pub mod path_buf_push_overwrite;
pub mod precedence;
pub mod ptr;
pub mod ptr_offset_with_cast;
pub mod question_mark;
pub mod ranges;
pub mod redundant_clone;
pub mod redundant_field_names;
pub mod redundant_pattern_matching;
pub mod redundant_pub_crate;
pub mod redundant_static_lifetimes;
pub mod reference;
pub mod regex;
pub mod returns;
pub mod serde_api;
pub mod shadow;
pub mod single_component_path_imports;
pub mod slow_vector_initialization;
pub mod strings;
pub mod suspicious_trait_impl;
pub mod swap;
pub mod tabs_in_doc_comments;
pub mod temporary_assignment;
pub mod to_digit_is_some;
pub mod trait_bounds;
pub mod transmute;
pub mod transmuting_null;
pub mod trivially_copy_pass_by_ref;
pub mod try_err;
pub mod types;
pub mod unicode;
pub mod unnamed_address;
pub mod unsafe_removed_from_name;
pub mod unused_io_amount;
pub mod unused_self;
pub mod unwrap;
pub mod use_self;
pub mod vec;
pub mod verbose_file_reads;
pub mod wildcard_dependencies;
pub mod wildcard_imports;
pub mod write;
pub mod zero_div_zero;
mod approx_const;
mod arithmetic;
mod as_conversions;
mod assertions_on_constants;
mod assign_ops;
mod atomic_ordering;
mod attrs;
mod bit_mask;
mod blacklisted_name;
mod block_in_if_condition;
mod booleans;
mod bytecount;
mod cargo_common_metadata;
mod checked_conversions;
mod cognitive_complexity;
mod collapsible_if;
mod comparison_chain;
mod copies;
mod copy_iterator;
mod dbg_macro;
mod default_trait_access;
mod derive;
mod doc;
mod double_comparison;
mod double_parens;
mod drop_bounds;
mod drop_forget_ref;
mod duration_subsec;
mod else_if_without_else;
mod empty_enum;
mod entry;
mod enum_clike;
mod enum_variants;
mod eq_op;
mod erasing_op;
mod escape;
mod eta_reduction;
mod eval_order_dependence;
mod excessive_bools;
mod exit;
mod explicit_write;
mod fallible_impl_from;
mod float_literal;
mod floating_point_arithmetic;
mod format;
mod formatting;
mod functions;
mod get_last_with_len;
mod identity_conversion;
mod identity_op;
mod if_let_some_result;
mod if_not_else;
mod implicit_return;
mod indexing_slicing;
mod infinite_iter;
mod inherent_impl;
mod inherent_to_string;
mod inline_fn_without_body;
mod int_plus_one;
mod integer_division;
mod items_after_statements;
mod large_enum_variant;
mod large_stack_arrays;
mod len_zero;
mod let_if_seq;
mod let_underscore;
mod lifetimes;
mod literal_representation;
mod loops;
mod macro_use;
mod main_recursion;
mod map_clone;
mod map_unit_fn;
mod matches;
mod mem_discriminant;
mod mem_forget;
mod mem_replace;
mod methods;
mod minmax;
mod misc;
mod misc_early;
mod missing_const_for_fn;
mod missing_doc;
mod missing_inline;
mod modulo_arithmetic;
mod multiple_crate_versions;
mod mut_key;
mod mut_mut;
mod mut_reference;
mod mutable_debug_assertion;
mod mutex_atomic;
mod needless_bool;
mod needless_borrow;
mod needless_borrowed_ref;
mod needless_continue;
mod needless_pass_by_value;
mod needless_update;
mod neg_cmp_op_on_partial_ord;
mod neg_multiply;
mod new_without_default;
mod no_effect;
mod non_copy_const;
mod non_expressive_names;
mod open_options;
mod option_env_unwrap;
mod overflow_check_conditional;
mod panic_unimplemented;
mod partialeq_ne_impl;
mod path_buf_push_overwrite;
mod precedence;
mod ptr;
mod ptr_offset_with_cast;
mod question_mark;
mod ranges;
mod redundant_clone;
mod redundant_field_names;
mod redundant_pattern_matching;
mod redundant_pub_crate;
mod redundant_static_lifetimes;
mod reference;
mod regex;
mod returns;
mod serde_api;
mod shadow;
mod single_component_path_imports;
mod slow_vector_initialization;
mod strings;
mod suspicious_trait_impl;
mod swap;
mod tabs_in_doc_comments;
mod temporary_assignment;
mod to_digit_is_some;
mod trait_bounds;
mod transmute;
mod transmuting_null;
mod trivially_copy_pass_by_ref;
mod try_err;
mod types;
mod unicode;
mod unnamed_address;
mod unsafe_removed_from_name;
mod unused_io_amount;
mod unused_self;
mod unwrap;
mod use_self;
mod vec;
mod verbose_file_reads;
mod wildcard_dependencies;
mod wildcard_imports;
mod write;
mod zero_div_zero;
// end lints modules, do not remove this comment, its used in `update_lints`
pub use crate::utils::conf::Conf;
@ -666,6 +666,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&methods::OPTION_UNWRAP_USED,
&methods::OR_FUN_CALL,
&methods::RESULT_EXPECT_USED,
&methods::RESULT_MAP_OR_INTO_OPTION,
&methods::RESULT_MAP_UNWRAP_OR_ELSE,
&methods::RESULT_UNWRAP_USED,
&methods::SEARCH_IS_SOME,
@ -828,6 +829,12 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&unwrap::PANICKING_UNWRAP,
&unwrap::UNNECESSARY_UNWRAP,
&use_self::USE_SELF,
&utils::internal_lints::CLIPPY_LINTS_INTERNAL,
&utils::internal_lints::COMPILER_LINT_FUNCTIONS,
&utils::internal_lints::DEFAULT_LINT,
&utils::internal_lints::LINT_WITHOUT_LINT_PASS,
&utils::internal_lints::OUTER_EXPN_EXPN_DATA,
&utils::internal_lints::PRODUCE_ICE,
&vec::USELESS_VEC,
&verbose_file_reads::VERBOSE_FILE_READS,
&wildcard_dependencies::WILDCARD_DEPENDENCIES,
@ -1098,6 +1105,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&items_after_statements::ITEMS_AFTER_STATEMENTS),
LintId::of(&large_stack_arrays::LARGE_STACK_ARRAYS),
LintId::of(&literal_representation::LARGE_DIGIT_GROUPS),
LintId::of(&literal_representation::UNREADABLE_LITERAL),
LintId::of(&loops::EXPLICIT_INTO_ITER_LOOP),
LintId::of(&loops::EXPLICIT_ITER_LOOP),
LintId::of(&macro_use::MACRO_USE_IMPORTS),
@ -1105,7 +1113,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&methods::FILTER_MAP),
LintId::of(&methods::FILTER_MAP_NEXT),
LintId::of(&methods::FIND_MAP),
LintId::of(&methods::INEFFICIENT_TO_STRING),
LintId::of(&methods::MAP_FLATTEN),
LintId::of(&methods::NEW_RET_NO_SELF),
LintId::of(&methods::OPTION_MAP_UNWRAP_OR),
LintId::of(&methods::OPTION_MAP_UNWRAP_OR_ELSE),
LintId::of(&methods::RESULT_MAP_UNWRAP_OR_ELSE),
@ -1119,12 +1129,14 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&shadow::SHADOW_UNRELATED),
LintId::of(&strings::STRING_ADD_ASSIGN),
LintId::of(&trait_bounds::TYPE_REPETITION_IN_BOUNDS),
LintId::of(&trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF),
LintId::of(&types::CAST_LOSSLESS),
LintId::of(&types::CAST_POSSIBLE_TRUNCATION),
LintId::of(&types::CAST_POSSIBLE_WRAP),
LintId::of(&types::CAST_PRECISION_LOSS),
LintId::of(&types::CAST_SIGN_LOSS),
LintId::of(&types::INVALID_UPCAST_COMPARISONS),
LintId::of(&types::LET_UNIT_VALUE),
LintId::of(&types::LINKEDLIST),
LintId::of(&types::OPTION_OPTION),
LintId::of(&unicode::NON_ASCII_LITERAL),
@ -1219,7 +1231,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&lifetimes::NEEDLESS_LIFETIMES),
LintId::of(&literal_representation::INCONSISTENT_DIGIT_GROUPING),
LintId::of(&literal_representation::MISTYPED_LITERAL_SUFFIXES),
LintId::of(&literal_representation::UNREADABLE_LITERAL),
LintId::of(&loops::EMPTY_LOOP),
LintId::of(&loops::EXPLICIT_COUNTER_LOOP),
LintId::of(&loops::FOR_KV_MAP),
@ -1259,7 +1270,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&methods::EXPECT_FUN_CALL),
LintId::of(&methods::FILTER_NEXT),
LintId::of(&methods::FLAT_MAP_IDENTITY),
LintId::of(&methods::INEFFICIENT_TO_STRING),
LintId::of(&methods::INTO_ITER_ON_REF),
LintId::of(&methods::ITERATOR_STEP_BY_ZERO),
LintId::of(&methods::ITER_CLONED_COLLECT),
@ -1267,12 +1277,12 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&methods::ITER_NTH_ZERO),
LintId::of(&methods::ITER_SKIP_NEXT),
LintId::of(&methods::MANUAL_SATURATING_ARITHMETIC),
LintId::of(&methods::NEW_RET_NO_SELF),
LintId::of(&methods::OK_EXPECT),
LintId::of(&methods::OPTION_AND_THEN_SOME),
LintId::of(&methods::OPTION_AS_REF_DEREF),
LintId::of(&methods::OPTION_MAP_OR_NONE),
LintId::of(&methods::OR_FUN_CALL),
LintId::of(&methods::RESULT_MAP_OR_INTO_OPTION),
LintId::of(&methods::SEARCH_IS_SOME),
LintId::of(&methods::SHOULD_IMPLEMENT_TRAIT),
LintId::of(&methods::SINGLE_CHAR_PATTERN),
@ -1365,7 +1375,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&transmute::UNSOUND_COLLECTION_TRANSMUTE),
LintId::of(&transmute::WRONG_TRANSMUTE),
LintId::of(&transmuting_null::TRANSMUTING_NULL),
LintId::of(&trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF),
LintId::of(&try_err::TRY_ERR),
LintId::of(&types::ABSURD_EXTREME_COMPARISONS),
LintId::of(&types::BORROWED_BOX),
@ -1376,7 +1385,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::FN_TO_NUMERIC_CAST),
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
LintId::of(&types::IMPLICIT_HASHER),
LintId::of(&types::LET_UNIT_VALUE),
LintId::of(&types::REDUNDANT_ALLOCATION),
LintId::of(&types::TYPE_COMPLEXITY),
LintId::of(&types::UNIT_ARG),
@ -1428,7 +1436,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&len_zero::LEN_ZERO),
LintId::of(&let_if_seq::USELESS_LET_IF_SEQ),
LintId::of(&literal_representation::INCONSISTENT_DIGIT_GROUPING),
LintId::of(&literal_representation::UNREADABLE_LITERAL),
LintId::of(&loops::EMPTY_LOOP),
LintId::of(&loops::FOR_KV_MAP),
LintId::of(&loops::NEEDLESS_RANGE_LOOP),
@ -1450,9 +1457,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&methods::ITER_NTH_ZERO),
LintId::of(&methods::ITER_SKIP_NEXT),
LintId::of(&methods::MANUAL_SATURATING_ARITHMETIC),
LintId::of(&methods::NEW_RET_NO_SELF),
LintId::of(&methods::OK_EXPECT),
LintId::of(&methods::OPTION_MAP_OR_NONE),
LintId::of(&methods::RESULT_MAP_OR_INTO_OPTION),
LintId::of(&methods::SHOULD_IMPLEMENT_TRAIT),
LintId::of(&methods::STRING_EXTEND_CHARS),
LintId::of(&methods::UNNECESSARY_FOLD),
@ -1489,7 +1496,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::FN_TO_NUMERIC_CAST),
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
LintId::of(&types::IMPLICIT_HASHER),
LintId::of(&types::LET_UNIT_VALUE),
LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME),
LintId::of(&write::PRINTLN_EMPTY_STRING),
LintId::of(&write::PRINT_LITERAL),
@ -1652,7 +1658,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&loops::MANUAL_MEMCPY),
LintId::of(&loops::NEEDLESS_COLLECT),
LintId::of(&methods::EXPECT_FUN_CALL),
LintId::of(&methods::INEFFICIENT_TO_STRING),
LintId::of(&methods::ITER_NTH),
LintId::of(&methods::OR_FUN_CALL),
LintId::of(&methods::SINGLE_CHAR_PATTERN),
@ -1660,7 +1665,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&mutex_atomic::MUTEX_ATOMIC),
LintId::of(&redundant_clone::REDUNDANT_CLONE),
LintId::of(&slow_vector_initialization::SLOW_VECTOR_INITIALIZATION),
LintId::of(&trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF),
LintId::of(&types::BOX_VEC),
LintId::of(&types::REDUNDANT_ALLOCATION),
LintId::of(&vec::USELESS_VEC),

View file

@ -27,7 +27,7 @@ declare_clippy_lint! {
/// let x: u64 = 61864918973511;
/// ```
pub UNREADABLE_LITERAL,
style,
pedantic,
"long integer literal without underscores"
}

View file

@ -654,7 +654,7 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult
fn never_loop_block(block: &Block<'_>, main_loop_id: HirId) -> NeverLoopResult {
let stmts = block.stmts.iter().map(stmt_to_expr);
let expr = once(block.expr.as_ref().map(|p| &**p));
let expr = once(block.expr.as_deref());
let mut iter = stmts.chain(expr).filter_map(|e| e);
never_loop_expr_seq(&mut iter, main_loop_id)
}
@ -662,7 +662,7 @@ fn never_loop_block(block: &Block<'_>, main_loop_id: HirId) -> NeverLoopResult {
fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<&'tcx Expr<'tcx>> {
match stmt.kind {
StmtKind::Semi(ref e, ..) | StmtKind::Expr(ref e, ..) => Some(e),
StmtKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
StmtKind::Local(ref local) => local.init.as_deref(),
_ => None,
}
}

View file

@ -1197,3 +1197,40 @@ where
None
}
#[test]
fn test_overlapping() {
use rustc_span::source_map::DUMMY_SP;
let sp = |s, e| SpannedRange {
span: DUMMY_SP,
node: (s, e),
};
assert_eq!(None, overlapping::<u8>(&[]));
assert_eq!(None, overlapping(&[sp(1, Bound::Included(4))]));
assert_eq!(
None,
overlapping(&[sp(1, Bound::Included(4)), sp(5, Bound::Included(6))])
);
assert_eq!(
None,
overlapping(&[
sp(1, Bound::Included(4)),
sp(5, Bound::Included(6)),
sp(10, Bound::Included(11))
],)
);
assert_eq!(
Some((&sp(1, Bound::Included(4)), &sp(3, Bound::Included(6)))),
overlapping(&[sp(1, Bound::Included(4)), sp(3, Bound::Included(6))])
);
assert_eq!(
Some((&sp(5, Bound::Included(6)), &sp(6, Bound::Included(11)))),
overlapping(&[
sp(1, Bound::Included(4)),
sp(5, Bound::Included(6)),
sp(6, Bound::Included(11))
],)
);
}

View file

@ -331,6 +331,32 @@ declare_clippy_lint! {
"using `Option.map_or(None, f)`, which is more succinctly expressed as `and_then(f)`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.map_or(None, Some)`.
///
/// **Why is this bad?** Readability, this can be written more concisely as
/// `_.ok()`.
///
/// **Known problems:** None.
///
/// **Example:**
///
/// Bad:
/// ```rust
/// # let r: Result<u32, &str> = Ok(1);
/// assert_eq!(Some(1), r.map_or(None, Some));
/// ```
///
/// Good:
/// ```rust
/// # let r: Result<u32, &str> = Ok(1);
/// assert_eq!(Some(1), r.ok());
/// ```
pub RESULT_MAP_OR_INTO_OPTION,
style,
"using `Result.map_or(None, Some)`, which is more succinctly expressed as `ok()`"
}
declare_clippy_lint! {
/// **What it does:** Checks for usage of `_.and_then(|x| Some(y))`.
///
@ -699,7 +725,7 @@ declare_clippy_lint! {
/// ["foo", "bar"].iter().map(|&s| s.to_string());
/// ```
pub INEFFICIENT_TO_STRING,
perf,
pedantic,
"using `to_string` on `&&T` where `T: ToString`"
}
@ -722,7 +748,7 @@ declare_clippy_lint! {
/// }
/// ```
pub NEW_RET_NO_SELF,
style,
pedantic,
"not returning `Self` in a `new` method"
}
@ -1249,6 +1275,7 @@ declare_lint_pass!(Methods => [
OPTION_MAP_UNWRAP_OR,
OPTION_MAP_UNWRAP_OR_ELSE,
RESULT_MAP_UNWRAP_OR_ELSE,
RESULT_MAP_OR_INTO_OPTION,
OPTION_MAP_OR_NONE,
OPTION_AND_THEN_SOME,
OR_FUN_CALL,
@ -2524,38 +2551,78 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
}
}
/// lint use of `_.map_or(None, _)` for `Option`s
/// lint use of `_.map_or(None, _)` for `Option`s and `Result`s
fn lint_map_or_none<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
expr: &'tcx hir::Expr<'_>,
map_or_args: &'tcx [hir::Expr<'_>],
) {
if match_type(cx, cx.tables.expr_ty(&map_or_args[0]), &paths::OPTION) {
// check if the first non-self argument to map_or() is None
let map_or_arg_is_none = if let hir::ExprKind::Path(ref qpath) = map_or_args[1].kind {
let is_option = match_type(cx, cx.tables.expr_ty(&map_or_args[0]), &paths::OPTION);
let is_result = match_type(cx, cx.tables.expr_ty(&map_or_args[0]), &paths::RESULT);
// There are two variants of this `map_or` lint:
// (1) using `map_or` as an adapter from `Result<T,E>` to `Option<T>`
// (2) using `map_or` as a combinator instead of `and_then`
//
// (For this lint) we don't care if any other type calls `map_or`
if !is_option && !is_result {
return;
}
let (lint_name, msg, instead, hint) = {
let default_arg_is_none = if let hir::ExprKind::Path(ref qpath) = map_or_args[1].kind {
match_qpath(qpath, &paths::OPTION_NONE)
} else {
return;
};
if !default_arg_is_none {
// nothing to lint!
return;
}
let f_arg_is_some = if let hir::ExprKind::Path(ref qpath) = map_or_args[2].kind {
match_qpath(qpath, &paths::OPTION_SOME)
} else {
false
};
if map_or_arg_is_none {
// lint message
if is_option {
let self_snippet = snippet(cx, map_or_args[0].span, "..");
let func_snippet = snippet(cx, map_or_args[2].span, "..");
let msg = "called `map_or(None, f)` on an `Option` value. This can be done more directly by calling \
`and_then(f)` instead";
let map_or_self_snippet = snippet(cx, map_or_args[0].span, "..");
let map_or_func_snippet = snippet(cx, map_or_args[2].span, "..");
let hint = format!("{0}.and_then({1})", map_or_self_snippet, map_or_func_snippet);
span_lint_and_sugg(
cx,
(
OPTION_MAP_OR_NONE,
expr.span,
msg,
"try using `and_then` instead",
hint,
Applicability::MachineApplicable,
);
format!("{0}.and_then({1})", self_snippet, func_snippet),
)
} else if f_arg_is_some {
let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \
`ok()` instead";
let self_snippet = snippet(cx, map_or_args[0].span, "..");
(
RESULT_MAP_OR_INTO_OPTION,
msg,
"try using `ok` instead",
format!("{0}.ok()", self_snippet),
)
} else {
// nothing to lint!
return;
}
}
};
span_lint_and_sugg(
cx,
lint_name,
expr.span,
msg,
instead,
hint,
Applicability::MachineApplicable,
);
}
/// Lint use of `_.and_then(|x| Some(y))` for `Option`s
@ -3166,6 +3233,8 @@ fn lint_option_as_ref_deref<'a, 'tcx>(
map_args: &[hir::Expr<'_>],
is_mut: bool,
) {
let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not);
let option_ty = cx.tables.expr_ty(&as_ref_args[0]);
if !match_type(cx, option_ty, &paths::OPTION) {
return;
@ -3188,39 +3257,56 @@ fn lint_option_as_ref_deref<'a, 'tcx>(
hir::ExprKind::Closure(_, _, body_id, _, _) => {
let closure_body = cx.tcx.hir().body(body_id);
let closure_expr = remove_blocks(&closure_body.value);
if_chain! {
if let hir::ExprKind::MethodCall(_, _, args) = &closure_expr.kind;
if args.len() == 1;
if let hir::ExprKind::Path(qpath) = &args[0].kind;
if let hir::def::Res::Local(local_id) = cx.tables.qpath_res(qpath, args[0].hir_id);
if closure_body.params[0].pat.hir_id == local_id;
let adj = cx.tables.expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
then {
let method_did = cx.tables.type_dependent_def_id(closure_expr.hir_id).unwrap();
deref_aliases.iter().any(|path| match_def_path(cx, method_did, path))
} else {
false
}
match &closure_expr.kind {
hir::ExprKind::MethodCall(_, _, args) => {
if_chain! {
if args.len() == 1;
if let hir::ExprKind::Path(qpath) = &args[0].kind;
if let hir::def::Res::Local(local_id) = cx.tables.qpath_res(qpath, args[0].hir_id);
if closure_body.params[0].pat.hir_id == local_id;
let adj = cx.tables.expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
then {
let method_did = cx.tables.type_dependent_def_id(closure_expr.hir_id).unwrap();
deref_aliases.iter().any(|path| match_def_path(cx, method_did, path))
} else {
false
}
}
},
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, m, ref inner) if same_mutability(m) => {
if_chain! {
if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner1) = inner.kind;
if let hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner2) = inner1.kind;
if let hir::ExprKind::Path(ref qpath) = inner2.kind;
if let hir::def::Res::Local(local_id) = cx.tables.qpath_res(qpath, inner2.hir_id);
then {
closure_body.params[0].pat.hir_id == local_id
} else {
false
}
}
},
_ => false,
}
},
_ => false,
};
if is_deref {
let current_method = if is_mut {
".as_mut().map(DerefMut::deref_mut)"
format!(".as_mut().map({})", snippet(cx, map_args[1].span, ".."))
} else {
".as_ref().map(Deref::deref)"
format!(".as_ref().map({})", snippet(cx, map_args[1].span, ".."))
};
let method_hint = if is_mut { "as_deref_mut" } else { "as_deref" };
let hint = format!("{}.{}()", snippet(cx, as_ref_args[0].span, ".."), method_hint);
let suggestion = format!("try using {} instead", method_hint);
let msg = format!(
"called `{0}` (or with one of deref aliases) on an Option value. \
This can be done more directly by calling `{1}` instead",
"called `{0}` on an Option value. This can be done more directly \
by calling `{1}` instead",
current_method, hint
);
span_lint_and_sugg(

View file

@ -54,7 +54,7 @@ declare_lint_pass!(SuspiciousImpl => [SUSPICIOUS_ARITHMETIC_IMPL, SUSPICIOUS_OP_
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
if let hir::ExprKind::Binary(binop, _, _) = expr.kind {
if let hir::ExprKind::Binary(binop, _, _) | hir::ExprKind::AssignOp(binop, ..) = expr.kind {
match binop.node {
hir::BinOpKind::Eq
| hir::BinOpKind::Lt
@ -65,14 +65,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
_ => {},
}
// Check if the binary expression is part of another bi/unary expression
// as a child node
// or operator assignment as a child node
let mut parent_expr = cx.tcx.hir().get_parent_node(expr.hir_id);
while parent_expr != hir::CRATE_HIR_ID {
if let hir::Node::Expr(e) = cx.tcx.hir().get(parent_expr) {
match e.kind {
hir::ExprKind::Binary(..)
| hir::ExprKind::Unary(hir::UnOp::UnNot, _)
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _) => return,
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _)
| hir::ExprKind::AssignOp(..) => return,
_ => {},
}
}
@ -191,7 +192,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BinaryExprVisitor {
match expr.kind {
hir::ExprKind::Binary(..)
| hir::ExprKind::Unary(hir::UnOp::UnNot, _)
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _) => self.in_binary_expr = true,
| hir::ExprKind::Unary(hir::UnOp::UnNeg, _)
| hir::ExprKind::AssignOp(..) => self.in_binary_expr = true,
_ => {},
}

View file

@ -49,7 +49,7 @@ declare_clippy_lint! {
/// fn foo(v: u32) {}
/// ```
pub TRIVIALLY_COPY_PASS_BY_REF,
perf,
pedantic,
"functions taking small copyable arguments by reference"
}

View file

@ -593,7 +593,7 @@ declare_clippy_lint! {
/// };
/// ```
pub LET_UNIT_VALUE,
style,
pedantic,
"creating a `let` binding to a value of unit type, which usually can't be used afterwards"
}

View file

@ -463,11 +463,11 @@ don't hesitate to ask on [Discord] or in the issue/PR.
[utils]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/mod.rs
[if_chain]: https://docs.rs/if_chain/*/if_chain/
[from_expansion]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion
[in_external_macro]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/fn.in_external_macro.html
[in_external_macro]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/fn.in_external_macro.html
[span]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html
[applicability]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/enum.Applicability.html
[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/
[nightly_docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/
[nightly_docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/
[ast]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/index.html
[ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/sty/index.html
[ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/sty/index.html
[Discord]: https://discord.gg/rust-lang

View file

@ -789,7 +789,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "inefficient_to_string",
group: "perf",
group: "pedantic",
desc: "using `to_string` on `&&T` where `T: ToString`",
deprecation: None,
module: "methods",
@ -999,7 +999,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "let_unit_value",
group: "style",
group: "pedantic",
desc: "creating a `let` binding to a value of unit type, which usually can\'t be used afterwards",
deprecation: None,
module: "types",
@ -1447,7 +1447,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "new_ret_no_self",
group: "style",
group: "pedantic",
desc: "not returning `Self` in a `new` method",
deprecation: None,
module: "methods",
@ -1823,6 +1823,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
deprecation: None,
module: "methods",
},
Lint {
name: "result_map_or_into_option",
group: "style",
desc: "using `Result.map_or(None, Some)`, which is more succinctly expressed as `ok()`",
deprecation: None,
module: "methods",
},
Lint {
name: "result_map_unit_fn",
group: "complexity",
@ -2161,7 +2168,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "trivially_copy_pass_by_ref",
group: "perf",
group: "pedantic",
desc: "functions taking small copyable arguments by reference",
deprecation: None,
module: "trivially_copy_pass_by_ref",
@ -2294,7 +2301,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "unreadable_literal",
group: "style",
group: "pedantic",
desc: "long integer literal without underscores",
deprecation: None,
module: "literal_representation",

View file

@ -1,42 +0,0 @@
#![feature(rustc_private)]
extern crate rustc_span;
use std::collections::Bound;
#[test]
fn test_overlapping() {
use clippy_lints::matches::overlapping;
use rustc_span::source_map::DUMMY_SP;
let sp = |s, e| clippy_lints::matches::SpannedRange {
span: DUMMY_SP,
node: (s, e),
};
assert_eq!(None, overlapping::<u8>(&[]));
assert_eq!(None, overlapping(&[sp(1, Bound::Included(4))]));
assert_eq!(
None,
overlapping(&[sp(1, Bound::Included(4)), sp(5, Bound::Included(6))])
);
assert_eq!(
None,
overlapping(&[
sp(1, Bound::Included(4)),
sp(5, Bound::Included(6)),
sp(10, Bound::Included(11))
],)
);
assert_eq!(
Some((&sp(1, Bound::Included(4)), &sp(3, Bound::Included(6)))),
overlapping(&[sp(1, Bound::Included(4)), sp(3, Bound::Included(6))])
);
assert_eq!(
Some((&sp(5, Bound::Included(6)), &sp(6, Bound::Included(11)))),
overlapping(&[
sp(1, Bound::Included(4)),
sp(5, Bound::Included(6)),
sp(6, Bound::Included(11))
],)
);
}

View file

@ -1,6 +1,7 @@
// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![deny(clippy::trivially_copy_pass_by_ref)]
#![allow(clippy::many_single_char_names)]
#[derive(Copy, Clone)]

View file

@ -1,13 +1,17 @@
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:14:11
--> $DIR/test.rs:15:11
|
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `u16`
|
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
note: the lint level is defined here
--> $DIR/test.rs:4:9
|
LL | #![deny(clippy::trivially_copy_pass_by_ref)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:14:20
--> $DIR/test.rs:15:20
|
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `Foo`

View file

@ -1,5 +1,5 @@
#[warn(clippy::approx_constant)]
#[allow(unused, clippy::shadow_unrelated, clippy::similar_names, clippy::unreadable_literal)]
#[allow(unused, clippy::shadow_unrelated, clippy::similar_names)]
fn main() {
let my_e = 2.7182;
let almost_e = 2.718;

View file

@ -5,7 +5,6 @@ pub fn dec_read_dec(i: &mut i32) -> i32 {
ret
}
#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn minus_1(i: &i32) -> i32 {
dec_read_dec(&mut i.clone())
}

View file

@ -2,7 +2,7 @@
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
#![warn(clippy::debug_assert_with_mut_call)]
#![allow(clippy::trivially_copy_pass_by_ref, clippy::cognitive_complexity, clippy::redundant_closure_call)]
#![allow(clippy::cognitive_complexity, clippy::redundant_closure_call)]
struct S;

View file

@ -88,7 +88,6 @@ very_unsafe!();
// we don't lint code from external macros
undocd_unsafe!();
#[allow(clippy::let_unit_value)]
fn main() {
unsafe {
you_dont_see_me();

View file

@ -6,8 +6,7 @@
clippy::redundant_closure_call,
clippy::many_single_char_names,
clippy::needless_pass_by_value,
clippy::option_map_unit_fn,
clippy::trivially_copy_pass_by_ref
clippy::option_map_unit_fn
)]
#![warn(
clippy::redundant_closure,

View file

@ -6,8 +6,7 @@
clippy::redundant_closure_call,
clippy::many_single_char_names,
clippy::needless_pass_by_value,
clippy::option_map_unit_fn,
clippy::trivially_copy_pass_by_ref
clippy::option_map_unit_fn
)]
#![warn(
clippy::redundant_closure,

View file

@ -1,5 +1,5 @@
error: redundant closure found
--> $DIR/eta.rs:21:27
--> $DIR/eta.rs:20:27
|
LL | let a = Some(1u8).map(|a| foo(a));
| ^^^^^^^^^^ help: remove closure as shown: `foo`
@ -7,13 +7,13 @@ LL | let a = Some(1u8).map(|a| foo(a));
= note: `-D clippy::redundant-closure` implied by `-D warnings`
error: redundant closure found
--> $DIR/eta.rs:22:10
--> $DIR/eta.rs:21:10
|
LL | meta(|a| foo(a));
| ^^^^^^^^^^ help: remove closure as shown: `foo`
error: this expression borrows a reference that is immediately dereferenced by the compiler
--> $DIR/eta.rs:25:21
--> $DIR/eta.rs:24:21
|
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
| ^^^ help: change this to: `&2`
@ -21,13 +21,13 @@ LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
= note: `-D clippy::needless-borrow` implied by `-D warnings`
error: redundant closure found
--> $DIR/eta.rs:32:27
--> $DIR/eta.rs:31:27
|
LL | let e = Some(1u8).map(|a| generic(a));
| ^^^^^^^^^^^^^^ help: remove closure as shown: `generic`
error: redundant closure found
--> $DIR/eta.rs:75:51
--> $DIR/eta.rs:74:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
| ^^^^^^^^^^^ help: remove closure as shown: `TestStruct::foo`
@ -35,43 +35,43 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings`
error: redundant closure found
--> $DIR/eta.rs:77:51
--> $DIR/eta.rs:76:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `TestTrait::trait_foo`
error: redundant closure found
--> $DIR/eta.rs:80:42
--> $DIR/eta.rs:79:42
|
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
| ^^^^^^^^^^^^^ help: remove closure as shown: `std::vec::Vec::clear`
error: redundant closure found
--> $DIR/eta.rs:85:29
--> $DIR/eta.rs:84:29
|
LL | let e = Some("str").map(|s| s.to_string());
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string`
error: redundant closure found
--> $DIR/eta.rs:87:27
--> $DIR/eta.rs:86:27
|
LL | let e = Some('a').map(|s| s.to_uppercase());
| ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_uppercase`
error: redundant closure found
--> $DIR/eta.rs:90:65
--> $DIR/eta.rs:89:65
|
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `char::to_ascii_uppercase`
error: redundant closure found
--> $DIR/eta.rs:173:27
--> $DIR/eta.rs:172:27
|
LL | let a = Some(1u8).map(|a| foo_ptr(a));
| ^^^^^^^^^^^^^^ help: remove closure as shown: `foo_ptr`
error: redundant closure found
--> $DIR/eta.rs:178:27
--> $DIR/eta.rs:177:27
|
LL | let a = Some(1u8).map(|a| closure(a));
| ^^^^^^^^^^^^^^ help: remove closure as shown: `closure`

View file

@ -1,10 +1,4 @@
#![allow(
unused,
dead_code,
clippy::needless_lifetimes,
clippy::needless_pass_by_value,
clippy::trivially_copy_pass_by_ref
)]
#![allow(unused, dead_code, clippy::needless_lifetimes, clippy::needless_pass_by_value)]
#![warn(clippy::extra_unused_lifetimes)]
fn empty() {}

View file

@ -1,5 +1,5 @@
error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:14:14
--> $DIR/extra_unused_lifetimes.rs:8:14
|
LL | fn unused_lt<'a>(x: u8) {}
| ^^
@ -7,19 +7,19 @@ LL | fn unused_lt<'a>(x: u8) {}
= note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings`
error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:16:25
--> $DIR/extra_unused_lifetimes.rs:10:25
|
LL | fn unused_lt_transitive<'a, 'b: 'a>(x: &'b u8) {
| ^^
error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:41:10
--> $DIR/extra_unused_lifetimes.rs:35:10
|
LL | fn x<'a>(&self) {}
| ^^
error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:67:22
--> $DIR/extra_unused_lifetimes.rs:61:22
|
LL | fn unused_lt<'a>(x: u8) {}
| ^^

View file

@ -5,8 +5,7 @@
clippy::shadow_unrelated,
clippy::no_effect,
clippy::unnecessary_operation,
clippy::op_ref,
clippy::trivially_copy_pass_by_ref
clippy::op_ref
)]
#[rustfmt::skip]

View file

@ -1,5 +1,5 @@
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:16:5
--> $DIR/float_arithmetic.rs:15:5
|
LL | f * 2.0;
| ^^^^^^^
@ -7,97 +7,97 @@ LL | f * 2.0;
= note: `-D clippy::float-arithmetic` implied by `-D warnings`
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:18:5
--> $DIR/float_arithmetic.rs:17:5
|
LL | 1.0 + f;
| ^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:19:5
--> $DIR/float_arithmetic.rs:18:5
|
LL | f * 2.0;
| ^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:20:5
--> $DIR/float_arithmetic.rs:19:5
|
LL | f / 2.0;
| ^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:21:5
--> $DIR/float_arithmetic.rs:20:5
|
LL | f - 2.0 * 4.2;
| ^^^^^^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:22:5
--> $DIR/float_arithmetic.rs:21:5
|
LL | -f;
| ^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:24:5
--> $DIR/float_arithmetic.rs:23:5
|
LL | f += 1.0;
| ^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:25:5
--> $DIR/float_arithmetic.rs:24:5
|
LL | f -= 1.0;
| ^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:26:5
--> $DIR/float_arithmetic.rs:25:5
|
LL | f *= 2.0;
| ^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:27:5
--> $DIR/float_arithmetic.rs:26:5
|
LL | f /= 2.0;
| ^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:33:5
--> $DIR/float_arithmetic.rs:32:5
|
LL | 3.1_f32 + &1.2_f32;
| ^^^^^^^^^^^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:34:5
--> $DIR/float_arithmetic.rs:33:5
|
LL | &3.4_f32 + 1.5_f32;
| ^^^^^^^^^^^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:35:5
--> $DIR/float_arithmetic.rs:34:5
|
LL | &3.5_f32 + &1.3_f32;
| ^^^^^^^^^^^^^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:40:5
--> $DIR/float_arithmetic.rs:39:5
|
LL | a + f
| ^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:44:5
--> $DIR/float_arithmetic.rs:43:5
|
LL | f1 + f2
| ^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:48:5
--> $DIR/float_arithmetic.rs:47:5
|
LL | f1 + f2
| ^^^^^^^
error: floating-point arithmetic detected
--> $DIR/float_arithmetic.rs:52:5
--> $DIR/float_arithmetic.rs:51:5
|
LL | (&f1 + &f2)
| ^^^^^^^^^^^

View file

@ -1,5 +1,6 @@
// run-rustfix
#[warn(clippy::inconsistent_digit_grouping)]
#[deny(clippy::unreadable_literal)]
#[allow(unused_variables, clippy::excessive_precision)]
fn main() {
macro_rules! mac1 {

View file

@ -1,5 +1,6 @@
// run-rustfix
#[warn(clippy::inconsistent_digit_grouping)]
#[deny(clippy::unreadable_literal)]
#[allow(unused_variables, clippy::excessive_precision)]
fn main() {
macro_rules! mac1 {

View file

@ -1,5 +1,5 @@
error: digits grouped inconsistently by underscores
--> $DIR/inconsistent_digit_grouping.rs:25:16
--> $DIR/inconsistent_digit_grouping.rs:26:16
|
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
| ^^^^^^^^ help: consider: `123_456`
@ -7,57 +7,61 @@ LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f
= note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings`
error: digits grouped inconsistently by underscores
--> $DIR/inconsistent_digit_grouping.rs:25:26
--> $DIR/inconsistent_digit_grouping.rs:26:26
|
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
| ^^^^^^^^^^ help: consider: `12_345_678`
error: digits grouped inconsistently by underscores
--> $DIR/inconsistent_digit_grouping.rs:25:38
--> $DIR/inconsistent_digit_grouping.rs:26:38
|
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
| ^^^^^^^^ help: consider: `1_234_567`
error: digits grouped inconsistently by underscores
--> $DIR/inconsistent_digit_grouping.rs:25:48
--> $DIR/inconsistent_digit_grouping.rs:26:48
|
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
| ^^^^^^^^^^^^^^ help: consider: `1_234.567_8_f32`
error: digits grouped inconsistently by underscores
--> $DIR/inconsistent_digit_grouping.rs:25:64
--> $DIR/inconsistent_digit_grouping.rs:26:64
|
LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32);
| ^^^^^^^^^^^^^^ help: consider: `1.234_567_8_f32`
error: long literal lacking separators
--> $DIR/inconsistent_digit_grouping.rs:28:13
--> $DIR/inconsistent_digit_grouping.rs:29:13
|
LL | let _ = 0x100000;
| ^^^^^^^^ help: consider: `0x0010_0000`
|
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
note: the lint level is defined here
--> $DIR/inconsistent_digit_grouping.rs:3:8
|
LL | #[deny(clippy::unreadable_literal)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: long literal lacking separators
--> $DIR/inconsistent_digit_grouping.rs:29:13
--> $DIR/inconsistent_digit_grouping.rs:30:13
|
LL | let _ = 0x1000000;
| ^^^^^^^^^ help: consider: `0x0100_0000`
error: long literal lacking separators
--> $DIR/inconsistent_digit_grouping.rs:30:13
--> $DIR/inconsistent_digit_grouping.rs:31:13
|
LL | let _ = 0x10000000;
| ^^^^^^^^^^ help: consider: `0x1000_0000`
error: long literal lacking separators
--> $DIR/inconsistent_digit_grouping.rs:31:13
--> $DIR/inconsistent_digit_grouping.rs:32:13
|
LL | let _ = 0x100000000_u64;
| ^^^^^^^^^^^^^^^ help: consider: `0x0001_0000_0000_u64`
error: digits grouped inconsistently by underscores
--> $DIR/inconsistent_digit_grouping.rs:34:18
--> $DIR/inconsistent_digit_grouping.rs:35:18
|
LL | let _: f32 = 1_23_456.;
| ^^^^^^^^^ help: consider: `123_456.`

View file

@ -1,5 +1,4 @@
use std::iter::repeat;
#[allow(clippy::trivially_copy_pass_by_ref)]
fn square_is_lower_64(x: &u32) -> bool {
x * x < 64
}

View file

@ -1,29 +1,29 @@
error: infinite iteration detected
--> $DIR/infinite_iter.rs:10:5
--> $DIR/infinite_iter.rs:9:5
|
LL | repeat(0_u8).collect::<Vec<_>>(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/infinite_iter.rs:8:8
--> $DIR/infinite_iter.rs:7:8
|
LL | #[deny(clippy::infinite_iter)]
| ^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
--> $DIR/infinite_iter.rs:11:5
--> $DIR/infinite_iter.rs:10:5
|
LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
--> $DIR/infinite_iter.rs:12:5
--> $DIR/infinite_iter.rs:11:5
|
LL | (0..8_u64).chain(0..).max(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
--> $DIR/infinite_iter.rs:17:5
--> $DIR/infinite_iter.rs:16:5
|
LL | / (0..8_u32)
LL | | .rev()
@ -33,37 +33,37 @@ LL | | .for_each(|x| println!("{}", x)); // infinite iter
| |________________________________________^
error: infinite iteration detected
--> $DIR/infinite_iter.rs:23:5
--> $DIR/infinite_iter.rs:22:5
|
LL | (0_usize..).flat_map(|x| 0..x).product::<usize>(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
--> $DIR/infinite_iter.rs:24:5
--> $DIR/infinite_iter.rs:23:5
|
LL | (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
--> $DIR/infinite_iter.rs:31:5
--> $DIR/infinite_iter.rs:30:5
|
LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/infinite_iter.rs:29:8
--> $DIR/infinite_iter.rs:28:8
|
LL | #[deny(clippy::maybe_infinite_iter)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
--> $DIR/infinite_iter.rs:32:5
--> $DIR/infinite_iter.rs:31:5
|
LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
--> $DIR/infinite_iter.rs:33:5
--> $DIR/infinite_iter.rs:32:5
|
LL | / (1..)
LL | | .scan(0, |state, x| {
@ -74,31 +74,31 @@ LL | | .min(); // maybe infinite iter
| |______________^
error: possible infinite iteration detected
--> $DIR/infinite_iter.rs:39:5
--> $DIR/infinite_iter.rs:38:5
|
LL | (0..).find(|x| *x == 24); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
--> $DIR/infinite_iter.rs:40:5
--> $DIR/infinite_iter.rs:39:5
|
LL | (0..).position(|x| x == 24); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
--> $DIR/infinite_iter.rs:41:5
--> $DIR/infinite_iter.rs:40:5
|
LL | (0..).any(|x| x == 24); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
--> $DIR/infinite_iter.rs:42:5
--> $DIR/infinite_iter.rs:41:5
|
LL | (0..).all(|x| x == 24); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
--> $DIR/infinite_iter.rs:65:31
--> $DIR/infinite_iter.rs:64:31
|
LL | let _: HashSet<i32> = (0..).collect(); // Infinite iter
| ^^^^^^^^^^^^^^^

View file

@ -1,5 +1,3 @@
#![allow(clippy::trivially_copy_pass_by_ref)]
fn fn_val(i: i32) -> i32 {
unimplemented!()
}

View file

@ -1,5 +1,5 @@
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:23:11
--> $DIR/infinite_loop.rs:21:11
|
LL | while y < 10 {
| ^^^^^^
@ -8,7 +8,7 @@ LL | while y < 10 {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:28:11
--> $DIR/infinite_loop.rs:26:11
|
LL | while y < 10 && x < 3 {
| ^^^^^^^^^^^^^^^
@ -16,7 +16,7 @@ LL | while y < 10 && x < 3 {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:35:11
--> $DIR/infinite_loop.rs:33:11
|
LL | while !cond {
| ^^^^^
@ -24,7 +24,7 @@ LL | while !cond {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:79:11
--> $DIR/infinite_loop.rs:77:11
|
LL | while i < 3 {
| ^^^^^
@ -32,7 +32,7 @@ LL | while i < 3 {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:84:11
--> $DIR/infinite_loop.rs:82:11
|
LL | while i < 3 && j > 0 {
| ^^^^^^^^^^^^^^
@ -40,7 +40,7 @@ LL | while i < 3 && j > 0 {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:88:11
--> $DIR/infinite_loop.rs:86:11
|
LL | while i < 3 {
| ^^^^^
@ -48,7 +48,7 @@ LL | while i < 3 {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:103:11
--> $DIR/infinite_loop.rs:101:11
|
LL | while i < 3 {
| ^^^^^
@ -56,7 +56,7 @@ LL | while i < 3 {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:108:11
--> $DIR/infinite_loop.rs:106:11
|
LL | while i < 3 {
| ^^^^^
@ -64,7 +64,7 @@ LL | while i < 3 {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:174:15
--> $DIR/infinite_loop.rs:172:15
|
LL | while self.count < n {
| ^^^^^^^^^^^^^^
@ -72,7 +72,7 @@ LL | while self.count < n {
= note: this may lead to an infinite or to a never running loop
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:182:11
--> $DIR/infinite_loop.rs:180:11
|
LL | while y < 10 {
| ^^^^^^
@ -82,7 +82,7 @@ LL | while y < 10 {
= help: rewrite it as `if cond { loop { } }`
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:189:11
--> $DIR/infinite_loop.rs:187:11
|
LL | while y < 10 {
| ^^^^^^

View file

@ -5,8 +5,7 @@
clippy::shadow_unrelated,
clippy::no_effect,
clippy::unnecessary_operation,
clippy::op_ref,
clippy::trivially_copy_pass_by_ref
clippy::op_ref
)]
#[rustfmt::skip]

View file

@ -1,5 +1,5 @@
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:15:5
--> $DIR/integer_arithmetic.rs:14:5
|
LL | 1 + i;
| ^^^^^
@ -7,98 +7,98 @@ LL | 1 + i;
= note: `-D clippy::integer-arithmetic` implied by `-D warnings`
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:16:5
--> $DIR/integer_arithmetic.rs:15:5
|
LL | i * 2;
| ^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:17:5
--> $DIR/integer_arithmetic.rs:16:5
|
LL | / 1 %
LL | | i / 2; // no error, this is part of the expression in the preceding line
| |_________^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:19:5
--> $DIR/integer_arithmetic.rs:18:5
|
LL | i - 2 + 2 - i;
| ^^^^^^^^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:20:5
--> $DIR/integer_arithmetic.rs:19:5
|
LL | -i;
| ^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:32:5
--> $DIR/integer_arithmetic.rs:31:5
|
LL | i += 1;
| ^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:33:5
--> $DIR/integer_arithmetic.rs:32:5
|
LL | i -= 1;
| ^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:34:5
--> $DIR/integer_arithmetic.rs:33:5
|
LL | i *= 2;
| ^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:35:5
--> $DIR/integer_arithmetic.rs:34:5
|
LL | i /= 2;
| ^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:36:5
--> $DIR/integer_arithmetic.rs:35:5
|
LL | i %= 2;
| ^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:82:5
--> $DIR/integer_arithmetic.rs:81:5
|
LL | 3 + &1;
| ^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:83:5
--> $DIR/integer_arithmetic.rs:82:5
|
LL | &3 + 1;
| ^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:84:5
--> $DIR/integer_arithmetic.rs:83:5
|
LL | &3 + &1;
| ^^^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:89:5
--> $DIR/integer_arithmetic.rs:88:5
|
LL | a + x
| ^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:93:5
--> $DIR/integer_arithmetic.rs:92:5
|
LL | x + y
| ^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:97:5
--> $DIR/integer_arithmetic.rs:96:5
|
LL | x + y
| ^^^^^
error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:101:5
--> $DIR/integer_arithmetic.rs:100:5
|
LL | (&x + &y)
| ^^^^^^^^^

View file

@ -1,4 +1,4 @@
#![allow(unused, clippy::trivially_copy_pass_by_ref)]
#![allow(unused)]
#![warn(clippy::mut_from_ref)]
struct Foo;

View file

@ -1,4 +1,4 @@
#![allow(unused_variables, clippy::trivially_copy_pass_by_ref)]
#![allow(unused_variables)]
fn takes_an_immutable_reference(a: &i32) {}
fn takes_a_mutable_reference(a: &mut i32) {}

View file

@ -2,7 +2,6 @@
#![allow(clippy::needless_borrowed_reference)]
#[allow(clippy::trivially_copy_pass_by_ref)]
fn x(y: &i32) -> i32 {
*y
}

View file

@ -2,7 +2,6 @@
#![allow(clippy::needless_borrowed_reference)]
#[allow(clippy::trivially_copy_pass_by_ref)]
fn x(y: &i32) -> i32 {
*y
}

View file

@ -1,5 +1,5 @@
error: this expression borrows a reference that is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:15:15
--> $DIR/needless_borrow.rs:14:15
|
LL | let c = x(&&a);
| ^^^ help: change this to: `&a`
@ -7,19 +7,19 @@ LL | let c = x(&&a);
= note: `-D clippy::needless-borrow` implied by `-D warnings`
error: this pattern creates a reference to a reference
--> $DIR/needless_borrow.rs:22:17
--> $DIR/needless_borrow.rs:21:17
|
LL | if let Some(ref cake) = Some(&5) {}
| ^^^^^^^^ help: change this to: `cake`
error: this expression borrows a reference that is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:29:15
--> $DIR/needless_borrow.rs:28:15
|
LL | 46 => &&a,
| ^^^ help: change this to: `&a`
error: this pattern creates a reference to a reference
--> $DIR/needless_borrow.rs:52:31
--> $DIR/needless_borrow.rs:51:31
|
LL | let _ = v.iter().filter(|&ref a| a.is_empty());
| ^^^^^ help: change this to: `a`

View file

@ -1,5 +1,5 @@
#![warn(clippy::needless_lifetimes)]
#![allow(dead_code, clippy::needless_pass_by_value, clippy::trivially_copy_pass_by_ref)]
#![allow(dead_code, clippy::needless_pass_by_value)]
fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}

View file

@ -1,5 +1,5 @@
#![warn(clippy::new_ret_no_self)]
#![allow(dead_code, clippy::trivially_copy_pass_by_ref)]
#![allow(dead_code)]
fn main() {}

View file

@ -35,4 +35,7 @@ fn main() {
let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted
let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted
let _ = opt.as_deref();
let _ = opt.as_deref_mut();
}

View file

@ -38,4 +38,7 @@ fn main() {
let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted
let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted
let _ = opt.as_ref().map(|x| &**x);
let _ = opt.as_mut().map(|x| &mut **x);
}

View file

@ -1,4 +1,4 @@
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
--> $DIR/option_as_ref_deref.rs:13:13
|
LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
@ -6,7 +6,7 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
|
= note: `-D clippy::option-as-ref-deref` implied by `-D warnings`
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
--> $DIR/option_as_ref_deref.rs:16:13
|
LL | let _ = opt.clone()
@ -16,77 +16,89 @@ LL | | Deref::deref
LL | | )
| |_________^ help: try using as_deref instead: `opt.clone().as_deref()`
error: called `.as_mut().map(DerefMut::deref_mut)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
error: called `.as_mut().map(DerefMut::deref_mut)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
--> $DIR/option_as_ref_deref.rs:22:13
|
LL | let _ = opt.as_mut().map(DerefMut::deref_mut);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.as_deref()` instead
error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
--> $DIR/option_as_ref_deref.rs:24:13
|
LL | let _ = opt.as_ref().map(String::as_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.as_deref()` instead
error: called `.as_ref().map(|x| x.as_str())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
--> $DIR/option_as_ref_deref.rs:25:13
|
LL | let _ = opt.as_ref().map(|x| x.as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(DerefMut::deref_mut)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
error: called `.as_mut().map(String::as_mut_str)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
--> $DIR/option_as_ref_deref.rs:26:13
|
LL | let _ = opt.as_mut().map(String::as_mut_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_mut().map(DerefMut::deref_mut)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
error: called `.as_mut().map(|x| x.as_mut_str())` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
--> $DIR/option_as_ref_deref.rs:27:13
|
LL | let _ = opt.as_mut().map(|x| x.as_mut_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead
error: called `.as_ref().map(CString::as_c_str)` on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead
--> $DIR/option_as_ref_deref.rs:28:13
|
LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()`
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead
error: called `.as_ref().map(OsString::as_os_str)` on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead
--> $DIR/option_as_ref_deref.rs:29:13
|
LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()`
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead
error: called `.as_ref().map(PathBuf::as_path)` on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead
--> $DIR/option_as_ref_deref.rs:30:13
|
LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()`
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead
error: called `.as_ref().map(Vec::as_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead
--> $DIR/option_as_ref_deref.rs:31:13
|
LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()`
error: called `.as_mut().map(DerefMut::deref_mut)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead
error: called `.as_mut().map(Vec::as_mut_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead
--> $DIR/option_as_ref_deref.rs:32:13
|
LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()`
error: called `.as_ref().map(Deref::deref)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.as_deref()` instead
error: called `.as_ref().map(|x| x.deref())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
--> $DIR/option_as_ref_deref.rs:34:13
|
LL | let _ = opt.as_ref().map(|x| x.deref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(DerefMut::deref_mut)` (or with one of deref aliases) on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead
error: called `.as_mut().map(|x| x.deref_mut())` on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead
--> $DIR/option_as_ref_deref.rs:35:13
|
LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()`
error: aborting due to 14 previous errors
error: called `.as_ref().map(|x| &**x)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
--> $DIR/option_as_ref_deref.rs:42:13
|
LL | let _ = opt.as_ref().map(|x| &**x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(|x| &mut **x)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
--> $DIR/option_as_ref_deref.rs:43:13
|
LL | let _ = opt.as_mut().map(|x| &mut **x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: aborting due to 16 previous errors

View file

@ -2,7 +2,7 @@
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
#![allow(clippy::unit_arg, clippy::let_unit_value, unused_must_use)]
#![allow(clippy::unit_arg, unused_must_use)]
fn main() {
Ok::<i32, i32>(42).is_ok();

View file

@ -2,7 +2,7 @@
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
#![allow(clippy::unit_arg, clippy::let_unit_value, unused_must_use)]
#![allow(clippy::unit_arg, unused_must_use)]
fn main() {
if let Ok(_) = Ok::<i32, i32>(42) {}

View file

@ -0,0 +1,19 @@
// run-rustfix
#![warn(clippy::result_map_or_into_option)]
fn main() {
let opt: Result<u32, &str> = Ok(1);
let _ = opt.ok();
let rewrap = |s: u32| -> Option<u32> { Some(s) };
// A non-Some `f` arg should not emit the lint
let opt: Result<u32, &str> = Ok(1);
let _ = opt.map_or(None, rewrap);
// A non-Some `f` closure where the argument is not used as the
// return should not emit the lint
let opt: Result<u32, &str> = Ok(1);
opt.map_or(None, |_x| Some(1));
}

View file

@ -0,0 +1,19 @@
// run-rustfix
#![warn(clippy::result_map_or_into_option)]
fn main() {
let opt: Result<u32, &str> = Ok(1);
let _ = opt.map_or(None, Some);
let rewrap = |s: u32| -> Option<u32> { Some(s) };
// A non-Some `f` arg should not emit the lint
let opt: Result<u32, &str> = Ok(1);
let _ = opt.map_or(None, rewrap);
// A non-Some `f` closure where the argument is not used as the
// return should not emit the lint
let opt: Result<u32, &str> = Ok(1);
opt.map_or(None, |_x| Some(1));
}

View file

@ -0,0 +1,10 @@
error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead
--> $DIR/result_map_or_into_option.rs:7:13
|
LL | let _ = opt.map_or(None, Some);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()`
|
= note: `-D clippy::result-map-or-into-option` implied by `-D warnings`
error: aborting due to previous error

View file

@ -1,5 +1,5 @@
#![warn(clippy::suspicious_arithmetic_impl)]
use std::ops::{Add, AddAssign, Div, Mul, Sub};
use std::ops::{Add, AddAssign, BitOrAssign, Div, DivAssign, Mul, MulAssign, Sub};
#[derive(Copy, Clone)]
struct Foo(u32);
@ -18,6 +18,25 @@ impl AddAssign for Foo {
}
}
impl BitOrAssign for Foo {
fn bitor_assign(&mut self, other: Foo) {
let idx = other.0;
self.0 |= 1 << idx; // OK: BinOpKind::Shl part of AssignOp as child node
}
}
impl MulAssign for Foo {
fn mul_assign(&mut self, other: Foo) {
self.0 /= other.0;
}
}
impl DivAssign for Foo {
fn div_assign(&mut self, other: Foo) {
self.0 /= other.0; // OK: BinOpKind::Div == DivAssign
}
}
impl Mul for Foo {
type Output = Foo;

View file

@ -14,5 +14,11 @@ LL | *self = *self - other;
|
= note: `#[deny(clippy::suspicious_op_assign_impl)]` on by default
error: aborting due to 2 previous errors
error: Suspicious use of binary operator in `MulAssign` impl
--> $DIR/suspicious_arithmetic_impl.rs:30:16
|
LL | self.0 /= other.0;
| ^^
error: aborting due to 3 previous errors

View file

@ -1,6 +1,7 @@
// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![deny(clippy::trivially_copy_pass_by_ref)]
#![allow(
clippy::many_single_char_names,
clippy::blacklisted_name,

View file

@ -1,91 +1,95 @@
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:50:11
--> $DIR/trivially_copy_pass_by_ref.rs:51:11
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
|
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
note: the lint level is defined here
--> $DIR/trivially_copy_pass_by_ref.rs:4:9
|
LL | #![deny(clippy::trivially_copy_pass_by_ref)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:50:20
--> $DIR/trivially_copy_pass_by_ref.rs:51:20
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:50:29
--> $DIR/trivially_copy_pass_by_ref.rs:51:29
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:57:12
--> $DIR/trivially_copy_pass_by_ref.rs:58:12
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^^ help: consider passing by value instead: `self`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:57:22
--> $DIR/trivially_copy_pass_by_ref.rs:58:22
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:57:31
--> $DIR/trivially_copy_pass_by_ref.rs:58:31
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:57:40
--> $DIR/trivially_copy_pass_by_ref.rs:58:40
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:59:16
--> $DIR/trivially_copy_pass_by_ref.rs:60:16
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:59:25
--> $DIR/trivially_copy_pass_by_ref.rs:60:25
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:59:34
--> $DIR/trivially_copy_pass_by_ref.rs:60:34
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:71:16
--> $DIR/trivially_copy_pass_by_ref.rs:72:16
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:71:25
--> $DIR/trivially_copy_pass_by_ref.rs:72:25
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:71:34
--> $DIR/trivially_copy_pass_by_ref.rs:72:34
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:75:34
--> $DIR/trivially_copy_pass_by_ref.rs:76:34
|
LL | fn trait_method(&self, _foo: &Foo);
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:79:37
--> $DIR/trivially_copy_pass_by_ref.rs:80:37
|
LL | fn trait_method2(&self, _color: &Color);
| ^^^^^^ help: consider passing by value instead: `Color`

View file

@ -2,7 +2,6 @@
use std::mem::MaybeUninit;
#[allow(clippy::let_unit_value)]
fn main() {
let _: usize = unsafe { MaybeUninit::uninit().assume_init() };

View file

@ -1,5 +1,5 @@
error: this call for this type may be undefined behavior
--> $DIR/uninit.rs:7:29
--> $DIR/uninit.rs:6:29
|
LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() };
= note: `#[deny(clippy::uninit_assumed_init)]` on by default
error: this call for this type may be undefined behavior
--> $DIR/uninit.rs:10:31
--> $DIR/uninit.rs:9:31
|
LL | let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,7 +1,6 @@
// run-rustfix
#![deny(clippy::useless_asref)]
#![allow(clippy::trivially_copy_pass_by_ref)]
use std::fmt::Debug;

View file

@ -1,7 +1,6 @@
// run-rustfix
#![deny(clippy::useless_asref)]
#![allow(clippy::trivially_copy_pass_by_ref)]
use std::fmt::Debug;

View file

@ -1,5 +1,5 @@
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:44:18
--> $DIR/useless_asref.rs:43:18
|
LL | foo_rstr(rstr.as_ref());
| ^^^^^^^^^^^^^ help: try this: `rstr`
@ -11,61 +11,61 @@ LL | #![deny(clippy::useless_asref)]
| ^^^^^^^^^^^^^^^^^^^^^
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:46:20
--> $DIR/useless_asref.rs:45:20
|
LL | foo_rslice(rslice.as_ref());
| ^^^^^^^^^^^^^^^ help: try this: `rslice`
error: this call to `as_mut` does nothing
--> $DIR/useless_asref.rs:50:21
--> $DIR/useless_asref.rs:49:21
|
LL | foo_mrslice(mrslice.as_mut());
| ^^^^^^^^^^^^^^^^ help: try this: `mrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:52:20
--> $DIR/useless_asref.rs:51:20
|
LL | foo_rslice(mrslice.as_ref());
| ^^^^^^^^^^^^^^^^ help: try this: `mrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:59:20
--> $DIR/useless_asref.rs:58:20
|
LL | foo_rslice(rrrrrslice.as_ref());
| ^^^^^^^^^^^^^^^^^^^ help: try this: `rrrrrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:61:18
--> $DIR/useless_asref.rs:60:18
|
LL | foo_rstr(rrrrrstr.as_ref());
| ^^^^^^^^^^^^^^^^^ help: try this: `rrrrrstr`
error: this call to `as_mut` does nothing
--> $DIR/useless_asref.rs:66:21
--> $DIR/useless_asref.rs:65:21
|
LL | foo_mrslice(mrrrrrslice.as_mut());
| ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:68:20
--> $DIR/useless_asref.rs:67:20
|
LL | foo_rslice(mrrrrrslice.as_ref());
| ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:72:16
--> $DIR/useless_asref.rs:71:16
|
LL | foo_rrrrmr((&&&&MoreRef).as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(&&&&MoreRef)`
error: this call to `as_mut` does nothing
--> $DIR/useless_asref.rs:122:13
--> $DIR/useless_asref.rs:121:13
|
LL | foo_mrt(mrt.as_mut());
| ^^^^^^^^^^^^ help: try this: `mrt`
error: this call to `as_ref` does nothing
--> $DIR/useless_asref.rs:124:12
--> $DIR/useless_asref.rs:123:12
|
LL | foo_rt(mrt.as_ref());
| ^^^^^^^^^^^^ help: try this: `mrt`

View file

@ -1,6 +1,6 @@
#![warn(clippy::wrong_self_convention)]
#![warn(clippy::wrong_pub_self_convention)]
#![allow(dead_code, clippy::trivially_copy_pass_by_ref)]
#![allow(dead_code)]
fn main() {}