Skip to content

Commit

Permalink
Always use ty:: qualifier for TyKind enum variants.
Browse files Browse the repository at this point in the history
Because that's the way it should be done.
  • Loading branch information
nnethercote committed Mar 21, 2024
1 parent f81866e commit 52b5d32
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 30 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
use rustc_middle::mir::{self, CallSource};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::TraitRef;
use rustc_middle::ty::{suggest_constraining_type_param, Adt, Closure, FnDef, FnPtr, Param, Ty};
use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
use rustc_middle::ty::{
self as middle_ty, suggest_constraining_type_param, Closure, FnDef, FnPtr, GenericArgKind,
GenericArgsRef, Param, TraitRef, Ty,
};
use rustc_middle::util::{call_kind, CallDesugaringKind, CallKind};
use rustc_session::parse::feature_err;
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -123,7 +124,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
);
}
}
Adt(..) => {
middle_ty::Adt(..) => {
let obligation =
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_typeck/src/method/prelude2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use hir::ItemKind;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_middle::ty::{Adt, Array, Ref, Ty};
use rustc_middle::ty::{self, Ty};
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
use rustc_span::symbol::kw::{Empty, Underscore};
use rustc_span::symbol::{sym, Ident};
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter
// before Rust 2021, which results in the same problem.
// It is only a problem for arrays.
sym::into_iter if let Array(..) = self_ty.kind() => {
sym::into_iter if let ty::Array(..) = self_ty.kind() => {
// In this case, it wasn't really a prelude addition that was the problem.
// Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
rustc_lint::ARRAY_INTO_ITER
Expand All @@ -64,7 +64,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pick.autoref_or_ptr_adjustment,
Some(probe::AutorefOrPtrAdjustment::Autoref { .. })
)
&& matches!(self_ty.kind(), Ref(..))
&& matches!(self_ty.kind(), ty::Ref(..))
{
return;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// the user has written the self type with generics already which we (naively) do by looking
// for a "<" in `self_ty_name`.
if !self_ty_name.contains('<') {
if let Adt(def, _) = self_ty.kind() {
if let ty::Adt(def, _) = self_ty.kind() {
let generics = self.tcx.generics_of(def.did());
if !generics.params.is_empty() {
let counts = generics.own_counts();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_hir::{HirId, Pat, PatKind};
use rustc_infer::infer;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::{self, Adt, BindingMode, Ty, TypeVisitableExt};
use rustc_middle::ty::{self, BindingMode, Ty, TypeVisitableExt};
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::hygiene::DesugaringKind;
Expand Down Expand Up @@ -1007,7 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
_ => {
let (type_def_id, item_def_id) = match pat_ty.kind() {
Adt(def, _) => match res {
ty::Adt(def, _) => match res {
Res::Def(DefKind::Const, def_id) => (Some(def.did()), Some(def_id)),
_ => (None, None),
},
Expand Down
5 changes: 2 additions & 3 deletions src/librustdoc/html/render/type_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use askama::Template;
use rustc_data_structures::captures::Captures;
use rustc_hir::def_id::DefId;
use rustc_middle::span_bug;
use rustc_middle::ty::layout::LayoutError;
use rustc_middle::ty::Adt;
use rustc_middle::ty::{self, layout::LayoutError};
use rustc_span::symbol::Symbol;
use rustc_target::abi::{Primitive, TagEncoding, Variants};

Expand Down Expand Up @@ -57,7 +56,7 @@ pub(crate) fn document_type_layout<'a, 'cx: 'a>(
variants
.iter_enumerated()
.map(|(variant_idx, variant_layout)| {
let Adt(adt, _) = type_layout.ty.kind() else {
let ty::Adt(adt, _) = type_layout.ty.kind() else {
span_bug!(tcx.def_span(ty_def_id), "not an adt")
};
let name = adt.variant(variant_idx).name;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/derivable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir::{
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults};
use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty, TypeckResults};
use rustc_session::impl_lint_pass;
use rustc_span::sym;

Expand Down Expand Up @@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
&& let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
&& let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
&& cx.tcx.hir().attrs(impl_item_hir).is_empty()
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void;
use rustc_hir::def_id::DefId;
use rustc_hir::{Expr, ExprKind, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{RawPtr, TypeAndMut};
use rustc_middle::ty::{self, TypeAndMut};
use rustc_session::declare_lint_pass;
use rustc_span::sym;

Expand Down Expand Up @@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr {
&& seg.ident.name == sym!(from_raw)
&& let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id))
&& let arg_kind = cx.typeck_results().expr_ty(arg).kind()
&& let RawPtr(TypeAndMut { ty, .. }) = arg_kind
&& let ty::RawPtr(TypeAndMut { ty, .. }) = arg_kind
&& is_c_void(cx, *ty)
{
let msg = format!("creating a `{type_str}` from a void raw pointer");
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/functions/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_errors::Diag;
use rustc_hir as hir;
use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Adt, Ty};
use rustc_middle::ty::{self, Ty};
use rustc_span::{sym, Span};

use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
Expand Down Expand Up @@ -86,7 +86,7 @@ fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: S
}

fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty_span: Span, large_err_threshold: u64) {
if let Adt(adt, subst) = err_ty.kind()
if let ty::Adt(adt, subst) = err_ty.kind()
&& let Some(local_def_id) = err_ty
.ty_adt_def()
.expect("already checked this is adt")
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_data_structures::packed::Pu128;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{Int, IntTy, Ty, Uint, UintTy};
use rustc_middle::ty::{IntTy, Ty, UintTy};
use rustc_session::declare_lint_pass;

declare_clippy_lint! {
Expand Down Expand Up @@ -97,6 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
}

fn get_int_max(ty: Ty<'_>) -> Option<u128> {
use rustc_middle::ty::{Int, Uint};
match ty.peel_refs().kind() {
Int(IntTy::I8) => i8::MAX.try_into().ok(),
Int(IntTy::I16) => i16::MAX.try_into().ok(),
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/large_enum_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{Adt, Ty};
use rustc_middle::ty::{self, Ty};
use rustc_session::impl_lint_pass;
use rustc_span::Span;

Expand Down Expand Up @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
}
if let ItemKind::Enum(ref def, _) = item.kind {
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
let Adt(adt, subst) = ty.kind() else {
let ty::Adt(adt, subst) = ty.kind() else {
panic!("already checked whether this is an enum")
};
if adt.variants().len() <= 1 {
Expand Down Expand Up @@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
}

fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
if let Adt(_def, args) = ty.kind()
if let ty::Adt(_def, args) = ty.kind()
&& args.types().next().is_some()
&& let Some(copy_trait) = cx.tcx.lang_items().copy_trait()
{
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, LangItem};
use rustc_lint::LateContext;
use rustc_middle::ty::{Ref, Slice};
use rustc_middle::ty;
use rustc_span::Span;

use super::UNNECESSARY_JOIN;
Expand All @@ -18,9 +18,9 @@ pub(super) fn check<'tcx>(
) {
let applicability = Applicability::MachineApplicable;
let collect_output_adjusted_type = cx.typeck_results().expr_ty_adjusted(join_self_arg);
if let Ref(_, ref_type, _) = collect_output_adjusted_type.kind()
if let ty::Ref(_, ref_type, _) = collect_output_adjusted_type.kind()
// the turbofish for collect is ::<Vec<String>>
&& let Slice(slice) = ref_type.kind()
&& let ty::Slice(slice) = ref_type.kind()
&& is_type_lang_item(cx, *slice, LangItem::String)
// the argument for join is ""
&& let ExprKind::Lit(spanned) = &join_arg.kind
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/mut_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method};
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{Adt, Ty};
use rustc_middle::ty::{self, Ty};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::LocalDefId;
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -153,7 +153,7 @@ impl MutableKeyType {
// generics (because the compiler cannot ensure immutability for unknown types).
fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
let ty = ty.peel_refs();
if let Adt(def, args) = ty.kind() {
if let ty::Adt(def, args) = ty.kind() {
let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet]
.iter()
.any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did()));
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_hir::{self as hir, HirId, ItemKind, Node};
use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::layout::LayoutOf as _;
use rustc_middle::ty::{Adt, Ty, TypeVisitableExt};
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
use rustc_session::declare_lint_pass;
use rustc_span::sym;

Expand Down Expand Up @@ -49,7 +49,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
&& !in_trait_impl(cx, hir_ty.hir_id)
&& let ty = ty_from_hir_ty(cx, hir_ty)
&& (is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap))
&& let Adt(_, args) = ty.kind()
&& let ty::Adt(_, args) = ty.kind()
&& let ty = args.type_at(1)
// Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968
Expand Down

0 comments on commit 52b5d32

Please sign in to comment.