@@ -2424,23 +2424,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24242424 let suggestion = if suggestion. is_some ( ) {
24252425 suggestion
24262426 } else if let Some ( m) = self . undeclared_module_exists ( ident) {
2427- let map = self . tcx . sess . source_map ( ) ;
2428- let sp = map
2429- . span_extend_to_prev_char (
2430- map. span_extend_to_prev_char ( ident. span , '\n' , true ) ,
2431- '\n' ,
2432- true ,
2433- )
2434- . shrink_to_lo ( ) ;
2435- Some ( (
2436- vec ! [ ( sp, format!( "mod {ident}\n " ) ) ] ,
2437- format ! (
2438- "to make use of source file {}, use `mod {ident}` \
2439- in this file to declare the module",
2440- m. display( )
2441- ) ,
2442- Applicability :: MaybeIncorrect ,
2443- ) )
2427+ self . undeclared_module_suggest_declare ( ident, m)
24442428 } else if was_invoked_from_cargo ( ) {
24452429 Some ( (
24462430 vec ! [ ] ,
@@ -2462,6 +2446,26 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24622446 }
24632447 }
24642448
2449+ fn undeclared_module_suggest_declare (
2450+ & mut self ,
2451+ ident : Ident ,
2452+ path : std:: path:: PathBuf ,
2453+ ) -> Option < ( Vec < ( Span , String ) > , String , Applicability ) > {
2454+ let map = self . tcx . sess . source_map ( ) ;
2455+ // get the line before this line
2456+ let sp = map. span_extend_to_prev_char ( ident. span , '\n' , true ) ;
2457+ let sp = map. span_extend_to_prev_char ( sp, '\n' , true ) . shrink_to_lo ( ) ;
2458+ Some ( (
2459+ vec ! [ ( sp, format!( "mod {ident};\n " ) ) ] ,
2460+ format ! (
2461+ "to make use of source file {}, use `mod {ident}` \
2462+ in this file to declare the module",
2463+ path. display( )
2464+ ) ,
2465+ Applicability :: MaybeIncorrect ,
2466+ ) )
2467+ }
2468+
24652469 fn undeclared_module_exists ( & mut self , ident : Ident ) -> Option < std:: path:: PathBuf > {
24662470 let map = self . tcx . sess . source_map ( ) ;
24672471
0 commit comments