]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/util.rs
refactor `ParamEnv::empty(Reveal)` into two distinct methods
[rust.git] / src / librustc / ty / util.rs
index cbd9a1b8d4f932de801e58e65ec3364310348a4b..ca6817d992b6e2e41f67e7e4967054095d16bbf1 100644 (file)
@@ -183,9 +183,22 @@ pub enum Representability {
 
 impl<'tcx> ty::ParamEnv<'tcx> {
     /// Construct a trait environment suitable for contexts where
-    /// there are no where clauses in scope.
-    pub fn empty(reveal: Reveal) -> Self {
-        Self::new(ty::Slice::empty(), reveal, ty::UniverseIndex::ROOT)
+    /// there are no where clauses in scope. Hidden types (like `impl
+    /// Trait`) are left hidden, so this is suitable for ordinary
+    /// type-checking.
+    pub fn empty() -> Self {
+        Self::new(ty::Slice::empty(), Reveal::UserFacing, ty::UniverseIndex::ROOT)
+    }
+
+    /// Construct a trait environment with no where clauses in scope
+    /// where the values of all `impl Trait` and other hidden types
+    /// are revealed. This is suitable for monomorphized, post-typeck
+    /// environments like trans or doing optimizations.
+    ///
+    /// NB. If you want to have predicates in scope, use `ParamEnv::new`,
+    /// or invoke `param_env.with_reveal_all()`.
+    pub fn reveal_all() -> Self {
+        Self::new(ty::Slice::empty(), Reveal::All, ty::UniverseIndex::ROOT)
     }
 
     /// Construct a trait environment with the given set of predicates.
@@ -202,10 +215,15 @@ pub fn new(caller_bounds: &'tcx ty::Slice<ty::Predicate<'tcx>>,
     /// the desired behavior during trans and certain other special
     /// contexts; normally though we want to use `Reveal::UserFacing`,
     /// which is the default.
-    pub fn reveal_all(self) -> Self {
+    pub fn with_reveal_all(self) -> Self {
         ty::ParamEnv { reveal: Reveal::All, ..self }
     }
 
+    /// Returns this same environment but with no caller bounds.
+    pub fn without_caller_bounds(self) -> Self {
+        ty::ParamEnv { caller_bounds: ty::Slice::empty(), ..self }
+    }
+
     pub fn can_type_implement_copy<'a>(self,
                                        tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                        self_type: Ty<'tcx>, span: Span)