mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Add missing diagnostic item Symbols
This commit is contained in:
parent
b303f7d6f9
commit
2b3a731e1c
7 changed files with 20 additions and 17 deletions
|
@ -9,6 +9,7 @@ use rustc_lint::{LateContext, LateLintPass};
|
|||
use rustc_middle::hir::map::Map;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_span::sym;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap`
|
||||
|
@ -111,7 +112,7 @@ fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static
|
|||
return if match_type(cx, obj_ty, &paths::BTREEMAP) {
|
||||
Some(("BTreeMap", map, key))
|
||||
}
|
||||
else if is_type_diagnostic_item(cx, obj_ty, sym!(hashmap_type)) {
|
||||
else if is_type_diagnostic_item(cx, obj_ty, sym::hashmap_type) {
|
||||
Some(("HashMap", map, key))
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1010,7 +1010,7 @@ fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'_>) -> bool {
|
|||
_ => false,
|
||||
};
|
||||
|
||||
is_slice || is_type_diagnostic_item(cx, ty, sym::vec_type) || is_type_diagnostic_item(cx, ty, sym!(vecdeque_type))
|
||||
is_slice || is_type_diagnostic_item(cx, ty, sym::vec_type) || is_type_diagnostic_item(cx, ty, sym::vecdeque_type)
|
||||
}
|
||||
|
||||
fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
|
||||
|
@ -1908,7 +1908,7 @@ fn check_for_loop_over_map_kv<'tcx>(
|
|||
_ => arg,
|
||||
};
|
||||
|
||||
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP) {
|
||||
if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || match_type(cx, ty, &paths::BTREEMAP) {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
FOR_KV_MAP,
|
||||
|
@ -2386,9 +2386,9 @@ fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
|||
is_iterable_array(ty, cx) ||
|
||||
is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
||||
match_type(cx, ty, &paths::LINKED_LIST) ||
|
||||
is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) ||
|
||||
is_type_diagnostic_item(cx, ty, sym!(hashset_type)) ||
|
||||
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
|
||||
is_type_diagnostic_item(cx, ty, sym::hashmap_type) ||
|
||||
is_type_diagnostic_item(cx, ty, sym::hashset_type) ||
|
||||
is_type_diagnostic_item(cx, ty, sym::vecdeque_type) ||
|
||||
match_type(cx, ty, &paths::BINARY_HEAP) ||
|
||||
match_type(cx, ty, &paths::BTREEMAP) ||
|
||||
match_type(cx, ty, &paths::BTREESET)
|
||||
|
@ -2922,9 +2922,9 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
|
|||
then {
|
||||
let ty = cx.typeck_results().node_type(ty.hir_id);
|
||||
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
||||
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
|
||||
is_type_diagnostic_item(cx, ty, sym::vecdeque_type) ||
|
||||
match_type(cx, ty, &paths::BTREEMAP) ||
|
||||
is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) {
|
||||
is_type_diagnostic_item(cx, ty, sym::hashmap_type) {
|
||||
if method.ident.name == sym!(len) {
|
||||
let span = shorten_needless_collect_span(expr);
|
||||
span_lint_and_sugg(
|
||||
|
@ -2992,7 +2992,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
|
|||
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
|
||||
if let ty = cx.typeck_results().node_type(ty.hir_id);
|
||||
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
||||
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
|
||||
is_type_diagnostic_item(cx, ty, sym::vecdeque_type) ||
|
||||
match_type(cx, ty, &paths::LINKED_LIST);
|
||||
if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident);
|
||||
if iter_calls.len() == 1;
|
||||
|
|
|
@ -2598,7 +2598,7 @@ fn lint_iter_nth<'tcx>(
|
|||
"slice"
|
||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym::vec_type) {
|
||||
"Vec"
|
||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym!(vecdeque_type)) {
|
||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym::vecdeque_type) {
|
||||
"VecDeque"
|
||||
} else {
|
||||
let nth_args = nth_and_iter_args[0];
|
||||
|
@ -2652,10 +2652,10 @@ fn lint_get_unwrap<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, get_args:
|
|||
} else if is_type_diagnostic_item(cx, expr_ty, sym::vec_type) {
|
||||
needs_ref = get_args_str.parse::<usize>().is_ok();
|
||||
"Vec"
|
||||
} else if is_type_diagnostic_item(cx, expr_ty, sym!(vecdeque_type)) {
|
||||
} else if is_type_diagnostic_item(cx, expr_ty, sym::vecdeque_type) {
|
||||
needs_ref = get_args_str.parse::<usize>().is_ok();
|
||||
"VecDeque"
|
||||
} else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym!(hashmap_type)) {
|
||||
} else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::hashmap_type) {
|
||||
needs_ref = true;
|
||||
"HashMap"
|
||||
} else if !is_mut && match_type(cx, expr_ty, &paths::BTREEMAP) {
|
||||
|
|
|
@ -199,7 +199,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<
|
|||
if matches!(ty.kind(), ty::Slice(_))
|
||||
|| matches!(ty.kind(), ty::Array(_, _))
|
||||
|| is_type_diagnostic_item(cx, ty, sym::vec_type)
|
||||
|| is_type_diagnostic_item(cx, ty, sym!(vecdeque_type))
|
||||
|| is_type_diagnostic_item(cx, ty, sym::vecdeque_type)
|
||||
{
|
||||
return Slice::Swappable(lhs1, idx1, idx2);
|
||||
}
|
||||
|
|
|
@ -2680,14 +2680,14 @@ impl<'tcx> ImplicitHasherType<'tcx> {
|
|||
|
||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
|
||||
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) && params_len == 2 {
|
||||
if is_type_diagnostic_item(cx, ty, sym::hashmap_type) && params_len == 2 {
|
||||
Some(ImplicitHasherType::HashMap(
|
||||
hir_ty.span,
|
||||
ty,
|
||||
snippet(cx, params[0].span, "K"),
|
||||
snippet(cx, params[1].span, "V"),
|
||||
))
|
||||
} else if is_type_diagnostic_item(cx, ty, sym!(hashset_type)) && params_len == 1 {
|
||||
} else if is_type_diagnostic_item(cx, ty, sym::hashset_type) && params_len == 1 {
|
||||
Some(ImplicitHasherType::HashSet(
|
||||
hir_ty.span,
|
||||
ty,
|
||||
|
|
|
@ -5,6 +5,7 @@ use rustc_middle::ty::{Adt, Ty};
|
|||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_target::abi::LayoutOf as _;
|
||||
use rustc_typeck::hir_ty_to_ty;
|
||||
use rustc_span::sym;
|
||||
|
||||
use crate::utils::{is_normalizable, is_type_diagnostic_item, match_type, paths, span_lint_and_help};
|
||||
|
||||
|
@ -47,7 +48,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
|
|||
if !hir_ty.span.from_expansion();
|
||||
if !in_trait_impl(cx, hir_ty.hir_id);
|
||||
let ty = ty_from_hir_ty(cx, hir_ty);
|
||||
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP);
|
||||
if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || match_type(cx, ty, &paths::BTREEMAP);
|
||||
if let Adt(_, ref substs) = ty.kind();
|
||||
let ty = substs.type_at(1);
|
||||
// Do this to prevent `layout_of` crashing, being unable to fully normalize `ty`.
|
||||
|
|
|
@ -18,6 +18,7 @@ use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
|
|||
use rustc_hir::{Block, Expr, ExprKind, Path, QPath};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_span::sym;
|
||||
|
||||
/// Is the expr pure (is it free from side-effects)?
|
||||
/// This function is named so to stress that it isn't exhaustive and returns FNs.
|
||||
|
@ -99,7 +100,7 @@ fn identify_some_potentially_expensive_patterns<'tcx>(cx: &LateContext<'tcx>, ex
|
|||
ExprKind::Call(..) => !is_ctor_or_promotable_const_function(self.cx, expr),
|
||||
ExprKind::Index(obj, _) => {
|
||||
let ty = self.cx.typeck_results().expr_ty(obj);
|
||||
is_type_diagnostic_item(self.cx, ty, sym!(hashmap_type))
|
||||
is_type_diagnostic_item(self.cx, ty, sym::hashmap_type)
|
||||
|| match_type(self.cx, ty, &paths::BTREEMAP)
|
||||
},
|
||||
ExprKind::MethodCall(..) => true,
|
||||
|
|
Loading…
Add table
Reference in a new issue