Skip to content

Commit b4f910d

Browse files
committed
just use full-normalization when for the impl trait ref
This seems better because I want to avoid the situation where unresolved inference variables make it into the environment. On the other hand, I am not 100% sure that this is correct. My assumption was that the WF check should ensure that this normalization can succeed. But it occurs to me that the WF checks may need to make use of the `specializes` predicate themselves, and hence we may have a kind of cycle here (this is a bigger problem with spec in any case that we need to resolve). On the other hand, this should just cause extra errors I think, so it seems like a safe thing to attempt. Certainly all tests pass.
1 parent d9bc860 commit b4f910d

File tree

1 file changed

+10
-15
lines changed
  • src/librustc/traits/specialize

1 file changed

+10
-15
lines changed

src/librustc/traits/specialize/mod.rs

+10-15
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, Reveal, ObligationCause, Normalized};
28+
use traits::{self, Reveal, ObligationCause};
2929
use ty::{self, TyCtxt, TypeFoldable};
3030
use syntax_pos::DUMMY_SP;
3131

@@ -187,21 +187,16 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
187187
.subst(tcx, &penv.free_substs);
188188

189189
// Create a infcx, taking the predicates of impl1 as assumptions:
190-
let result = tcx.infer_ctxt(None, Some(penv), Reveal::ExactMatch).enter(|mut infcx| {
191-
// Normalize the trait reference, adding any obligations
192-
// that arise into the impl1 assumptions.
193-
let Normalized { value: impl1_trait_ref, obligations: normalization_obligations } = {
194-
let selcx = &mut SelectionContext::new(&infcx);
195-
traits::normalize(selcx, ObligationCause::dummy(), &impl1_trait_ref)
196-
};
197-
infcx.parameter_environment.caller_bounds.extend(normalization_obligations.into_iter().map(|o| {
198-
match tcx.lift_to_global(&o.predicate) {
199-
Some(predicate) => predicate,
200-
None => {
201-
bug!("specializes: obligation `{:?}` has inference types/regions", o);
190+
let result = tcx.infer_ctxt(None, Some(penv), Reveal::ExactMatch).enter(|infcx| {
191+
// Normalize the trait reference. The WF rules ought to ensure
192+
// that this always succeeds.
193+
let impl1_trait_ref =
194+
match traits::fully_normalize(&infcx, ObligationCause::dummy(), &impl1_trait_ref) {
195+
Ok(impl1_trait_ref) => impl1_trait_ref,
196+
Err(err) => {
197+
bug!("failed to fully normalize {:?}: {:?}", impl1_trait_ref, err);
202198
}
203-
}
204-
}));
199+
};
205200

206201
// Attempt to prove that impl2 applies, given all of the above.
207202
fulfill_implication(&infcx, impl1_trait_ref, impl2_def_id).is_ok()

0 commit comments

Comments
 (0)