-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(elidable_lifetime_names): avoid overlapping spans in suggestions #15667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(elidable_lifetime_names): avoid overlapping spans in suggestions #15667
Conversation
r? @Alexendoo rustbot has assigned @Alexendoo. Use |
f4f156f
to
aa1cea1
Compare
if !elidable_lts | ||
.iter() | ||
.all(|lt| explicit_params.iter().any(|param| param.def_id == *lt)) | ||
{ | ||
return None; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function used to return None
in a lot of places which would realistically never fail. I think let pos = explicit_params.iter().position(|param| param.def_id == id)?;
was the only exception, because it effectively made sure that all elidable_lts
were actually present in explicit_params
, so this is the check I added to replace that
aa1cea1
to
a817c89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r? samueltardieu @rustbot author
clippy_lints/src/lifetimes.rs
Outdated
[first, second] => { | ||
// NOTE: we could theoretically remove this case for the next one, | ||
// but the latter likely has quite a lot of overhead, so don't | ||
match ( | ||
elidable_lts.contains(&first.def_id), | ||
elidable_lts.contains(&second.def_id), | ||
) { | ||
(false, false) => unreachable!("handled by `elidable_lts.is_empty()`"), | ||
(true, true) => unreachable!("handled by `elidable_lts.len() == explicit_params.len()`"), | ||
|
||
// <'a, 'b> -> <'a, 'b> | ||
// ^^ ^^^^ | ||
(false, true) => vec![(second.span.with_lo(first.span.hi()), String::new())], | ||
// <'a, 'b> -> <'a, 'b> | ||
// ^^ ^^^^ | ||
(true, false) => vec![(first.span.until(second.span), String::new())], | ||
} | ||
}, | ||
// Time for the big guns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this, as this is not on the hot path: it is called only when actually emitting the suggestion, and in this case we do not care much about some extra overhead.
[first, second] => { | |
// NOTE: we could theoretically remove this case for the next one, | |
// but the latter likely has quite a lot of overhead, so don't | |
match ( | |
elidable_lts.contains(&first.def_id), | |
elidable_lts.contains(&second.def_id), | |
) { | |
(false, false) => unreachable!("handled by `elidable_lts.is_empty()`"), | |
(true, true) => unreachable!("handled by `elidable_lts.len() == explicit_params.len()`"), | |
// <'a, 'b> -> <'a, 'b> | |
// ^^ ^^^^ | |
(false, true) => vec![(second.span.with_lo(first.span.hi()), String::new())], | |
// <'a, 'b> -> <'a, 'b> | |
// ^^ ^^^^ | |
(true, false) => vec![(first.span.until(second.span), String::new())], | |
} | |
}, | |
// Time for the big guns |
Reminder, once the PR becomes ready for a review, use |
a817c89
to
25881bf
Compare
Fixes #14157
Fixes #15666
changelog: [
elidable_lifetime_names
]: avoid overlapping spans in suggestionsr? clippy