8000 fix(elidable_lifetime_names): avoid overlapping spans in suggestions by ada4a · Pull Request #15667 · rust-lang/rust-clippy · GitHub
[go: up one dir, main page]

Skip to content

Conversation

ada4a
Copy link
Contributor
@ada4a ada4a commented Sep 12, 2025

Fixes #14157
Fixes #15666

changelog: [elidable_lifetime_names]: avoid overlapping spans in suggestions

r? clippy

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 12, 2025
@rustbot
Copy link
Collaborator
rustbot commented Sep 12, 2025

r? @Alexendoo

rustbot has assigned @Alexendoo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot assigned y21 and unassigned Alexendoo Sep 12, 2025
@ada4a ada4a force-pushed the 15666-elidable_lifetime_names branch from f4f156f to aa1cea1 Compare September 12, 2025 22:49
Comment on lines +859 to +864
if !elidable_lts
.iter()
.all(|lt| explicit_params.iter().any(|param| param.def_id == *lt))
{
return None;
}
Copy link
Contributor Author

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

@ada4a ada4a force-pushed the 15666-elidable_lifetime_names branch from aa1cea1 to a817c89 Compare September 13, 2025 14:38
Copy link
Member
@samueltardieu samueltardieu left a 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

View changes since this review

Comment on lines 885 to 903
[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
Copy link
Member

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.

Suggested change
[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

@rustbot rustbot assigned samueltardieu and unassigned y21 Sep 14, 2025
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 14, 2025
@rustbot
Copy link
Collaborator
rustbot commented Sep 14, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@ada4a ada4a force-pushed the 15666-elidable_lifetime_names branch from a817c89 to 25881bf Compare September 14, 2025 09:32
@samueltardieu samueltardieu added this pull request to the merge queue Sep 14, 2025
Merged via the queue into rust-lang:master with commit e7421cc Sep 14, 2025
11 checks passed
@ada4a ada4a deleted the 15666-elidable_lifetime_names branch September 14, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

elidable_lifetime_names : ICE on neighbouring elision suggestions Clippy fails to automatically fix issues for serde-json-core
5 participants
0