Skip to content

Commit 64d4ed3

Browse files
committed
move ParamEnv methods from ty/util to ty/mod
1 parent 6d0f931 commit 64d4ed3

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

src/librustc/ty/mod.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use mir::Mir;
2929
use mir::interpret::{GlobalId, Value, PrimVal};
3030
use mir::GeneratorLayout;
3131
use session::CrateDisambiguator;
32-
use traits;
32+
use traits::{self, Reveal};
3333
use ty;
3434
use ty::subst::{Subst, Substs};
3535
use ty::util::{IntTypeExt, Discr};
@@ -1396,6 +1396,48 @@ pub struct ParamEnv<'tcx> {
13961396
}
13971397

13981398
impl<'tcx> ParamEnv<'tcx> {
1399+
/// Construct a trait environment suitable for contexts where
1400+
/// there are no where clauses in scope. Hidden types (like `impl
1401+
/// Trait`) are left hidden, so this is suitable for ordinary
1402+
/// type-checking.
1403+
pub fn empty() -> Self {
1404+
Self::new(ty::Slice::empty(), Reveal::UserFacing, ty::UniverseIndex::ROOT)
1405+
}
1406+
1407+
/// Construct a trait environment with no where clauses in scope
1408+
/// where the values of all `impl Trait` and other hidden types
1409+
/// are revealed. This is suitable for monomorphized, post-typeck
1410+
/// environments like trans or doing optimizations.
1411+
///
1412+
/// NB. If you want to have predicates in scope, use `ParamEnv::new`,
1413+
/// or invoke `param_env.with_reveal_all()`.
1414+
pub fn reveal_all() -> Self {
1415+
Self::new(ty::Slice::empty(), Reveal::All, ty::UniverseIndex::ROOT)
1416+
}
1417+
1418+
/// Construct a trait environment with the given set of predicates.
1419+
pub fn new(caller_bounds: &'tcx ty::Slice<ty::Predicate<'tcx>>,
1420+
reveal: Reveal,
1421+
universe: ty::UniverseIndex)
1422+
-> Self {
1423+
ty::ParamEnv { caller_bounds, reveal, universe }
1424+
}
1425+
1426+
/// Returns a new parameter environment with the same clauses, but
1427+
/// which "reveals" the true results of projections in all cases
1428+
/// (even for associated types that are specializable). This is
1429+
/// the desired behavior during trans and certain other special
1430+
/// contexts; normally though we want to use `Reveal::UserFacing`,
1431+
/// which is the default.
1432+
pub fn with_reveal_all(self) -> Self {
1433+
ty::ParamEnv { reveal: Reveal::All, ..self }
1434+
}
1435+
1436+
/// Returns this same environment but with no caller bounds.
1437+
pub fn without_caller_bounds(self) -> Self {
1438+
ty::ParamEnv { caller_bounds: ty::Slice::empty(), ..self }
1439+
}
1440+
13991441
/// Creates a suitable environment in which to perform trait
14001442
/// queries on the given value. This will either be `self` *or*
14011443
/// the empty environment, depending on whether `value` references

src/librustc/ty/util.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use hir::map::{DefPathData, Node};
1616
use hir;
1717
use ich::NodeIdHashingMode;
1818
use middle::const_val::ConstVal;
19-
use traits::{self, Reveal};
19+
use traits;
2020
use ty::{self, Ty, TyCtxt, TypeFoldable};
2121
use ty::fold::TypeVisitor;
2222
use ty::subst::{Subst, UnpackedKind};
@@ -182,48 +182,6 @@ pub enum Representability {
182182
}
183183

184184
impl<'tcx> ty::ParamEnv<'tcx> {
185-
/// Construct a trait environment suitable for contexts where
186-
/// there are no where clauses in scope. Hidden types (like `impl
187-
/// Trait`) are left hidden, so this is suitable for ordinary
188-
/// type-checking.
189-
pub fn empty() -> Self {
190-
Self::new(ty::Slice::empty(), Reveal::UserFacing, ty::UniverseIndex::ROOT)
191-
}
192-
193-
/// Construct a trait environment with no where clauses in scope
194-
/// where the values of all `impl Trait` and other hidden types
195-
/// are revealed. This is suitable for monomorphized, post-typeck
196-
/// environments like trans or doing optimizations.
197-
///
198-
/// NB. If you want to have predicates in scope, use `ParamEnv::new`,
199-
/// or invoke `param_env.with_reveal_all()`.
200-
pub fn reveal_all() -> Self {
201-
Self::new(ty::Slice::empty(), Reveal::All, ty::UniverseIndex::ROOT)
202-
}
203-
204-
/// Construct a trait environment with the given set of predicates.
205-
pub fn new(caller_bounds: &'tcx ty::Slice<ty::Predicate<'tcx>>,
206-
reveal: Reveal,
207-
universe: ty::UniverseIndex)
208-
-> Self {
209-
ty::ParamEnv { caller_bounds, reveal, universe }
210-
}
211-
212-
/// Returns a new parameter environment with the same clauses, but
213-
/// which "reveals" the true results of projections in all cases
214-
/// (even for associated types that are specializable). This is
215-
/// the desired behavior during trans and certain other special
216-
/// contexts; normally though we want to use `Reveal::UserFacing`,
217-
/// which is the default.
218-
pub fn with_reveal_all(self) -> Self {
219-
ty::ParamEnv { reveal: Reveal::All, ..self }
220-
}
221-
222-
/// Returns this same environment but with no caller bounds.
223-
pub fn without_caller_bounds(self) -> Self {
224-
ty::ParamEnv { caller_bounds: ty::Slice::empty(), ..self }
225-
}
226-
227185
pub fn can_type_implement_copy<'a>(self,
228186
tcx: TyCtxt<'a, 'tcx, 'tcx>,
229187
self_type: Ty<'tcx>, span: Span)

0 commit comments

Comments
 (0)