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