Fix ICE #91268 by checking that the snippet ends with a )
This commit is contained in:
parent
6d246f0c8d
commit
0da3a0f56e
3 changed files with 72 additions and 9 deletions
|
@ -231,15 +231,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
|
||||
// Do not suggest going from `Trait()` to `Trait<>`
|
||||
if !data.inputs.is_empty() {
|
||||
if let Some(split) = snippet.find('(') {
|
||||
let trait_name = &snippet[0..split];
|
||||
let args = &snippet[split + 1..snippet.len() - 1];
|
||||
err.span_suggestion(
|
||||
data.span,
|
||||
"use angle brackets instead",
|
||||
format!("{}<{}>", trait_name, args),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
// Suggest replacing `(` and `)` with `<` and `>`
|
||||
// The snippet may be missing the closing `)`, skip that case
|
||||
if snippet.ends_with(')') {
|
||||
if let Some(split) = snippet.find('(') {
|
||||
let trait_name = &snippet[0..split];
|
||||
let args = &snippet[split + 1..snippet.len() - 1];
|
||||
err.span_suggestion(
|
||||
data.span,
|
||||
"use angle brackets instead",
|
||||
format!("{}<{}>", trait_name, args),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue