@@ -55,6 +55,7 @@ use std::{fmt, str};
5555
5656pub use crate :: ty:: diagnostics:: * ;
5757pub use rustc_type_ir:: InferTy :: * ;
58+ pub use rustc_type_ir:: RegionKind :: * ;
5859pub use rustc_type_ir:: TyKind :: * ;
5960pub use rustc_type_ir:: * ;
6061
@@ -80,7 +81,6 @@ pub use self::list::List;
8081pub use self :: parameterized:: ParameterizedOverTcx ;
8182pub use self :: rvalue_scopes:: RvalueScopes ;
8283pub use self :: sty:: BoundRegionKind :: * ;
83- pub use self :: sty:: RegionKind :: * ;
8484pub use self :: sty:: {
8585 Article , Binder , BoundRegion , BoundRegionKind , BoundTy , BoundTyKind , BoundVar ,
8686 BoundVariableKind , CanonicalPolyFnSig , ClosureSubsts , ClosureSubstsParts , ConstVid ,
@@ -1161,83 +1161,6 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
11611161 }
11621162}
11631163
1164- rustc_index:: newtype_index! {
1165- /// "Universes" are used during type- and trait-checking in the
1166- /// presence of `for<..>` binders to control what sets of names are
1167- /// visible. Universes are arranged into a tree: the root universe
1168- /// contains names that are always visible. Each child then adds a new
1169- /// set of names that are visible, in addition to those of its parent.
1170- /// We say that the child universe "extends" the parent universe with
1171- /// new names.
1172- ///
1173- /// To make this more concrete, consider this program:
1174- ///
1175- /// ```ignore (illustrative)
1176- /// struct Foo { }
1177- /// fn bar<T>(x: T) {
1178- /// let y: for<'a> fn(&'a u8, Foo) = ...;
1179- /// }
1180- /// ```
1181- ///
1182- /// The struct name `Foo` is in the root universe U0. But the type
1183- /// parameter `T`, introduced on `bar`, is in an extended universe U1
1184- /// -- i.e., within `bar`, we can name both `T` and `Foo`, but outside
1185- /// of `bar`, we cannot name `T`. Then, within the type of `y`, the
1186- /// region `'a` is in a universe U2 that extends U1, because we can
1187- /// name it inside the fn type but not outside.
1188- ///
1189- /// Universes are used to do type- and trait-checking around these
1190- /// "forall" binders (also called **universal quantification**). The
1191- /// idea is that when, in the body of `bar`, we refer to `T` as a
1192- /// type, we aren't referring to any type in particular, but rather a
1193- /// kind of "fresh" type that is distinct from all other types we have
1194- /// actually declared. This is called a **placeholder** type, and we
1195- /// use universes to talk about this. In other words, a type name in
1196- /// universe 0 always corresponds to some "ground" type that the user
1197- /// declared, but a type name in a non-zero universe is a placeholder
1198- /// type -- an idealized representative of "types in general" that we
1199- /// use for checking generic functions.
1200- pub struct UniverseIndex {
1201- derive [ HashStable ]
1202- DEBUG_FORMAT = "U{}" ,
1203- }
1204- }
1205-
1206- impl UniverseIndex {
1207- pub const ROOT : UniverseIndex = UniverseIndex :: from_u32 ( 0 ) ;
1208-
1209- /// Returns the "next" universe index in order -- this new index
1210- /// is considered to extend all previous universes. This
1211- /// corresponds to entering a `forall` quantifier. So, for
1212- /// example, suppose we have this type in universe `U`:
1213- ///
1214- /// ```ignore (illustrative)
1215- /// for<'a> fn(&'a u32)
1216- /// ```
1217- ///
1218- /// Once we "enter" into this `for<'a>` quantifier, we are in a
1219- /// new universe that extends `U` -- in this new universe, we can
1220- /// name the region `'a`, but that region was not nameable from
1221- /// `U` because it was not in scope there.
1222- pub fn next_universe ( self ) -> UniverseIndex {
1223- UniverseIndex :: from_u32 ( self . private . checked_add ( 1 ) . unwrap ( ) )
1224- }
1225-
1226- /// Returns `true` if `self` can name a name from `other` -- in other words,
1227- /// if the set of names in `self` is a superset of those in
1228- /// `other` (`self >= other`).
1229- pub fn can_name ( self , other : UniverseIndex ) -> bool {
1230- self . private >= other. private
1231- }
1232-
1233- /// Returns `true` if `self` cannot name some names from `other` -- in other
1234- /// words, if the set of names in `self` is a strict subset of
1235- /// those in `other` (`self < other`).
1236- pub fn cannot_name ( self , other : UniverseIndex ) -> bool {
1237- self . private < other. private
1238- }
1239- }
1240-
12411164/// The "placeholder index" fully defines a placeholder region, type, or const. Placeholders are
12421165/// identified by both a universe, as well as a name residing within that universe. Distinct bound
12431166/// regions/types/consts within the same universe simply have an unknown relationship to one
0 commit comments