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

Don't apply string_lit_as_bytes if in macro expansion #10665

Merged
merged 4 commits into from
Apr 25, 2023

Conversation

Centri3
Copy link
Member

@Centri3 Centri3 commented Apr 18, 2023

The following code will emit a warning on both w! and h!, despite there being nothing the user (or library author) could do about it:

#![warn(clippy::string_lit_as_bytes)]

use windows::w;
use windows::h;

fn main() {
    let _w = w!("example");
    let _h = h!("example");
}

This is because windows-rs will create a binding const INPUT: &[u8] = $s.as_bytes(), and changing this to b"$s" is, well, suboptimal. I don't know enough about Rust to know if this is something that can be detected though if it can be I'm happy with closing this in favor of implementing that.

I'm not sure whether this is how it should be done though, as this simply tells clippy to not invoke this even if it's applicable (this also affects the other string lints, but didn't cause any tests to fail).

changelog: [string_lit_as_bytes]: Don't lint if in external macro

@rustbot
Copy link
Collaborator

rustbot commented Apr 18, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @giraffate (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 18, 2023
Copy link
Contributor

@giraffate giraffate left a comment

Choose a reason for hiding this comment

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

Thanks for creating the pull request! I made some comments. If you have any questions, feel free to ask us.

  • It would be better to ignore it only in an external macro, so this would be helpful for it: fix almost_swapped: Ignore external macros #10502
  • It looks like that this fix affects the string_from_utf8_as_bytes lint. At first, it would be better to fix only string_lit_as_bytes.

@Centri3
Copy link
Member Author

Centri3 commented Apr 20, 2023

Thanks for creating the pull request! I made some comments. If you have any questions, feel free to ask us.

* It would be better to ignore it only in an external macro, so this would be helpful for it: [fix `almost_swapped`: Ignore external macros #10502](https://github.com/rust-lang/rust-clippy/pull/10502)

* It looks like that this fix affects the `string_from_utf8_as_bytes` lint. At first, it would be better to fix only `string_lit_as_bytes`.

Thanks, I wasn't sure how to do that. Done

@bors
Copy link
Contributor

bors commented Apr 20, 2023

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

Copy link
Contributor

@giraffate giraffate left a comment

Choose a reason for hiding this comment

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

Overall looks good, thanks!

We follow the no merge-commit policy, so can you do the rebase the master branch, not merge? Once this is resolved, I'll merge this.
https://github.com/rust-lang/rust-clippy/blob/master/book/src/development/basics.md#pr

@Centri3 Centri3 force-pushed the string_lit_as_bytes_changes branch from 97a49c0 to 14a6fa4 Compare April 25, 2023 10:08
@giraffate
Copy link
Contributor

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Apr 25, 2023

📌 Commit 14a6fa4 has been approved by giraffate

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Apr 25, 2023

⌛ Testing commit 14a6fa4 with merge abd2c1e...

@bors
Copy link
Contributor

bors commented Apr 25, 2023

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

@bors bors merged commit abd2c1e into rust-lang:master Apr 25, 2023
@Centri3 Centri3 deleted the string_lit_as_bytes_changes branch June 2, 2023 00:35
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.

4 participants