@@ -407,15 +407,19 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
407
407
push_to_s ( & mut info. crate_attrs , source, attr. span , & mut prev_span_hi) ;
408
408
}
409
409
}
410
+ let mut has_non_module_items = false ;
410
411
for stmt in & body. stmts {
411
412
let mut is_extern_crate = false ;
412
413
match stmt. kind {
413
414
StmtKind :: Item ( ref item) => {
414
415
is_extern_crate = check_item ( & item, & mut info, crate_name) ;
415
416
}
416
- StmtKind :: Expr ( ref expr) if matches ! ( expr. kind, ast:: ExprKind :: Err ( _) ) => {
417
- reset_error_count ( & psess) ;
418
- return Err ( ( ) ) ;
417
+ StmtKind :: Expr ( ref expr) => {
418
+ if matches ! ( expr. kind, ast:: ExprKind :: Err ( _) ) {
419
+ reset_error_count ( & psess) ;
420
+ return Err ( ( ) ) ;
421
+ }
422
+ has_non_module_items = true ;
419
423
}
420
424
StmtKind :: MacCall ( ref mac_call) if !info. has_main_fn => {
421
425
let mut iter = mac_call. mac . args . tokens . iter ( ) ;
@@ -437,7 +441,11 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
437
441
}
438
442
}
439
443
}
440
- _ => { }
444
+ // We do nothing in this case. Not marking it as `non_module_items` either.
445
+ StmtKind :: Empty => { }
446
+ _ => {
447
+ has_non_module_items = true ;
448
+ }
441
449
}
442
450
443
451
// Weirdly enough, the `Stmt` span doesn't include its attributes, so we need to
@@ -462,6 +470,11 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
462
470
push_to_s ( & mut info. crates , source, span, & mut prev_span_hi) ;
463
471
}
464
472
}
473
+ if has_non_module_items {
474
+ // FIXME: if `info.has_main_fn` is `true`, emit a warning here to mention that
475
+ // this code will not be called.
476
+ info. has_main_fn = false ;
477
+ }
465
478
Ok ( info)
466
479
}
467
480
Err ( e) => {
0 commit comments