Rollup merge of #82578 - camsteffen:diag-items, r=oli-obk
Add some diagnostic items for Clippy
This commit is contained in:
commit
efb9ee2df5
|
@ -126,6 +126,9 @@ symbols! {
|
||||||
Argument,
|
Argument,
|
||||||
ArgumentV1,
|
ArgumentV1,
|
||||||
Arguments,
|
Arguments,
|
||||||
|
BTreeMap,
|
||||||
|
BTreeSet,
|
||||||
|
BinaryHeap,
|
||||||
C,
|
C,
|
||||||
CString,
|
CString,
|
||||||
Center,
|
Center,
|
||||||
|
@ -163,6 +166,7 @@ symbols! {
|
||||||
Iterator,
|
Iterator,
|
||||||
Layout,
|
Layout,
|
||||||
Left,
|
Left,
|
||||||
|
LinkedList,
|
||||||
LintPass,
|
LintPass,
|
||||||
None,
|
None,
|
||||||
Ok,
|
Ok,
|
||||||
|
@ -191,6 +195,7 @@ symbols! {
|
||||||
RangeToInclusive,
|
RangeToInclusive,
|
||||||
Rc,
|
Rc,
|
||||||
Ready,
|
Ready,
|
||||||
|
Receiver,
|
||||||
Result,
|
Result,
|
||||||
Return,
|
Return,
|
||||||
Right,
|
Right,
|
||||||
|
@ -592,6 +597,8 @@ symbols! {
|
||||||
gt,
|
gt,
|
||||||
half_open_range_patterns,
|
half_open_range_patterns,
|
||||||
hash,
|
hash,
|
||||||
|
hashmap_type,
|
||||||
|
hashset_type,
|
||||||
hexagon_target_feature,
|
hexagon_target_feature,
|
||||||
hidden,
|
hidden,
|
||||||
homogeneous_aggregate,
|
homogeneous_aggregate,
|
||||||
|
@ -1256,6 +1263,7 @@ symbols! {
|
||||||
variant_count,
|
variant_count,
|
||||||
vec,
|
vec,
|
||||||
vec_type,
|
vec_type,
|
||||||
|
vecdeque_type,
|
||||||
version,
|
version,
|
||||||
vis,
|
vis,
|
||||||
visible_private_types,
|
visible_private_types,
|
||||||
|
|
|
@ -247,6 +247,7 @@ use super::SpecExtend;
|
||||||
/// [peek]: BinaryHeap::peek
|
/// [peek]: BinaryHeap::peek
|
||||||
/// [peek\_mut]: BinaryHeap::peek_mut
|
/// [peek\_mut]: BinaryHeap::peek_mut
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "BinaryHeap")]
|
||||||
pub struct BinaryHeap<T> {
|
pub struct BinaryHeap<T> {
|
||||||
data: Vec<T>,
|
data: Vec<T>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
|
||||||
/// *stat += random_stat_buff();
|
/// *stat += random_stat_buff();
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeMap")]
|
||||||
pub struct BTreeMap<K, V> {
|
pub struct BTreeMap<K, V> {
|
||||||
root: Option<Root<K, V>>,
|
root: Option<Root<K, V>>,
|
||||||
length: usize,
|
length: usize,
|
||||||
|
|
|
@ -61,6 +61,7 @@ use super::Recover;
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Hash, PartialEq, Eq, Ord, PartialOrd)]
|
#[derive(Hash, PartialEq, Eq, Ord, PartialOrd)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeSet")]
|
||||||
pub struct BTreeSet<T> {
|
pub struct BTreeSet<T> {
|
||||||
map: BTreeMap<T, ()>,
|
map: BTreeMap<T, ()>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ mod tests;
|
||||||
/// array-based containers are generally faster,
|
/// array-based containers are generally faster,
|
||||||
/// more memory efficient, and make better use of CPU cache.
|
/// more memory efficient, and make better use of CPU cache.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "LinkedList")]
|
||||||
pub struct LinkedList<T> {
|
pub struct LinkedList<T> {
|
||||||
head: Option<NonNull<Node<T>>>,
|
head: Option<NonNull<Node<T>>>,
|
||||||
tail: Option<NonNull<Node<T>>>,
|
tail: Option<NonNull<Node<T>>>,
|
||||||
|
|
|
@ -310,6 +310,7 @@ mod cache_aligned;
|
||||||
/// println!("{}", recv.recv().unwrap()); // Received after 2 seconds
|
/// println!("{}", recv.recv().unwrap()); // Received after 2 seconds
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Receiver")]
|
||||||
pub struct Receiver<T> {
|
pub struct Receiver<T> {
|
||||||
inner: UnsafeCell<Flavor<T>>,
|
inner: UnsafeCell<Flavor<T>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
|
use rustc_span::sym;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for uses of `contains_key` + `insert` on `HashMap`
|
/// **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) {
|
return if match_type(cx, obj_ty, &paths::BTREEMAP) {
|
||||||
Some(("BTreeMap", map, key))
|
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))
|
Some(("HashMap", map, key))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1010,7 +1010,7 @@ fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'_>) -> bool {
|
||||||
_ => false,
|
_ => 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> {
|
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,
|
_ => 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(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
FOR_KV_MAP,
|
FOR_KV_MAP,
|
||||||
|
@ -2386,9 +2386,9 @@ fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||||
is_iterable_array(ty, cx) ||
|
is_iterable_array(ty, cx) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
||||||
match_type(cx, ty, &paths::LINKED_LIST) ||
|
match_type(cx, ty, &paths::LINKED_LIST) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym!(hashmap_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::hashset_type) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
|
is_type_diagnostic_item(cx, ty, sym::vecdeque_type) ||
|
||||||
match_type(cx, ty, &paths::BINARY_HEAP) ||
|
match_type(cx, ty, &paths::BINARY_HEAP) ||
|
||||||
match_type(cx, ty, &paths::BTREEMAP) ||
|
match_type(cx, ty, &paths::BTREEMAP) ||
|
||||||
match_type(cx, ty, &paths::BTREESET)
|
match_type(cx, ty, &paths::BTREESET)
|
||||||
|
@ -2922,9 +2922,9 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
|
||||||
then {
|
then {
|
||||||
let ty = cx.typeck_results().node_type(ty.hir_id);
|
let ty = cx.typeck_results().node_type(ty.hir_id);
|
||||||
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
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) ||
|
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) {
|
if method.ident.name == sym!(len) {
|
||||||
let span = shorten_needless_collect_span(expr);
|
let span = shorten_needless_collect_span(expr);
|
||||||
span_lint_and_sugg(
|
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 Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
|
||||||
if let ty = cx.typeck_results().node_type(ty.hir_id);
|
if let ty = cx.typeck_results().node_type(ty.hir_id);
|
||||||
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
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);
|
match_type(cx, ty, &paths::LINKED_LIST);
|
||||||
if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident);
|
if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident);
|
||||||
if iter_calls.len() == 1;
|
if iter_calls.len() == 1;
|
||||||
|
|
|
@ -24,7 +24,7 @@ use rustc_middle::ty::{self, TraitRef, Ty, TyS};
|
||||||
use rustc_semver::RustcVersion;
|
use rustc_semver::RustcVersion;
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
use rustc_span::symbol::{sym, SymbolStr};
|
use rustc_span::symbol::{sym, Symbol, SymbolStr};
|
||||||
use rustc_typeck::hir_ty_to_ty;
|
use rustc_typeck::hir_ty_to_ty;
|
||||||
|
|
||||||
use crate::consts::{constant, Constant};
|
use crate::consts::{constant, Constant};
|
||||||
|
@ -2598,7 +2598,7 @@ fn lint_iter_nth<'tcx>(
|
||||||
"slice"
|
"slice"
|
||||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym::vec_type) {
|
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&iter_args[0]), sym::vec_type) {
|
||||||
"Vec"
|
"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"
|
"VecDeque"
|
||||||
} else {
|
} else {
|
||||||
let nth_args = nth_and_iter_args[0];
|
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) {
|
} else if is_type_diagnostic_item(cx, expr_ty, sym::vec_type) {
|
||||||
needs_ref = get_args_str.parse::<usize>().is_ok();
|
needs_ref = get_args_str.parse::<usize>().is_ok();
|
||||||
"Vec"
|
"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();
|
needs_ref = get_args_str.parse::<usize>().is_ok();
|
||||||
"VecDeque"
|
"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;
|
needs_ref = true;
|
||||||
"HashMap"
|
"HashMap"
|
||||||
} else if !is_mut && match_type(cx, expr_ty, &paths::BTREEMAP) {
|
} else if !is_mut && match_type(cx, expr_ty, &paths::BTREEMAP) {
|
||||||
|
@ -3619,7 +3619,7 @@ fn lint_asref(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, as_re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(&'static str, &'static str)> {
|
fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(Symbol, &'static str)> {
|
||||||
has_iter_method(cx, self_ref_ty).map(|ty_name| {
|
has_iter_method(cx, self_ref_ty).map(|ty_name| {
|
||||||
let mutbl = match self_ref_ty.kind() {
|
let mutbl = match self_ref_ty.kind() {
|
||||||
ty::Ref(_, _, mutbl) => mutbl,
|
ty::Ref(_, _, mutbl) => mutbl,
|
||||||
|
|
|
@ -199,7 +199,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<
|
||||||
if matches!(ty.kind(), ty::Slice(_))
|
if matches!(ty.kind(), ty::Slice(_))
|
||||||
|| matches!(ty.kind(), ty::Array(_, _))
|
|| matches!(ty.kind(), ty::Array(_, _))
|
||||||
|| is_type_diagnostic_item(cx, ty, sym::vec_type)
|
|| 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);
|
return Slice::Swappable(lhs1, idx1, idx2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2680,14 +2680,14 @@ impl<'tcx> ImplicitHasherType<'tcx> {
|
||||||
|
|
||||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
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(
|
Some(ImplicitHasherType::HashMap(
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
ty,
|
ty,
|
||||||
snippet(cx, params[0].span, "K"),
|
snippet(cx, params[0].span, "K"),
|
||||||
snippet(cx, params[1].span, "V"),
|
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(
|
Some(ImplicitHasherType::HashSet(
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
ty,
|
ty,
|
||||||
|
|
|
@ -5,6 +5,7 @@ use rustc_middle::ty::{Adt, Ty};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_target::abi::LayoutOf as _;
|
use rustc_target::abi::LayoutOf as _;
|
||||||
use rustc_typeck::hir_ty_to_ty;
|
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};
|
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 !hir_ty.span.from_expansion();
|
||||||
if !in_trait_impl(cx, hir_ty.hir_id);
|
if !in_trait_impl(cx, hir_ty.hir_id);
|
||||||
let ty = ty_from_hir_ty(cx, hir_ty);
|
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();
|
if let Adt(_, ref substs) = ty.kind();
|
||||||
let ty = substs.type_at(1);
|
let ty = substs.type_at(1);
|
||||||
// Do this to prevent `layout_of` crashing, being unable to fully normalize `ty`.
|
// 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_hir::{Block, Expr, ExprKind, Path, QPath};
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
|
use rustc_span::sym;
|
||||||
|
|
||||||
/// Is the expr pure (is it free from side-effects)?
|
/// 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.
|
/// 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::Call(..) => !is_ctor_or_promotable_const_function(self.cx, expr),
|
||||||
ExprKind::Index(obj, _) => {
|
ExprKind::Index(obj, _) => {
|
||||||
let ty = self.cx.typeck_results().expr_ty(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)
|
|| match_type(self.cx, ty, &paths::BTREEMAP)
|
||||||
},
|
},
|
||||||
ExprKind::MethodCall(..) => true,
|
ExprKind::MethodCall(..) => true,
|
||||||
|
|
|
@ -1295,24 +1295,24 @@ pub fn any_parent_is_automatically_derived(tcx: TyCtxt<'_>, node: HirId) -> bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if ty has `iter` or `iter_mut` methods
|
/// Returns true if ty has `iter` or `iter_mut` methods
|
||||||
pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<&'static str> {
|
pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<Symbol> {
|
||||||
// FIXME: instead of this hard-coded list, we should check if `<adt>::iter`
|
// FIXME: instead of this hard-coded list, we should check if `<adt>::iter`
|
||||||
// exists and has the desired signature. Unfortunately FnCtxt is not exported
|
// exists and has the desired signature. Unfortunately FnCtxt is not exported
|
||||||
// so we can't use its `lookup_method` method.
|
// so we can't use its `lookup_method` method.
|
||||||
let into_iter_collections: [&[&str]; 13] = [
|
let into_iter_collections: &[Symbol] = &[
|
||||||
&paths::VEC,
|
sym::vec_type,
|
||||||
&paths::OPTION,
|
sym::option_type,
|
||||||
&paths::RESULT,
|
sym::result_type,
|
||||||
&paths::BTREESET,
|
sym::BTreeMap,
|
||||||
&paths::BTREEMAP,
|
sym::BTreeSet,
|
||||||
&paths::VEC_DEQUE,
|
sym::vecdeque_type,
|
||||||
&paths::LINKED_LIST,
|
sym::LinkedList,
|
||||||
&paths::BINARY_HEAP,
|
sym::BinaryHeap,
|
||||||
&paths::HASHSET,
|
sym::hashset_type,
|
||||||
&paths::HASHMAP,
|
sym::hashmap_type,
|
||||||
&paths::PATH_BUF,
|
sym::PathBuf,
|
||||||
&paths::PATH,
|
sym::Path,
|
||||||
&paths::RECEIVER,
|
sym::Receiver,
|
||||||
];
|
];
|
||||||
|
|
||||||
let ty_to_check = match probably_ref_ty.kind() {
|
let ty_to_check = match probably_ref_ty.kind() {
|
||||||
|
@ -1321,15 +1321,15 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<
|
||||||
};
|
};
|
||||||
|
|
||||||
let def_id = match ty_to_check.kind() {
|
let def_id = match ty_to_check.kind() {
|
||||||
ty::Array(..) => return Some("array"),
|
ty::Array(..) => return Some(sym::array),
|
||||||
ty::Slice(..) => return Some("slice"),
|
ty::Slice(..) => return Some(sym::slice),
|
||||||
ty::Adt(adt, _) => adt.did,
|
ty::Adt(adt, _) => adt.did,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
for path in &into_iter_collections {
|
for &name in into_iter_collections {
|
||||||
if match_def_path(cx, def_id, path) {
|
if cx.tcx.is_diagnostic_item(name, def_id) {
|
||||||
return Some(*path.last().unwrap());
|
return Some(cx.tcx.item_name(def_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
|
@ -99,7 +99,6 @@ pub(super) const PANIC_ANY: [&str; 3] = ["std", "panic", "panic_any"];
|
||||||
pub const PARKING_LOT_MUTEX_GUARD: [&str; 2] = ["parking_lot", "MutexGuard"];
|
pub const PARKING_LOT_MUTEX_GUARD: [&str; 2] = ["parking_lot", "MutexGuard"];
|
||||||
pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 2] = ["parking_lot", "RwLockReadGuard"];
|
pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 2] = ["parking_lot", "RwLockReadGuard"];
|
||||||
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 2] = ["parking_lot", "RwLockWriteGuard"];
|
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 2] = ["parking_lot", "RwLockWriteGuard"];
|
||||||
pub const PATH: [&str; 3] = ["std", "path", "Path"];
|
|
||||||
pub const PATH_BUF: [&str; 3] = ["std", "path", "PathBuf"];
|
pub const PATH_BUF: [&str; 3] = ["std", "path", "PathBuf"];
|
||||||
pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"];
|
pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"];
|
||||||
pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"];
|
pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"];
|
||||||
|
@ -116,7 +115,6 @@ pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
|
||||||
pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"];
|
pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"];
|
||||||
pub const RC: [&str; 3] = ["alloc", "rc", "Rc"];
|
pub const RC: [&str; 3] = ["alloc", "rc", "Rc"];
|
||||||
pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"];
|
pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"];
|
||||||
pub const RECEIVER: [&str; 4] = ["std", "sync", "mpsc", "Receiver"];
|
|
||||||
pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"];
|
pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"];
|
||||||
pub const REFCELL_REFMUT: [&str; 3] = ["core", "cell", "RefMut"];
|
pub const REFCELL_REFMUT: [&str; 3] = ["core", "cell", "RefMut"];
|
||||||
pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
|
pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
|
||||||
|
|
Loading…
Reference in New Issue