Rustdoc and Clippy stop misusing Key for Ty -> (adt) DefId

This commit is contained in:
Michael Goulet 2023-11-12 18:57:24 +00:00
parent 122520d80c
commit 89f511e4dd
6 changed files with 9 additions and 19 deletions

View file

@ -12,7 +12,6 @@ use rustc_errors::Applicability;
use rustc_hir::def_id::DefIdSet; use rustc_hir::def_id::DefIdSet;
use rustc_hir::{intravisit, BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, Stmt, StmtKind}; use rustc_hir::{intravisit, BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::query::Key;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::hygiene::walk_chain; use rustc_span::hygiene::walk_chain;
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
@ -574,7 +573,7 @@ fn method_caller_is_mutable(cx: &LateContext<'_>, caller_expr: &Expr<'_>, ignore
let caller_ty = cx.typeck_results().expr_ty(caller_expr); let caller_ty = cx.typeck_results().expr_ty(caller_expr);
// Check if given type has inner mutability and was not set to ignored by the configuration // Check if given type has inner mutability and was not set to ignored by the configuration
let is_inner_mut_ty = is_interior_mut_ty(cx, caller_ty) let is_inner_mut_ty = is_interior_mut_ty(cx, caller_ty)
&& !matches!(caller_ty.ty_adt_id(), Some(adt_id) if ignored_ty_ids.contains(&adt_id)); && !matches!(caller_ty.ty_adt_def(), Some(adt) if ignored_ty_ids.contains(&adt.did()));
is_inner_mut_ty is_inner_mut_ty
|| caller_ty.is_mutable_ptr() || caller_ty.is_mutable_ptr()

View file

@ -6,7 +6,6 @@ use clippy_utils::ty::is_type_lang_item;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, LangItem, Path, QPath}; use rustc_hir::{Expr, ExprKind, LangItem, Path, QPath};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::query::Key;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_span::{sym, Symbol}; use rustc_span::{sym, Symbol};
@ -18,10 +17,10 @@ use rustc_span::{sym, Symbol};
/// `vec![1,2].drain(..).collect::<HashSet<_>>()` /// `vec![1,2].drain(..).collect::<HashSet<_>>()`
/// ^^^^^^^^^ ^^^^^^^^^^ false /// ^^^^^^^^^ ^^^^^^^^^^ false
fn types_match_diagnostic_item(cx: &LateContext<'_>, expr: Ty<'_>, recv: Ty<'_>, sym: Symbol) -> bool { fn types_match_diagnostic_item(cx: &LateContext<'_>, expr: Ty<'_>, recv: Ty<'_>, sym: Symbol) -> bool {
if let Some(expr_adt_did) = expr.ty_adt_id() if let Some(expr_adt) = expr.ty_adt_def()
&& let Some(recv_adt_did) = recv.ty_adt_id() && let Some(recv_adt) = recv.ty_adt_def()
{ {
cx.tcx.is_diagnostic_item(sym, expr_adt_did) && cx.tcx.is_diagnostic_item(sym, recv_adt_did) cx.tcx.is_diagnostic_item(sym, expr_adt.did()) && cx.tcx.is_diagnostic_item(sym, recv_adt.did())
} else { } else {
false false
} }

View file

@ -4,7 +4,6 @@ use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::Expr; use rustc_hir::Expr;
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::query::Key;
use rustc_span::Span; use rustc_span::Span;
pub(super) fn check( pub(super) fn check(
@ -14,11 +13,7 @@ pub(super) fn check(
as_str_span: Span, as_str_span: Span,
other_method_span: Span, other_method_span: Span,
) { ) {
if cx if cx.typeck_results().expr_ty(recv).ty_adt_def().is_some_and(|adt| Some(adt.did()) == cx.tcx.lang_items().string())
.tcx
.lang_items()
.string()
.is_some_and(|id| Some(id) == cx.typeck_results().expr_ty(recv).ty_adt_id())
{ {
let mut applicability = Applicability::MachineApplicable; let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg( span_lint_and_sugg(

View file

@ -4,7 +4,6 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::query::Key;
use rustc_middle::ty::{Adt, Ty}; use rustc_middle::ty::{Adt, Ty};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
@ -166,7 +165,7 @@ impl MutableKeyType {
// Determines if a type contains interior mutability which would affect its implementation of // Determines if a type contains interior mutability which would affect its implementation of
// [`Hash`] or [`Ord`]. // [`Hash`] or [`Ord`].
if is_interior_mut_ty(cx, subst_ty) if is_interior_mut_ty(cx, subst_ty)
&& !matches!(subst_ty.ty_adt_id(), Some(adt_id) if self.ignore_mut_def_ids.contains(&adt_id)) && !matches!(subst_ty.ty_adt_def(), Some(adt) if self.ignore_mut_def_ids.contains(&adt.did()))
{ {
span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type"); span_lint(cx, MUTABLE_KEY_TYPE, span, "mutable key type");
} }

View file

@ -15,7 +15,6 @@ use rustc_hir::{
}; };
use rustc_lint::{LateContext, LateLintPass, Lint}; use rustc_lint::{LateContext, LateLintPass, Lint};
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId}; use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId};
use rustc_middle::query::Key;
use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
@ -188,7 +187,7 @@ impl NonCopyConst {
} }
fn is_ty_ignored(&self, ty: Ty<'_>) -> bool { fn is_ty_ignored(&self, ty: Ty<'_>) -> bool {
matches!(ty.ty_adt_id(), Some(adt_id) if self.ignore_mut_def_ids.contains(&adt_id)) matches!(ty.ty_adt_def(), Some(adt) if self.ignore_mut_def_ids.contains(&adt.did()))
} }
fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {

View file

@ -4,7 +4,6 @@ use clippy_utils::sugg;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::Expr; use rustc_hir::Expr;
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::query::Key;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -17,10 +16,10 @@ pub(super) fn check<'tcx>(
to_ty: Ty<'tcx>, to_ty: Ty<'tcx>,
arg: &'tcx Expr<'_>, arg: &'tcx Expr<'_>,
) -> bool { ) -> bool {
let (ty::Int(_) | ty::Uint(_), Some(to_ty_id)) = (&from_ty.kind(), to_ty.ty_adt_id()) else { let (ty::Int(_) | ty::Uint(_), Some(to_ty_adt)) = (&from_ty.kind(), to_ty.ty_adt_def()) else {
return false; return false;
}; };
let Some(to_type_sym) = cx.tcx.get_diagnostic_name(to_ty_id) else { let Some(to_type_sym) = cx.tcx.get_diagnostic_name(to_ty_adt.did()) else {
return false; return false;
}; };