Skip to content

Commit cdbdfe8

Browse files
committed
Allow the Self type to benefit from builtin-kinds-as-supertraits (rust-lang#7083).
1 parent 4fd404f commit cdbdfe8

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/librustc/middle/ty.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,17 +2161,19 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
21612161
// def-id.
21622162
assert_eq!(p.def_id.crate, ast::LOCAL_CRATE);
21632163

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)
21662167
}
21672168

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) => {
21732170
// 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)
21752177
}
21762178

21772179
ty_infer(_) => {
@@ -2315,14 +2317,12 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
23152317
st + mt + bt
23162318
}
23172319

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 {
23222322
let _i = indenter();
23232323

23242324
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| {
23262326
debug!("tc = %s, bound = %?", tc.to_str(), bound);
23272327
tc = tc - match bound {
23282328
BoundStatic => TypeContents::nonstatic(cx),
@@ -2338,13 +2338,13 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
23382338

23392339
// Iterates over all builtin bounds on the type parameter def, including
23402340
// 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() {
23442344
f(bound);
23452345
}
23462346

2347-
do each_bound_trait_and_supertraits(cx, bounds.trait_bounds) |trait_ref| {
2347+
do each_bound_trait_and_supertraits(cx, traits) |trait_ref| {
23482348
let trait_def = lookup_trait_def(cx, trait_ref.def_id);
23492349
for bound in trait_def.bounds.iter() {
23502350
f(bound);

0 commit comments

Comments
 (0)