Do not ICE with incorrect empty suggestion
When we have two types with the same name, one without type parameters and the other with type parameters and a derive macro, we were before incorrectly suggesting to remove type parameters from the former, which ICEd because we were suggesting to remove nothing. We now gate against this. The output is still not perfect. E0107 should explicitly detect this case and provide better context, but for now let's avoid the ICE.
This commit is contained in:
parent
aaed38b2a6
commit
bd8e88fd7b
3 changed files with 99 additions and 1 deletions
|
@ -1048,7 +1048,17 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
},
|
||||
);
|
||||
|
||||
err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect);
|
||||
if span.is_empty() {
|
||||
// Avoid ICE when types with the same name with `derive`s are in the same scope:
|
||||
// struct NotSM;
|
||||
// #[derive(PartialEq, Eq)]
|
||||
// struct NotSM<T>(T);
|
||||
// With the above code, the suggestion is to remove the generics of the first
|
||||
// `NotSM`, which doesn't *have* generics, so we're suggesting to remove no code
|
||||
// with no code, which ICEs on nightly due to an `assert!`.
|
||||
} else {
|
||||
err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect);
|
||||
}
|
||||
} else if redundant_lifetime_args && redundant_type_or_const_args {
|
||||
remove_lifetime_args(err);
|
||||
remove_type_or_const_args(err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue