Skip to content

Commit 7174cb4

Browse files
committed
add suggestion
1 parent c20b393 commit 7174cb4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,7 +2425,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24252425
} else {
24262426
let suggestion = if suggestion.is_some() {
24272427
suggestion
2428-
} else if let Some(src) = self.tcx.sess.source_map().span_to_filename(ident.span).into_local_path()
2428+
} else if let map = self.tcx.sess.source_map()
2429+
&& let Some(src) = map.span_to_filename(ident.span).into_local_path()
24292430
&& let i = ident.as_str()
24302431
// FIXME: add case where non parent using undeclared module (hard?)
24312432
&& let Some(dir) = src.parent()
@@ -2454,9 +2455,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24542455
)
24552456
.find(|x| x.exists())
24562457
{
2458+
let sp = map
2459+
.span_extend_to_prev_char(
2460+
map.span_extend_to_prev_char(ident.span, '\n', true),
2461+
'\n',
2462+
true,
2463+
)
2464+
.shrink_to_lo();
24572465
Some((
2458-
// FIXME: add suggestion
2459-
vec![],
2466+
vec![(sp, format!("mod {ident}\n"))],
24602467
format!(
24612468
"to make use of source file {}, use `mod {ident}` \
24622469
in this file to declare the module",

0 commit comments

Comments
 (0)