diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-06-25 22:10:28 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-06-26 11:14:39 -0700 |
| commit | cf69604551324f68d1fc7ab0386ecbe9e1aaa504 (patch) | |
| tree | de351651ef98070c47a68a19ce658a72b66b85a9 /src/rustc | |
| parent | d513d9893ecd416943d96822f794c3212c8b60b8 (diff) | |
| download | rust-cf69604551324f68d1fc7ab0386ecbe9e1aaa504.tar.gz rust-cf69604551324f68d1fc7ab0386ecbe9e1aaa504.zip | |
Incorporate class fields into recursive-type check
Noticed while investigating issue 2718 that the typechecker allowed some non-instantiable types involving classes. This wasn't the root of 2718, but fixed it anyway.
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/middle/ty.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index fa93925fa88..3a9d320c77e 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -1218,7 +1218,6 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool { accum } } - ty_tup(elts) { for elts.each {|m| if type_needs_drop(cx, m) { accum = true; } } accum @@ -1720,6 +1719,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) -> bool { let sty = get(ty).struct; + #debug("type_structurally_contains: %s", ty_to_str(cx, ty)); if test(sty) { ret true; } alt sty { ty_enum(did, substs) { @@ -1737,6 +1737,14 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) -> } ret false; } + ty_class(did, substs) { + for lookup_class_fields(cx, did).each {|field| + let ft = lookup_field_type(cx, did, field.id, substs); + if type_structurally_contains(cx, ft, test) { ret true; } + } + ret false; + } + ty_tup(ts) { for ts.each {|tt| if type_structurally_contains(cx, tt, test) { ret true; } |
