diff options
| author | bors <bors@rust-lang.org> | 2025-03-15 08:36:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-15 08:36:38 +0000 |
| commit | aa95b9648ad0383a3fd73b5271dd86f848b7c00c (patch) | |
| tree | baf5f5a301cc7127f3b056257138d5970d96282e /compiler/rustc_ty_utils/src | |
| parent | adea7cbc093434a527baa4c39df6a1f0c27341e6 (diff) | |
| parent | b88f85a4106ca0a53a1dab6d605cf56a0cc945ac (diff) | |
| download | rust-aa95b9648ad0383a3fd73b5271dd86f848b7c00c.tar.gz rust-aa95b9648ad0383a3fd73b5271dd86f848b7c00c.zip | |
Auto merge of #138464 - compiler-errors:less-type-ir, r=lcnr
Use `rustc_type_ir` directly less in the codebase
cc https://github.com/rust-lang/rust/issues/138449
This is a somewhat opinionated bundle of changes that will make working on https://github.com/rust-lang/rust/issues/138449 more easy, since it cuts out the bulk of the changes that would be necessitated by the lint. Namely:
1. Fold `rustc_middle::ty::fold` and `rustc_middle::ty::visit` into `rustc_middle::ty`. This is because we already reexport some parts of these modules into `rustc_middle::ty`, and there's really no benefit from namespacing away the rest of these modules's functionality given how important folding and visiting is to the type layer.
2. Rename `{Decodable,Encodable}_Generic` to `{Decodable,Encodable}_NoContext`[^why], change it to be "perfect derive" (`synstructure::AddBounds::Fields`), use it throughout `rustc_type_ir` instead of `TyEncodable`/`TyDecodable`.
3. Make `TyEncodable` and `TyDecodable` derives use `::rustc_middle::ty::codec::TyEncoder` (etc) for its generated paths, and move the `rustc_type_ir::codec` module back to `rustc_middle::ty::codec` :tada:.
4. Stop using `rustc_type_ir` in crates that aren't "fundamental" to the type system, namely middle/infer/trait-selection. This amounted mostly to changing imports from `use rustc_type_ir::...` to `use rustc_middle::ty::...`, but also this means that we can't glob import `TyKind::*` since the reexport into `rustc_middle::ty::TyKind` is a type alias. Instead, use the prefixed variants like `ty::Str` everywhere -- IMO this is a good change, since it makes it more regularized with most of the rest of the compiler.
[^why]: `_NoContext` is the name for derive macros with no additional generic bounds and which do "perfect derive" by generating bounds based on field types. See `HashStable_NoContext`.
I'm happy to cut out some of these changes into separate PRs to make landing it a bit easier, though I don't expect to have much trouble with bitrot.
r? lcnr
Diffstat (limited to 'compiler/rustc_ty_utils/src')
| -rw-r--r-- | compiler/rustc_ty_utils/src/implied_bounds.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/sig_types.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/ty.rs | 55 |
4 files changed, 31 insertions, 34 deletions
diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index aeaa83c77b5..088d5e76b86 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -6,8 +6,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_middle::bug; use rustc_middle::query::Providers; -use rustc_middle::ty::fold::fold_regions; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, fold_regions}; use rustc_span::Span; pub(crate) fn provide(providers: &mut Providers) { diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 90b3517eded..962e1353ebc 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -7,11 +7,10 @@ use rustc_middle::query::Providers; use rustc_middle::traits::{BuiltinImplSource, CodegenObligationError}; use rustc_middle::ty::util::AsyncDropGlueMorphology; use rustc_middle::ty::{ - self, GenericArgsRef, Instance, PseudoCanonicalInput, TyCtxt, TypeVisitableExt, + self, ClosureKind, GenericArgsRef, Instance, PseudoCanonicalInput, TyCtxt, TypeVisitableExt, }; use rustc_span::sym; use rustc_trait_selection::traits; -use rustc_type_ir::ClosureKind; use tracing::debug; use traits::translate_args; diff --git a/compiler/rustc_ty_utils/src/sig_types.rs b/compiler/rustc_ty_utils/src/sig_types.rs index d6f9277813d..5bb96f90029 100644 --- a/compiler/rustc_ty_utils/src/sig_types.rs +++ b/compiler/rustc_ty_utils/src/sig_types.rs @@ -4,10 +4,8 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_middle::span_bug; -use rustc_middle::ty::visit::{VisitorResult, try_visit}; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, TyCtxt, TypeVisitable, VisitorResult, try_visit}; use rustc_span::Span; -use rustc_type_ir::visit::TypeVisitable; use tracing::{instrument, trace}; pub trait SpannedTypeVisitor<'tcx> { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index bb61f4bee66..9dc4f11e456 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -5,8 +5,9 @@ use rustc_hir::def::DefKind; use rustc_index::bit_set::DenseBitSet; use rustc_middle::bug; use rustc_middle::query::Providers; -use rustc_middle::ty::fold::fold_regions; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast}; +use rustc_middle::ty::{ + self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast, fold_regions, +}; use rustc_span::DUMMY_SP; use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId}; use rustc_trait_selection::traits; @@ -14,49 +15,49 @@ use tracing::instrument; #[instrument(level = "debug", skip(tcx), ret)] fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> { - use rustc_type_ir::TyKind::*; - match ty.kind() { // these are always sized - Bool - | Char - | Int(..) - | Uint(..) - | Float(..) - | RawPtr(..) - | Ref(..) - | FnDef(..) - | FnPtr(..) - | Array(..) - | Closure(..) - | CoroutineClosure(..) - | Coroutine(..) - | CoroutineWitness(..) - | Never - | Dynamic(_, _, ty::DynStar) => None, + ty::Bool + | ty::Char + | ty::Int(..) + | ty::Uint(..) + | ty::Float(..) + | ty::RawPtr(..) + | ty::Ref(..) + | ty::FnDef(..) + | ty::FnPtr(..) + | ty::Array(..) + | ty::Closure(..) + | ty::CoroutineClosure(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) + | ty::Never + | ty::Dynamic(_, _, ty::DynStar) => None, // these are never sized - Str | Slice(..) | Dynamic(_, _, ty::Dyn) | Foreign(..) => Some(ty), + ty::Str | ty::Slice(..) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => Some(ty), - Pat(ty, _) => sized_constraint_for_ty(tcx, *ty), + ty::Pat(ty, _) => sized_constraint_for_ty(tcx, *ty), - Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)), + ty::Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)), // recursive case - Adt(adt, args) => adt.sized_constraint(tcx).and_then(|intermediate| { + ty::Adt(adt, args) => adt.sized_constraint(tcx).and_then(|intermediate| { let ty = intermediate.instantiate(tcx, args); sized_constraint_for_ty(tcx, ty) }), // these can be sized or unsized. - Param(..) | Alias(..) | Error(_) => Some(ty), + ty::Param(..) | ty::Alias(..) | ty::Error(_) => Some(ty), // We cannot instantiate the binder, so just return the *original* type back, // but only if the inner type has a sized constraint. Thus we skip the binder, // but don't actually use the result from `sized_constraint_for_ty`. - UnsafeBinder(inner_ty) => sized_constraint_for_ty(tcx, inner_ty.skip_binder()).map(|_| ty), + ty::UnsafeBinder(inner_ty) => { + sized_constraint_for_ty(tcx, inner_ty.skip_binder()).map(|_| ty) + } - Placeholder(..) | Bound(..) | Infer(..) => { + ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) => { bug!("unexpected type `{ty:?}` in sized_constraint_for_ty") } } |
