diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-03-05 05:46:12 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-03-05 05:46:12 -0500 |
| commit | 9b332ff2c71480bc9350bb9dd43e0af00d04e1a1 (patch) | |
| tree | 24acbe8c0b1bee22f60aff044853b5f70d125934 | |
| parent | 1d3de19e99603cd2666f25335f02a096eb6d9b46 (diff) | |
| download | rust-9b332ff2c71480bc9350bb9dd43e0af00d04e1a1.tar.gz rust-9b332ff2c71480bc9350bb9dd43e0af00d04e1a1.zip | |
Address nits by @nrc.
| -rw-r--r-- | src/librustc/middle/traits/select.rs | 7 | ||||
| -rw-r--r-- | src/librustc/middle/traits/util.rs | 16 | ||||
| -rw-r--r-- | src/librustc/middle/ty.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/trans/meth.rs | 10 | ||||
| -rw-r--r-- | src/librustc_typeck/collect.rs | 12 |
5 files changed, 32 insertions, 15 deletions
diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index a4aa685c090..e57c16b5a0f 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -2501,7 +2501,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let obligation_def_id = obligation.predicate.def_id(); let mut upcast_trait_refs = util::upcast(self.tcx(), obj_trait_ref, obligation_def_id); - // retain only those upcast versions that match the trait-ref we are looking for + // Retain only those upcast versions that match the trait-ref + // we are looking for. In particular, we know that all of + // `upcast_trait_refs` apply to the correct trait, but + // possibly with incorrect type parameters. For example, we + // may be trying to upcast `Foo` to `Bar<i32>`, but `Foo` is + // declared as `trait Foo : Bar<u32>`. upcast_trait_refs.retain(|upcast_trait_ref| { let upcast_trait_ref = upcast_trait_ref.clone(); self.infcx.probe(|_| self.match_poly_trait_ref(obligation, upcast_trait_ref)).is_ok() diff --git a/src/librustc/middle/traits/util.rs b/src/librustc/middle/traits/util.rs index d6dc57c5def..4527985302a 100644 --- a/src/librustc/middle/traits/util.rs +++ b/src/librustc/middle/traits/util.rs @@ -110,8 +110,8 @@ pub fn elaborate_predicates<'cx, 'tcx>( } impl<'cx, 'tcx> Elaborator<'cx, 'tcx> { - pub fn filter_to_traits(self) -> JustTraits<Elaborator<'cx, 'tcx>> { - JustTraits::new(self) + pub fn filter_to_traits(self) -> FilterToTraits<Elaborator<'cx, 'tcx>> { + FilterToTraits::new(self) } fn push(&mut self, predicate: &ty::Predicate<'tcx>) { @@ -193,7 +193,7 @@ impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> { // Supertrait iterator /////////////////////////////////////////////////////////////////////////// -pub type Supertraits<'cx, 'tcx> = JustTraits<Elaborator<'cx, 'tcx>>; +pub type Supertraits<'cx, 'tcx> = FilterToTraits<Elaborator<'cx, 'tcx>>; pub fn supertraits<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) @@ -215,17 +215,17 @@ pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>, /// A filter around an iterator of predicates that makes it yield up /// just trait references. -pub struct JustTraits<I> { +pub struct FilterToTraits<I> { base_iterator: I } -impl<I> JustTraits<I> { - fn new(base: I) -> JustTraits<I> { - JustTraits { base_iterator: base } +impl<I> FilterToTraits<I> { + fn new(base: I) -> FilterToTraits<I> { + FilterToTraits { base_iterator: base } } } -impl<'tcx,I:Iterator<Item=ty::Predicate<'tcx>>> Iterator for JustTraits<I> { +impl<'tcx,I:Iterator<Item=ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> { type Item = ty::PolyTraitRef<'tcx>; fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index dfdb4002be2..add829074c4 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1510,7 +1510,7 @@ impl<T> Binder<T> { /// /// Some examples where `skip_binder` is reasonable: /// - extracting the def-id from a PolyTraitRef; - /// - compariing the self type of a PolyTraitRef to see if it is equal to + /// - comparing the self type of a PolyTraitRef to see if it is equal to /// a type parameter `X`, since the type `X` does not reference any regions pub fn skip_binder(&self) -> &T { &self.0 diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index 7b4e3956cbd..0c82d681eed 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -300,7 +300,9 @@ pub fn trans_static_method_callee<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, .position(|item| item.def_id() == method_id) .unwrap(); let (llfn, ty) = - trans_object_shim(ccx, data.object_ty, data.upcast_trait_ref.clone(), + trans_object_shim(ccx, + data.object_ty, + data.upcast_trait_ref.clone(), method_offset_in_trait); immediate_rvalue(llfn, ty) } @@ -387,8 +389,10 @@ fn trans_monomorphized_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, Callee { bcx: bcx, data: Fn(llfn) } } traits::VtableObject(ref data) => { - let (llfn, _) = trans_object_shim(bcx.ccx(), data.object_ty, - data.upcast_trait_ref.clone(), n_method); + let (llfn, _) = trans_object_shim(bcx.ccx(), + data.object_ty, + data.upcast_trait_ref.clone(), + n_method); Callee { bcx: bcx, data: Fn(llfn) } } traits::VtableBuiltin(..) | diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 8f9ede32ae4..12bcf5cf5ad 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1251,6 +1251,11 @@ fn ensure_super_predicates_step(ccx: &CrateCtxt, debug!("ensure_super_predicates_step(trait_def_id={})", trait_def_id.repr(tcx)); if trait_def_id.krate != ast::LOCAL_CRATE { + // If this trait comes from an external crate, then all of the + // supertraits it may depend on also must come from external + // crates, and hence all of them already have their + // super-predicates "converted" (and available from crate + // meta-data), so there is no need to transitively test them. return Vec::new(); } @@ -2111,8 +2116,11 @@ fn compute_bounds<'tcx>(astconv: &AstConv<'tcx>, param_bounds } -/// Converts a specific TyParamBound from the AST into the -/// appropriate poly-trait-reference. +/// Converts a specific TyParamBound from the AST into a set of +/// predicates that apply to the self-type. A vector is returned +/// because this can be anywhere from 0 predicates (`T:?Sized` adds no +/// predicates) to 1 (`T:Foo`) to many (`T:Bar<X=i32>` adds `T:Bar` +/// and `<T as Bar>::X == i32`). fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx>, param_ty: Ty<'tcx>, bound: &ast::TyParamBound) |
