aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-07-09 11:59:00 -0700
committerGraydon Hoare <[email protected]>2010-07-09 11:59:00 -0700
commitab3921f27e7cc0114568cac3def629a867ae4a54 (patch)
tree334fffa625f550aa946e29b0a98edf7c2e5330bd
parentEncode and decode DW_AT_rust_iterator on DW_TAG_subprogram DIEs. (diff)
downloadrust-ab3921f27e7cc0114568cac3def629a867ae4a54.tar.xz
rust-ab3921f27e7cc0114568cac3def629a867ae4a54.zip
Catch cyclic imports harder. Add 2 tests to confirm.
-rw-r--r--src/boot/me/semant.ml25
-rw-r--r--src/test/compile-fail/import-loop-2.rs13
-rw-r--r--src/test/compile-fail/import-loop.rs7
3 files changed, 34 insertions, 11 deletions
diff --git a/src/boot/me/semant.ml b/src/boot/me/semant.ml
index 61eb1485..64f2c939 100644
--- a/src/boot/me/semant.ml
+++ b/src/boot/me/semant.ml
@@ -1545,10 +1545,18 @@ let rec project_ident_from_items
(cx:ctxt)
(lchk:loop_check)
(scopes:scope list)
+ (scope_id:node_id)
((view:Ast.mod_view),(items:Ast.mod_items))
(ident:Ast.ident)
(inside:bool)
: resolved =
+
+ let lchk =
+ if List.mem (scope_id, ident) lchk
+ then err (Some scope_id) "cyclic import for ident %s" ident
+ else (scope_id, ident)::lchk
+ in
+
if not (inside || (exports_permit view ident))
then None
else
@@ -1558,7 +1566,8 @@ let rec project_ident_from_items
| None ->
match htab_search view.Ast.view_imports ident with
None -> None
- | Some name -> lookup_by_name cx lchk scopes name
+ | Some name ->
+ lookup_by_name cx lchk scopes name
and found cx scopes id =
Hashtbl.replace cx.ctxt_node_referenced id ();
@@ -1578,7 +1587,7 @@ and project_name_comp_from_resolved
let ident = get_name_comp_ident ext in
let md = get_mod_item cx id in
Hashtbl.replace cx.ctxt_node_referenced id ();
- project_ident_from_items cx lchk scopes md ident false
+ project_ident_from_items cx lchk scopes id md ident false
and lookup_by_name
(cx:ctxt)
@@ -1602,12 +1611,6 @@ and lookup_by_ident
(ident:Ast.ident)
: resolved =
- let passing id =
- if List.mem (id, ident) lchk
- then err (Some id) "cyclic import for ident %s" ident
- else (id, ident)::lchk
- in
-
let check_slots scopes islots =
arr_search islots
(fun _ (sloti,ident') ->
@@ -1651,7 +1654,7 @@ and lookup_by_ident
| SCOPE_crate crate ->
project_ident_from_items
- cx (passing crate.id) scopes crate.node.Ast.crate_items ident true
+ cx lchk scopes crate.id crate.node.Ast.crate_items ident true
| SCOPE_obj_fn fn ->
would_capture (check_slots scopes fn.node.Ast.fn_input_slots)
@@ -1671,8 +1674,8 @@ and lookup_by_ident
end
| Ast.MOD_ITEM_mod md ->
- project_ident_from_items cx (passing item.id)
- scopes md ident true
+ project_ident_from_items cx lchk
+ scopes item.id md ident true
| _ -> None
in
diff --git a/src/test/compile-fail/import-loop-2.rs b/src/test/compile-fail/import-loop-2.rs
new file mode 100644
index 00000000..474634b5
--- /dev/null
+++ b/src/test/compile-fail/import-loop-2.rs
@@ -0,0 +1,13 @@
+// error-pattern:cyclic import
+
+mod a {
+ import b.x;
+}
+
+mod b {
+ import a.x;
+
+ fn main() {
+ auto y = x;
+ }
+}
diff --git a/src/test/compile-fail/import-loop.rs b/src/test/compile-fail/import-loop.rs
new file mode 100644
index 00000000..649e2d5d
--- /dev/null
+++ b/src/test/compile-fail/import-loop.rs
@@ -0,0 +1,7 @@
+// error-pattern:cyclic import
+
+import x;
+
+fn main() {
+ auto y = x;
+}