Skip to content

Conversation

@ada4a
Copy link
Contributor

@ada4a ada4a commented Aug 2, 2025

Apparently, one can surround a pattern with an arbitrary number of parens, and the resulting Pat won't include the span of those parens. And the previous approach extended the to-be-deleted span all the way to the end of Pat's span, so it included the closing paren.

I think the new approach is more robust anyway, since all we care to remove (besides the _) is the :, so we search just for that.

This does leave one extra whitespace in one of the test cases, but I'd say let rustfmt handle that. fixed in the third commit

changelog: [let_with_type_underscore]: don't eat closing paren in let (i): _ = 0;

fixes #15377

@rustbot
Copy link
Collaborator

rustbot commented Aug 2, 2025

r? @blyxyas

rustbot has assigned @blyxyas.
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 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 2, 2025
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 rustbot assigned samueltardieu and unassigned blyxyas Aug 2, 2025
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.

LGTM. Could you squash the commits?

add failing tests

fix

also remove whitespace before `:`
@ada4a ada4a force-pushed the let-with-type-underscore branch from 2c938a3 to 0f98da7 Compare August 2, 2025 07:48
@ada4a
Copy link
Contributor Author

ada4a commented Aug 2, 2025

thank you! done

@samueltardieu samueltardieu enabled auto-merge August 2, 2025 07:49
@samueltardieu samueltardieu added this pull request to the merge queue Aug 2, 2025
Merged via the queue into rust-lang:master with commit e42586d Aug 2, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 2, 2025
@ada4a ada4a deleted the let-with-type-underscore branch August 3, 2025 15:23
github-merge-queue bot pushed a commit that referenced this pull request Sep 7, 2025
This kind of supersedes
#15386 -- by making the
lint early-pass, we get access to `TyKind::Paren`s that surround the
type ascription. And with that, we can return to the simpler calculation
of `span_to_remove`.

The biggest hurdle was `is_from_proc_macro` -- calling that function
required me to `impl WithSearchPat for rustc_ast::Ty`, i.e.
`ast_ty_search_pat`, which I based on `ty_search_pat`. Since that's a
larger change, I could extract it into a PR of its own.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

let-with-type-underscore is removing ) causing syntax error

4 participants