Rustdoc and Clippy stop misusing Key for Ty -> (adt) DefId
This commit is contained in:
parent
755b2da841
commit
dfb9f5df2c
@ -4,7 +4,6 @@
|
|||||||
use rustc_hir::def::CtorKind;
|
use rustc_hir::def::CtorKind;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_middle::query::Key;
|
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
@ -1259,7 +1258,7 @@ fn write_content(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::
|
|||||||
clean::TypeAliasInnerType::Enum { variants, is_non_exhaustive } => {
|
clean::TypeAliasInnerType::Enum { variants, is_non_exhaustive } => {
|
||||||
let variants_iter = || variants.iter().filter(|i| !i.is_stripped());
|
let variants_iter = || variants.iter().filter(|i| !i.is_stripped());
|
||||||
let ty = cx.tcx().type_of(it.def_id().unwrap()).instantiate_identity();
|
let ty = cx.tcx().type_of(it.def_id().unwrap()).instantiate_identity();
|
||||||
let enum_def_id = ty.ty_adt_id().unwrap();
|
let enum_def_id = ty.ty_adt_def().unwrap().did();
|
||||||
|
|
||||||
wrap_item(w, |w| {
|
wrap_item(w, |w| {
|
||||||
let variants_len = variants.len();
|
let variants_len = variants.len();
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
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()
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
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 @@
|
|||||||
/// `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
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
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(
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
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 @@ fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
|
|||||||
// 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");
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
};
|
};
|
||||||
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 @@ pub fn new(ignore_interior_mutability: Vec<String>) -> Self {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user