Skip to content

Commit c1a4a41

Browse files
committed
move
1 parent 6039c49 commit c1a4a41

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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,30 @@ 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+
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+
24652473
fn undeclared_module_exists(&mut self, ident: Ident) -> Option<std::path::PathBuf> {
24662474
let map = self.tcx.sess.source_map();
24672475

0 commit comments

Comments
 (0)