diff options
| author | Mateusz Gacek <96mateusz.gacek@gmail.com> | 2021-05-18 15:19:56 +0200 |
|---|---|---|
| committer | Mateusz Gacek <96mateusz.gacek@gmail.com> | 2021-07-05 11:10:45 +0200 |
| commit | 59a164e86c41b4ccfa1e41ec60d7bb8a0f2c87d2 (patch) | |
| tree | a5a8c1ebd92f7ce1139ed1ca2db80c8fa8cf49a6 /clippy_utils | |
| parent | 3cc67785121c57d285987770bec9a49471639d18 (diff) | |
| download | rust-59a164e86c41b4ccfa1e41ec60d7bb8a0f2c87d2.tar.gz rust-59a164e86c41b4ccfa1e41ec60d7bb8a0f2c87d2.zip | |
Add new lint: strlen_on_c_strings
Diffstat (limited to 'clippy_utils')
| -rw-r--r-- | clippy_utils/src/paths.rs | 1 | ||||
| -rw-r--r-- | clippy_utils/src/ty.rs | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clippy_utils/src/paths.rs b/clippy_utils/src/paths.rs index b913d1ce8b1..9ebfbd6b423 100644 --- a/clippy_utils/src/paths.rs +++ b/clippy_utils/src/paths.rs @@ -82,6 +82,7 @@ pub const ITER_REPEAT: [&str; 5] = ["core", "iter", "sources", "repeat", "repeat pub const KW_MODULE: [&str; 3] = ["rustc_span", "symbol", "kw"]; #[cfg(feature = "internal-lints")] pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"]; +pub const LIBC_STRLEN: [&str; 2] = ["libc", "strlen"]; pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"]; #[cfg(any(feature = "internal-lints", feature = "metadata-collector-lint"))] pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"]; diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs index a92d3be5d3c..9e271b71204 100644 --- a/clippy_utils/src/ty.rs +++ b/clippy_utils/src/ty.rs @@ -231,6 +231,17 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { } } +/// Checks if the type is a reference equals to a diagnostic item +pub fn is_type_ref_to_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symbol) -> bool { + match ty.kind() { + ty::Ref(_, ref_ty, _) => match ref_ty.kind() { + ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(diag_item, adt.did), + _ => false, + }, + _ => false, + } +} + /// Checks if the type is equal to a diagnostic item /// /// If you change the signature, remember to update the internal lint `MatchTypeOnDiagItem` |
