Skip to content
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 suggestion error in [useless_vec] #12116

Merged
merged 2 commits into from Feb 26, 2024
Merged

Conversation

J-ZhengLi
Copy link
Member

fixes: #12101


changelog: fix suggestion error in [useless_vec]

r+ @matthiaskrgr since they opened the issue?

@rustbot
Copy link
Collaborator

rustbot commented Jan 10, 2024

r? @Alexendoo

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 10, 2024
@J-ZhengLi
Copy link
Member Author

Oops, I... messed up the command, I'm sorry 😅

r? @matthiaskrgr

@rustbot rustbot assigned matthiaskrgr and unassigned Alexendoo Jan 10, 2024
{
// report the error around the `vec!` not inside `<std macros>:`
let span = expr.span.ctxt().outer_expn_data().call_site;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the real question is: why does this return an empty span?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the example from the issue:

for elt in &(vec![...]) {
//         ^^^^^^^^^^^^ expr

expr is the reference to the expansion of the vec macro because vec_args is constructed from higher::VecArgs::hir(cx, expr.peel_borrows()), I think a clearer solution would be get the parent callsite of expr.peel_borrows(), can stick it at the top once since outer_expn_data().call_site seems to repeated many times currently

Comment on lines 211 to 206
let maybe_len = len_span
.map(|sp| format!("; {}", snippet_with_applicability(cx, sp, "len", app)))
.unwrap_or_default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this get an empty string, that would result in ; ?
I wonder if we should trim in this case to not suggest adding empty spaces in the suggestion, if that makes sense.

Copy link
Member Author

@J-ZhengLi J-ZhengLi Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, it might, if the span is empty in some rare occasions when macros involved (?).
Or, suggesting ; len by default... which is not a correct suggestion anyway...

I'll make sure no suggestion is given in these scenarios, but I can't guarantee to come up with some test cases to test it lol 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, was just trying to think of "what could go wrong"

@matthiaskrgr
Copy link
Member

LGTM but I'm also kinda a noob at reviewing clippy prs, so I'd like to have a second eye on this by someone who is more knowledgeable (aka literally anyone else :D )

@bors
Copy link
Collaborator

bors commented Feb 22, 2024

☔ The latest upstream changes (presumably #12331) made this pull request unmergeable. Please resolve the merge conflicts.

@J-ZhengLi J-ZhengLi force-pushed the issue12101 branch 3 times, most recently from d19011e to 929f746 Compare February 23, 2024 08:35
@J-ZhengLi
Copy link
Member Author

I think a clearer solution would be get the parent callsite of expr.peel_borrows()

@Alexendoo Thanks for the hint 😄 Also, since you already looked this one, and matthiaskrgr asked for a second eye, do you want to be assigned to this?

@Alexendoo
Copy link
Member

Thanks, looks good!

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 24, 2024

📌 Commit 929f746 has been approved by Alexendoo

It is now in the queue for this repository.

bors added a commit that referenced this pull request Feb 24, 2024
fix suggestion error in [`useless_vec`]

fixes: #12101

---

changelog: fix suggestion error in [`useless_vec`]

r+ `@matthiaskrgr` since they opened the issue?
@bors
Copy link
Collaborator

bors commented Feb 24, 2024

⌛ Testing commit 929f746 with merge 4088676...

@bors
Copy link
Collaborator

bors commented Feb 24, 2024

💔 Test failed - checks-action_test

@J-ZhengLi
Copy link
Member Author

hmmm @Alexendoo, this is weird, bot says I need to run cargo bless which I did already, and I couldn't reproduce the error, so I assuming it was the macos machine had a hiccup or something? Could you retry please?

@Alexendoo
Copy link
Member

@bors retry

@bors
Copy link
Collaborator

bors commented Feb 26, 2024

⌛ Testing commit 929f746 with merge 580b32a...

bors added a commit that referenced this pull request Feb 26, 2024
fix suggestion error in [`useless_vec`]

fixes: #12101

---

changelog: fix suggestion error in [`useless_vec`]

r+ `@matthiaskrgr` since they opened the issue?
@bors
Copy link
Collaborator

bors commented Feb 26, 2024

💔 Test failed - checks-action_test

@Alexendoo
Copy link
Member

@bors retry

bors added a commit that referenced this pull request Feb 26, 2024
fix suggestion error in [`useless_vec`]

fixes: #12101

---

changelog: fix suggestion error in [`useless_vec`]

r+ `@matthiaskrgr` since they opened the issue?
@bors
Copy link
Collaborator

bors commented Feb 26, 2024

⌛ Testing commit 929f746 with merge 8a35f20...

@bors
Copy link
Collaborator

bors commented Feb 26, 2024

💔 Test failed - checks-action_test

@Alexendoo
Copy link
Member

Still a different error each time... @bors r+

@bors
Copy link
Collaborator

bors commented Feb 26, 2024

💡 This pull request was already approved, no need to approve it again.

  • This pull request previously failed. You should add more commits to fix the bug, or use retry to trigger a build again.

@bors
Copy link
Collaborator

bors commented Feb 26, 2024

📌 Commit 929f746 has been approved by Alexendoo

It is now in the queue for this repository.

@Alexendoo
Copy link
Member

Oops, @bors retry

bors added a commit that referenced this pull request Feb 26, 2024
fix suggestion error in [`useless_vec`]

fixes: #12101

---

changelog: fix suggestion error in [`useless_vec`]

r+ `@matthiaskrgr` since they opened the issue?
@bors
Copy link
Collaborator

bors commented Feb 26, 2024

⌛ Testing commit 929f746 with merge 8b91b30...

@bors
Copy link
Collaborator

bors commented Feb 26, 2024

💔 Test failed - checks-action_test

@Alexendoo
Copy link
Member

@bors retry

@bors
Copy link
Collaborator

bors commented Feb 26, 2024

⌛ Testing commit 929f746 with merge d12b53e...

@bors
Copy link
Collaborator

bors commented Feb 26, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Alexendoo
Pushing d12b53e to master...

@bors bors merged commit d12b53e into rust-lang:master Feb 26, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useless_vec: missing spans if vec is not a fn param
5 participants