@@ -118,15 +118,7 @@ fn eval_src_mod<'a>(
118
118
id : ast:: Ident ,
119
119
) -> PResult < ' a , ( Mod , Vec < Attribute > ) > {
120
120
let mut included_mod_stack = sess. included_mod_stack . borrow_mut ( ) ;
121
- if let Some ( i) = included_mod_stack. iter ( ) . position ( |p| * p == path) {
122
- let mut err = String :: from ( "circular modules: " ) ;
123
- for p in & included_mod_stack[ i..] {
124
- err. push_str ( & p. to_string_lossy ( ) ) ;
125
- err. push_str ( " -> " ) ;
126
- }
127
- err. push_str ( & path. to_string_lossy ( ) ) ;
128
- return Err ( sess. span_diagnostic . struct_span_err ( id. span , & err[ ..] ) ) ;
129
- }
121
+ error_on_circular_module ( sess, id. span , & path, & included_mod_stack) ?;
130
122
included_mod_stack. push ( path. clone ( ) ) ;
131
123
drop ( included_mod_stack) ;
132
124
@@ -140,6 +132,24 @@ fn eval_src_mod<'a>(
140
132
Ok ( module)
141
133
}
142
134
135
+ fn error_on_circular_module < ' a > (
136
+ sess : & ' a ParseSess ,
137
+ span : Span ,
138
+ path : & Path ,
139
+ included_mod_stack : & [ PathBuf ] ,
140
+ ) -> PResult < ' a , ( ) > {
141
+ if let Some ( i) = included_mod_stack. iter ( ) . position ( |p| * p == path) {
142
+ let mut err = String :: from ( "circular modules: " ) ;
143
+ for p in & included_mod_stack[ i..] {
144
+ err. push_str ( & p. to_string_lossy ( ) ) ;
145
+ err. push_str ( " -> " ) ;
146
+ }
147
+ err. push_str ( & path. to_string_lossy ( ) ) ;
148
+ return Err ( sess. span_diagnostic . struct_span_err ( span, & err[ ..] ) ) ;
149
+ }
150
+ Ok ( ( ) )
151
+ }
152
+
143
153
pub fn push_directory (
144
154
id : Ident ,
145
155
attrs : & [ Attribute ] ,
0 commit comments