Skip to content

Commit 18ca511

Browse files
committed
move
1 parent 6039c49 commit 18ca511

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
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

tests/ui/modules_and_files_visibility/mod_file_disambig.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | assert_eq!(mod_file_aux::bar(), 10);
1414
|
1515
help: to make use of source file $DIR/mod_file_aux.rs, use `mod mod_file_aux` in this file to declare the module
1616
|
17-
LL + mod mod_file_aux
17+
LL + mod mod_file_aux;
1818
|
1919

2020
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)