Skip to content

Commit b11b2e8

Browse files
committed
---
yaml --- r: 159683 b: refs/heads/auto c: d7bb01e h: refs/heads/master i: 159681: 49c478b 159679: 50a5ce3 v: v3
1 parent a8528ff commit b11b2e8

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: d93921b348f37d10850c5f9b077300158a623e35
13+
refs/heads/auto: d7bb01eb52d6b3b40084450d99eb928d74d25d6e
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/middle/traits/select.rs

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

30+
use middle::fast_reject;
3031
use middle::mem_categorization::Typer;
3132
use middle::subst::{Subst, Substs, VecPerParamSpace};
3233
use middle::ty;
@@ -1767,12 +1768,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17671768
obligation: &Obligation)
17681769
-> Result<Substs, ()>
17691770
{
1771+
let impl_trait_ref = ty::impl_trait_ref(self.tcx(),
1772+
impl_def_id).unwrap();
1773+
1774+
// Before we create the substitutions and everything, first
1775+
// consider a "quick reject". This avoids creating more types
1776+
// and so forth that we need to.
1777+
if self.fast_reject_trait_refs(obligation, &*impl_trait_ref) {
1778+
return Err(());
1779+
}
1780+
17701781
let impl_substs = util::fresh_substs_for_impl(self.infcx,
17711782
obligation.cause.span,
17721783
impl_def_id);
17731784

1774-
let impl_trait_ref = ty::impl_trait_ref(self.tcx(),
1775-
impl_def_id).unwrap();
17761785
let impl_trait_ref = impl_trait_ref.subst(self.tcx(),
17771786
&impl_substs);
17781787

@@ -1782,6 +1791,29 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17821791
}
17831792
}
17841793

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

0 commit comments

Comments
 (0)