@@ -2161,17 +2161,19 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
2161
2161
// def-id.
2162
2162
assert_eq ! ( p. def_id. crate , ast:: LOCAL_CRATE ) ;
2163
2163
2164
- type_param_def_to_contents (
2165
- cx, cx. ty_param_defs . get ( & p. def_id . node ) )
2164
+ let tp_def = cx. ty_param_defs . get ( & p. def_id . node ) ;
2165
+ kind_bounds_to_contents ( cx, & tp_def. bounds . builtin_bounds ,
2166
+ tp_def. bounds . trait_bounds )
2166
2167
}
2167
2168
2168
- ty_self( _) => {
2169
- // Currently, self is not bounded, so we must assume the
2170
- // worst. But in the future we should examine the super
2171
- // traits.
2172
- //
2169
+ ty_self( def_id) => {
2173
2170
// FIXME(#4678)---self should just be a ty param
2174
- TC_ALL
2171
+
2172
+ // Self may be bounded if the associated trait has builtin kinds
2173
+ // for supertraits. If so we can use those bounds.
2174
+ let trait_def = lookup_trait_def ( cx, def_id) ;
2175
+ let traits = [ trait_def. trait_ref ] ;
2176
+ kind_bounds_to_contents ( cx, & trait_def. bounds , traits)
2175
2177
}
2176
2178
2177
2179
ty_infer( _) => {
@@ -2315,14 +2317,12 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
2315
2317
st + mt + bt
2316
2318
}
2317
2319
2318
- fn type_param_def_to_contents ( cx : ctxt ,
2319
- type_param_def : & TypeParameterDef ) -> TypeContents
2320
- {
2321
- debug ! ( "type_param_def_to_contents(%s)" , type_param_def. repr( cx) ) ;
2320
+ fn kind_bounds_to_contents ( cx : ctxt , bounds : & BuiltinBounds , traits : & [ @TraitRef ] )
2321
+ -> TypeContents {
2322
2322
let _i = indenter ( ) ;
2323
2323
2324
2324
let mut tc = TC_ALL ;
2325
- do each_inherited_builtin_bound ( cx, type_param_def . bounds ) |bound| {
2325
+ do each_inherited_builtin_bound ( cx, bounds, traits ) |bound| {
2326
2326
debug ! ( "tc = %s, bound = %?" , tc. to_str( ) , bound) ;
2327
2327
tc = tc - match bound {
2328
2328
BoundStatic => TypeContents :: nonstatic ( cx) ,
@@ -2338,13 +2338,13 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
2338
2338
2339
2339
// Iterates over all builtin bounds on the type parameter def, including
2340
2340
// those inherited from traits with builtin-kind-supertraits.
2341
- fn each_inherited_builtin_bound ( cx : ctxt , bounds : & ParamBounds ,
2342
- f : & fn ( BuiltinBound ) ) {
2343
- for bound in bounds. builtin_bounds . iter ( ) {
2341
+ fn each_inherited_builtin_bound ( cx : ctxt , bounds : & BuiltinBounds ,
2342
+ traits : & [ @ TraitRef ] , f : & fn ( BuiltinBound ) ) {
2343
+ for bound in bounds. iter ( ) {
2344
2344
f ( bound) ;
2345
2345
}
2346
2346
2347
- do each_bound_trait_and_supertraits ( cx, bounds . trait_bounds ) |trait_ref| {
2347
+ do each_bound_trait_and_supertraits ( cx, traits ) |trait_ref| {
2348
2348
let trait_def = lookup_trait_def ( cx, trait_ref. def_id ) ;
2349
2349
for bound in trait_def. bounds . iter ( ) {
2350
2350
f ( bound) ;
0 commit comments