Fix remaining dogfood errors (internal lints)

This commit is contained in:
flip1995 2021-03-11 10:57:49 +01:00
parent ae6be4f361
commit 9c1dd0c227
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
6 changed files with 16 additions and 14 deletions

View file

@ -4,7 +4,7 @@ use rustc_errors::Applicability;
use rustc_hir::{Expr, Mutability}; use rustc_hir::{Expr, Mutability};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty, TyS}; use rustc_middle::ty::{self, Ty, TyS};
use rustc_span::symbol::sym; use rustc_span::sym;
use crate::utils::{is_type_diagnostic_item, match_type, paths}; use crate::utils::{is_type_diagnostic_item, match_type, paths};
@ -55,9 +55,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)

View file

@ -4,6 +4,7 @@ use crate::utils::{is_type_diagnostic_item, match_type, multispan_sugg, paths, s
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind}; use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_span::sym;
/// Checks for the `FOR_KV_MAP` lint. /// Checks for the `FOR_KV_MAP` lint.
pub(super) fn check<'tcx>( pub(super) fn check<'tcx>(
@ -35,7 +36,7 @@ pub(super) fn check<'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,

View file

@ -328,7 +328,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> {

View file

@ -29,9 +29,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(
@ -99,7 +99,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;

View file

@ -14,11 +14,11 @@ pub(crate) fn lints<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, iter_args: &'
"slice" "slice"
} else if is_type_diagnostic_item(cx, ty, sym::vec_type) { } else if is_type_diagnostic_item(cx, ty, sym::vec_type) {
"Vec" "Vec"
} else if is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) { } else if is_type_diagnostic_item(cx, ty, sym::vecdeque_type) {
"VecDeque" "VecDeque"
} else if is_type_diagnostic_item(cx, ty, sym!(hashset_type)) { } else if is_type_diagnostic_item(cx, ty, sym::hashset_type) {
"HashSet" "HashSet"
} else if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) { } else if is_type_diagnostic_item(cx, ty, sym::hashmap_type) {
"HashMap" "HashMap"
} else if match_type(cx, ty, &paths::BTREEMAP) { } else if match_type(cx, ty, &paths::BTREEMAP) {
"BTreeMap" "BTreeMap"

View file

@ -9,7 +9,7 @@
//! - or-fun-call //! - or-fun-call
//! - option-if-let-else //! - option-if-let-else
use crate::{is_ctor_or_promotable_const_function, is_type_diagnostic_item, match_type, paths}; use crate::{is_ctor_or_promotable_const_function, is_type_diagnostic_item};
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit; use rustc_hir::intravisit;
@ -100,7 +100,8 @@ 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) || match_type(self.cx, ty, &paths::BTREEMAP) is_type_diagnostic_item(self.cx, ty, sym::hashmap_type)
|| is_type_diagnostic_item(self.cx, ty, sym::BTreeMap)
}, },
ExprKind::MethodCall(..) => true, ExprKind::MethodCall(..) => true,
_ => false, _ => false,