@@ -2424,23 +2424,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2424
2424
let suggestion = if suggestion. is_some ( ) {
2425
2425
suggestion
2426
2426
} 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)
2444
2428
} else if was_invoked_from_cargo ( ) {
2445
2429
Some ( (
2446
2430
vec ! [ ] ,
@@ -2462,6 +2446,30 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2462
2446
}
2463
2447
}
2464
2448
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
+ let sp = map
2456
+ . span_extend_to_prev_char (
2457
+ map. span_extend_to_prev_char ( ident. span , '\n' , true ) ,
2458
+ '\n' ,
2459
+ true ,
2460
+ )
2461
+ . shrink_to_lo ( ) ;
2462
+ Some ( (
2463
+ vec ! [ ( sp, format!( "mod {ident};\n " ) ) ] ,
2464
+ format ! (
2465
+ "to make use of source file {}, use `mod {ident}` \
2466
+ in this file to declare the module",
2467
+ path. display( )
2468
+ ) ,
2469
+ Applicability :: MaybeIncorrect ,
2470
+ ) )
2471
+ }
2472
+
2465
2473
fn undeclared_module_exists ( & mut self , ident : Ident ) -> Option < std:: path:: PathBuf > {
2466
2474
let map = self . tcx . sess . source_map ( ) ;
2467
2475
0 commit comments