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