Skip to content

Support method notation with projected associated types #20665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/librustc/middle/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,16 @@ impl<'tcx> Combineable<'tcx> for ty::TraitRef<'tcx> {
}
}

impl<'tcx> Combineable<'tcx> for Ty<'tcx> {
fn combine<C:Combine<'tcx>>(combiner: &C,
a: &Ty<'tcx>,
b: &Ty<'tcx>)
-> cres<'tcx, Ty<'tcx>>
{
combiner.tys(*a, *b)
}
}

impl<'tcx> Combineable<'tcx> for ty::ProjectionPredicate<'tcx> {
fn combine<C:Combine<'tcx>>(combiner: &C,
a: &ty::ProjectionPredicate<'tcx>,
Expand Down
33 changes: 21 additions & 12 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use util::ppaux::{ty_to_string};
use util::ppaux::{Repr, UserString};

use self::coercion::Coerce;
use self::combine::{Combine, CombineFields};
use self::combine::{Combine, Combineable, CombineFields};
use self::region_inference::{RegionVarBindings, RegionSnapshot};
use self::equate::Equate;
use self::sub::Sub;
Expand Down Expand Up @@ -360,17 +360,9 @@ pub fn can_mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
})
}

pub fn can_mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
a: Ty<'tcx>, b: Ty<'tcx>)
-> ures<'tcx> {
debug!("can_mk_subty({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx));
cx.probe(|_| {
let trace = TypeTrace {
origin: Misc(codemap::DUMMY_SP),
values: Types(expected_found(true, a, b))
};
cx.equate(true, trace).tys(a, b)
}).to_ures()
pub fn can_mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> ures<'tcx>
{
cx.can_equate(&a, &b)
}

pub fn mk_subr<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
Expand Down Expand Up @@ -1072,6 +1064,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

self.region_vars.verify_generic_bound(origin, kind, a, bs);
}

pub fn can_equate<T>(&self, a: &T, b: &T) -> ures<'tcx>
where T : Combineable<'tcx> + Repr<'tcx>
{
debug!("can_equate({}, {})", a.repr(self.tcx), b.repr(self.tcx));
self.probe(|_| {
// Gin up a dummy trace, since this won't be committed
// anyhow. We should make this typetrace stuff more
// generic so we don't have to do anything quite this
// terrible.
let e = self.tcx.types.err;
let trace = TypeTrace { origin: Misc(codemap::DUMMY_SP),
values: Types(expected_found(true, e, e)) };
let eq = self.equate(true, trace);
Combineable::combine(&eq, a, b)
}).to_ures()
}
}

impl<'tcx> TypeTrace<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl<T> VecPerParamSpace<T> {
self.content.as_slice()
}

pub fn to_vec(self) -> Vec<T> {
pub fn into_vec(self) -> Vec<T> {
self.content
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ fn confirm_candidate<'cx,'tcx>(
}

match impl_ty {
Some(ty) => (ty, impl_vtable.nested.to_vec()),
Some(ty) => (ty, impl_vtable.nested.into_vec()),
None => {
// This means that the impl is missing a
// definition for the associated type. This error
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
bounds.repr(self.tcx()));

let matching_bound =
util::elaborate_predicates(self.tcx(), bounds.predicates.to_vec())
util::elaborate_predicates(self.tcx(), bounds.predicates.into_vec())
.filter_to_traits()
.find(
|bound| self.infcx.probe(
Expand Down
15 changes: 15 additions & 0 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ pub struct FnSig<'tcx> {

pub type PolyFnSig<'tcx> = Binder<FnSig<'tcx>>;

impl<'tcx> PolyFnSig<'tcx> {
pub fn input(&self, index: uint) -> ty::Binder<Ty<'tcx>> {
ty::Binder(self.0.inputs[index])
}
}

#[derive(Clone, Copy, PartialEq, Eq, Hash, Show)]
pub struct ParamTy {
pub space: subst::ParamSpace,
Expand Down Expand Up @@ -1464,10 +1470,12 @@ impl<'tcx> PolyTraitRef<'tcx> {
}

pub fn substs(&self) -> &'tcx Substs<'tcx> {
// FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
self.0.substs
}

pub fn input_types(&self) -> &[Ty<'tcx>] {
// FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
self.0.input_types()
}

Expand Down Expand Up @@ -6950,6 +6958,13 @@ impl<'tcx> RegionEscape for Ty<'tcx> {
}
}

impl<'tcx> RegionEscape for Substs<'tcx> {
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
self.types.has_regions_escaping_depth(depth) ||
self.regions.has_regions_escaping_depth(depth)
}
}

impl<'tcx,T:RegionEscape> RegionEscape for VecPerParamSpace<T> {
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
self.iter_enumerated().any(|(space, _, t)| {
Expand Down
Loading