Skip to content

Commit ae7916a

Browse files
committed
---
yaml --- r: 160131 b: refs/heads/issue-18208-method-dispatch-3-quick-reject c: 2009f85 h: refs/heads/master i: 160129: 10f496f 160127: 3989d9c v: v3
1 parent 6de229f commit ae7916a

File tree

2 files changed

+35
-3
lines changed
  • branches/issue-18208-method-dispatch-3-quick-reject/src/librustc/middle/traits

2 files changed

+35
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2828
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/issue-18208-method-dispatch-2: 9e1eae4fb9b6527315b4441cf8a0f5ca911d1671
3030
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
31-
refs/heads/issue-18208-method-dispatch-3-quick-reject: 7c2c232c55f8ca63f5308ea88c279fc70f4b8773
31+
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2

branches/issue-18208-method-dispatch-3-quick-reject/src/librustc/middle/traits/select.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use super::{VtableBuiltin, VtableImpl, VtableParam, VtableUnboxedClosure};
2121
use super::{VtableImplData, VtableParamData, VtableBuiltinData};
2222
use super::{util};
2323

24+
use middle::fast_reject;
2425
use middle::mem_categorization::Typer;
2526
use middle::subst::{Subst, Substs, VecPerParamSpace};
2627
use middle::ty;
@@ -1762,12 +1763,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17621763
obligation: &Obligation)
17631764
-> Result<Substs, ()>
17641765
{
1766+
let impl_trait_ref = ty::impl_trait_ref(self.tcx(),
1767+
impl_def_id).unwrap();
1768+
1769+
// Before we create the substitutions and everything, first
1770+
// consider a "quick reject". This avoids creating more types
1771+
// and so forth that we need to.
1772+
if self.fast_reject_trait_refs(obligation, &*impl_trait_ref) {
1773+
return Err(());
1774+
}
1775+
17651776
let impl_substs = util::fresh_substs_for_impl(self.infcx,
17661777
obligation.cause.span,
17671778
impl_def_id);
17681779

1769-
let impl_trait_ref = ty::impl_trait_ref(self.tcx(),
1770-
impl_def_id).unwrap();
17711780
let impl_trait_ref = impl_trait_ref.subst(self.tcx(),
17721781
&impl_substs);
17731782

@@ -1777,6 +1786,29 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17771786
}
17781787
}
17791788

1789+
fn fast_reject_trait_refs(&mut self,
1790+
obligation: &Obligation,
1791+
impl_trait_ref: &ty::TraitRef)
1792+
-> bool
1793+
{
1794+
// We can avoid creating type variables and doing the full
1795+
// substitution if we find that any of the input types, when
1796+
// simplified, do not match.
1797+
1798+
obligation.trait_ref.input_types().iter()
1799+
.zip(impl_trait_ref.input_types().iter())
1800+
.any(|(&obligation_ty, &impl_ty)| {
1801+
let simplified_obligation_ty =
1802+
fast_reject::simplify_type(self.tcx(), obligation_ty, true);
1803+
let simplified_impl_ty =
1804+
fast_reject::simplify_type(self.tcx(), impl_ty, false);
1805+
1806+
simplified_obligation_ty.is_some() &&
1807+
simplified_impl_ty.is_some() &&
1808+
simplified_obligation_ty != simplified_impl_ty
1809+
})
1810+
}
1811+
17801812
fn match_trait_refs(&mut self,
17811813
obligation: &Obligation,
17821814
trait_ref: Rc<ty::TraitRef>)

0 commit comments

Comments
 (0)