Skip to content

Commit 41c0d70

Browse files
committed
librustc: Fix type_use for generic newtype structs. Closes rust-lang#4188. rs=bugfix
1 parent 8a9ccf8 commit 41c0d70

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Diff for: src/librustc/middle/trans/type_use.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,18 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
139139
ast_map::node_dtor(_, dtor, _, _) => {
140140
handle_body(cx, dtor.node.body);
141141
}
142-
_ => fail ~"unknown node type in type_use"
142+
ast_map::node_struct_ctor(*) => {
143+
// Similarly to node_variant, this monomorphized function just uses
144+
// the representations of all of its type parameters.
145+
for uint::range(0, n_tps) |n| { cx.uses[n] |= use_repr; }
146+
}
147+
_ => {
148+
ccx.tcx.sess.bug(fmt!("unknown node type in type_use: %s",
149+
ast_map::node_id_to_str(
150+
ccx.tcx.items,
151+
fn_id_loc.node,
152+
ccx.tcx.sess.parse_sess.interner)));
153+
}
143154
}
144155
let uses = vec::from_mut(copy cx.uses);
145156
ccx.type_use_cache.insert(fn_id, uses);

Diff for: src/test/run-pass/generic-newtype-struct.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct S<T>(T);
2+
3+
fn main() {
4+
let s = S(2);
5+
io::println(s.to_str());
6+
}
7+

0 commit comments

Comments
 (0)