Stop relying on rustc_type_ir in non-type-system crates
This commit is contained in:
parent
19c84c8812
commit
b88f85a410
37 changed files with 136 additions and 163 deletions
|
@ -21,6 +21,5 @@ rustc_session = { path = "../rustc_session" }
|
|||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{self, TyCtxt, VisitorResult, try_visit};
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitable, VisitorResult, try_visit};
|
||||
use rustc_span::Span;
|
||||
use rustc_type_ir::TypeVisitable;
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
pub trait SpannedTypeVisitor<'tcx> {
|
||||
|
|
|
@ -15,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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue