@@ -118,15 +118,7 @@ fn eval_src_mod<'a>(
118118 id : ast:: Ident ,
119119) -> PResult < ' a , ( Mod , Vec < Attribute > ) > {
120120 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) ?;
130122 included_mod_stack. push ( path. clone ( ) ) ;
131123 drop ( included_mod_stack) ;
132124
@@ -140,6 +132,24 @@ fn eval_src_mod<'a>(
140132 Ok ( module)
141133}
142134
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+
143153pub fn push_directory (
144154 id : Ident ,
145155 attrs : & [ Attribute ] ,
0 commit comments