Skip to content

Commit ee90185

Browse files
committed
rustboot: Emit an error instead of asserting in trans when a T is passed by value
1 parent 429964b commit ee90185

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/boot/me/type.ml

+20-1
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,23 @@ let process_crate (cx:Semant.ctxt) (crate:Ast.crate) : unit =
13081308
Common.err (Some item_id) "this function must return a value"
13091309
in
13101310

1311+
let check_fn_ty_validity item_id (ty_sig, _) =
1312+
let check_input_slot i slot =
1313+
match slot with
1314+
{
1315+
Ast.slot_ty = Some (Ast.TY_param _);
1316+
Ast.slot_mode = Ast.MODE_local
1317+
} ->
1318+
Common.err
1319+
(Some item_id)
1320+
"parameter %d of this type-parametric function must be \
1321+
passed by reference, not by value"
1322+
(i + 1)
1323+
| _ -> ()
1324+
in
1325+
Array.iteri check_input_slot ty_sig.Ast.sig_input_slots
1326+
in
1327+
13111328
let visit_mod_item_pre _ _ item =
13121329
let { Common.node = item; Common.id = item_id } = item in
13131330
match item.Ast.decl_item with
@@ -1316,7 +1333,9 @@ let process_crate (cx:Semant.ctxt) (crate:Ast.crate) : unit =
13161333
let fn_ty = Hashtbl.find cx.Semant.ctxt_all_item_types item_id in
13171334
begin
13181335
match fn_ty with
1319-
Ast.TY_fn ty_fn -> push_fn_ctx_of_ty_fn ty_fn
1336+
Ast.TY_fn ty_fn ->
1337+
check_fn_ty_validity item_id ty_fn;
1338+
push_fn_ctx_of_ty_fn ty_fn
13201339
| _ ->
13211340
Common.bug ()
13221341
"Type.visit_mod_item_pre: fn item didn't have a fn type"

src/lib/list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tag list[T] {
1212
nil;
1313
}
1414

15-
fn foldl[T,U](&list[T] ls, U u, fn(&T t, U u) -> U f) -> U {
15+
fn foldl[T,U](&list[T] ls, &U u, fn(&T t, U u) -> U f) -> U {
1616
alt(ls) {
1717
case (cons[T](?hd, ?tl)) {
1818
auto u_ = f(hd, u);

0 commit comments

Comments
 (0)