Skip to content

Commit d1d16c9

Browse files
committed
rustc: rename ProjectionMode and its variant to be more memorable.
1 parent 8787a12 commit d1d16c9

File tree

30 files changed

+83
-109
lines changed

30 files changed

+83
-109
lines changed

src/librustc/infer/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use ty::{self, Ty, TyCtxt};
3434
use ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
3535
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
3636
use ty::relate::{Relate, RelateResult, TypeRelation};
37-
use traits::{self, PredicateObligations, ProjectionMode};
37+
use traits::{self, PredicateObligations, Reveal};
3838
use rustc_data_structures::unify::{self, UnificationTable};
3939
use std::cell::{Cell, RefCell, Ref, RefMut};
4040
use std::fmt;
@@ -147,8 +147,8 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
147147

148148
// Sadly, the behavior of projection varies a bit depending on the
149149
// stage of compilation. The specifics are given in the
150-
// documentation for `ProjectionMode`.
151-
projection_mode: ProjectionMode,
150+
// documentation for `Reveal`.
151+
projection_mode: Reveal,
152152

153153
// When an error occurs, we want to avoid reporting "derived"
154154
// errors that are due to this original failure. Normally, we
@@ -459,15 +459,15 @@ pub struct InferCtxtBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
459459
arenas: ty::CtxtArenas<'tcx>,
460460
tables: Option<RefCell<ty::Tables<'tcx>>>,
461461
param_env: Option<ty::ParameterEnvironment<'gcx>>,
462-
projection_mode: ProjectionMode,
462+
projection_mode: Reveal,
463463
normalize: bool
464464
}
465465

466466
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
467467
pub fn infer_ctxt(self,
468468
tables: Option<ty::Tables<'tcx>>,
469469
param_env: Option<ty::ParameterEnvironment<'gcx>>,
470-
projection_mode: ProjectionMode)
470+
projection_mode: Reveal)
471471
-> InferCtxtBuilder<'a, 'gcx, 'tcx> {
472472
InferCtxtBuilder {
473473
global_tcx: self,
@@ -479,7 +479,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
479479
}
480480
}
481481

482-
pub fn normalizing_infer_ctxt(self, projection_mode: ProjectionMode)
482+
pub fn normalizing_infer_ctxt(self, projection_mode: Reveal)
483483
-> InferCtxtBuilder<'a, 'gcx, 'tcx> {
484484
InferCtxtBuilder {
485485
global_tcx: self,
@@ -509,7 +509,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
509509
projection_cache: RefCell::new(traits::ProjectionCache::new()),
510510
reported_trait_errors: RefCell::new(FnvHashSet()),
511511
normalize: false,
512-
projection_mode: ProjectionMode::AnyFinal,
512+
projection_mode: Reveal::NotSpecializable,
513513
tainted_by_errors_flag: Cell::new(false),
514514
err_count_on_creation: self.sess.err_count(),
515515
obligations_in_snapshot: Cell::new(false),
@@ -641,7 +641,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
641641
return value;
642642
}
643643

644-
self.infer_ctxt(None, None, ProjectionMode::Any).enter(|infcx| {
644+
self.infer_ctxt(None, None, Reveal::All).enter(|infcx| {
645645
value.trans_normalize(&infcx)
646646
})
647647
}
@@ -659,7 +659,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
659659
return value;
660660
}
661661

662-
self.infer_ctxt(None, Some(env.clone()), ProjectionMode::Any).enter(|infcx| {
662+
self.infer_ctxt(None, Some(env.clone()), Reveal::All).enter(|infcx| {
663663
value.trans_normalize(&infcx)
664664
})
665665
}
@@ -736,7 +736,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
736736
Ok(self.tcx.erase_regions(&result))
737737
}
738738

739-
pub fn projection_mode(&self) -> ProjectionMode {
739+
pub fn projection_mode(&self) -> Reveal {
740740
self.projection_mode
741741
}
742742

src/librustc/middle/intrinsicck.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use dep_graph::DepNode;
1212
use hir::def::Def;
1313
use hir::def_id::DefId;
1414
use infer::InferCtxt;
15-
use traits::ProjectionMode;
15+
use traits::Reveal;
1616
use ty::{self, Ty, TyCtxt};
1717
use ty::layout::{LayoutError, Pointer, SizeSkeleton};
1818

@@ -36,7 +36,7 @@ struct ItemVisitor<'a, 'tcx: 'a> {
3636
impl<'a, 'tcx> ItemVisitor<'a, 'tcx> {
3737
fn visit_const(&mut self, item_id: ast::NodeId, expr: &hir::Expr) {
3838
let param_env = ty::ParameterEnvironment::for_item(self.tcx, item_id);
39-
self.tcx.infer_ctxt(None, Some(param_env), ProjectionMode::Any).enter(|infcx| {
39+
self.tcx.infer_ctxt(None, Some(param_env), Reveal::All).enter(|infcx| {
4040
let mut visitor = ExprVisitor {
4141
infcx: &infcx
4242
};
@@ -114,7 +114,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
114114
impl<'a, 'tcx, 'v> Visitor<'v> for ItemVisitor<'a, 'tcx> {
115115
// const, static and N in [T; N].
116116
fn visit_expr(&mut self, expr: &hir::Expr) {
117-
self.tcx.infer_ctxt(None, None, ProjectionMode::Any).enter(|infcx| {
117+
self.tcx.infer_ctxt(None, None, Reveal::All).enter(|infcx| {
118118
let mut visitor = ExprVisitor {
119119
infcx: &infcx
120120
};
@@ -144,7 +144,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ItemVisitor<'a, 'tcx> {
144144
span_bug!(s, "intrinsicck: closure outside of function")
145145
}
146146
let param_env = ty::ParameterEnvironment::for_item(self.tcx, id);
147-
self.tcx.infer_ctxt(None, Some(param_env), ProjectionMode::Any).enter(|infcx| {
147+
self.tcx.infer_ctxt(None, Some(param_env), Reveal::All).enter(|infcx| {
148148
let mut visitor = ExprVisitor {
149149
infcx: &infcx
150150
};

src/librustc/middle/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ use dep_graph::DepNode;
113113
use hir::def::*;
114114
use hir::pat_util;
115115
use ty::{self, TyCtxt, ParameterEnvironment};
116-
use traits::{self, ProjectionMode};
116+
use traits::{self, Reveal};
117117
use ty::subst::Subst;
118118
use lint;
119119
use util::nodemap::NodeMap;
@@ -1484,7 +1484,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14841484
let param_env = ParameterEnvironment::for_item(self.ir.tcx, id);
14851485
let t_ret_subst = t_ret.subst(self.ir.tcx, &param_env.free_substs);
14861486
let is_nil = self.ir.tcx.infer_ctxt(None, Some(param_env),
1487-
ProjectionMode::Any).enter(|infcx| {
1487+
Reveal::All).enter(|infcx| {
14881488
let cause = traits::ObligationCause::dummy();
14891489
traits::fully_normalize(&infcx, cause, &t_ret_subst).unwrap().is_nil()
14901490
});

src/librustc/traits/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub use self::coherence::OrphanCheckErr;
3232
pub use self::fulfill::{FulfillmentContext, GlobalFulfilledPredicates, RegionObligation};
3333
pub use self::project::MismatchedProjectionTypes;
3434
pub use self::project::{normalize, normalize_projection_type, Normalized};
35-
pub use self::project::{ProjectionCache, ProjectionCacheSnapshot, ProjectionMode};
35+
pub use self::project::{ProjectionCache, ProjectionCacheSnapshot, Reveal};
3636
pub use self::object_safety::ObjectSafetyViolation;
3737
pub use self::object_safety::MethodViolationCode;
3838
pub use self::select::{EvaluationCache, SelectionContext, SelectionCache};
@@ -435,7 +435,7 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
435435

436436
let elaborated_env = unnormalized_env.with_caller_bounds(predicates);
437437

438-
tcx.infer_ctxt(None, Some(elaborated_env), ProjectionMode::AnyFinal).enter(|infcx| {
438+
tcx.infer_ctxt(None, Some(elaborated_env), Reveal::NotSpecializable).enter(|infcx| {
439439
let predicates = match fully_normalize(&infcx, cause,
440440
&infcx.parameter_environment.caller_bounds) {
441441
Ok(predicates) => predicates,

src/librustc/traits/project.rs

+8-32
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::rc::Rc;
3838
/// Depending on the stage of compilation, we want projection to be
3939
/// more or less conservative.
4040
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
41-
pub enum ProjectionMode {
41+
pub enum Reveal {
4242
/// FIXME (#32205)
4343
/// At coherence-checking time, we're still constructing the
4444
/// specialization graph, and thus we only project
@@ -67,7 +67,7 @@ pub enum ProjectionMode {
6767
///
6868
/// The projection would succeed if `Output` had been defined
6969
/// directly in the impl for `u8`.
70-
Topmost,
70+
ExactMatch,
7171

7272
/// At type-checking time, we refuse to project any associated
7373
/// type that is marked `default`. Non-`default` ("final") types
@@ -91,36 +91,12 @@ pub enum ProjectionMode {
9191
/// fn main() {
9292
/// let <() as Assoc>::Output = true;
9393
/// }
94-
AnyFinal,
94+
NotSpecializable,
9595

9696
/// At trans time, all projections will succeed.
97-
Any,
97+
All,
9898
}
9999

100-
impl ProjectionMode {
101-
pub fn is_topmost(&self) -> bool {
102-
match *self {
103-
ProjectionMode::Topmost => true,
104-
_ => false,
105-
}
106-
}
107-
108-
pub fn is_any_final(&self) -> bool {
109-
match *self {
110-
ProjectionMode::AnyFinal => true,
111-
_ => false,
112-
}
113-
}
114-
115-
pub fn is_any(&self) -> bool {
116-
match *self {
117-
ProjectionMode::Any => true,
118-
_ => false,
119-
}
120-
}
121-
}
122-
123-
124100
pub type PolyProjectionObligation<'tcx> =
125101
Obligation<'tcx, ty::PolyProjectionPredicate<'tcx>>;
126102

@@ -902,7 +878,7 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
902878

903879
candidate_set.vec.push(ProjectionTyCandidate::Select);
904880
}
905-
super::VtableImpl(ref impl_data) if !selcx.projection_mode().is_any() => {
881+
super::VtableImpl(ref impl_data) if selcx.projection_mode() != Reveal::All => {
906882
// We have to be careful when projecting out of an
907883
// impl because of specialization. If we are not in
908884
// trans (i.e., projection mode is not "any"), and the
@@ -1008,7 +984,7 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
1008984
}
1009985
super::VtableImpl(_) => {
1010986
// In trans mode, we can just project out of impls, no prob.
1011-
assert!(selcx.projection_mode().is_any());
987+
assert!(selcx.projection_mode() == Reveal::All);
1012988
candidate_set.vec.push(ProjectionTyCandidate::Select);
1013989
}
1014990
super::VtableParam(..) => {
@@ -1332,7 +1308,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
13321308
/// starting from the given impl.
13331309
///
13341310
/// Based on the "projection mode", this lookup may in fact only examine the
1335-
/// topmost impl. See the comments for `ProjectionMode` for more details.
1311+
/// topmost impl. See the comments for `Reveal` for more details.
13361312
fn assoc_ty_def<'cx, 'gcx, 'tcx>(
13371313
selcx: &SelectionContext<'cx, 'gcx, 'tcx>,
13381314
impl_def_id: DefId,
@@ -1341,7 +1317,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>(
13411317
{
13421318
let trait_def_id = selcx.tcx().impl_trait_ref(impl_def_id).unwrap().def_id;
13431319

1344-
if selcx.projection_mode().is_topmost() {
1320+
if selcx.projection_mode() == Reveal::ExactMatch {
13451321
let impl_node = specialization_graph::Node::Impl(impl_def_id);
13461322
for item in impl_node.items(selcx.tcx()) {
13471323
if let ty::TypeTraitItem(assoc_ty) = item {

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use super::{PredicateObligation, TraitObligation, ObligationCause};
2323
use super::{ObligationCauseCode, BuiltinDerivedObligation, ImplDerivedObligation};
2424
use super::{SelectionError, Unimplemented, OutputTypeParameterMismatch};
2525
use super::{ObjectCastObligation, Obligation};
26-
use super::ProjectionMode;
26+
use super::Reveal;
2727
use super::TraitNotObjectSafe;
2828
use super::Selection;
2929
use super::SelectionResult;
@@ -343,7 +343,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
343343
self.infcx
344344
}
345345

346-
pub fn projection_mode(&self) -> ProjectionMode {
346+
pub fn projection_mode(&self) -> Reveal {
347347
self.infcx.projection_mode()
348348
}
349349

src/librustc/traits/specialize/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use hir::def_id::DefId;
2525
use infer::{InferCtxt, TypeOrigin};
2626
use middle::region;
2727
use ty::subst::{Subst, Substs};
28-
use traits::{self, ProjectionMode, ObligationCause, Normalized};
28+
use traits::{self, Reveal, ObligationCause, Normalized};
2929
use ty::{self, TyCtxt};
3030
use syntax_pos::DUMMY_SP;
3131

@@ -151,7 +151,7 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
151151
.unwrap()
152152
.subst(tcx, &penv.free_substs);
153153

154-
let result = tcx.normalizing_infer_ctxt(ProjectionMode::Topmost).enter(|mut infcx| {
154+
let result = tcx.normalizing_infer_ctxt(Reveal::ExactMatch).enter(|mut infcx| {
155155
// Normalize the trait reference, adding any obligations
156156
// that arise into the impl1 assumptions.
157157
let Normalized { value: impl1_trait_ref, obligations: normalization_obligations } = {

src/librustc/traits/specialize/specialization_graph.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::rc::Rc;
1414
use super::{OverlapError, specializes};
1515

1616
use hir::def_id::DefId;
17-
use traits::{self, ProjectionMode};
17+
use traits::{self, Reveal};
1818
use ty::{self, TyCtxt, ImplOrTraitItem, TraitDef, TypeFoldable};
1919
use ty::fast_reject::{self, SimplifiedType};
2020
use syntax::ast::Name;
@@ -111,8 +111,7 @@ impl<'a, 'gcx, 'tcx> Children {
111111
let possible_sibling = *slot;
112112

113113
let tcx = tcx.global_tcx();
114-
let (le, ge) = tcx.infer_ctxt(None, None,
115-
ProjectionMode::Topmost).enter(|infcx| {
114+
let (le, ge) = tcx.infer_ctxt(None, None, Reveal::ExactMatch).enter(|infcx| {
116115
let overlap = traits::overlapping_impls(&infcx,
117116
possible_sibling,
118117
impl_def_id);

src/librustc/ty/util.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use hir::def_id::DefId;
1414
use ty::subst;
1515
use infer::InferCtxt;
1616
use hir::pat_util;
17-
use traits::{self, ProjectionMode};
17+
use traits::{self, Reveal};
1818
use ty::{self, Ty, TyCtxt, TypeAndMut, TypeFlags, TypeFoldable};
1919
use ty::{Disr, ParameterEnvironment};
2020
use ty::fold::TypeVisitor;
@@ -137,8 +137,7 @@ impl<'tcx> ParameterEnvironment<'tcx> {
137137
self_type: Ty<'tcx>, span: Span)
138138
-> Result<(),CopyImplementationError> {
139139
// FIXME: (@jroesch) float this code up
140-
tcx.infer_ctxt(None, Some(self.clone()),
141-
ProjectionMode::Topmost).enter(|infcx| {
140+
tcx.infer_ctxt(None, Some(self.clone()), Reveal::ExactMatch).enter(|infcx| {
142141
let adt = match self_type.sty {
143142
ty::TyStruct(struct_def, substs) => {
144143
for field in struct_def.all_fields() {
@@ -533,7 +532,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
533532
param_env: &ParameterEnvironment<'tcx>,
534533
bound: ty::BuiltinBound, span: Span) -> bool
535534
{
536-
tcx.infer_ctxt(None, Some(param_env.clone()), ProjectionMode::Topmost).enter(|infcx| {
535+
tcx.infer_ctxt(None, Some(param_env.clone()), Reveal::ExactMatch).enter(|infcx| {
537536
traits::type_known_to_meet_builtin_bound(&infcx, self, bound, span)
538537
})
539538
}

src/librustc_const_eval/check_match.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
2525
use rustc::middle::expr_use_visitor as euv;
2626
use rustc::middle::mem_categorization::{cmt};
2727
use rustc::hir::pat_util::*;
28-
use rustc::traits::ProjectionMode;
28+
use rustc::traits::Reveal;
2929
use rustc::ty::*;
3030
use rustc::ty;
3131
use std::cmp::Ordering;
@@ -1133,7 +1133,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
11331133
let pat_ty = cx.tcx.node_id_to_type(p.id);
11341134
//FIXME: (@jroesch) this code should be floated up as well
11351135
cx.tcx.infer_ctxt(None, Some(cx.param_env.clone()),
1136-
ProjectionMode::AnyFinal).enter(|infcx| {
1136+
Reveal::NotSpecializable).enter(|infcx| {
11371137
if infcx.type_moves_by_default(pat_ty, pat.span) {
11381138
check_move(p, sub.as_ref().map(|p| &**p));
11391139
}
@@ -1149,7 +1149,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
11491149
fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>,
11501150
guard: &hir::Expr) {
11511151
cx.tcx.infer_ctxt(None, Some(cx.param_env.clone()),
1152-
ProjectionMode::AnyFinal).enter(|infcx| {
1152+
Reveal::NotSpecializable).enter(|infcx| {
11531153
let mut checker = MutationChecker {
11541154
cx: cx,
11551155
};

src/librustc_const_eval/eval.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::hir::def_id::DefId;
2424
use rustc::hir::pat_util::def_to_path;
2525
use rustc::ty::{self, Ty, TyCtxt, subst};
2626
use rustc::ty::util::IntTypeExt;
27-
use rustc::traits::ProjectionMode;
27+
use rustc::traits::Reveal;
2828
use rustc::util::common::ErrorReported;
2929
use rustc::util::nodemap::NodeMap;
3030
use rustc::lint;
@@ -1055,7 +1055,7 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10551055
trait_ref);
10561056

10571057
tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id());
1058-
tcx.infer_ctxt(None, None, ProjectionMode::AnyFinal).enter(|infcx| {
1058+
tcx.infer_ctxt(None, None, Reveal::NotSpecializable).enter(|infcx| {
10591059
let mut selcx = traits::SelectionContext::new(&infcx);
10601060
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(),
10611061
trait_ref.to_poly_trait_predicate());
@@ -1073,9 +1073,9 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10731073
};
10741074

10751075
// NOTE: this code does not currently account for specialization, but when
1076-
// it does so, it should hook into the ProjectionMode to determine when the
1076+
// it does so, it should hook into the Reveal to determine when the
10771077
// constant should resolve; this will also require plumbing through to this
1078-
// function whether we are in "trans mode" to pick the right ProjectionMode
1078+
// function whether we are in "trans mode" to pick the right Reveal
10791079
// when constructing the inference context above.
10801080
match selection {
10811081
traits::VtableImpl(ref impl_data) => {

0 commit comments

Comments
 (0)