Skip to content

Commit

Permalink
Don't ICE while suggesting updating item path.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luqmana committed Aug 7, 2022
1 parent e141246 commit fc83a0c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2544,12 +2544,15 @@ fn show_candidates(
Applicability::MaybeIncorrect,
);
if let [first, .., last] = &path[..] {
err.span_suggestion_verbose(
first.ident.span.until(last.ident.span),
&format!("if you import `{}`, refer to it directly", last.ident),
"",
Applicability::Unspecified,
);
let sp = first.ident.span.until(last.ident.span);
if sp.can_be_used_for_suggestions() {
err.span_suggestion_verbose(
sp,
&format!("if you import `{}`, refer to it directly", last.ident),
"",
Applicability::Unspecified,
);
}
}
} else {
msg.push(':');
Expand Down

0 comments on commit fc83a0c

Please sign in to comment.