@@ -257,16 +257,7 @@ impl<'a> Parser<'a> {
257
257
id_sp : Span ,
258
258
) -> PResult < ' a , ( Mod , Vec < Attribute > ) > {
259
259
let mut included_mod_stack = self . sess . included_mod_stack . borrow_mut ( ) ;
260
- if let Some ( i) = included_mod_stack. iter ( ) . position ( |p| * p == path) {
261
- let mut err = String :: from ( "circular modules: " ) ;
262
- let len = included_mod_stack. len ( ) ;
263
- for p in & included_mod_stack[ i..len] {
264
- err. push_str ( & p. to_string_lossy ( ) ) ;
265
- err. push_str ( " -> " ) ;
266
- }
267
- err. push_str ( & path. to_string_lossy ( ) ) ;
268
- return Err ( self . struct_span_err ( id_sp, & err[ ..] ) ) ;
269
- }
260
+ self . error_on_circular_module ( id_sp, & path, & included_mod_stack) ?;
270
261
included_mod_stack. push ( path. clone ( ) ) ;
271
262
drop ( included_mod_stack) ;
272
263
@@ -280,6 +271,25 @@ impl<'a> Parser<'a> {
280
271
Ok ( module)
281
272
}
282
273
274
+ fn error_on_circular_module (
275
+ & self ,
276
+ span : Span ,
277
+ path : & Path ,
278
+ included_mod_stack : & [ PathBuf ] ,
279
+ ) -> PResult < ' a , ( ) > {
280
+ if let Some ( i) = included_mod_stack. iter ( ) . position ( |p| * p == path) {
281
+ let mut err = String :: from ( "circular modules: " ) ;
282
+ let len = included_mod_stack. len ( ) ;
283
+ for p in & included_mod_stack[ i..len] {
284
+ err. push_str ( & p. to_string_lossy ( ) ) ;
285
+ err. push_str ( " -> " ) ;
286
+ }
287
+ err. push_str ( & path. to_string_lossy ( ) ) ;
288
+ return Err ( self . struct_span_err ( span, & err[ ..] ) ) ;
289
+ }
290
+ Ok ( ( ) )
291
+ }
292
+
283
293
fn push_directory ( & mut self , id : Ident , attrs : & [ Attribute ] ) {
284
294
if let Some ( path) = attr:: first_attr_value_str_by_name ( attrs, sym:: path) {
285
295
self . directory . path . push ( & * path. as_str ( ) ) ;
0 commit comments