needless_pass_by_value: Whitelist RangeArgument (fixes #2357)
This commit is contained in:
parent
2a30c8a194
commit
552e950080
4 changed files with 61 additions and 52 deletions
|
|
@ -102,10 +102,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
|
||||
// Allow `Borrow` or functions to be taken by value
|
||||
let borrow_trait = need!(get_trait_def_id(cx, &paths::BORROW_TRAIT));
|
||||
let fn_traits = [
|
||||
let whitelisted_traits = [
|
||||
need!(cx.tcx.lang_items().fn_trait()),
|
||||
need!(cx.tcx.lang_items().fn_once_trait()),
|
||||
need!(cx.tcx.lang_items().fn_mut_trait()),
|
||||
need!(get_trait_def_id(cx, &paths::RANGE_ARGUMENT_TRAIT))
|
||||
];
|
||||
|
||||
let sized_trait = need!(cx.tcx.lang_items().sized_trait());
|
||||
|
|
@ -189,7 +190,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
if !is_self(arg);
|
||||
if !ty.is_mutable_pointer();
|
||||
if !is_copy(cx, ty);
|
||||
if !fn_traits.iter().any(|&t| implements_trait(cx, ty, t, &[]));
|
||||
if !whitelisted_traits.iter().any(|&t| implements_trait(cx, ty, t, &[]));
|
||||
if !implements_borrow_trait;
|
||||
if !all_borrowable_trait;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ pub const OPTION_SOME: [&str; 4] = ["core", "option", "Option", "Some"];
|
|||
pub const PTR_NULL: [&str; 2] = ["ptr", "null"];
|
||||
pub const PTR_NULL_MUT: [&str; 2] = ["ptr", "null_mut"];
|
||||
pub const RANGE: [&str; 3] = ["core", "ops", "Range"];
|
||||
pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["alloc", "range", "RangeArgument"];
|
||||
pub const RANGE_FROM: [&str; 3] = ["core", "ops", "RangeFrom"];
|
||||
pub const RANGE_FROM_STD: [&str; 3] = ["std", "ops", "RangeFrom"];
|
||||
pub const RANGE_FULL: [&str; 3] = ["core", "ops", "RangeFull"];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue