Skip to content

Commit 9b332ff

Browse files
committed
Address nits by @nrc.
1 parent 1d3de19 commit 9b332ff

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

src/librustc/middle/traits/select.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
25012501
let obligation_def_id = obligation.predicate.def_id();
25022502
let mut upcast_trait_refs = util::upcast(self.tcx(), obj_trait_ref, obligation_def_id);
25032503

2504-
// retain only those upcast versions that match the trait-ref we are looking for
2504+
// Retain only those upcast versions that match the trait-ref
2505+
// we are looking for. In particular, we know that all of
2506+
// `upcast_trait_refs` apply to the correct trait, but
2507+
// possibly with incorrect type parameters. For example, we
2508+
// may be trying to upcast `Foo` to `Bar<i32>`, but `Foo` is
2509+
// declared as `trait Foo : Bar<u32>`.
25052510
upcast_trait_refs.retain(|upcast_trait_ref| {
25062511
let upcast_trait_ref = upcast_trait_ref.clone();
25072512
self.infcx.probe(|_| self.match_poly_trait_ref(obligation, upcast_trait_ref)).is_ok()

src/librustc/middle/traits/util.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ pub fn elaborate_predicates<'cx, 'tcx>(
110110
}
111111

112112
impl<'cx, 'tcx> Elaborator<'cx, 'tcx> {
113-
pub fn filter_to_traits(self) -> JustTraits<Elaborator<'cx, 'tcx>> {
114-
JustTraits::new(self)
113+
pub fn filter_to_traits(self) -> FilterToTraits<Elaborator<'cx, 'tcx>> {
114+
FilterToTraits::new(self)
115115
}
116116

117117
fn push(&mut self, predicate: &ty::Predicate<'tcx>) {
@@ -193,7 +193,7 @@ impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> {
193193
// Supertrait iterator
194194
///////////////////////////////////////////////////////////////////////////
195195

196-
pub type Supertraits<'cx, 'tcx> = JustTraits<Elaborator<'cx, 'tcx>>;
196+
pub type Supertraits<'cx, 'tcx> = FilterToTraits<Elaborator<'cx, 'tcx>>;
197197

198198
pub fn supertraits<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
199199
trait_ref: ty::PolyTraitRef<'tcx>)
@@ -215,17 +215,17 @@ pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
215215

216216
/// A filter around an iterator of predicates that makes it yield up
217217
/// just trait references.
218-
pub struct JustTraits<I> {
218+
pub struct FilterToTraits<I> {
219219
base_iterator: I
220220
}
221221

222-
impl<I> JustTraits<I> {
223-
fn new(base: I) -> JustTraits<I> {
224-
JustTraits { base_iterator: base }
222+
impl<I> FilterToTraits<I> {
223+
fn new(base: I) -> FilterToTraits<I> {
224+
FilterToTraits { base_iterator: base }
225225
}
226226
}
227227

228-
impl<'tcx,I:Iterator<Item=ty::Predicate<'tcx>>> Iterator for JustTraits<I> {
228+
impl<'tcx,I:Iterator<Item=ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> {
229229
type Item = ty::PolyTraitRef<'tcx>;
230230

231231
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ impl<T> Binder<T> {
15101510
///
15111511
/// Some examples where `skip_binder` is reasonable:
15121512
/// - extracting the def-id from a PolyTraitRef;
1513-
/// - compariing the self type of a PolyTraitRef to see if it is equal to
1513+
/// - comparing the self type of a PolyTraitRef to see if it is equal to
15141514
/// a type parameter `X`, since the type `X` does not reference any regions
15151515
pub fn skip_binder(&self) -> &T {
15161516
&self.0

src/librustc_trans/trans/meth.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ pub fn trans_static_method_callee<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
300300
.position(|item| item.def_id() == method_id)
301301
.unwrap();
302302
let (llfn, ty) =
303-
trans_object_shim(ccx, data.object_ty, data.upcast_trait_ref.clone(),
303+
trans_object_shim(ccx,
304+
data.object_ty,
305+
data.upcast_trait_ref.clone(),
304306
method_offset_in_trait);
305307
immediate_rvalue(llfn, ty)
306308
}
@@ -387,8 +389,10 @@ fn trans_monomorphized_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
387389
Callee { bcx: bcx, data: Fn(llfn) }
388390
}
389391
traits::VtableObject(ref data) => {
390-
let (llfn, _) = trans_object_shim(bcx.ccx(), data.object_ty,
391-
data.upcast_trait_ref.clone(), n_method);
392+
let (llfn, _) = trans_object_shim(bcx.ccx(),
393+
data.object_ty,
394+
data.upcast_trait_ref.clone(),
395+
n_method);
392396
Callee { bcx: bcx, data: Fn(llfn) }
393397
}
394398
traits::VtableBuiltin(..) |

src/librustc_typeck/collect.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,11 @@ fn ensure_super_predicates_step(ccx: &CrateCtxt,
12511251
debug!("ensure_super_predicates_step(trait_def_id={})", trait_def_id.repr(tcx));
12521252

12531253
if trait_def_id.krate != ast::LOCAL_CRATE {
1254+
// If this trait comes from an external crate, then all of the
1255+
// supertraits it may depend on also must come from external
1256+
// crates, and hence all of them already have their
1257+
// super-predicates "converted" (and available from crate
1258+
// meta-data), so there is no need to transitively test them.
12541259
return Vec::new();
12551260
}
12561261

@@ -2111,8 +2116,11 @@ fn compute_bounds<'tcx>(astconv: &AstConv<'tcx>,
21112116
param_bounds
21122117
}
21132118

2114-
/// Converts a specific TyParamBound from the AST into the
2115-
/// appropriate poly-trait-reference.
2119+
/// Converts a specific TyParamBound from the AST into a set of
2120+
/// predicates that apply to the self-type. A vector is returned
2121+
/// because this can be anywhere from 0 predicates (`T:?Sized` adds no
2122+
/// predicates) to 1 (`T:Foo`) to many (`T:Bar<X=i32>` adds `T:Bar`
2123+
/// and `<T as Bar>::X == i32`).
21162124
fn predicates_from_bound<'tcx>(astconv: &AstConv<'tcx>,
21172125
param_ty: Ty<'tcx>,
21182126
bound: &ast::TyParamBound)

0 commit comments

Comments
 (0)