Skip to content

Commit 3362c7c

Browse files
committed
---
yaml --- r: 273137 b: refs/heads/beta c: 45f4bf1 h: refs/heads/master i: 273135: d67c8f6
1 parent 657ba74 commit 3362c7c

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 991f32a6cae575755a6991f594da377e593c94f3
26+
refs/heads/beta: 45f4bf112a422fe62b9152ecf557f8550eb9c7ca
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/middle/traits/coherence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
//! See `README.md` for high-level documentation
1212
13-
use super::{SelectionContext};
14-
use super::{Obligation, ObligationCause};
13+
use super::{SelectionContext, Obligation, ObligationCause};
14+
use super::util;
1515

1616
use middle::cstore::LOCAL_CRATE;
1717
use middle::def_id::DefId;

branches/beta/src/librustc/middle/traits/util.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
use middle::def_id::DefId;
1212
use middle::infer::InferCtxt;
13-
use middle::subst::Substs;
13+
use middle::subst::{Subst, Substs};
1414
use middle::ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef};
1515
use syntax::codemap::Span;
1616
use util::common::ErrorReported;
1717
use util::nodemap::FnvHashSet;
1818

19-
use super::{Obligation, ObligationCause, PredicateObligation};
19+
use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized};
2020

2121
struct PredicateSet<'a,'tcx:'a> {
2222
tcx: &'a TyCtxt<'tcx>,
@@ -299,6 +299,38 @@ impl<'tcx,I:Iterator<Item=ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> {
299299
// Other
300300
///////////////////////////////////////////////////////////////////////////
301301

302+
/// Instantiate all bound parameters of the impl with the given substs,
303+
/// returning the resulting trait ref and all obligations that arise.
304+
/// The obligations are closed under normalization.
305+
pub fn impl_trait_ref_and_oblig<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
306+
impl_def_id: DefId,
307+
impl_substs: &Substs<'tcx>)
308+
-> (ty::TraitRef<'tcx>,
309+
Vec<PredicateObligation<'tcx>>)
310+
{
311+
let impl_trait_ref =
312+
selcx.tcx().impl_trait_ref(impl_def_id).unwrap();
313+
let impl_trait_ref =
314+
impl_trait_ref.subst(selcx.tcx(), impl_substs);
315+
let Normalized { value: impl_trait_ref, obligations: normalization_obligations1 } =
316+
super::normalize(selcx, ObligationCause::dummy(), &impl_trait_ref);
317+
318+
let predicates = selcx.tcx().lookup_predicates(impl_def_id);
319+
let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
320+
let Normalized { value: predicates, obligations: normalization_obligations2 } =
321+
super::normalize(selcx, ObligationCause::dummy(), &predicates);
322+
let impl_obligations =
323+
predicates_for_generics(ObligationCause::dummy(), 0, &predicates);
324+
325+
let impl_obligations: Vec<_> =
326+
impl_obligations.into_iter()
327+
.chain(normalization_obligations1)
328+
.chain(normalization_obligations2)
329+
.collect();
330+
331+
(impl_trait_ref, impl_obligations)
332+
}
333+
302334
// determine the `self` type, using fresh variables for all variables
303335
// declared on the impl declaration e.g., `impl<A,B> for Box<[(A,B)]>`
304336
// would return ($0, $1) where $0 and $1 are freshly instantiated type

0 commit comments

Comments
 (0)