Skip to content

Commit 48dc6e2

Browse files
committed
register infer-ok obligations properly
Or at least, more properly. I think I left one or two FIXMEs still in there. cc #32730
1 parent 19c1a47 commit 48dc6e2

File tree

13 files changed

+89
-119
lines changed

13 files changed

+89
-119
lines changed

src/librustc/infer/sub.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::combine::CombineFields;
1211
use super::SubregionOrigin;
12+
use super::combine::CombineFields;
1313
use super::type_variable::{SubtypeOf, SupertypeOf};
1414

1515
use ty::{self, Ty, TyCtxt};
@@ -117,6 +117,7 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>
117117
// error messages.
118118
let origin = SubregionOrigin::Subtype(self.fields.trace.clone());
119119
self.fields.infcx.region_vars.make_subregion(origin, a, b);
120+
120121
Ok(a)
121122
}
122123

src/librustc/traits/fulfill.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,8 @@ fn process_predicate<'a, 'gcx, 'tcx>(
520520

521521
ty::Predicate::Equate(ref binder) => {
522522
match selcx.infcx().equality_predicate(&obligation.cause, binder) {
523-
Ok(InferOk { obligations, .. }) => {
524-
// FIXME(#32730) propagate obligations
525-
assert!(obligations.is_empty());
526-
Ok(Some(Vec::new()))
523+
Ok(InferOk { obligations, value: () }) => {
524+
Ok(Some(obligations))
527525
},
528526
Err(_) => Err(CodeSelectionError(Unimplemented)),
529527
}

src/librustc/traits/project.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ fn project_and_unify_type<'cx, 'gcx, 'tcx>(
210210

211211
let infcx = selcx.infcx();
212212
match infcx.eq_types(true, &obligation.cause, normalized_ty, obligation.predicate.ty) {
213-
Ok(InferOk { obligations: inferred_obligations, .. }) => {
214-
// FIXME(#32730) once obligations are generated in inference, drop this assertion
215-
assert!(inferred_obligations.is_empty());
213+
Ok(InferOk { obligations: inferred_obligations, value: () }) => {
216214
obligations.extend(inferred_obligations);
217215
Ok(Some(obligations))
218216
},
@@ -847,9 +845,10 @@ fn assemble_candidates_from_predicates<'cx, 'gcx, 'tcx, I>(
847845
obligation.cause.clone(),
848846
data_poly_trait_ref,
849847
obligation_poly_trait_ref)
850-
// FIXME(#32730) once obligations are propagated from unification in
851-
// inference, drop this assertion
852-
.map(|InferOk { obligations, .. }| assert!(obligations.is_empty()))
848+
.map(|InferOk { obligations: _, value: () }| {
849+
// FIXME(#32730) -- do we need to take obligations
850+
// into account in any way? At the moment, no.
851+
})
853852
.is_ok()
854853
});
855854

@@ -1184,12 +1183,10 @@ fn confirm_fn_pointer_candidate<'cx, 'gcx, 'tcx>(
11841183
fn_pointer_vtable: VtableFnPointerData<'tcx, PredicateObligation<'tcx>>)
11851184
-> Progress<'tcx>
11861185
{
1187-
// FIXME(#32730) drop this assertion once obligations are propagated from inference (fn pointer
1188-
// vtable nested obligations ONLY come from unification in inference)
1189-
assert!(fn_pointer_vtable.nested.is_empty());
11901186
let fn_type = selcx.infcx().shallow_resolve(fn_pointer_vtable.fn_ty);
11911187
let sig = fn_type.fn_sig();
11921188
confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
1189+
.with_addl_obligations(fn_pointer_vtable.nested)
11931190
}
11941191

11951192
fn confirm_closure_candidate<'cx, 'gcx, 'tcx>(
@@ -1266,8 +1263,6 @@ fn confirm_param_env_candidate<'cx, 'gcx, 'tcx>(
12661263
let trait_ref = obligation.predicate.trait_ref;
12671264
match infcx.match_poly_projection_predicate(cause, poly_projection, trait_ref) {
12681265
Ok(InferOk { value: ty_match, obligations }) => {
1269-
// FIXME(#32730) once obligations are generated in inference, drop this assertion
1270-
assert!(obligations.is_empty());
12711266
Progress {
12721267
ty: ty_match.value,
12731268
obligations: obligations,

src/librustc/traits/select.rs

-3
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
418418
None => Ok(None),
419419
Some(candidate) => {
420420
let mut candidate = self.confirm_candidate(obligation, candidate)?;
421-
// FIXME(#32730) remove this assertion once inferred obligations are propagated
422-
// from inference
423-
assert!(self.inferred_obligations.len() == 0);
424421
let inferred_obligations = (*self.inferred_obligations).into_iter().cloned();
425422
candidate.nested_obligations_mut().extend(inferred_obligations);
426423
Ok(Some(candidate))

src/librustc_mir/transform/type_check.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -324,20 +324,25 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
324324
traits::ObligationCause::misc(span, self.body_id)
325325
}
326326

327-
fn sub_types(&self, span: Span, sup: Ty<'tcx>, sub: Ty<'tcx>)
327+
pub fn register_infer_ok_obligations<T>(&mut self, infer_ok: InferOk<'tcx, T>) -> T {
328+
for obligation in infer_ok.obligations {
329+
self.fulfillment_cx.register_predicate_obligation(self.infcx, obligation);
330+
}
331+
infer_ok.value
332+
}
333+
334+
fn sub_types(&mut self, sup: Ty<'tcx>, sub: Ty<'tcx>)
328335
-> infer::UnitResult<'tcx>
329336
{
330-
self.infcx.sub_types(false, &self.misc(span), sup, sub)
331-
// FIXME(#32730) propagate obligations
332-
.map(|InferOk { obligations, .. }| assert!(obligations.is_empty()))
337+
self.infcx.sub_types(false, &self.misc(self.last_span), sup, sub)
338+
.map(|ok| self.register_infer_ok_obligations(ok))
333339
}
334340

335-
fn eq_types(&self, span: Span, a: Ty<'tcx>, b: Ty<'tcx>)
341+
fn eq_types(&mut self, span: Span, a: Ty<'tcx>, b: Ty<'tcx>)
336342
-> infer::UnitResult<'tcx>
337343
{
338344
self.infcx.eq_types(false, &self.misc(span), a, b)
339-
// FIXME(#32730) propagate obligations
340-
.map(|InferOk { obligations, .. }| assert!(obligations.is_empty()))
345+
.map(|ok| self.register_infer_ok_obligations(ok))
341346
}
342347

343348
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
@@ -352,7 +357,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
352357
let lv_ty = lv.ty(mir, tcx).to_ty(tcx);
353358
let rv_ty = rv.ty(mir, tcx);
354359
if let Some(rv_ty) = rv_ty {
355-
if let Err(terr) = self.sub_types(self.last_span, rv_ty, lv_ty) {
360+
if let Err(terr) = self.sub_types(rv_ty, lv_ty) {
356361
span_mirbug!(self, stmt, "bad assignment ({:?} = {:?}): {:?}",
357362
lv_ty, rv_ty, terr);
358363
}
@@ -413,7 +418,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
413418
} => {
414419
let lv_ty = location.ty(mir, tcx).to_ty(tcx);
415420
let rv_ty = value.ty(mir, tcx);
416-
if let Err(terr) = self.sub_types(self.last_span, rv_ty, lv_ty) {
421+
if let Err(terr) = self.sub_types(rv_ty, lv_ty) {
417422
span_mirbug!(self, term, "bad DropAndReplace ({:?} = {:?}): {:?}",
418423
lv_ty, rv_ty, terr);
419424
}
@@ -430,7 +435,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
430435
}
431436
TerminatorKind::SwitchInt { ref discr, switch_ty, .. } => {
432437
let discr_ty = discr.ty(mir, tcx).to_ty(tcx);
433-
if let Err(terr) = self.sub_types(self.last_span, discr_ty, switch_ty) {
438+
if let Err(terr) = self.sub_types(discr_ty, switch_ty) {
434439
span_mirbug!(self, term, "bad SwitchInt ({:?} on {:?}): {:?}",
435440
switch_ty, discr_ty, terr);
436441
}
@@ -492,7 +497,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
492497
}
493498
}
494499

495-
fn check_call_dest(&self,
500+
fn check_call_dest(&mut self,
496501
mir: &Mir<'tcx>,
497502
term: &Terminator<'tcx>,
498503
sig: &ty::FnSig<'tcx>,
@@ -501,7 +506,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
501506
match *destination {
502507
Some((ref dest, _)) => {
503508
let dest_ty = dest.ty(mir, tcx).to_ty(tcx);
504-
if let Err(terr) = self.sub_types(self.last_span, sig.output, dest_ty) {
509+
if let Err(terr) = self.sub_types(sig.output, dest_ty) {
505510
span_mirbug!(self, term,
506511
"call dest mismatch ({:?} <- {:?}): {:?}",
507512
dest_ty, sig.output, terr);
@@ -516,7 +521,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
516521
}
517522
}
518523

519-
fn check_call_inputs(&self,
524+
fn check_call_inputs(&mut self,
520525
mir: &Mir<'tcx>,
521526
term: &Terminator<'tcx>,
522527
sig: &ty::FnSig<'tcx>,
@@ -529,7 +534,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
529534
}
530535
for (n, (fn_arg, op_arg)) in sig.inputs.iter().zip(args).enumerate() {
531536
let op_arg_ty = op_arg.ty(mir, self.tcx());
532-
if let Err(terr) = self.sub_types(self.last_span, op_arg_ty, fn_arg) {
537+
if let Err(terr) = self.sub_types(op_arg_ty, fn_arg) {
533538
span_mirbug!(self, term, "bad arg #{:?} ({:?} <- {:?}): {:?}",
534539
n, fn_arg, op_arg_ty, terr);
535540
}
@@ -547,7 +552,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
547552
}
548553
}
549554

550-
fn check_box_free_inputs(&self,
555+
fn check_box_free_inputs(&mut self,
551556
mir: &Mir<'tcx>,
552557
term: &Terminator<'tcx>,
553558
sig: &ty::FnSig<'tcx>,
@@ -584,7 +589,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
584589
}
585590
};
586591

587-
if let Err(terr) = self.sub_types(self.last_span, arg_ty, pointee_ty) {
592+
if let Err(terr) = self.sub_types(arg_ty, pointee_ty) {
588593
span_mirbug!(self, term, "bad box_free arg ({:?} <- {:?}): {:?}",
589594
pointee_ty, arg_ty, terr);
590595
}

src/librustc_typeck/check/_match.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use rustc::hir::{self, PatKind};
1212
use rustc::hir::def::{Def, CtorKind};
1313
use rustc::hir::pat_util::EnumerateAndAdjustIterator;
14-
use rustc::infer::{self, InferOk};
14+
use rustc::infer;
1515
use rustc::traits::ObligationCauseCode;
1616
use rustc::ty::{self, Ty, TypeFoldable, LvaluePreference};
1717
use check::{FnCtxt, Expectation, Diverges};
@@ -462,9 +462,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
462462

463463
let result = if is_if_let_fallback {
464464
self.eq_types(true, &cause, arm_ty, result_ty)
465-
.map(|InferOk { obligations, .. }| {
466-
// FIXME(#32730) propagate obligations
467-
assert!(obligations.is_empty());
465+
.map(|infer_ok| {
466+
self.register_infer_ok_obligations(infer_ok);
468467
arm_ty
469468
})
470469
} else if i == 0 {

src/librustc_typeck/check/coercion.rs

+6-27
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,11 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
118118
let trace = TypeTrace::types(&self.cause, false, a, b);
119119
if self.use_lub {
120120
self.lub(false, trace, &a, &b)
121-
.map(|InferOk { value, obligations }| {
122-
// FIXME(#32730) propagate obligations
123-
assert!(obligations.is_empty());
124-
value
125-
})
121+
.map(|ok| self.register_infer_ok_obligations(ok))
126122
} else {
127123
self.sub(false, trace, &a, &b)
128124
.map(|InferOk { value, obligations }| {
129-
// FIXME(#32730) propagate obligations
130-
assert!(obligations.is_empty());
125+
self.fcx.register_predicates(obligations);
131126
value
132127
})
133128
}
@@ -678,21 +673,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
678673
(&ty::TyFnDef(a_def_id, a_substs, a_fty), &ty::TyFnDef(b_def_id, b_substs, b_fty)) => {
679674
// The signature must always match.
680675
let fty = self.lub(true, trace.clone(), &a_fty, &b_fty)
681-
.map(|InferOk { value, obligations }| {
682-
// FIXME(#32730) propagate obligations
683-
assert!(obligations.is_empty());
684-
value
685-
})?;
676+
.map(|ok| self.register_infer_ok_obligations(ok))?;
686677

687678
if a_def_id == b_def_id {
688679
// Same function, maybe the parameters match.
689680
let substs = self.commit_if_ok(|_| {
690681
self.lub(true, trace.clone(), &a_substs, &b_substs)
691-
.map(|InferOk { value, obligations }| {
692-
// FIXME(#32730) propagate obligations
693-
assert!(obligations.is_empty());
694-
value
695-
})
682+
.map(|ok| self.register_infer_ok_obligations(ok))
696683
});
697684

698685
if let Ok(substs) = substs {
@@ -761,11 +748,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
761748
if !noop {
762749
return self.commit_if_ok(|_| {
763750
self.lub(true, trace.clone(), &prev_ty, &new_ty)
764-
.map(|InferOk { value, obligations }| {
765-
// FIXME(#32730) propagate obligations
766-
assert!(obligations.is_empty());
767-
value
768-
})
751+
.map(|ok| self.register_infer_ok_obligations(ok))
769752
});
770753
}
771754
}
@@ -778,11 +761,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
778761
} else {
779762
self.commit_if_ok(|_| {
780763
self.lub(true, trace, &prev_ty, &new_ty)
781-
.map(|InferOk { value, obligations }| {
782-
// FIXME(#32730) propagate obligations
783-
assert!(obligations.is_empty());
784-
value
785-
})
764+
.map(|ok| self.register_infer_ok_obligations(ok))
786765
})
787766
}
788767
}

src/librustc_typeck/check/compare_method.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,11 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
810810
debug!("compare_const_impl: trait_ty={:?}", trait_ty);
811811

812812
infcx.sub_types(false, &cause, impl_ty, trait_ty)
813-
.map(|InferOk { obligations, .. }| {
814-
// FIXME(#32730) propagate obligations
815-
assert!(obligations.is_empty())
816-
})
813+
.map(|InferOk { obligations, value: () }| {
814+
for obligation in obligations {
815+
fulfillment_cx.register_predicate_obligation(&infcx, obligation);
816+
}
817+
})
817818
});
818819

819820
if let Err(terr) = err {

src/librustc_typeck/check/demand.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2323
pub fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
2424
let cause = self.misc(sp);
2525
match self.sub_types(false, &cause, actual, expected) {
26-
Ok(InferOk { obligations, .. }) => {
27-
// FIXME(#32730) propagate obligations
28-
assert!(obligations.is_empty());
26+
Ok(InferOk { obligations, value: () }) => {
27+
self.register_predicates(obligations);
2928
},
3029
Err(e) => {
3130
self.report_mismatched_types(&cause, expected, actual, e);
@@ -43,9 +42,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4342
actual: Ty<'tcx>)
4443
{
4544
match self.eq_types(false, cause, actual, expected) {
46-
Ok(InferOk { obligations, .. }) => {
47-
// FIXME(#32730) propagate obligations
48-
assert!(obligations.is_empty());
45+
Ok(InferOk { obligations, value: () }) => {
46+
self.register_predicates(obligations);
4947
},
5048
Err(e) => {
5149
self.report_mismatched_types(cause, expected, actual, e);

src/librustc_typeck/check/method/confirm.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,8 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
331331

332332
fn unify_receivers(&mut self, self_ty: Ty<'tcx>, method_self_ty: Ty<'tcx>) {
333333
match self.sub_types(false, &self.misc(self.span), self_ty, method_self_ty) {
334-
Ok(InferOk { obligations, .. }) => {
335-
// FIXME(#32730) propagate obligations
336-
assert!(obligations.is_empty());
334+
Ok(InferOk { obligations, value: () }) => {
335+
self.register_predicates(obligations);
337336
}
338337
Err(_) => {
339338
span_bug!(self.span,

src/librustc_typeck/check/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use super::suggest;
1616
use check::FnCtxt;
1717
use hir::def_id::DefId;
1818
use hir::def::Def;
19+
use rustc::infer::InferOk;
1920
use rustc::ty::subst::{Subst, Substs};
2021
use rustc::traits::{self, ObligationCause};
2122
use rustc::ty::{self, Ty, ToPolyTraitRef, TraitRef, TypeFoldable};
22-
use rustc::infer::InferOk;
2323
use rustc::util::nodemap::FxHashSet;
2424
use syntax::ast;
2525
use syntax_pos::Span;
@@ -1035,7 +1035,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10351035
&ObligationCause::dummy(),
10361036
self_ty,
10371037
probe.xform_self_ty) {
1038-
Ok(InferOk { obligations, .. }) => {
1038+
Ok(InferOk { obligations, value: () }) => {
10391039
// FIXME(#32730) propagate obligations
10401040
assert!(obligations.is_empty())
10411041
}

0 commit comments

Comments
 (0)