Skip to content

Commit d08a42b

Browse files
committed
Look at projections from supertraits when constructing trait objects.
1 parent 25a42b2 commit d08a42b

File tree

5 files changed

+77
-69
lines changed

5 files changed

+77
-69
lines changed

src/librustc/hir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,9 @@ pub enum TraitBoundModifier {
506506
}
507507

508508
/// The AST represents all type param bounds as types.
509-
/// typeck::collect::compute_bounds matches these against
510-
/// the "special" built-in traits (see middle::lang_items) and
511-
/// detects Copy, Send and Sync.
509+
/// `typeck::collect::compute_bounds` matches these against
510+
/// the "special" built-in traits (see `middle::lang_items`) and
511+
/// detects `Copy`, `Send` and `Sync`.
512512
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
513513
pub enum GenericBound {
514514
Trait(PolyTraitRef, TraitBoundModifier),

src/librustc/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<I> FilterToTraits<I> {
333333
}
334334
}
335335

336-
impl<'tcx,I:Iterator<Item = ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> {
336+
impl<'tcx, I: Iterator<Item = ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> {
337337
type Item = ty::PolyTraitRef<'tcx>;
338338

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

src/librustc/ty/mod.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl Visibility {
294294
}
295295
}
296296

297-
/// Returns true if an item with this visibility is accessible from the given block.
297+
/// Returns `true` if an item with this visibility is accessible from the given block.
298298
pub fn is_accessible_from<T: DefIdTree>(self, module: DefId, tree: T) -> bool {
299299
let restriction = match self {
300300
// Public items are visible everywhere.
@@ -309,7 +309,7 @@ impl Visibility {
309309
tree.is_descendant_of(module, restriction)
310310
}
311311

312-
/// Returns true if this visibility is at least as accessible as the given visibility
312+
/// Returns `true` if this visibility is at least as accessible as the given visibility
313313
pub fn is_at_least<T: DefIdTree>(self, vis: Visibility, tree: T) -> bool {
314314
let vis_restriction = match vis {
315315
Visibility::Public => return self == Visibility::Public,
@@ -320,7 +320,7 @@ impl Visibility {
320320
self.is_accessible_from(vis_restriction, tree)
321321
}
322322

323-
// Returns true if this item is visible anywhere in the local crate.
323+
// Returns `true` if this item is visible anywhere in the local crate.
324324
pub fn is_visible_locally(self) -> bool {
325325
match self {
326326
Visibility::Public => true,
@@ -451,7 +451,7 @@ bitflags! {
451451
// FIXME: Rename this to the actual property since it's used for generators too
452452
const HAS_TY_CLOSURE = 1 << 9;
453453

454-
// true if there are "names" of types and regions and so forth
454+
// `true` if there are "names" of types and regions and so forth
455455
// that are local to a particular fn
456456
const HAS_FREE_LOCAL_NAMES = 1 << 10;
457457

@@ -953,7 +953,7 @@ impl<'a, 'gcx, 'tcx> Generics {
953953
_ => bug!("expected lifetime parameter, but found another generic parameter")
954954
}
955955
} else {
956-
tcx.generics_of(self.parent.expect("parent_count>0 but no parent?"))
956+
tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
957957
.region_param(param, tcx)
958958
}
959959
}
@@ -970,7 +970,7 @@ impl<'a, 'gcx, 'tcx> Generics {
970970
_ => bug!("expected type parameter, but found another generic parameter")
971971
}
972972
} else {
973-
tcx.generics_of(self.parent.expect("parent_count>0 but no parent?"))
973+
tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
974974
.type_param(param, tcx)
975975
}
976976
}
@@ -993,6 +993,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
993993
self.instantiate_into(tcx, &mut instantiated, substs);
994994
instantiated
995995
}
996+
996997
pub fn instantiate_own(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: &Substs<'tcx>)
997998
-> InstantiatedPredicates<'tcx> {
998999
InstantiatedPredicates {
@@ -1256,14 +1257,14 @@ pub struct ProjectionPredicate<'tcx> {
12561257
pub type PolyProjectionPredicate<'tcx> = Binder<ProjectionPredicate<'tcx>>;
12571258

12581259
impl<'tcx> PolyProjectionPredicate<'tcx> {
1259-
/// Returns the def-id of the associated item being projected.
1260+
/// Returns the `DefId` of the associated item being projected.
12601261
pub fn item_def_id(&self) -> DefId {
12611262
self.skip_binder().projection_ty.item_def_id
12621263
}
12631264

12641265
pub fn to_poly_trait_ref(&self, tcx: TyCtxt<'_, '_, '_>) -> PolyTraitRef<'tcx> {
1265-
// Note: unlike with TraitRef::to_poly_trait_ref(),
1266-
// self.0.trait_ref is permitted to have escaping regions.
1266+
// Note: unlike with `TraitRef::to_poly_trait_ref()`,
1267+
// `self.0.trait_ref` is permitted to have escaping regions.
12671268
// This is because here `self` has a `Binder` and so does our
12681269
// return value, so we are preserving the number of binding
12691270
// levels.
@@ -1274,12 +1275,12 @@ impl<'tcx> PolyProjectionPredicate<'tcx> {
12741275
self.map_bound(|predicate| predicate.ty)
12751276
}
12761277

1277-
/// The DefId of the TraitItem for the associated type.
1278+
/// The `DefId` of the `TraitItem` for the associated type.
12781279
///
1279-
/// Note that this is not the DefId of the TraitRef containing this
1280-
/// associated type, which is in tcx.associated_item(projection_def_id()).container.
1280+
/// Note that this is not the `DefId` of the `TraitRef` containing this
1281+
/// associated type, which is in `tcx.associated_item(projection_def_id()).container`.
12811282
pub fn projection_def_id(&self) -> DefId {
1282-
// ok to skip binder since trait def-id does not care about regions
1283+
// okay to skip binder since trait def-id does not care about regions
12831284
self.skip_binder().projection_ty.item_def_id
12841285
}
12851286
}
@@ -1515,14 +1516,14 @@ impl UniverseIndex {
15151516
UniverseIndex::from_u32(self.private.checked_add(1).unwrap())
15161517
}
15171518

1518-
/// True if `self` can name a name from `other` -- in other words,
1519+
/// `true` if `self` can name a name from `other` -- in other words,
15191520
/// if the set of names in `self` is a superset of those in
15201521
/// `other` (`self >= other`).
15211522
pub fn can_name(self, other: UniverseIndex) -> bool {
15221523
self.private >= other.private
15231524
}
15241525

1525-
/// True if `self` cannot name some names from `other` -- in other
1526+
/// `true` if `self` cannot name some names from `other` -- in other
15261527
/// words, if the set of names in `self` is a strict subset of
15271528
/// those in `other` (`self < other`).
15281529
pub fn cannot_name(self, other: UniverseIndex) -> bool {
@@ -1574,7 +1575,7 @@ impl<'tcx> ParamEnv<'tcx> {
15741575
/// are revealed. This is suitable for monomorphized, post-typeck
15751576
/// environments like codegen or doing optimizations.
15761577
///
1577-
/// NB. If you want to have predicates in scope, use `ParamEnv::new`,
1578+
/// N.B. If you want to have predicates in scope, use `ParamEnv::new`,
15781579
/// or invoke `param_env.with_reveal_all()`.
15791580
pub fn reveal_all() -> Self {
15801581
Self::new(List::empty(), Reveal::All)
@@ -1979,14 +1980,14 @@ impl ReprOptions {
19791980
self.int.unwrap_or(attr::SignedInt(ast::IntTy::Isize))
19801981
}
19811982

1982-
/// Returns true if this `#[repr()]` should inhabit "smart enum
1983+
/// Returns `true` if this `#[repr()]` should inhabit "smart enum
19831984
/// layout" optimizations, such as representing `Foo<&T>` as a
19841985
/// single pointer.
19851986
pub fn inhibit_enum_layout_opt(&self) -> bool {
19861987
self.c() || self.int.is_some()
19871988
}
19881989

1989-
/// Returns true if this `#[repr()]` should inhibit struct field reordering
1990+
/// Returns `true` if this `#[repr()]` should inhibit struct field reordering
19901991
/// optimizations, such as with repr(C) or repr(packed(1)).
19911992
pub fn inhibit_struct_field_reordering_opt(&self) -> bool {
19921993
!(self.flags & ReprFlags::IS_UNOPTIMISABLE).is_empty() || (self.pack == 1)
@@ -2089,7 +2090,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
20892090
self.flags.intersects(AdtFlags::IS_FUNDAMENTAL)
20902091
}
20912092

2092-
/// Returns true if this is PhantomData<T>.
2093+
/// Returns `true` if this is PhantomData<T>.
20932094
#[inline]
20942095
pub fn is_phantom_data(&self) -> bool {
20952096
self.flags.intersects(AdtFlags::IS_PHANTOM_DATA)
@@ -2105,7 +2106,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
21052106
self.flags.intersects(AdtFlags::IS_RC)
21062107
}
21072108

2108-
/// Returns true if this is Box<T>.
2109+
/// Returns `true` if this is Box<T>.
21092110
#[inline]
21102111
pub fn is_box(&self) -> bool {
21112112
self.flags.intersects(AdtFlags::IS_BOX)
@@ -2422,7 +2423,7 @@ impl<'a, 'tcx> ClosureKind {
24222423
}
24232424
}
24242425

2425-
/// True if this a type that impls this closure kind
2426+
/// Returns `true` if this a type that impls this closure kind
24262427
/// must also implement `other`.
24272428
pub fn extends(self, other: ty::ClosureKind) -> bool {
24282429
match (self, other) {
@@ -2678,7 +2679,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26782679
as Box<dyn Iterator<Item = AssociatedItem> + 'a>
26792680
}
26802681

2681-
/// Returns true if the impls are the same polarity and the trait either
2682+
/// Returns `true` if the impls are the same polarity and the trait either
26822683
/// has no items or is annotated #[marker] and prevents item overrides.
26832684
pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId) -> bool {
26842685
if self.features().overlapping_marker_traits {
@@ -2802,7 +2803,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28022803
attr::contains_name(&self.get_attrs(did), attr)
28032804
}
28042805

2805-
/// Returns true if this is an `auto trait`.
2806+
/// Returns `true` if this is an `auto trait`.
28062807
pub fn trait_is_auto(self, trait_def_id: DefId) -> bool {
28072808
self.trait_def(trait_def_id).has_auto_impl
28082809
}

0 commit comments

Comments
 (0)