@@ -11,7 +11,9 @@ use crate::emitter::rustfmt_diff::{make_diff, print_diff, Mismatch, ModifiedChun
1111use crate :: config:: { Config , FileName , NewlineStyle } ;
1212use crate :: {
1313 emitter:: { emit_format_report, Color , EmitMode , EmitterConfig } ,
14- format, is_nightly_channel, FormatReport , FormatReportFormatterBuilder , Input , OperationError ,
14+ format,
15+ formatting:: modules:: { ModuleResolutionError , ModuleResolutionErrorKind } ,
16+ is_nightly_channel, FormatReport , FormatReportFormatterBuilder , Input , OperationError ,
1517 OperationSetting ,
1618} ;
1719
@@ -519,6 +521,28 @@ fn format_lines_errors_are_reported_with_tabs() {
519521 assert ! ( report. has_errors( ) ) ;
520522}
521523
524+ #[ test]
525+ fn parser_errors_in_submods_are_surfaced ( ) {
526+ // See also https://github.com/rust-lang/rustfmt/issues/4126
527+ let filename = "tests/parser/issue-4126/lib.rs" ;
528+ let file = PathBuf :: from ( filename) ;
529+ let exp_mod_name = "invalid" ;
530+ let ( config, operation, _) = read_config ( & file) ;
531+ if let Err ( OperationError :: ModuleResolutionError { 0 : inner } ) =
532+ format_file ( & file, operation, config)
533+ {
534+ let ModuleResolutionError { module, kind } = inner;
535+ assert_eq ! ( & module, exp_mod_name) ;
536+ if let ModuleResolutionErrorKind :: ParseError { file } = kind {
537+ assert_eq ! ( file, PathBuf :: from( "tests/parser/issue-4126/invalid.rs" ) ) ;
538+ } else {
539+ panic ! ( "Expected parser error" ) ;
540+ }
541+ } else {
542+ panic ! ( "Expected ModuleResolution operation error" ) ;
543+ }
544+ }
545+
522546// For each file, run rustfmt and collect the output.
523547// Returns the number of files checked and the number of failures.
524548fn check_files ( files : Vec < PathBuf > , opt_config : & Option < PathBuf > ) -> ( Vec < FormatReport > , u32 , u32 ) {
0 commit comments