From 1003b7f85e75e3a726adc34b9c315e98094176d5 Mon Sep 17 00:00:00 2001 From: scalexm Date: Mon, 22 Oct 2018 20:37:56 +0200 Subject: [PATCH] Move `BoundTy` to `ty::TyKind` --- src/librustc/ich/impls_ty.rs | 4 ++- src/librustc/infer/canonical/canonicalizer.rs | 21 +++++------- .../infer/canonical/query_response.rs | 2 +- src/librustc/infer/canonical/substitute.rs | 3 +- src/librustc/infer/freshen.rs | 4 +-- src/librustc/traits/coherence.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/query/dropck_outlives.rs | 1 + src/librustc/traits/select.rs | 6 ++-- src/librustc/ty/context.rs | 2 +- src/librustc/ty/error.rs | 2 +- src/librustc/ty/fast_reject.rs | 2 +- src/librustc/ty/flags.rs | 5 +-- src/librustc/ty/item_path.rs | 1 + src/librustc/ty/layout.rs | 9 ++++-- src/librustc/ty/mod.rs | 3 +- src/librustc/ty/outlives.rs | 1 + src/librustc/ty/structural_impls.rs | 32 +++++++++++++++---- src/librustc/ty/sty.rs | 30 ++++++++++++++--- src/librustc/ty/subst.rs | 2 +- src/librustc/ty/util.rs | 2 +- src/librustc/ty/walk.rs | 2 +- src/librustc/ty/wf.rs | 1 + src/librustc/util/ppaux.rs | 17 ++++++++-- .../debuginfo/type_names.rs | 1 + src/librustc_lint/types.rs | 1 + src/librustc_mir/monomorphize/item.rs | 1 + src/librustc_traits/chalk_context.rs | 1 + src/librustc_traits/dropck_outlives.rs | 2 +- src/librustc_traits/lowering/environment.rs | 1 + src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 1 + src/librustdoc/clean/mod.rs | 1 + 33 files changed, 116 insertions(+), 51 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 0c93b86ee4d..5873dd2eab7 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -852,6 +852,9 @@ fn hash_stable(&self, Param(param_ty) => { param_ty.hash_stable(hcx, hasher); } + Bound(bound_ty) => { + bound_ty.hash_stable(hcx, hasher); + } Foreign(def_id) => { def_id.hash_stable(hcx, hasher); } @@ -869,7 +872,6 @@ fn hash_stable(&self, FreshTy(a), FreshIntTy(a), FreshFloatTy(a), - BoundTy(a), }); impl<'a, 'gcx> HashStable> diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs index cc6e4df0710..a7634b8bd2a 100644 --- a/src/librustc/infer/canonical/canonicalizer.rs +++ b/src/librustc/infer/canonical/canonicalizer.rs @@ -337,8 +337,8 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { bug!("encountered a fresh type during canonicalization") } - ty::Infer(ty::BoundTy(_)) => { - bug!("encountered a canonical type during canonicalization") + ty::Bound(_) => { + bug!("encountered a bound type during canonicalization") } ty::Closure(..) @@ -455,7 +455,7 @@ fn canonicalize( /// or returns an existing variable if `kind` has already been /// seen. `kind` is expected to be an unbound variable (or /// potentially a free region). - fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy { + fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTyIndex { let Canonicalizer { variables, query_state, @@ -506,10 +506,7 @@ fn canonical_var(&mut self, info: CanonicalVarInfo, kind: Kind<'tcx>) -> BoundTy }) }; - BoundTy { - level: ty::INNERMOST, - var, - } + var } /// Shorthand helper that creates a canonical region variable for @@ -552,9 +549,8 @@ fn canonical_var_for_region( info: CanonicalVarInfo, r: ty::Region<'tcx>, ) -> ty::Region<'tcx> { - let b = self.canonical_var(info, r.into()); - debug_assert_eq!(ty::INNERMOST, b.level); - self.tcx().mk_region(ty::ReCanonical(b.var)) + let var = self.canonical_var(info, r.into()); + self.tcx().mk_region(ty::ReCanonical(var)) } /// Given a type variable `ty_var` of the given kind, first check @@ -570,9 +566,8 @@ fn canonicalize_ty_var(&mut self, ty_kind: CanonicalTyVarKind, ty_var: Ty<'tcx>) let info = CanonicalVarInfo { kind: CanonicalVarKind::Ty(ty_kind), }; - let b = self.canonical_var(info, ty_var.into()); - debug_assert_eq!(ty::INNERMOST, b.level); - self.tcx().mk_infer(ty::InferTy::BoundTy(b)) + let var = self.canonical_var(info, ty_var.into()); + self.tcx().mk_ty(ty::Bound(BoundTy::new(ty::INNERMOST, var))) } } } diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs index b3ce5eb7e56..27ee33a452e 100644 --- a/src/librustc/infer/canonical/query_response.rs +++ b/src/librustc/infer/canonical/query_response.rs @@ -432,7 +432,7 @@ fn query_response_substitution_guess( match result_value.unpack() { UnpackedKind::Type(result_value) => { // e.g., here `result_value` might be `?0` in the example above... - if let ty::Infer(ty::InferTy::BoundTy(b)) = result_value.sty { + if let ty::Bound(b) = result_value.sty { // in which case we would set `canonical_vars[0]` to `Some(?U)`. opt_values[b.var] = Some(*original_value); } diff --git a/src/librustc/infer/canonical/substitute.rs b/src/librustc/infer/canonical/substitute.rs index 03441c3dee3..80a2497bbf6 100644 --- a/src/librustc/infer/canonical/substitute.rs +++ b/src/librustc/infer/canonical/substitute.rs @@ -85,8 +85,7 @@ fn tcx(&self) -> TyCtxt<'_, 'gcx, 'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { match t.sty { - ty::Infer(ty::InferTy::BoundTy(b)) => { - debug_assert_eq!(ty::INNERMOST, b.level); + ty::Bound(b) => { match self.var_values.var_values[b.var].unpack() { UnpackedKind::Type(ty) => ty, r => bug!("{:?} is a type but value is {:?}", b, r), diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs index 1647f259db9..c12e64b4c2c 100644 --- a/src/librustc/infer/freshen.rs +++ b/src/librustc/infer/freshen.rs @@ -171,8 +171,8 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { t } - ty::Infer(ty::BoundTy(..)) => - bug!("encountered canonical ty during freshening"), + ty::Bound(..) => + bug!("encountered bound ty during freshening"), ty::Generator(..) | ty::Bool | diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index 817e9ffcbb5..71b77909b82 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -455,7 +455,7 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool { false } - ty::Infer(..) => match in_crate { + ty::Bound(..) | ty::Infer(..) => match in_crate { InCrate::Local => false, // The inference variable might be unified with a local // type in that remote crate. diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 18ee98c515f..e6ae0557c33 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -280,7 +280,7 @@ fn type_category<'tcx>(t: Ty<'tcx>) -> Option { ty::Generator(..) => Some(18), ty::Foreign(..) => Some(19), ty::GeneratorWitness(..) => Some(20), - ty::Infer(..) | ty::Error => None, + ty::Bound(..) | ty::Infer(..) | ty::Error => None, ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"), } } diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index 8f7b0df8b95..62317f07476 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -252,6 +252,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) -> | ty::Param(_) | ty::Opaque(..) | ty::Infer(_) + | ty::Bound(..) | ty::Generator(..) => false, ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"), diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index ce515c45077..691c9d9da49 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -2445,7 +2445,7 @@ fn sized_conditions( ty::Infer(ty::TyVar(_)) => Ambiguous, ty::UnnormalizedProjection(..) - | ty::Infer(ty::BoundTy(_)) + | ty::Bound(_) | ty::Infer(ty::FreshTy(_)) | ty::Infer(ty::FreshIntTy(_)) | ty::Infer(ty::FreshFloatTy(_)) => { @@ -2530,7 +2530,7 @@ fn copy_clone_conditions( } ty::UnnormalizedProjection(..) - | ty::Infer(ty::BoundTy(_)) + | ty::Bound(_) | ty::Infer(ty::FreshTy(_)) | ty::Infer(ty::FreshIntTy(_)) | ty::Infer(ty::FreshFloatTy(_)) => { @@ -2573,7 +2573,7 @@ fn constituent_types_for_ty(&self, t: Ty<'tcx>) -> Vec> { | ty::Param(..) | ty::Foreign(..) | ty::Projection(..) - | ty::Infer(ty::BoundTy(_)) + | ty::Bound(_) | ty::Infer(ty::TyVar(_)) | ty::Infer(ty::FreshTy(_)) | ty::Infer(ty::FreshIntTy(_)) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 409665e4777..05d9d4bc37d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2243,7 +2243,7 @@ pub fn print_debug_stats(self) { sty_debug_print!( self, Adt, Array, Slice, RawPtr, Ref, FnDef, FnPtr, - Generator, GeneratorWitness, Dynamic, Closure, Tuple, + Generator, GeneratorWitness, Dynamic, Closure, Tuple, Bound, Param, Infer, UnnormalizedProjection, Projection, Opaque, Foreign); println!("Substs interner: #{}", self.interners.substs.borrow().len()); diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 855983042c0..4737c72b1ef 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -212,7 +212,7 @@ pub fn sort_string(&self, tcx: TyCtxt<'a, 'gcx, 'lcx>) -> Cow<'static, str> { ty::Infer(ty::TyVar(_)) => "inferred type".into(), ty::Infer(ty::IntVar(_)) => "integral variable".into(), ty::Infer(ty::FloatVar(_)) => "floating-point variable".into(), - ty::Infer(ty::BoundTy(_)) | + ty::Bound(_) | ty::Infer(ty::FreshTy(_)) => "fresh type".into(), ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(), ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(), diff --git a/src/librustc/ty/fast_reject.rs b/src/librustc/ty/fast_reject.rs index e6aaf8b1bb2..380f95993f8 100644 --- a/src/librustc/ty/fast_reject.rs +++ b/src/librustc/ty/fast_reject.rs @@ -122,7 +122,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, ty::Foreign(def_id) => { Some(ForeignSimplifiedType(def_id)) } - ty::Infer(_) | ty::Error => None, + ty::Bound(..) | ty::Infer(_) | ty::Error => None, } } diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index a7b21688fbe..92e08878708 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -115,14 +115,15 @@ fn add_sty(&mut self, st: &ty::TyKind<'_>) { self.add_substs(&substs.substs); } + &ty::Bound(_) => self.add_flags(TypeFlags::HAS_CANONICAL_VARS), + &ty::Infer(infer) => { self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES); // it might, right? self.add_flags(TypeFlags::HAS_TY_INFER); match infer { ty::FreshTy(_) | ty::FreshIntTy(_) | - ty::FreshFloatTy(_) | - ty::BoundTy(_) => { + ty::FreshFloatTy(_) => { self.add_flags(TypeFlags::HAS_CANONICAL_VARS); } diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 7153c729d15..d44ba030841 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -519,6 +519,7 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option { ty::Param(_) | ty::Opaque(..) | ty::Infer(_) | + ty::Bound(..) | ty::Error | ty::GeneratorWitness(..) | ty::Never | diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 05d4aeb6dde..55005721617 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1124,9 +1124,14 @@ enum StructKind { } tcx.layout_raw(param_env.and(normalized))? } - ty::UnnormalizedProjection(..) | ty::GeneratorWitness(..) | ty::Infer(_) => { + + ty::Bound(..) | + ty::UnnormalizedProjection(..) | + ty::GeneratorWitness(..) | + ty::Infer(_) => { bug!("LayoutDetails::compute: unexpected type `{}`", ty) } + ty::Param(_) | ty::Error => { return Err(LayoutError::Unknown(ty)); } @@ -1703,7 +1708,7 @@ fn field(this: TyLayout<'tcx>, cx: C, i: usize) -> C::TyLayout { } } - ty::Projection(_) | ty::UnnormalizedProjection(..) | + ty::Projection(_) | ty::UnnormalizedProjection(..) | ty::Bound(..) | ty::Opaque(..) | ty::Param(_) | ty::Infer(_) | ty::Error => { bug!("TyLayout::field_type: unexpected type `{}`", this.ty) } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index ad26383df6a..6ce65177442 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -63,7 +63,7 @@ use hir; -pub use self::sty::{Binder, BoundTy, BoundTyIndex, DebruijnIndex, INNERMOST}; +pub use self::sty::{Binder, BoundTy, BoundTyKind, BoundTyIndex, DebruijnIndex, INNERMOST}; pub use self::sty::{FnSig, GenSig, CanonicalPolyFnSig, PolyFnSig, PolyGenSig}; pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate}; pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut}; @@ -2378,6 +2378,7 @@ fn sized_constraint_for_ty(&self, } } + Bound(..) | Infer(..) => { bug!("unexpected type `{:?}` in sized_constraint_for_ty", ty) diff --git a/src/librustc/ty/outlives.rs b/src/librustc/ty/outlives.rs index b49664b6247..4c820447be2 100644 --- a/src/librustc/ty/outlives.rs +++ b/src/librustc/ty/outlives.rs @@ -156,6 +156,7 @@ fn compute_components(&self, ty: Ty<'tcx>, out: &mut Vec>) { ty::FnDef(..) | // OutlivesFunction (*) ty::FnPtr(_) | // OutlivesFunction (*) ty::Dynamic(..) | // OutlivesObject, OutlivesFragment (*) + ty::Bound(..) | ty::Error => { // (*) Bare functions and traits are both binders. In the // RFC, this means we would add the bound regions to the diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 05f5f923557..59a66513eef 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -734,9 +734,19 @@ fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) ty::UnnormalizedProjection(data.fold_with(folder)) } ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)), - ty::Bool | ty::Char | ty::Str | ty::Int(_) | - ty::Uint(_) | ty::Float(_) | ty::Error | ty::Infer(_) | - ty::Param(..) | ty::Never | ty::Foreign(..) => return self + + ty::Bool | + ty::Char | + ty::Str | + ty::Int(_) | + ty::Uint(_) | + ty::Float(_) | + ty::Error | + ty::Infer(_) | + ty::Param(..) | + ty::Bound(..) | + ty::Never | + ty::Foreign(..) => return self }; if self.sty == sty { @@ -771,9 +781,19 @@ fn super_visit_with>(&self, visitor: &mut V) -> bool { data.visit_with(visitor) } ty::Opaque(_, ref substs) => substs.visit_with(visitor), - ty::Bool | ty::Char | ty::Str | ty::Int(_) | - ty::Uint(_) | ty::Float(_) | ty::Error | ty::Infer(_) | - ty::Param(..) | ty::Never | ty::Foreign(..) => false, + + ty::Bool | + ty::Char | + ty::Str | + ty::Int(_) | + ty::Uint(_) | + ty::Float(_) | + ty::Error | + ty::Infer(_) | + ty::Bound(..) | + ty::Param(..) | + ty::Never | + ty::Foreign(..) => false, } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 62e38ad9bfa..25f7496e893 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -188,6 +188,9 @@ pub enum TyKind<'tcx> { /// A type parameter; for example, `T` in `fn f(x: T) {} Param(ParamTy), + /// Bound type variable, used only when preparing a trait query. + Bound(BoundTy), + /// A type variable used during type checking. Infer(InferTy), @@ -1219,9 +1222,6 @@ pub enum InferTy { FreshTy(u32), FreshIntTy(u32), FreshFloatTy(u32), - - /// Bound type variable, used only when preparing a trait query. - BoundTy(BoundTy), } newtype_index! { @@ -1232,9 +1232,28 @@ pub struct BoundTyIndex { .. } pub struct BoundTy { pub level: DebruijnIndex, pub var: BoundTyIndex, + pub kind: BoundTyKind, } -impl_stable_hash_for!(struct BoundTy { level, var }); +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +pub enum BoundTyKind { + Anon, + Param(InternedString), +} + +impl_stable_hash_for!(struct BoundTy { level, var, kind }); +impl_stable_hash_for!(enum self::BoundTyKind { Anon, Param(a) }); + +impl BoundTy { + pub fn new(level: DebruijnIndex, var: BoundTyIndex) -> Self { + debug_assert_eq!(ty::INNERMOST, level); + BoundTy { + level, + var, + kind: BoundTyKind::Anon, + } + } +} /// A `ProjectionPredicate` for an `ExistentialTraitRef`. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] @@ -1865,6 +1884,7 @@ pub fn regions(&self) -> Vec> { Tuple(..) | Foreign(..) | Param(_) | + Bound(..) | Infer(_) | Error => { vec![] @@ -1930,7 +1950,7 @@ pub fn is_trivially_sized(&self, tcx: TyCtxt<'_, '_, 'tcx>) -> bool { ty::Infer(ty::TyVar(_)) => false, - ty::Infer(ty::BoundTy(_)) | + ty::Bound(_) | ty::Infer(ty::FreshTy(_)) | ty::Infer(ty::FreshIntTy(_)) | ty::Infer(ty::FreshFloatTy(_)) => diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 02b5d36ecce..87c2c9b6005 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -556,7 +556,7 @@ pub fn is_identity(&self) -> bool { self.value.substs.iter().zip(BoundTyIndex::new(0)..).all(|(kind, cvar)| { match kind.unpack() { UnpackedKind::Type(ty) => match ty.sty { - ty::Infer(ty::BoundTy(ref b)) => cvar == b.var, + ty::Bound(ref b) => cvar == b.var, _ => false, }, diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 00a1bfaacd7..0a758285a29 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -951,7 +951,7 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Can refer to a type which may drop. // FIXME(eddyb) check this against a ParamEnv. - ty::Dynamic(..) | ty::Projection(..) | ty::Param(_) | + ty::Dynamic(..) | ty::Projection(..) | ty::Param(_) | ty::Bound(..) | ty::Opaque(..) | ty::Infer(_) | ty::Error => true, ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"), diff --git a/src/librustc/ty/walk.rs b/src/librustc/ty/walk.rs index 47fbfba8774..284c595ee2d 100644 --- a/src/librustc/ty/walk.rs +++ b/src/librustc/ty/walk.rs @@ -82,7 +82,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) { match parent_ty.sty { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str | ty::Infer(_) | ty::Param(_) | ty::Never | ty::Error | - ty::Foreign(..) => { + ty::Bound(..) | ty::Foreign(..) => { } ty::Array(ty, len) => { push_const(stack, len); diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 27747970f76..eb97f1177af 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -258,6 +258,7 @@ fn compute(&mut self, ty0: Ty<'tcx>) -> bool { ty::GeneratorWitness(..) | ty::Never | ty::Param(_) | + ty::Bound(..) | ty::Foreign(..) => { // WfScalar, WfParameter, etc } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index abdd7fd8d40..320fee5638e 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -16,7 +16,7 @@ use ty::{BrAnon, BrEnv, BrFresh, BrNamed}; use ty::{Bool, Char, Adt}; use ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr}; -use ty::{Param, RawPtr, Ref, Never, Tuple}; +use ty::{Param, Bound, RawPtr, Ref, Never, Tuple}; use ty::{Closure, Generator, GeneratorWitness, Foreign, Projection, Opaque}; use ty::{UnnormalizedProjection, Dynamic, Int, Uint, Infer}; use ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind}; @@ -976,7 +976,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ty::TyVar(_) => write!(f, "_"), ty::IntVar(_) => write!(f, "{}", "{integer}"), ty::FloatVar(_) => write!(f, "{}", "{float}"), - ty::BoundTy(_) => write!(f, "_"), ty::FreshTy(v) => write!(f, "FreshTy({})", v), ty::FreshIntTy(v) => write!(f, "FreshIntTy({})", v), ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v) @@ -988,7 +987,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ty::TyVar(ref v) => write!(f, "{:?}", v), ty::IntVar(ref v) => write!(f, "{:?}", v), ty::FloatVar(ref v) => write!(f, "{:?}", v), - ty::BoundTy(v) => write!(f, "?{:?}", v.var.index()), ty::FreshTy(v) => write!(f, "FreshTy({:?})", v), ty::FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v), ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v) @@ -1119,6 +1117,19 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { Infer(infer_ty) => write!(f, "{}", infer_ty), Error => write!(f, "[type error]"), Param(ref param_ty) => write!(f, "{}", param_ty), + Bound(bound_ty) => { + match bound_ty.kind { + ty::BoundTyKind::Anon => { + if bound_ty.level == ty::INNERMOST { + write!(f, "?{}", bound_ty.var.index()) + } else { + write!(f, "?{}_{}", bound_ty.level.index(), bound_ty.var.index()) + } + } + + ty::BoundTyKind::Param(p) => write!(f, "{}", p), + } + } Adt(def, substs) => cx.parameterized(f, substs, def.did, &[]), Dynamic(data, r) => { let r = r.print_to_string(cx); diff --git a/src/librustc_codegen_llvm/debuginfo/type_names.rs b/src/librustc_codegen_llvm/debuginfo/type_names.rs index f5abb527e43..eb5ae81b218 100644 --- a/src/librustc_codegen_llvm/debuginfo/type_names.rs +++ b/src/librustc_codegen_llvm/debuginfo/type_names.rs @@ -173,6 +173,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, ty::Infer(_) | ty::UnnormalizedProjection(..) | ty::Projection(..) | + ty::Bound(..) | ty::Opaque(..) | ty::GeneratorWitness(..) | ty::Param(_) => { diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 5197876f921..2e19b441d0e 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -718,6 +718,7 @@ fn check_type_for_ffi(&self, ty::Param(..) | ty::Infer(..) | + ty::Bound(..) | ty::Error | ty::Closure(..) | ty::Generator(..) | diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index 4c4d56c8938..9d69a5669b1 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -382,6 +382,7 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String) { self.push_type_params(substs, iter::empty(), output); } ty::Error | + ty::Bound(..) | ty::Infer(_) | ty::UnnormalizedProjection(..) | ty::Projection(..) | diff --git a/src/librustc_traits/chalk_context.rs b/src/librustc_traits/chalk_context.rs index 5d6badf1202..bf252053199 100644 --- a/src/librustc_traits/chalk_context.rs +++ b/src/librustc_traits/chalk_context.rs @@ -506,6 +506,7 @@ fn assemble_clauses_from_assoc_ty_values<'tcx>( ty::GeneratorWitness(..) | ty::UnnormalizedProjection(..) | ty::Infer(..) | + ty::Bound(..) | ty::Error => { bug!("unexpected type {:?}", ty) } diff --git a/src/librustc_traits/dropck_outlives.rs b/src/librustc_traits/dropck_outlives.rs index 2ad7ab7c4d9..af64522f183 100644 --- a/src/librustc_traits/dropck_outlives.rs +++ b/src/librustc_traits/dropck_outlives.rs @@ -274,7 +274,7 @@ fn dtorck_constraint_for_ty<'a, 'gcx, 'tcx>( ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"), - ty::Infer(..) | ty::Error => { + ty::Bound(..) | ty::Infer(..) | ty::Error => { // By the time this code runs, all type variables ought to // be fully resolved. Err(NoSolution) diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index c71898f73ec..052ca37b313 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -93,6 +93,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) { ty::GeneratorWitness(..) | ty::UnnormalizedProjection(..) | ty::Infer(..) | + ty::Bound(..) | ty::Error => { bug!("unexpected type {:?}", ty); } diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index e0ee26cba08..3f0a3531244 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -128,7 +128,7 @@ fn pointer_kind(&self, t: Ty<'tcx>, span: Span) -> ty::Opaque(def_id, substs) => Some(PointerKind::OfOpaque(def_id, substs)), ty::Param(ref p) => Some(PointerKind::OfParam(p)), // Insufficient type information. - ty::Infer(_) => None, + ty::Bound(..) | ty::Infer(_) => None, ty::Bool | ty::Char | ty::Int(..) | ty::Uint(..) | ty::Float(_) | ty::Array(..) | ty::GeneratorWitness(..) | diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 3e523c0c7f5..b11b034ee13 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -338,6 +338,7 @@ fn add_constraints_from_ty(&mut self, ty::UnnormalizedProjection(..) | ty::GeneratorWitness(..) | + ty::Bound(..) | ty::Infer(..) => { bug!("unexpected type encountered in \ variance inference: {}", diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 88240e844ed..8391db9a37d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2733,6 +2733,7 @@ fn clean(&self, cx: &DocContext) -> Type { ty::Closure(..) | ty::Generator(..) => Tuple(vec![]), // FIXME(pcwalton) + ty::Bound(..) => panic!("Bound"), ty::UnnormalizedProjection(..) => panic!("UnnormalizedProjection"), ty::GeneratorWitness(..) => panic!("GeneratorWitness"), ty::Infer(..) => panic!("Infer"), -- 2.44.0