Skip to content

Commit 3e88b5b

Browse files
committed
Rote changes to fix fallout throughout the compiler from splitting the
predicates and renaming some things.
1 parent 3764699 commit 3e88b5b

File tree

20 files changed

+180
-149
lines changed

20 files changed

+180
-149
lines changed

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pub fn overlapping_impls(infcx: &InferCtxt,
283283
/// Creates predicate obligations from the generic bounds.
284284
pub fn predicates_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
285285
cause: ObligationCause<'tcx>,
286-
generic_bounds: &ty::GenericBounds<'tcx>)
286+
generic_bounds: &ty::InstantiatedPredicates<'tcx>)
287287
-> PredicateObligations<'tcx>
288288
{
289289
util::predicates_for_generics(tcx, cause, 0, generic_bounds)

src/librustc/middle/traits/object_safety.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ fn trait_has_sized_self<'tcx>(tcx: &ty::ctxt<'tcx>,
130130
// Search for a predicate like `Self : Sized` amongst the trait bounds.
131131
let trait_def = ty::lookup_trait_def(tcx, trait_def_id);
132132
let free_substs = ty::construct_free_substs(tcx, &trait_def.generics, ast::DUMMY_NODE_ID);
133-
let predicates = trait_def.generics.to_bounds(tcx, &free_substs).predicates.into_vec();
133+
134+
let trait_predicates = ty::lookup_predicates(tcx, trait_def_id);
135+
let predicates = trait_predicates.instantiate(tcx, &free_substs).predicates.into_vec();
136+
134137
elaborate_predicates(tcx, predicates)
135138
.any(|predicate| {
136139
match predicate {

src/librustc/middle/traits/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ fn assemble_candidates_from_trait_def<'cx,'tcx>(
561561
};
562562

563563
// If so, extract what we know from the trait and try to come up with a good answer.
564-
let trait_def = ty::lookup_trait_def(selcx.tcx(), trait_ref.def_id);
565-
let bounds = trait_def.generics.to_bounds(selcx.tcx(), trait_ref.substs);
564+
let trait_predicates = ty::lookup_predicates(selcx.tcx(), trait_ref.def_id);
565+
let bounds = trait_predicates.instantiate(selcx.tcx(), trait_ref.substs);
566566
assemble_candidates_from_predicates(selcx, obligation, obligation_trait_ref,
567567
candidate_set, bounds.predicates.into_vec());
568568
}

src/librustc/middle/traits/select.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
923923
projection_trait_ref={}",
924924
projection_trait_ref.repr(self.tcx()));
925925

926-
let trait_def = ty::lookup_trait_def(self.tcx(), projection_trait_ref.def_id);
927-
let bounds = trait_def.generics.to_bounds(self.tcx(), projection_trait_ref.substs);
926+
let trait_predicates = ty::lookup_predicates(self.tcx(), projection_trait_ref.def_id);
927+
let bounds = trait_predicates.instantiate(self.tcx(), projection_trait_ref.substs);
928928
debug!("match_projection_obligation_against_bounds_from_trait: \
929929
bounds={}",
930930
bounds.repr(self.tcx()));
@@ -2314,8 +2314,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23142314
snapshot: &infer::CombinedSnapshot)
23152315
-> VecPerParamSpace<PredicateObligation<'tcx>>
23162316
{
2317-
let impl_generics = ty::lookup_item_type(self.tcx(), impl_def_id).generics;
2318-
let bounds = impl_generics.to_bounds(self.tcx(), impl_substs);
2317+
let impl_bounds = ty::lookup_predicates(self.tcx(), impl_def_id);
2318+
let bounds = impl_bounds.instantiate(self.tcx(), impl_substs);
23192319
let normalized_bounds =
23202320
project::normalize_with_depth(self, cause.clone(), recursion_depth, &bounds);
23212321
let normalized_bounds =

src/librustc/middle/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'tcx> fmt::Debug for super::VtableObjectData<'tcx> {
290290
pub fn predicates_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
291291
cause: ObligationCause<'tcx>,
292292
recursion_depth: uint,
293-
generic_bounds: &ty::GenericBounds<'tcx>)
293+
generic_bounds: &ty::InstantiatedPredicates<'tcx>)
294294
-> VecPerParamSpace<PredicateObligation<'tcx>>
295295
{
296296
debug!("predicates_for_generics(generic_bounds={})",

src/librustc/middle/ty.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,10 +2153,12 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
21532153
match ty::impl_or_trait_item(cx, method_def_id) {
21542154
MethodTraitItem(ref method_ty) => {
21552155
let method_generics = &method_ty.generics;
2156+
let method_bounds = &method_ty.predicates;
21562157
construct_parameter_environment(
21572158
cx,
21582159
method.span,
21592160
method_generics,
2161+
method_bounds,
21602162
method.pe_body().id)
21612163
}
21622164
TypeTraitItem(_) => {
@@ -2188,10 +2190,12 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
21882190
match ty::impl_or_trait_item(cx, method_def_id) {
21892191
MethodTraitItem(ref method_ty) => {
21902192
let method_generics = &method_ty.generics;
2193+
let method_bounds = &method_ty.predicates;
21912194
construct_parameter_environment(
21922195
cx,
21932196
method.span,
21942197
method_generics,
2198+
method_bounds,
21952199
method.pe_body().id)
21962200
}
21972201
TypeTraitItem(_) => {
@@ -2214,11 +2218,13 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
22142218
ast::ItemFn(_, _, _, _, ref body) => {
22152219
// We assume this is a function.
22162220
let fn_def_id = ast_util::local_def(id);
2217-
let fn_pty = ty::lookup_item_type(cx, fn_def_id);
2221+
let fn_scheme = lookup_item_type(cx, fn_def_id);
2222+
let fn_predicates = lookup_predicates(cx, fn_def_id);
22182223

22192224
construct_parameter_environment(cx,
22202225
item.span,
2221-
&fn_pty.generics,
2226+
&fn_scheme.generics,
2227+
&fn_predicates,
22222228
body.id)
22232229
}
22242230
ast::ItemEnum(..) |
@@ -2227,8 +2233,13 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
22272233
ast::ItemConst(..) |
22282234
ast::ItemStatic(..) => {
22292235
let def_id = ast_util::local_def(id);
2230-
let pty = ty::lookup_item_type(cx, def_id);
2231-
construct_parameter_environment(cx, item.span, &pty.generics, id)
2236+
let scheme = lookup_item_type(cx, def_id);
2237+
let predicates = lookup_predicates(cx, def_id);
2238+
construct_parameter_environment(cx,
2239+
item.span,
2240+
&scheme.generics,
2241+
&predicates,
2242+
id)
22322243
}
22332244
_ => {
22342245
cx.sess.span_bug(item.span,
@@ -6320,7 +6331,7 @@ pub fn empty_parameter_environment<'a,'tcx>(cx: &'a ctxt<'tcx>) -> ParameterEnvi
63206331
/// parameters in the same way, this only has an effect on regions.
63216332
pub fn construct_free_substs<'a,'tcx>(
63226333
tcx: &'a ctxt<'tcx>,
6323-
generics: &ty::Generics<'tcx>,
6334+
generics: &Generics<'tcx>,
63246335
free_id: ast::NodeId)
63256336
-> Substs<'tcx>
63266337
{
@@ -6365,6 +6376,7 @@ pub fn construct_parameter_environment<'a,'tcx>(
63656376
tcx: &'a ctxt<'tcx>,
63666377
span: Span,
63676378
generics: &ty::Generics<'tcx>,
6379+
generic_predicates: &ty::GenericPredicates<'tcx>,
63686380
free_id: ast::NodeId)
63696381
-> ParameterEnvironment<'a, 'tcx>
63706382
{
@@ -6379,7 +6391,7 @@ pub fn construct_parameter_environment<'a,'tcx>(
63796391
// Compute the bounds on Self and the type parameters.
63806392
//
63816393

6382-
let bounds = generics.to_bounds(tcx, &free_substs);
6394+
let bounds = generic_predicates.instantiate(tcx, &free_substs);
63836395
let bounds = liberate_late_bound_regions(tcx, free_id_outlive, &ty::Binder(bounds));
63846396
let predicates = bounds.predicates.into_vec();
63856397

@@ -7013,8 +7025,7 @@ impl<'tcx,T:RegionEscape> RegionEscape for VecPerParamSpace<T> {
70137025

70147026
impl<'tcx> RegionEscape for TypeScheme<'tcx> {
70157027
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
7016-
self.ty.has_regions_escaping_depth(depth) ||
7017-
self.generics.has_regions_escaping_depth(depth)
7028+
self.ty.has_regions_escaping_depth(depth)
70187029
}
70197030
}
70207031

@@ -7024,7 +7035,7 @@ impl RegionEscape for Region {
70247035
}
70257036
}
70267037

7027-
impl<'tcx> RegionEscape for Generics<'tcx> {
7038+
impl<'tcx> RegionEscape for GenericPredicates<'tcx> {
70287039
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
70297040
self.predicates.has_regions_escaping_depth(depth)
70307041
}
@@ -7133,7 +7144,7 @@ impl<'tcx> HasProjectionTypes for ClosureUpvar<'tcx> {
71337144
}
71347145
}
71357146

7136-
impl<'tcx> HasProjectionTypes for ty::GenericBounds<'tcx> {
7147+
impl<'tcx> HasProjectionTypes for ty::InstantiatedPredicates<'tcx> {
71377148
fn has_projection_types(&self) -> bool {
71387149
self.predicates.has_projection_types()
71397150
}

src/librustc/middle/ty_fold.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Generics<'tcx> {
400400
ty::Generics {
401401
types: self.types.fold_with(folder),
402402
regions: self.regions.fold_with(folder),
403+
}
404+
}
405+
}
406+
407+
impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> {
408+
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::GenericPredicates<'tcx> {
409+
ty::GenericPredicates {
403410
predicates: self.predicates.fold_with(folder),
404411
}
405412
}
@@ -440,9 +447,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
440447
}
441448
}
442449

443-
impl<'tcx> TypeFoldable<'tcx> for ty::GenericBounds<'tcx> {
444-
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::GenericBounds<'tcx> {
445-
ty::GenericBounds {
450+
impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
451+
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::InstantiatedPredicates<'tcx> {
452+
ty::InstantiatedPredicates {
446453
predicates: self.predicates.fold_with(folder),
447454
}
448455
}

src/librustc_typeck/check/_match.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,14 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx ast::Pat,
467467
}
468468
};
469469

470-
instantiate_path(pcx.fcx, path, ty::lookup_item_type(tcx, enum_def_id),
471-
None, def, pat.span, pat.id);
470+
instantiate_path(pcx.fcx,
471+
path,
472+
ty::lookup_item_type(tcx, enum_def_id),
473+
&ty::lookup_predicates(tcx, enum_def_id),
474+
None,
475+
def,
476+
pat.span,
477+
pat.id);
472478

473479
let pat_ty = fcx.node_ty(pat.id);
474480
demand::eqtype(fcx, pat.span, expected, pat_ty);
@@ -499,6 +505,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
499505
.map_or_else(|| def.def_id(), |(enum_def, _)| enum_def);
500506

501507
let ctor_scheme = ty::lookup_item_type(tcx, enum_def);
508+
let ctor_predicates = ty::lookup_predicates(tcx, enum_def);
502509
let path_scheme = if ty::is_fn_ty(ctor_scheme.ty) {
503510
let fn_ret = ty::assert_no_late_bound_regions(tcx, &ty::ty_fn_ret(ctor_scheme.ty));
504511
ty::TypeScheme {
@@ -508,7 +515,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
508515
} else {
509516
ctor_scheme
510517
};
511-
instantiate_path(pcx.fcx, path, path_scheme, None, def, pat.span, pat.id);
518+
instantiate_path(pcx.fcx, path, path_scheme, &ctor_predicates, None, def, pat.span, pat.id);
512519

513520
let pat_ty = fcx.node_ty(pat.id);
514521
demand::eqtype(fcx, pat.span, expected, pat_ty);

src/librustc_typeck/check/compare_method.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
205205
// however, because we want to replace all late-bound regions with
206206
// region variables.
207207
let impl_bounds =
208-
impl_m.generics.to_bounds(tcx, impl_to_skol_substs);
208+
impl_m.predicates.instantiate(tcx, impl_to_skol_substs);
209209

210210
let (impl_bounds, _) =
211211
infcx.replace_late_bound_regions_with_fresh_var(
@@ -216,7 +216,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
216216
impl_bounds.repr(tcx));
217217

218218
// Normalize the associated types in the trait_bounds.
219-
let trait_bounds = trait_m.generics.to_bounds(tcx, &trait_to_skol_substs);
219+
let trait_bounds = trait_m.predicates.instantiate(tcx, &trait_to_skol_substs);
220220

221221
// Obtain the predicate split predicate sets for each.
222222
let trait_pred = trait_bounds.predicates.split();

src/librustc_typeck/check/dropck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'tcx>(
131131

132132
let dtor_typescheme = ty::lookup_item_type(rcx.tcx(), impl_did);
133133
let dtor_generics = dtor_typescheme.generics;
134+
let dtor_predicates = ty::lookup_predicates(rcx.tcx(), impl_did);
134135

135-
let has_pred_of_interest = dtor_generics.predicates.iter().any(|pred| {
136+
let has_pred_of_interest = dtor_predicates.predicates.iter().any(|pred| {
136137
// In `impl<T> Drop where ...`, we automatically
137138
// assume some predicate will be meaningful and thus
138139
// represents a type through which we could reach

src/librustc_typeck/check/method/confirm.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct InstantiatedMethodSig<'tcx> {
4646

4747
/// Generic bounds on the method's parameters which must be added
4848
/// as pending obligations.
49-
method_bounds: ty::GenericBounds<'tcx>,
49+
method_predicates: ty::InstantiatedPredicates<'tcx>,
5050
}
5151

5252
pub fn confirm<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
@@ -99,15 +99,15 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
9999

100100
// Create the final signature for the method, replacing late-bound regions.
101101
let InstantiatedMethodSig {
102-
method_sig, all_substs, method_bounds
102+
method_sig, all_substs, method_predicates
103103
} = self.instantiate_method_sig(&pick, all_substs);
104104
let method_self_ty = method_sig.inputs[0];
105105

106106
// Unify the (adjusted) self type with what the method expects.
107107
self.unify_receivers(self_ty, method_self_ty);
108108

109109
// Add any trait/regions obligations specified on the method's type parameters.
110-
self.add_obligations(&pick, &all_substs, &method_bounds);
110+
self.add_obligations(&pick, &all_substs, &method_predicates);
111111

112112
// Create the final `MethodCallee`.
113113
let fty = ty::mk_bare_fn(self.tcx(), None, self.tcx().mk_bare_fn(ty::BareFnTy {
@@ -416,18 +416,19 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
416416
// that obligation is not necessarily satisfied. (In the
417417
// future, it would be.) But we know that the true `Self` DOES implement
418418
// the trait. So we just delete this requirement. Hack hack hack.
419-
let mut method_bounds = pick.method_ty.generics.to_bounds(self.tcx(), &all_substs);
419+
let mut method_predicates = pick.method_ty.predicates.instantiate(self.tcx(), &all_substs);
420420
match pick.kind {
421421
probe::ObjectPick(..) => {
422-
assert_eq!(method_bounds.predicates.get_slice(subst::SelfSpace).len(), 1);
423-
method_bounds.predicates.pop(subst::SelfSpace);
422+
assert_eq!(method_predicates.predicates.get_slice(subst::SelfSpace).len(), 1);
423+
method_predicates.predicates.pop(subst::SelfSpace);
424424
}
425425
_ => { }
426426
}
427-
let method_bounds = self.fcx.normalize_associated_types_in(self.span, &method_bounds);
427+
let method_predicates = self.fcx.normalize_associated_types_in(self.span,
428+
&method_predicates);
428429

429-
debug!("method_bounds after subst = {}",
430-
method_bounds.repr(self.tcx()));
430+
debug!("method_predicates after subst = {}",
431+
method_predicates.repr(self.tcx()));
431432

432433
// Instantiate late-bound regions and substitute the trait
433434
// parameters into the method type to get the actual method type.
@@ -446,22 +447,22 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
446447
InstantiatedMethodSig {
447448
method_sig: method_sig,
448449
all_substs: all_substs,
449-
method_bounds: method_bounds,
450+
method_predicates: method_predicates,
450451
}
451452
}
452453

453454
fn add_obligations(&mut self,
454455
pick: &probe::Pick<'tcx>,
455456
all_substs: &subst::Substs<'tcx>,
456-
method_bounds: &ty::GenericBounds<'tcx>) {
457-
debug!("add_obligations: pick={} all_substs={} method_bounds={}",
457+
method_predicates: &ty::InstantiatedPredicates<'tcx>) {
458+
debug!("add_obligations: pick={} all_substs={} method_predicates={}",
458459
pick.repr(self.tcx()),
459460
all_substs.repr(self.tcx()),
460-
method_bounds.repr(self.tcx()));
461+
method_predicates.repr(self.tcx()));
461462

462463
self.fcx.add_obligations_for_parameters(
463464
traits::ObligationCause::misc(self.span, self.fcx.body_id),
464-
method_bounds);
465+
method_predicates);
465466

466467
self.fcx.add_default_region_param_bounds(
467468
all_substs,

src/librustc_typeck/check/method/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
221221
//
222222
// Note that as the method comes from a trait, it should not have
223223
// any late-bound regions appearing in its bounds.
224-
let method_bounds = fcx.instantiate_bounds(span, trait_ref.substs, &method_ty.generics);
224+
let method_bounds = fcx.instantiate_bounds(span, trait_ref.substs, &method_ty.predicates);
225225
assert!(!method_bounds.has_escaping_regions());
226226
fcx.add_obligations_for_parameters(
227227
traits::ObligationCause::misc(span, fcx.body_id),

src/librustc_typeck/check/method/probe.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,9 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
666666
debug!("assemble_projection_candidates: projection_trait_ref={}",
667667
projection_trait_ref.repr(self.tcx()));
668668

669-
let trait_def = ty::lookup_trait_def(self.tcx(), projection_trait_ref.def_id);
670-
let bounds = trait_def.generics.to_bounds(self.tcx(), projection_trait_ref.substs);
669+
let trait_predicates = ty::lookup_predicates(self.tcx(),
670+
projection_trait_ref.def_id);
671+
let bounds = trait_predicates.instantiate(self.tcx(), projection_trait_ref.substs);
671672
let predicates = bounds.predicates.into_vec();
672673
debug!("assemble_projection_candidates: predicates={}",
673674
predicates.repr(self.tcx()));
@@ -943,8 +944,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
943944
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
944945

945946
// Check whether the impl imposes obligations we have to worry about.
946-
let impl_generics = ty::lookup_item_type(self.tcx(), impl_def_id).generics;
947-
let impl_bounds = impl_generics.to_bounds(self.tcx(), substs);
947+
let impl_bounds = ty::lookup_predicates(self.tcx(), impl_def_id);
948+
let impl_bounds = impl_bounds.instantiate(self.tcx(), substs);
948949
let traits::Normalized { value: impl_bounds,
949950
obligations: norm_obligations } =
950951
traits::normalize(selcx, cause.clone(), &impl_bounds);

0 commit comments

Comments
 (0)