From 2a241ece3a8fdaa536946b29eeab4524da164903 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 3 Mar 2011 14:10:36 -0800 Subject: [PATCH] rustc: Disallow calling type_of() on dynamically-sized types --- src/comp/middle/trans.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 9587b008dc6..65f5b135e68 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -417,7 +417,17 @@ fn T_opaque_obj_ptr(type_names tn) -> TypeRef { } +// This function now fails if called on a type with dynamic size (as its +// return value was always meaningless in that case anyhow). Beware! +// +// TODO: Enforce via a predicate. fn type_of(@crate_ctxt cx, @ty.t t) -> TypeRef { + if (ty.type_has_dynamic_size(t)) { + log "type_of() called on a type with dynamic size: " + + ty.ty_to_str(t); + fail; + } + ret type_of_inner(cx, t); }