Skip to content

Commit fc83a0c

Browse files
committed
Don't ICE while suggesting updating item path.
When an item isn't found, we may suggest an appropriate import to `use`. Along with that, we also suggest updating the path to work with the `use`. Unfortunately, if the code in question originates from a macro, the span used to indicate which part of the path needs updating may not be suitable and cause an ICE. Since, such code is not adjustable directly by the user without modifying the macro, just skip the suggestion in such cases.
1 parent e141246 commit fc83a0c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -2544,12 +2544,15 @@ fn show_candidates(
25442544
Applicability::MaybeIncorrect,
25452545
);
25462546
if let [first, .., last] = &path[..] {
2547-
err.span_suggestion_verbose(
2548-
first.ident.span.until(last.ident.span),
2549-
&format!("if you import `{}`, refer to it directly", last.ident),
2550-
"",
2551-
Applicability::Unspecified,
2552-
);
2547+
let sp = first.ident.span.until(last.ident.span);
2548+
if sp.can_be_used_for_suggestions() {
2549+
err.span_suggestion_verbose(
2550+
sp,
2551+
&format!("if you import `{}`, refer to it directly", last.ident),
2552+
"",
2553+
Applicability::Unspecified,
2554+
);
2555+
}
25532556
}
25542557
} else {
25552558
msg.push(':');

0 commit comments

Comments
 (0)