Replace str path utils with new PathLookup type
This commit is contained in:
parent
ea13461967
commit
b768fbe4bc
70 changed files with 799 additions and 1400 deletions
|
|
@ -1,4 +0,0 @@
|
|||
#![allow(clippy::unnecessary_def_path)]
|
||||
|
||||
pub static OPTION: [&str; 3] = ["core", "option", "Option"];
|
||||
pub const RESULT: &[&str] = &["core", "result", "Result"];
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
#![deny(clippy::invalid_paths)]
|
||||
#![allow(clippy::missing_clippy_version_attribute, clippy::unnecessary_def_path)]
|
||||
|
||||
mod paths {
|
||||
// Good path
|
||||
pub const ANY_TRAIT: [&str; 3] = ["std", "any", "Any"];
|
||||
|
||||
// Path to method on inherent impl of a primitive type
|
||||
pub const F32_EPSILON: [&str; 4] = ["core", "f32", "<impl f32>", "EPSILON"];
|
||||
|
||||
// Path to method on inherent impl
|
||||
pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"];
|
||||
|
||||
// Path with empty segment
|
||||
pub const TRANSMUTE: [&str; 4] = ["core", "intrinsics", "", "transmute"];
|
||||
//~^ invalid_paths
|
||||
|
||||
// Path with bad crate
|
||||
pub const BAD_CRATE_PATH: [&str; 2] = ["bad", "path"];
|
||||
//~^ invalid_paths
|
||||
|
||||
// Path with bad module
|
||||
pub const BAD_MOD_PATH: [&str; 2] = ["std", "xxx"];
|
||||
//~^ invalid_paths
|
||||
|
||||
// Path to method on an enum inherent impl
|
||||
pub const OPTION_IS_SOME: [&str; 4] = ["core", "option", "Option", "is_some"];
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
error: invalid path
|
||||
--> tests/ui-internal/invalid_paths.rs:15:5
|
||||
|
|
||||
LL | pub const TRANSMUTE: [&str; 4] = ["core", "intrinsics", "", "transmute"];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> tests/ui-internal/invalid_paths.rs:1:9
|
||||
|
|
||||
LL | #![deny(clippy::invalid_paths)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: invalid path
|
||||
--> tests/ui-internal/invalid_paths.rs:19:5
|
||||
|
|
||||
LL | pub const BAD_CRATE_PATH: [&str; 2] = ["bad", "path"];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: invalid path
|
||||
--> tests/ui-internal/invalid_paths.rs:23:5
|
||||
|
|
||||
LL | pub const BAD_MOD_PATH: [&str; 2] = ["std", "xxx"];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
//@aux-build:paths.rs
|
||||
#![deny(clippy::unnecessary_def_path)]
|
||||
#![feature(rustc_private)]
|
||||
#![allow(clippy::unnecessary_map_or)]
|
||||
|
||||
extern crate clippy_utils;
|
||||
extern crate paths;
|
||||
extern crate rustc_hir;
|
||||
extern crate rustc_lint;
|
||||
extern crate rustc_middle;
|
||||
extern crate rustc_span;
|
||||
|
||||
#[allow(unused)]
|
||||
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item, match_type};
|
||||
#[allow(unused)]
|
||||
use clippy_utils::{
|
||||
is_enum_variant_ctor, is_expr_path_def_path, is_path_diagnostic_item, is_res_lang_ctor, is_trait_method,
|
||||
match_def_path, match_trait_method, path_res,
|
||||
};
|
||||
|
||||
#[allow(unused)]
|
||||
use rustc_hir::LangItem;
|
||||
#[allow(unused)]
|
||||
use rustc_span::sym;
|
||||
|
||||
use rustc_hir::Expr;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::Ty;
|
||||
|
||||
#[allow(unused, clippy::unnecessary_def_path)]
|
||||
static OPTION: [&str; 3] = ["core", "option", "Option"];
|
||||
#[allow(unused, clippy::unnecessary_def_path)]
|
||||
const RESULT: &[&str] = &["core", "result", "Result"];
|
||||
|
||||
fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) {
|
||||
let _ = is_type_diagnostic_item(cx, ty, sym::Option);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = is_type_diagnostic_item(cx, ty, sym::Result);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = is_type_diagnostic_item(cx, ty, sym::Result);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
#[allow(unused, clippy::unnecessary_def_path)]
|
||||
let rc_path = &["alloc", "rc", "Rc"];
|
||||
let _ = is_type_diagnostic_item(cx, ty, sym::Rc);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = is_type_diagnostic_item(cx, ty, sym::Option);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = is_type_diagnostic_item(cx, ty, sym::Result);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = is_type_lang_item(cx, ty, LangItem::OwnedBox);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = cx.tcx.is_diagnostic_item(sym::Option, did);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = is_trait_method(cx, expr, sym::AsRef);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = is_path_diagnostic_item(cx, expr, sym::Option);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id));
|
||||
//~^ unnecessary_def_path
|
||||
let _ = is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome);
|
||||
//~^ unnecessary_def_path
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,77 +1,20 @@
|
|||
//@aux-build:paths.rs
|
||||
#![deny(clippy::unnecessary_def_path)]
|
||||
#![feature(rustc_private)]
|
||||
#![allow(clippy::unnecessary_map_or)]
|
||||
|
||||
extern crate clippy_utils;
|
||||
extern crate paths;
|
||||
extern crate rustc_hir;
|
||||
extern crate rustc_lint;
|
||||
extern crate rustc_middle;
|
||||
extern crate rustc_span;
|
||||
use clippy_utils::paths::PathLookup;
|
||||
use clippy_utils::{PathNS, macro_path, sym, type_path, value_path};
|
||||
|
||||
#[allow(unused)]
|
||||
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item, match_type};
|
||||
#[allow(unused)]
|
||||
use clippy_utils::{
|
||||
is_enum_variant_ctor, is_expr_path_def_path, is_path_diagnostic_item, is_res_lang_ctor, is_trait_method,
|
||||
match_def_path, match_trait_method, path_res,
|
||||
};
|
||||
static OPTION: PathLookup = type_path!(core::option::Option);
|
||||
//~^ unnecessary_def_path
|
||||
static SOME: PathLookup = type_path!(core::option::Option::Some);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
#[allow(unused)]
|
||||
use rustc_hir::LangItem;
|
||||
#[allow(unused)]
|
||||
use rustc_span::sym;
|
||||
static RESULT: PathLookup = type_path!(core::result::Result);
|
||||
//~^ unnecessary_def_path
|
||||
static RESULT_VIA_STD: PathLookup = type_path!(std::result::Result);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
use rustc_hir::Expr;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::Ty;
|
||||
static VEC_NEW: PathLookup = value_path!(alloc::vec::Vec::new);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
#[allow(unused, clippy::unnecessary_def_path)]
|
||||
static OPTION: [&str; 3] = ["core", "option", "Option"];
|
||||
#[allow(unused, clippy::unnecessary_def_path)]
|
||||
const RESULT: &[&str] = &["core", "result", "Result"];
|
||||
|
||||
fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) {
|
||||
let _ = match_type(cx, ty, &OPTION);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = match_type(cx, ty, RESULT);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = match_type(cx, ty, &["core", "result", "Result"]);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
#[allow(unused, clippy::unnecessary_def_path)]
|
||||
let rc_path = &["alloc", "rc", "Rc"];
|
||||
let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = match_type(cx, ty, &paths::OPTION);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = match_type(cx, ty, paths::RESULT);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = match_def_path(cx, did, &["core", "option", "Option"]);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]);
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]);
|
||||
//~^ unnecessary_def_path
|
||||
let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]);
|
||||
//~^ unnecessary_def_path
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
static VEC_MACRO: PathLookup = macro_path!(std::vec);
|
||||
//~^ unnecessary_def_path
|
||||
|
|
|
|||
|
|
@ -1,100 +1,58 @@
|
|||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:37:13
|
||||
error: a diagnostic name exists for this path: sym::Option
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:6:29
|
||||
|
|
||||
LL | let _ = match_type(cx, ty, &OPTION);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)`
|
||||
LL | static OPTION: PathLookup = type_path!(core::option::Option);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:2:9
|
||||
|
|
||||
LL | #![deny(clippy::unnecessary_def_path)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: remove the `PathLookup` and use utilities such as `cx.tcx.is_diagnostic_item` instead
|
||||
= help: see also https://doc.rust-lang.org/nightly/nightly-rustc/?search=diag&filter-crate=clippy_utils
|
||||
= note: `-D clippy::unnecessary-def-path` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_def_path)]`
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:39:13
|
||||
error: a language item exists for this path: LangItem::OptionSome
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:8:27
|
||||
|
|
||||
LL | let _ = match_type(cx, ty, RESULT);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:41:13
|
||||
LL | static SOME: PathLookup = type_path!(core::option::Option::Some);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
LL | let _ = match_type(cx, ty, &["core", "result", "Result"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
|
||||
= help: remove the `PathLookup` and use utilities such as `cx.tcx.lang_items` instead
|
||||
= help: see also https://doc.rust-lang.org/nightly/nightly-rustc/?search=lang&filter-crate=clippy_utils
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:46:13
|
||||
error: a diagnostic name exists for this path: sym::Result
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:11:29
|
||||
|
|
||||
LL | let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Rc)`
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:49:13
|
||||
LL | static RESULT: PathLookup = type_path!(core::result::Result);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
LL | let _ = match_type(cx, ty, &paths::OPTION);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)`
|
||||
= help: remove the `PathLookup` and use utilities such as `cx.tcx.is_diagnostic_item` instead
|
||||
= help: see also https://doc.rust-lang.org/nightly/nightly-rustc/?search=diag&filter-crate=clippy_utils
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:51:13
|
||||
error: a diagnostic name exists for this path: sym::Result
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:13:37
|
||||
|
|
||||
LL | let _ = match_type(cx, ty, paths::RESULT);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
|
||||
|
||||
error: use of a def path to a `LangItem`
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:54:13
|
||||
LL | static RESULT_VIA_STD: PathLookup = type_path!(std::result::Result);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
LL | let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_lang_item(cx, ty, LangItem::OwnedBox)`
|
||||
= help: remove the `PathLookup` and use utilities such as `cx.tcx.is_diagnostic_item` instead
|
||||
= help: see also https://doc.rust-lang.org/nightly/nightly-rustc/?search=diag&filter-crate=clippy_utils
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:56:13
|
||||
error: a diagnostic name exists for this path: sym::vec_new
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:16:30
|
||||
|
|
||||
LL | let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit)`
|
||||
|
||||
error: use of a def path to a `LangItem`
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:59:13
|
||||
LL | static VEC_NEW: PathLookup = value_path!(alloc::vec::Vec::new);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
LL | let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did)`
|
||||
= help: remove the `PathLookup` and use utilities such as `cx.tcx.is_diagnostic_item` instead
|
||||
= help: see also https://doc.rust-lang.org/nightly/nightly-rustc/?search=diag&filter-crate=clippy_utils
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:61:13
|
||||
error: a diagnostic name exists for this path: sym::vec_macro
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:19:32
|
||||
|
|
||||
LL | let _ = match_def_path(cx, did, &["core", "option", "Option"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.is_diagnostic_item(sym::Option, did)`
|
||||
|
||||
error: use of a def path to a `LangItem`
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:63:13
|
||||
LL | static VEC_MACRO: PathLookup = macro_path!(std::vec);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did)`
|
||||
|
|
||||
= help: if this `DefId` came from a constructor expression or pattern then the parent `DefId` should be used instead
|
||||
= help: remove the `PathLookup` and use utilities such as `cx.tcx.is_diagnostic_item` instead
|
||||
= help: see also https://doc.rust-lang.org/nightly/nightly-rustc/?search=diag&filter-crate=clippy_utils
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:66:13
|
||||
|
|
||||
LL | let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_trait_method(cx, expr, sym::AsRef)`
|
||||
|
||||
error: use of a def path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:69:13
|
||||
|
|
||||
LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_path_diagnostic_item(cx, expr, sym::Option)`
|
||||
|
||||
error: use of a def path to a `LangItem`
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:71:13
|
||||
|
|
||||
LL | let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id))`
|
||||
|
||||
error: use of a def path to a `LangItem`
|
||||
--> tests/ui-internal/unnecessary_def_path.rs:73:13
|
||||
|
|
||||
LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome)`
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
#![feature(rustc_private)]
|
||||
#![allow(unused)]
|
||||
#![deny(clippy::unnecessary_def_path)]
|
||||
|
||||
extern crate rustc_hir;
|
||||
|
||||
use rustc_hir::LangItem;
|
||||
|
||||
fn main() {
|
||||
const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
|
||||
//~^ unnecessary_def_path
|
||||
const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"];
|
||||
//~^ unnecessary_def_path
|
||||
const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
|
||||
//~^ unnecessary_def_path
|
||||
|
||||
// Don't lint, not a diagnostic or language item
|
||||
const OPS_MOD: [&str; 2] = ["core", "ops"];
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
error: hardcoded path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:10:36
|
||||
|
|
||||
LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: convert all references to use `sym::Deref`
|
||||
note: the lint level is defined here
|
||||
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:3:9
|
||||
|
|
||||
LL | #![deny(clippy::unnecessary_def_path)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: hardcoded path to a language item
|
||||
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:12:40
|
||||
|
|
||||
LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: convert all references to use `LangItem::DerefMut`
|
||||
|
||||
error: hardcoded path to a diagnostic item
|
||||
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:14:43
|
||||
|
|
||||
LL | const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: convert all references to use `sym::deref_method`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -6,7 +6,7 @@ disallowed-types = [
|
|||
"std::thread::Thread",
|
||||
"std::time::Instant",
|
||||
"std::io::Read",
|
||||
"std::primitive::usize",
|
||||
"usize",
|
||||
"bool",
|
||||
# can give path and reason with an inline table
|
||||
{ path = "std::net::Ipv4Addr", reason = "no IPv4 allowed" },
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ error: use of a disallowed type `std::io::Read`
|
|||
LL | fn trait_obj(_: &dyn std::io::Read) {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed type `std::primitive::usize`
|
||||
error: use of a disallowed type `usize`
|
||||
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:26:33
|
||||
|
|
||||
LL | fn full_and_single_path_prim(_: usize, _: bool) {}
|
||||
|
|
@ -49,13 +49,13 @@ error: use of a disallowed type `bool`
|
|||
LL | fn full_and_single_path_prim(_: usize, _: bool) {}
|
||||
| ^^^^
|
||||
|
||||
error: use of a disallowed type `std::primitive::usize`
|
||||
error: use of a disallowed type `usize`
|
||||
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:30:28
|
||||
|
|
||||
LL | fn const_generics<const C: usize>() {}
|
||||
| ^^^^^
|
||||
|
||||
error: use of a disallowed type `std::primitive::usize`
|
||||
error: use of a disallowed type `usize`
|
||||
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:33:24
|
||||
|
|
||||
LL | struct GenArg<const U: usize>([u8; U]);
|
||||
|
|
@ -123,7 +123,7 @@ error: use of a disallowed type `proc_macro2::Ident`
|
|||
LL | let _ = syn::Ident::new("", todo!());
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: use of a disallowed type `std::primitive::usize`
|
||||
error: use of a disallowed type `usize`
|
||||
--> tests/ui-toml/toml_disallowed_types/conf_disallowed_types.rs:61:12
|
||||
|
|
||||
LL | let _: usize = 64_usize;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
[[disallowed-types]]
|
||||
path = "std::result::Result::Err"
|
||||
|
||||
[[disallowed-macros]]
|
||||
path = "bool"
|
||||
|
||||
[[disallowed-methods]]
|
||||
path = "std::process::current_exe"
|
||||
|
||||
[[disallowed-methods]]
|
||||
path = ""
|
||||
|
||||
[[disallowed-types]]
|
||||
path = "std::result::Result::Err"
|
||||
|
||||
# negative test
|
||||
|
||||
[[disallowed-methods]]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//@error-in-other-file: expected a macro, found a primitive type
|
||||
//@error-in-other-file: `std::process::current_exe` does not refer to an existing function
|
||||
//@error-in-other-file: expected a type, found a tuple variant
|
||||
//@error-in-other-file: `std::process::current_exe` does not refer to a reachable function
|
||||
//@error-in-other-file: `` does not refer to a reachable function
|
||||
//@error-in-other-file: expected a type, found a variant
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,38 @@
|
|||
warning: expected a macro, found a primitive type
|
||||
--> $DIR/tests/ui-toml/toml_invalid_path/clippy.toml:4:1
|
||||
--> $DIR/tests/ui-toml/toml_invalid_path/clippy.toml:1:1
|
||||
|
|
||||
LL | / [[disallowed-macros]]
|
||||
LL | | path = "bool"
|
||||
| |_____________^
|
||||
|
|
||||
= help: add `allow-invalid = true` to the entry to suppress this warning
|
||||
|
||||
warning: `std::process::current_exe` does not refer to an existing function
|
||||
--> $DIR/tests/ui-toml/toml_invalid_path/clippy.toml:7:1
|
||||
warning: `std::process::current_exe` does not refer to a reachable function
|
||||
--> $DIR/tests/ui-toml/toml_invalid_path/clippy.toml:4:1
|
||||
|
|
||||
LL | / [[disallowed-methods]]
|
||||
LL | | path = "std::process::current_exe"
|
||||
| |__________________________________^
|
||||
|
|
||||
= help: add `allow-invalid = true` to the entry to suppress this warning
|
||||
|
||||
warning: expected a type, found a tuple variant
|
||||
--> $DIR/tests/ui-toml/toml_invalid_path/clippy.toml:1:1
|
||||
warning: `` does not refer to a reachable function
|
||||
--> $DIR/tests/ui-toml/toml_invalid_path/clippy.toml:7:1
|
||||
|
|
||||
LL | / [[disallowed-methods]]
|
||||
LL | | path = ""
|
||||
| |_________^
|
||||
|
|
||||
= help: add `allow-invalid = true` to the entry to suppress this warning
|
||||
|
||||
warning: expected a type, found a variant
|
||||
--> $DIR/tests/ui-toml/toml_invalid_path/clippy.toml:10:1
|
||||
|
|
||||
LL | / [[disallowed-types]]
|
||||
LL | | path = "std::result::Result::Err"
|
||||
| |_________________________________^
|
||||
|
|
||||
= help: add `allow-invalid = true` to the entry to suppress this warning
|
||||
|
||||
warning: 3 warnings emitted
|
||||
warning: 4 warnings emitted
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//@error-in-other-file: `regex::Regex::new_` does not refer to an existing function
|
||||
//@error-in-other-file: `regex::Regex_::new` does not refer to an existing function
|
||||
//@error-in-other-file: `regex::Regex::new_` does not refer to a reachable function
|
||||
//@error-in-other-file: `regex::Regex_::new` does not refer to a reachable function
|
||||
|
||||
extern crate regex;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,20 @@
|
|||
warning: `regex::Regex::new_` does not refer to an existing function
|
||||
warning: `regex::Regex::new_` does not refer to a reachable function
|
||||
--> $DIR/tests/ui-toml/toml_unloaded_crate/clippy.toml:3:1
|
||||
|
|
||||
LL | / [[disallowed-methods]]
|
||||
LL | | path = "regex::Regex::new_"
|
||||
| |___________________________^
|
||||
|
|
||||
= help: add `allow-invalid = true` to the entry to suppress this warning
|
||||
|
||||
warning: `regex::Regex_::new` does not refer to an existing function
|
||||
warning: `regex::Regex_::new` does not refer to a reachable function
|
||||
--> $DIR/tests/ui-toml/toml_unloaded_crate/clippy.toml:6:1
|
||||
|
|
||||
LL | / [[disallowed-methods]]
|
||||
LL | | path = "regex::Regex_::new"
|
||||
| |___________________________^
|
||||
|
|
||||
= help: add `allow-invalid = true` to the entry to suppress this warning
|
||||
|
||||
warning: 2 warnings emitted
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
if let StmtKind::Let(local) = stmt.kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Cast(expr, cast_ty) = init.kind
|
||||
&& let TyKind::Path(ref qpath) = cast_ty.kind
|
||||
&& match_qpath(qpath, &["char"])
|
||||
&& let ExprKind::Lit(ref lit) = expr.kind
|
||||
&& let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node
|
||||
&& let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ if let ExprKind::Block(block, None) = expr.kind
|
|||
&& name1.as_str() == "_t"
|
||||
&& let StmtKind::Semi(e) = block.stmts[2].kind
|
||||
&& let ExprKind::Unary(UnOp::Neg, inner) = e.kind
|
||||
&& let ExprKind::Path(ref qpath) = inner.kind
|
||||
&& match_qpath(qpath, &["x"])
|
||||
&& block.expr.is_none()
|
||||
{
|
||||
// report your lint here
|
||||
|
|
@ -25,18 +23,14 @@ if let ExprKind::Block(block, None) = expr.kind
|
|||
&& let StmtKind::Let(local) = block.stmts[0].kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Call(func, args) = init.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["String", "new"])
|
||||
&& is_path_diagnostic_item(cx, func, sym::string_new)
|
||||
&& args.is_empty()
|
||||
&& let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
|
||||
&& name.as_str() == "expr"
|
||||
&& let Some(trailing_expr) = block.expr
|
||||
&& let ExprKind::Call(func1, args1) = trailing_expr.kind
|
||||
&& let ExprKind::Path(ref qpath1) = func1.kind
|
||||
&& match_qpath(qpath1, &["drop"])
|
||||
&& is_path_diagnostic_item(cx, func1, sym::mem_drop)
|
||||
&& args1.len() == 1
|
||||
&& let ExprKind::Path(ref qpath2) = args1[0].kind
|
||||
&& match_qpath(qpath2, &["expr"])
|
||||
{
|
||||
// report your lint here
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
if let StmtKind::Let(local) = stmt.kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Call(func, args) = init.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["{{root}}", "std", "cmp", "min"])
|
||||
&& is_path_diagnostic_item(cx, func, sym::cmp_min)
|
||||
&& args.len() == 2
|
||||
&& let ExprKind::Lit(ref lit) = args[0].kind
|
||||
&& let LitKind::Int(3, LitIntType::Unsuffixed) = lit.node
|
||||
|
|
|
|||
|
|
@ -31,10 +31,8 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind
|
||||
&& let ExprKind::Let(let_expr) = cond.kind
|
||||
&& let PatKind::Expr(lit_expr) = let_expr.pat.kind
|
||||
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit, negated } = lit_expr.kind
|
||||
&& let LitKind::Bool(true) = lit.node
|
||||
&& let ExprKind::Path(ref qpath) = let_expr.init.kind
|
||||
&& match_qpath(qpath, &["a"])
|
||||
&& let ExprKind::Block(block, None) = then.kind
|
||||
&& block.stmts.is_empty()
|
||||
&& block.expr.is_none()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
if let StmtKind::Let(local) = stmt.kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Call(func, args) = init.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["std", "mem", "transmute"])
|
||||
&& is_path_diagnostic_item(cx, func, sym::transmute)
|
||||
&& args.len() == 1
|
||||
&& let ExprKind::Path(ref qpath1) = args[0].kind
|
||||
&& match_qpath(qpath1, &["ZPTR"])
|
||||
&& let PatKind::Wild = local.pat.kind
|
||||
{
|
||||
// report your lint here
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
|
|||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Let(local) = block.stmts[0].kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Path(ref qpath1) = init.kind
|
||||
&& match_qpath(qpath1, &["y"])
|
||||
&& let PatKind::Binding(BindingMode::NONE, _, name1, None) = local.pat.kind
|
||||
&& name1.as_str() == "z"
|
||||
&& block.expr.is_none()
|
||||
|
|
@ -64,8 +62,6 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
|
|||
// report your lint here
|
||||
}
|
||||
if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr)
|
||||
&& let ExprKind::Path(ref qpath) = condition.kind
|
||||
&& match_qpath(qpath, &["a"])
|
||||
&& let ExprKind::Block(block, None) = body.kind
|
||||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e) = block.stmts[0].kind
|
||||
|
|
@ -77,10 +73,8 @@ if let Some(higher::While { condition: condition, body: body }) = higher::While:
|
|||
}
|
||||
if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr)
|
||||
&& let PatKind::Expr(lit_expr) = let_pat.kind
|
||||
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit, negated } = lit_expr.kind
|
||||
&& let LitKind::Bool(true) = lit.node
|
||||
&& let ExprKind::Path(ref qpath) = let_expr.kind
|
||||
&& match_qpath(qpath, &["a"])
|
||||
&& let ExprKind::Block(block, None) = if_then.kind
|
||||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e) = block.stmts[0].kind
|
||||
|
|
|
|||
|
|
@ -7,12 +7,10 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e) = block.stmts[0].kind
|
||||
&& let ExprKind::Call(func, args) = e.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["$crate", "io", "_print"])
|
||||
&& paths::STD_IO_STDIO__PRINT.matches_path(cx, func) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args.len() == 1
|
||||
&& let ExprKind::Call(func1, args1) = args[0].kind
|
||||
&& let ExprKind::Path(ref qpath1) = func1.kind
|
||||
&& match_qpath(qpath1, &["format_arguments", "new_v1"])
|
||||
&& paths::CORE_FMT_ARGUMENTS_NEW_V1.matches_path(cx, func1) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args1.len() == 2
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
|
||||
&& let ExprKind::Array(elements) = inner.kind
|
||||
|
|
@ -27,12 +25,9 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
&& let ExprKind::Array(elements1) = inner1.kind
|
||||
&& elements1.len() == 1
|
||||
&& let ExprKind::Call(func2, args2) = elements1[0].kind
|
||||
&& let ExprKind::Path(ref qpath2) = func2.kind
|
||||
&& match_qpath(qpath2, &["format_argument", "new_display"])
|
||||
&& paths::CORE_FMT_RT_ARGUMENT_NEW_DISPLAY.matches_path(cx, func2) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args2.len() == 1
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
|
||||
&& let ExprKind::Path(ref qpath3) = inner2.kind
|
||||
&& match_qpath(qpath3, &["x"])
|
||||
&& block.expr.is_none()
|
||||
&& let PatKind::Binding(BindingMode::NONE, _, name, None) = local.pat.kind
|
||||
&& name.as_str() == "print_text"
|
||||
|
|
|
|||
|
|
@ -17,12 +17,10 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
|
|||
&& block1.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e1) = block1.stmts[0].kind
|
||||
&& let ExprKind::Call(func, args) = e1.kind
|
||||
&& let ExprKind::Path(ref qpath1) = func.kind
|
||||
&& match_qpath(qpath1, &["$crate", "io", "_print"])
|
||||
&& paths::STD_IO_STDIO__PRINT.matches_path(cx, func) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args.len() == 1
|
||||
&& let ExprKind::Call(func1, args1) = args[0].kind
|
||||
&& let ExprKind::Path(ref qpath2) = func1.kind
|
||||
&& match_qpath(qpath2, &["format_arguments", "new_v1"])
|
||||
&& paths::CORE_FMT_ARGUMENTS_NEW_V1.matches_path(cx, func1) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args1.len() == 2
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
|
||||
&& let ExprKind::Array(elements) = inner.kind
|
||||
|
|
@ -37,12 +35,9 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
|
|||
&& let ExprKind::Array(elements1) = inner1.kind
|
||||
&& elements1.len() == 1
|
||||
&& let ExprKind::Call(func2, args2) = elements1[0].kind
|
||||
&& let ExprKind::Path(ref qpath3) = func2.kind
|
||||
&& match_qpath(qpath3, &["format_argument", "new_display"])
|
||||
&& paths::CORE_FMT_RT_ARGUMENT_NEW_DISPLAY.matches_path(cx, func2) // Add the path to `clippy_utils::paths` if needed
|
||||
&& args2.len() == 1
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
|
||||
&& let ExprKind::Path(ref qpath4) = inner2.kind
|
||||
&& match_qpath(qpath4, &["i"])
|
||||
&& block1.expr.is_none()
|
||||
&& block.expr.is_none()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
&& let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node
|
||||
&& arms.len() == 3
|
||||
&& let PatKind::Expr(lit_expr) = arms[0].pat.kind
|
||||
&& let PatExprKind::Lit{ref lit1, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit1, negated } = lit_expr.kind
|
||||
&& let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node
|
||||
&& arms[0].guard.is_none()
|
||||
&& let ExprKind::Lit(ref lit2) = arms[0].body.kind
|
||||
&& let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node
|
||||
&& let PatKind::Expr(lit_expr1) = arms[1].pat.kind
|
||||
&& let PatExprKind::Lit{ref lit3, negated1 } = lit_expr1.kind
|
||||
&& let PatExprKind::Lit { ref lit3, negated1 } = lit_expr1.kind
|
||||
&& let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node
|
||||
&& arms[1].guard.is_none()
|
||||
&& let ExprKind::Block(block, None) = arms[1].body.kind
|
||||
|
|
@ -23,8 +23,6 @@ if let StmtKind::Let(local) = stmt.kind
|
|||
&& let PatKind::Binding(BindingMode::NONE, _, name, None) = local1.pat.kind
|
||||
&& name.as_str() == "x"
|
||||
&& let Some(trailing_expr) = block.expr
|
||||
&& let ExprKind::Path(ref qpath) = trailing_expr.kind
|
||||
&& match_qpath(qpath, &["x"])
|
||||
&& let PatKind::Wild = arms[2].pat.kind
|
||||
&& arms[2].guard.is_none()
|
||||
&& let ExprKind::Lit(ref lit5) = arms[2].body.kind
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
if let ExprKind::Struct(qpath, fields, None) = expr.kind
|
||||
&& match_qpath(qpath, &["Test"])
|
||||
&& fields.len() == 1
|
||||
&& fields[0].ident.as_str() == "field"
|
||||
&& let ExprKind::If(cond, then, Some(else_expr)) = fields[0].expr.kind
|
||||
|
|
@ -20,11 +19,10 @@ if let ExprKind::Struct(qpath, fields, None) = expr.kind
|
|||
// report your lint here
|
||||
}
|
||||
if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
|
||||
&& match_qpath(qpath, &["Test"])
|
||||
&& fields.len() == 1
|
||||
&& fields[0].ident.as_str() == "field"
|
||||
&& let PatKind::Expr(lit_expr) = fields[0].pat.kind
|
||||
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit, negated } = lit_expr.kind
|
||||
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
|
||||
&& arm.guard.is_none()
|
||||
&& let ExprKind::Block(block, None) = arm.body.kind
|
||||
|
|
@ -34,10 +32,9 @@ if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
|
|||
// report your lint here
|
||||
}
|
||||
if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind
|
||||
&& match_qpath(qpath, &["TestTuple"])
|
||||
&& fields.len() == 1
|
||||
&& let PatKind::Expr(lit_expr) = fields[0].kind
|
||||
&& let PatExprKind::Lit{ref lit, negated } = lit_expr.kind
|
||||
&& let PatExprKind::Lit { ref lit, negated } = lit_expr.kind
|
||||
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
|
||||
&& arm.guard.is_none()
|
||||
&& let ExprKind::Block(block, None) = arm.body.kind
|
||||
|
|
@ -48,8 +45,6 @@ if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind
|
|||
}
|
||||
if let ExprKind::MethodCall(method_name, receiver, args, _) = expr.kind
|
||||
&& method_name.ident.as_str() == "test"
|
||||
&& let ExprKind::Path(ref qpath) = receiver.kind
|
||||
&& match_qpath(qpath, &["test_method_call"])
|
||||
&& args.is_empty()
|
||||
{
|
||||
// report your lint here
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#![allow(clippy::legacy_numeric_constants, unused_imports)]
|
||||
|
||||
use std::{i32, i128, u32, u128};
|
||||
|
||||
fn main() {
|
||||
let _ = 1u32.saturating_add(1);
|
||||
//~^ manual_saturating_arithmetic
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#![allow(clippy::legacy_numeric_constants, unused_imports)]
|
||||
|
||||
use std::{i32, i128, u32, u128};
|
||||
|
||||
fn main() {
|
||||
let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());
|
||||
//~^ manual_saturating_arithmetic
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:6:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:4:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u32.saturating_add(1)`
|
||||
|
|
@ -8,19 +8,19 @@ LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());
|
|||
= help: to override `-D warnings` add `#[allow(clippy::manual_saturating_arithmetic)]`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:8:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:6:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u32.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:10:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:8:13
|
||||
|
|
||||
LL | let _ = 1u8.checked_add(1).unwrap_or(255);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u8.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:12:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:10:13
|
||||
|
|
||||
LL | let _ = 1u128
|
||||
| _____________^
|
||||
|
|
@ -30,49 +30,49 @@ LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455);
|
|||
| |_______________________________________________________________________^ help: consider using `saturating_add`: `1u128.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:18:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:16:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_mul`: `1u32.saturating_mul(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:21:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:19:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:23:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:21:13
|
||||
|
|
||||
LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:25:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:23:13
|
||||
|
|
||||
LL | let _ = 1u8.checked_sub(1).unwrap_or(0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u8.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:30:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:28:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:32:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:30:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:34:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:32:13
|
||||
|
|
||||
LL | let _ = 1i8.checked_add(1).unwrap_or(127);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:36:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:34:13
|
||||
|
|
||||
LL | let _ = 1i128
|
||||
| _____________^
|
||||
|
|
@ -82,25 +82,25 @@ LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727);
|
|||
| |_______________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:40:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:38:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:42:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:40:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:44:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:42:13
|
||||
|
|
||||
LL | let _ = 1i8.checked_add(-1).unwrap_or(-128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:46:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:44:13
|
||||
|
|
||||
LL | let _ = 1i128
|
||||
| _____________^
|
||||
|
|
@ -110,25 +110,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728);
|
|||
| |________________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:54:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:52:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:56:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:54:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:58:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:56:13
|
||||
|
|
||||
LL | let _ = 1i8.checked_sub(1).unwrap_or(-128);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:60:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:58:13
|
||||
|
|
||||
LL | let _ = 1i128
|
||||
| _____________^
|
||||
|
|
@ -138,25 +138,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728);
|
|||
| |________________________________________________________________________^ help: consider using `saturating_sub`: `1i128.saturating_sub(1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:64:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:62:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:66:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:64:13
|
||||
|
|
||||
LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:68:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:66:13
|
||||
|
|
||||
LL | let _ = 1i8.checked_sub(-1).unwrap_or(127);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(-1)`
|
||||
|
||||
error: manual saturating arithmetic
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:70:13
|
||||
--> tests/ui/manual_saturating_arithmetic.rs:68:13
|
||||
|
|
||||
LL | let _ = 1i128
|
||||
| _____________^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue