Fix trailing comma in lifetime suggestion for empty angle brackets#154703
Fix trailing comma in lifetime suggestion for empty angle brackets#154703fru1tworld wants to merge 1 commit intorust-lang:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
37c3b75 to
0f7bc29
Compare
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
i personally think, that having trailing comma is fine, because i mean, sure that ideally we want to not have this trailing comma, but looking at fix it looks to me like using a tank against a fly so, if I were to weigh up the pros and cons, i think i'd be against it |
Thanks for the feedback Would a more minimal fix be acceptable? Instead of adding fields to Segment/MissingLifetime, I could just adjust the suggestion string in the MissingLifetimeKind::Comma branch — no struct changes, no new field propagation. That would keep the diff to a few lines in diagnostics.rs only. If you still feel it's not worth it even at that scope, I'm fine closing this. |
|
if you know more easier approach why was this chosen originally? |
f7e0899 to
adf06b7
Compare
|
I wasn't aware of span_look_ahead when I wrote the original version |
adf06b7 to
e0fc2da
Compare
Fixes #154600
When suggesting a lifetime parameter (e.g.,
'a) for a type likeFoo<>(empty angle brackets), the compiler was incorrectly producingFoo<'a, >with a trailing comma.Root Cause
The
has_existing_paramscheck usedsegment.argsto determine if generic parameters exist. However, for empty angle brackets (<>), the parser doesn't create anyargs, sohas_existing_paramswasfalse— even though the angle brackets themselves exist.This caused the suggestion logic to skip the comma+space suffix (
"'a, "), but the insert position was still inside the angle brackets, leading toFoo<'a, >instead ofFoo<'a>.Fix
Replace the
segment.args-based check with a source text inspection usingspan_to_snippet. The new logic:<character in the source text<and>This correctly identifies
<>as having no existing parameters, avoiding the trailing comma.Test
Added
tests/ui/lifetimes/E0106-trailing-comma-in-lifetime-suggestion.rscovering the specific case of empty angle brackets with lifetime suggestions.