2020-04-01 15:20:27 +00:00
|
|
|
use crate::ty::subst::{GenericArg, GenericArgKind};
|
2022-09-05 04:03:53 +00:00
|
|
|
use crate::ty::{self, InferConst, Ty, TypeFlags};
|
2020-06-10 08:30:39 +00:00
|
|
|
use std::slice;
|
2015-09-06 18:51:58 +00:00
|
|
|
|
2016-10-19 22:39:49 +00:00
|
|
|
#[derive(Debug)]
|
2015-09-06 18:51:58 +00:00
|
|
|
pub struct FlagComputation {
|
|
|
|
pub flags: TypeFlags,
|
|
|
|
|
2022-11-27 11:15:06 +00:00
|
|
|
/// see `Ty::outer_exclusive_binder` for details
|
2018-05-28 16:38:39 +00:00
|
|
|
pub outer_exclusive_binder: ty::DebruijnIndex,
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FlagComputation {
|
|
|
|
fn new() -> FlagComputation {
|
2018-06-10 12:44:15 +00:00
|
|
|
FlagComputation { flags: TypeFlags::empty(), outer_exclusive_binder: ty::INNERMOST }
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-11 16:55:14 +00:00
|
|
|
#[allow(rustc::usage_of_ty_tykind)]
|
2019-09-26 11:10:43 +00:00
|
|
|
pub fn for_kind(kind: &ty::TyKind<'_>) -> FlagComputation {
|
2015-09-06 18:51:58 +00:00
|
|
|
let mut result = FlagComputation::new();
|
2019-09-26 11:10:43 +00:00
|
|
|
result.add_kind(kind);
|
2015-09-06 18:51:58 +00:00
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2021-12-16 00:32:30 +00:00
|
|
|
pub fn for_predicate<'tcx>(binder: ty::Binder<'tcx, ty::PredicateKind<'_>>) -> FlagComputation {
|
2020-06-10 08:30:39 +00:00
|
|
|
let mut result = FlagComputation::new();
|
2021-01-04 06:58:33 +00:00
|
|
|
result.add_predicate(binder);
|
2020-06-10 08:30:39 +00:00
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2022-02-02 03:24:45 +00:00
|
|
|
pub fn for_const(c: ty::Const<'_>) -> TypeFlags {
|
2019-03-14 09:19:31 +00:00
|
|
|
let mut result = FlagComputation::new();
|
|
|
|
result.add_const(c);
|
|
|
|
result.flags
|
|
|
|
}
|
|
|
|
|
2015-09-06 18:51:58 +00:00
|
|
|
fn add_flags(&mut self, flags: TypeFlags) {
|
2020-04-08 01:57:31 +00:00
|
|
|
self.flags = self.flags | flags;
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 16:38:39 +00:00
|
|
|
/// indicates that `self` refers to something at binding level `binder`
|
2020-06-10 08:30:39 +00:00
|
|
|
fn add_bound_var(&mut self, binder: ty::DebruijnIndex) {
|
2018-05-28 16:38:39 +00:00
|
|
|
let exclusive_binder = binder.shifted_in(1);
|
|
|
|
self.add_exclusive_binder(exclusive_binder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// indicates that `self` refers to something *inside* binding
|
|
|
|
/// level `binder` -- not bound by `binder`, but bound by the next
|
|
|
|
/// binder internal to it
|
|
|
|
fn add_exclusive_binder(&mut self, exclusive_binder: ty::DebruijnIndex) {
|
|
|
|
self.outer_exclusive_binder = self.outer_exclusive_binder.max(exclusive_binder);
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Adds the flags/depth from a set of types that appear within the current type, but within a
|
|
|
|
/// region binder.
|
2020-10-05 20:51:33 +00:00
|
|
|
fn bound_computation<T, F>(&mut self, value: ty::Binder<'_, T>, f: F)
|
2020-09-18 20:24:53 +00:00
|
|
|
where
|
|
|
|
F: FnOnce(&mut Self, T),
|
|
|
|
{
|
|
|
|
let mut computation = FlagComputation::new();
|
|
|
|
|
2021-04-28 14:18:52 +00:00
|
|
|
if !value.bound_vars().is_empty() {
|
|
|
|
computation.flags = computation.flags | TypeFlags::HAS_RE_LATE_BOUND;
|
|
|
|
}
|
|
|
|
|
2020-09-18 20:24:53 +00:00
|
|
|
f(&mut computation, value.skip_binder());
|
|
|
|
|
2015-09-06 18:51:58 +00:00
|
|
|
self.add_flags(computation.flags);
|
|
|
|
|
|
|
|
// The types that contributed to `computation` occurred within
|
|
|
|
// a region binder, so subtract one from the region depth
|
|
|
|
// within when adding the depth to `self`.
|
2018-05-28 16:38:39 +00:00
|
|
|
let outer_exclusive_binder = computation.outer_exclusive_binder;
|
2018-06-10 12:44:15 +00:00
|
|
|
if outer_exclusive_binder > ty::INNERMOST {
|
2018-05-28 16:38:39 +00:00
|
|
|
self.add_exclusive_binder(outer_exclusive_binder.shifted_out(1));
|
2018-10-01 13:37:14 +00:00
|
|
|
} // otherwise, this binder captures nothing
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-11 16:55:14 +00:00
|
|
|
#[allow(rustc::usage_of_ty_tykind)]
|
2019-09-26 11:10:43 +00:00
|
|
|
fn add_kind(&mut self, kind: &ty::TyKind<'_>) {
|
|
|
|
match kind {
|
2018-08-22 00:35:55 +00:00
|
|
|
&ty::Bool
|
|
|
|
| &ty::Char
|
|
|
|
| &ty::Int(_)
|
|
|
|
| &ty::Float(_)
|
|
|
|
| &ty::Uint(_)
|
2018-08-22 00:35:02 +00:00
|
|
|
| &ty::Never
|
2018-08-22 00:35:55 +00:00
|
|
|
| &ty::Str
|
2018-08-22 00:35:29 +00:00
|
|
|
| &ty::Foreign(..) => {}
|
2015-09-06 18:51:58 +00:00
|
|
|
|
2020-05-06 04:02:09 +00:00
|
|
|
&ty::Error(_) => self.add_flags(TypeFlags::HAS_ERROR),
|
2015-09-06 18:51:58 +00:00
|
|
|
|
2019-07-07 15:34:06 +00:00
|
|
|
&ty::Param(_) => {
|
2022-01-12 03:19:52 +00:00
|
|
|
self.add_flags(TypeFlags::HAS_TY_PARAM);
|
2020-04-01 15:20:27 +00:00
|
|
|
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:02 +00:00
|
|
|
&ty::Generator(_, ref substs, _) => {
|
2020-06-22 12:07:05 +00:00
|
|
|
let substs = substs.as_generator();
|
|
|
|
let should_remove_further_specializable =
|
|
|
|
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
|
|
|
|
self.add_substs(substs.parent_substs());
|
|
|
|
if should_remove_further_specializable {
|
|
|
|
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.add_ty(substs.resume_ty());
|
|
|
|
self.add_ty(substs.return_ty());
|
|
|
|
self.add_ty(substs.witness());
|
|
|
|
self.add_ty(substs.yield_ty());
|
|
|
|
self.add_ty(substs.tupled_upvars_ty());
|
2016-12-26 13:34:03 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 21:40:33 +00:00
|
|
|
&ty::GeneratorWitness(ts) => {
|
2020-09-18 20:24:53 +00:00
|
|
|
self.bound_computation(ts, |flags, ts| flags.add_tys(ts));
|
2017-10-07 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 21:40:33 +00:00
|
|
|
&ty::Closure(_, substs) => {
|
2020-06-22 12:07:05 +00:00
|
|
|
let substs = substs.as_closure();
|
|
|
|
let should_remove_further_specializable =
|
|
|
|
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
|
|
|
|
self.add_substs(substs.parent_substs());
|
|
|
|
if should_remove_further_specializable {
|
|
|
|
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.add_ty(substs.sig_as_fn_ptr_ty());
|
|
|
|
self.add_ty(substs.kind_ty());
|
|
|
|
self.add_ty(substs.tupled_upvars_ty());
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-11-03 14:15:33 +00:00
|
|
|
&ty::Bound(debruijn, _) => {
|
2020-06-10 08:30:39 +00:00
|
|
|
self.add_bound_var(debruijn);
|
2018-10-22 20:38:51 +00:00
|
|
|
}
|
2018-10-22 18:37:56 +00:00
|
|
|
|
2018-11-02 18:25:20 +00:00
|
|
|
&ty::Placeholder(..) => {
|
|
|
|
self.add_flags(TypeFlags::HAS_TY_PLACEHOLDER);
|
2020-04-01 15:20:27 +00:00
|
|
|
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
|
2018-11-02 18:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:02 +00:00
|
|
|
&ty::Infer(infer) => {
|
2020-04-01 15:20:27 +00:00
|
|
|
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
|
2016-05-11 01:14:41 +00:00
|
|
|
match infer {
|
2021-05-01 20:52:54 +00:00
|
|
|
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => {
|
|
|
|
self.add_flags(TypeFlags::HAS_TY_FRESH)
|
|
|
|
}
|
2018-02-09 15:39:36 +00:00
|
|
|
|
|
|
|
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => {
|
2020-04-06 20:29:18 +00:00
|
|
|
self.add_flags(TypeFlags::HAS_TY_INFER)
|
2018-02-09 15:39:36 +00:00
|
|
|
}
|
2016-05-11 01:14:41 +00:00
|
|
|
}
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:02 +00:00
|
|
|
&ty::Adt(_, substs) => {
|
2015-09-06 18:51:58 +00:00
|
|
|
self.add_substs(substs);
|
|
|
|
}
|
|
|
|
|
2020-06-24 21:40:33 +00:00
|
|
|
&ty::Projection(data) => {
|
2020-02-22 15:09:17 +00:00
|
|
|
self.add_flags(TypeFlags::HAS_TY_PROJECTION);
|
2015-09-06 18:51:58 +00:00
|
|
|
self.add_projection_ty(data);
|
|
|
|
}
|
|
|
|
|
2018-08-23 19:51:32 +00:00
|
|
|
&ty::Opaque(_, substs) => {
|
2020-02-22 15:09:17 +00:00
|
|
|
self.add_flags(TypeFlags::HAS_TY_OPAQUE);
|
2016-07-22 15:56:22 +00:00
|
|
|
self.add_substs(substs);
|
|
|
|
}
|
|
|
|
|
2022-04-13 23:11:28 +00:00
|
|
|
&ty::Dynamic(obj, r, _) => {
|
2020-12-11 20:02:46 +00:00
|
|
|
for predicate in obj.iter() {
|
|
|
|
self.bound_computation(predicate, |computation, predicate| match predicate {
|
|
|
|
ty::ExistentialPredicate::Trait(tr) => computation.add_substs(tr.substs),
|
|
|
|
ty::ExistentialPredicate::Projection(p) => {
|
|
|
|
computation.add_existential_projection(&p);
|
2016-11-16 16:21:49 +00:00
|
|
|
}
|
2020-12-11 20:02:46 +00:00
|
|
|
ty::ExistentialPredicate::AutoTrait(_) => {}
|
|
|
|
});
|
|
|
|
}
|
2020-09-18 20:24:53 +00:00
|
|
|
|
2016-11-16 16:21:49 +00:00
|
|
|
self.add_region(r);
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:02 +00:00
|
|
|
&ty::Array(tt, len) => {
|
2017-08-05 13:11:24 +00:00
|
|
|
self.add_ty(tt);
|
2019-03-14 09:19:31 +00:00
|
|
|
self.add_const(len);
|
2017-08-05 13:11:24 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:02 +00:00
|
|
|
&ty::Slice(tt) => self.add_ty(tt),
|
2015-09-06 18:51:58 +00:00
|
|
|
|
2018-08-22 00:35:02 +00:00
|
|
|
&ty::RawPtr(ref m) => {
|
2015-09-06 18:51:58 +00:00
|
|
|
self.add_ty(m.ty);
|
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:02 +00:00
|
|
|
&ty::Ref(r, ty, _) => {
|
2016-08-25 20:58:52 +00:00
|
|
|
self.add_region(r);
|
2018-05-02 13:21:05 +00:00
|
|
|
self.add_ty(ty);
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 15:06:31 +00:00
|
|
|
&ty::Tuple(types) => {
|
|
|
|
self.add_tys(types);
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 00:35:02 +00:00
|
|
|
&ty::FnDef(_, substs) => {
|
2016-02-16 16:36:41 +00:00
|
|
|
self.add_substs(substs);
|
|
|
|
}
|
|
|
|
|
2020-09-18 20:24:53 +00:00
|
|
|
&ty::FnPtr(fn_sig) => self.bound_computation(fn_sig, |computation, fn_sig| {
|
|
|
|
computation.add_tys(fn_sig.inputs());
|
|
|
|
computation.add_ty(fn_sig.output());
|
|
|
|
}),
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 00:32:30 +00:00
|
|
|
fn add_predicate(&mut self, binder: ty::Binder<'_, ty::PredicateKind<'_>>) {
|
2020-12-23 18:16:25 +00:00
|
|
|
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
|
2020-07-18 09:46:38 +00:00
|
|
|
}
|
|
|
|
|
2021-01-07 16:20:28 +00:00
|
|
|
fn add_predicate_atom(&mut self, atom: ty::PredicateKind<'_>) {
|
2020-07-18 09:46:38 +00:00
|
|
|
match atom {
|
2022-11-24 21:14:58 +00:00
|
|
|
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) => {
|
2020-07-18 09:46:38 +00:00
|
|
|
self.add_substs(trait_pred.trait_ref.substs);
|
|
|
|
}
|
2022-11-24 21:14:58 +00:00
|
|
|
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(a, b))) => {
|
2020-07-18 09:46:38 +00:00
|
|
|
self.add_region(a);
|
|
|
|
self.add_region(b);
|
|
|
|
}
|
2022-11-24 21:14:58 +00:00
|
|
|
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
|
|
|
ty,
|
|
|
|
region,
|
|
|
|
))) => {
|
2020-07-18 09:46:38 +00:00
|
|
|
self.add_ty(ty);
|
|
|
|
self.add_region(region);
|
|
|
|
}
|
2021-01-07 16:20:28 +00:00
|
|
|
ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
|
2020-07-18 09:46:38 +00:00
|
|
|
self.add_ty(a);
|
|
|
|
self.add_ty(b);
|
|
|
|
}
|
2020-11-21 12:06:16 +00:00
|
|
|
ty::PredicateKind::Coerce(ty::CoercePredicate { a, b }) => {
|
|
|
|
self.add_ty(a);
|
|
|
|
self.add_ty(b);
|
|
|
|
}
|
2022-11-24 21:14:58 +00:00
|
|
|
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
|
|
|
|
projection_ty,
|
|
|
|
term,
|
|
|
|
})) => {
|
2020-07-18 09:46:38 +00:00
|
|
|
self.add_projection_ty(projection_ty);
|
2022-09-05 04:03:53 +00:00
|
|
|
match term.unpack() {
|
|
|
|
ty::TermKind::Ty(ty) => self.add_ty(ty),
|
|
|
|
ty::TermKind::Const(c) => self.add_const(c),
|
2022-01-08 09:28:12 +00:00
|
|
|
}
|
2020-07-18 09:46:38 +00:00
|
|
|
}
|
2021-01-07 16:20:28 +00:00
|
|
|
ty::PredicateKind::WellFormed(arg) => {
|
2020-07-18 09:46:38 +00:00
|
|
|
self.add_substs(slice::from_ref(&arg));
|
|
|
|
}
|
2021-01-07 16:20:28 +00:00
|
|
|
ty::PredicateKind::ObjectSafe(_def_id) => {}
|
|
|
|
ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => {
|
2020-07-18 09:46:38 +00:00
|
|
|
self.add_substs(substs);
|
|
|
|
}
|
2022-01-12 23:29:10 +00:00
|
|
|
ty::PredicateKind::ConstEvaluatable(uv) => {
|
2022-10-18 14:09:04 +00:00
|
|
|
self.add_const(uv);
|
2020-07-18 09:46:38 +00:00
|
|
|
}
|
2021-01-07 16:20:28 +00:00
|
|
|
ty::PredicateKind::ConstEquate(expected, found) => {
|
2020-07-18 09:46:38 +00:00
|
|
|
self.add_const(expected);
|
|
|
|
self.add_const(found);
|
|
|
|
}
|
2021-01-07 16:20:28 +00:00
|
|
|
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
|
2020-09-01 15:58:34 +00:00
|
|
|
self.add_ty(ty);
|
|
|
|
}
|
2022-11-02 15:10:05 +00:00
|
|
|
ty::PredicateKind::Ambiguous => {}
|
2020-06-10 08:30:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 05:02:42 +00:00
|
|
|
fn add_ty(&mut self, ty: Ty<'_>) {
|
2020-08-06 15:49:46 +00:00
|
|
|
self.add_flags(ty.flags());
|
Overhaul `TyS` and `Ty`.
Specifically, change `Ty` from this:
```
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
```
to this
```
pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>);
```
There are two benefits to this.
- It's now a first class type, so we can define methods on it. This
means we can move a lot of methods away from `TyS`, leaving `TyS` as a
barely-used type, which is appropriate given that it's not meant to
be used directly.
- The uniqueness requirement is now explicit, via the `Interned` type.
E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather
than via `TyS`, which wasn't obvious at all.
Much of this commit is boring churn. The interesting changes are in
these files:
- compiler/rustc_middle/src/arena.rs
- compiler/rustc_middle/src/mir/visit.rs
- compiler/rustc_middle/src/ty/context.rs
- compiler/rustc_middle/src/ty/mod.rs
Specifically:
- Most mentions of `TyS` are removed. It's very much a dumb struct now;
`Ty` has all the smarts.
- `TyS` now has `crate` visibility instead of `pub`.
- `TyS::make_for_test` is removed in favour of the static `BOOL_TY`,
which just works better with the new structure.
- The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls
of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned`
(pointer-based, for the `Equal` case) and partly on `TyS`
(contents-based, for the other cases).
- There are many tedious sigil adjustments, i.e. adding or removing `*`
or `&`. They seem to be unavoidable.
2022-01-25 03:13:38 +00:00
|
|
|
self.add_exclusive_binder(ty.outer_exclusive_binder());
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-30 05:02:42 +00:00
|
|
|
fn add_tys(&mut self, tys: &[Ty<'_>]) {
|
2015-09-06 18:51:58 +00:00
|
|
|
for &ty in tys {
|
|
|
|
self.add_ty(ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 05:02:42 +00:00
|
|
|
fn add_region(&mut self, r: ty::Region<'_>) {
|
2016-10-19 22:39:49 +00:00
|
|
|
self.add_flags(r.type_flags());
|
|
|
|
if let ty::ReLateBound(debruijn, _) = *r {
|
2020-06-10 08:30:39 +00:00
|
|
|
self.add_bound_var(debruijn);
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-02 03:24:45 +00:00
|
|
|
fn add_const(&mut self, c: ty::Const<'_>) {
|
|
|
|
self.add_ty(c.ty());
|
2022-06-10 01:18:06 +00:00
|
|
|
match c.kind() {
|
2022-10-19 08:03:23 +00:00
|
|
|
ty::ConstKind::Unevaluated(uv) => {
|
|
|
|
self.add_substs(uv.substs);
|
|
|
|
self.add_flags(TypeFlags::HAS_CT_PROJECTION);
|
|
|
|
}
|
2019-11-08 20:32:56 +00:00
|
|
|
ty::ConstKind::Infer(infer) => {
|
2020-04-01 15:20:27 +00:00
|
|
|
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
|
2019-03-14 09:19:31 +00:00
|
|
|
match infer {
|
2021-05-01 20:52:54 +00:00
|
|
|
InferConst::Fresh(_) => self.add_flags(TypeFlags::HAS_CT_FRESH),
|
2020-04-06 20:29:18 +00:00
|
|
|
InferConst::Var(_) => self.add_flags(TypeFlags::HAS_CT_INFER),
|
2019-02-20 01:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-01 15:20:27 +00:00
|
|
|
ty::ConstKind::Bound(debruijn, _) => {
|
2020-06-10 08:30:39 +00:00
|
|
|
self.add_bound_var(debruijn);
|
2020-04-01 15:20:27 +00:00
|
|
|
}
|
2019-11-08 20:32:56 +00:00
|
|
|
ty::ConstKind::Param(_) => {
|
2022-01-12 03:19:52 +00:00
|
|
|
self.add_flags(TypeFlags::HAS_CT_PARAM);
|
2020-04-01 15:20:27 +00:00
|
|
|
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
|
2019-03-14 09:19:31 +00:00
|
|
|
}
|
2019-11-08 20:32:56 +00:00
|
|
|
ty::ConstKind::Placeholder(_) => {
|
2019-10-20 22:44:41 +00:00
|
|
|
self.add_flags(TypeFlags::HAS_CT_PLACEHOLDER);
|
2020-04-01 15:20:27 +00:00
|
|
|
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
|
2019-03-12 20:25:41 +00:00
|
|
|
}
|
2019-11-08 20:32:56 +00:00
|
|
|
ty::ConstKind::Value(_) => {}
|
2022-07-27 07:27:52 +00:00
|
|
|
ty::ConstKind::Expr(e) => {
|
|
|
|
use ty::Expr;
|
|
|
|
match e {
|
|
|
|
Expr::Binop(_, l, r) => {
|
|
|
|
self.add_const(l);
|
|
|
|
self.add_const(r);
|
|
|
|
}
|
|
|
|
Expr::UnOp(_, v) => self.add_const(v),
|
|
|
|
Expr::FunctionCall(f, args) => {
|
|
|
|
self.add_const(f);
|
|
|
|
for arg in args {
|
|
|
|
self.add_const(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Expr::Cast(_, c, t) => {
|
|
|
|
self.add_ty(t);
|
|
|
|
self.add_const(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-06 04:02:09 +00:00
|
|
|
ty::ConstKind::Error(_) => self.add_flags(TypeFlags::HAS_ERROR),
|
2019-02-20 01:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 05:02:42 +00:00
|
|
|
fn add_existential_projection(&mut self, projection: &ty::ExistentialProjection<'_>) {
|
2017-07-11 14:33:09 +00:00
|
|
|
self.add_substs(projection.substs);
|
2022-09-05 04:03:53 +00:00
|
|
|
match projection.term.unpack() {
|
|
|
|
ty::TermKind::Ty(ty) => self.add_ty(ty),
|
|
|
|
ty::TermKind::Const(ct) => self.add_const(ct),
|
2022-01-13 07:39:58 +00:00
|
|
|
}
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 21:40:33 +00:00
|
|
|
fn add_projection_ty(&mut self, projection_ty: ty::ProjectionTy<'_>) {
|
2017-07-11 14:33:09 +00:00
|
|
|
self.add_substs(projection_ty.substs);
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 15:20:27 +00:00
|
|
|
fn add_substs(&mut self, substs: &[GenericArg<'_>]) {
|
2019-02-20 01:15:21 +00:00
|
|
|
for kind in substs {
|
|
|
|
match kind.unpack() {
|
2019-09-25 15:39:44 +00:00
|
|
|
GenericArgKind::Type(ty) => self.add_ty(ty),
|
|
|
|
GenericArgKind::Lifetime(lt) => self.add_region(lt),
|
|
|
|
GenericArgKind::Const(ct) => self.add_const(ct),
|
2019-02-20 01:15:21 +00:00
|
|
|
}
|
2015-09-06 18:51:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|