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

string_lit_as_bytes lint isn't trigged when string contains escaped characters #4796

Closed
upsuper opened this issue Nov 9, 2019 · 2 comments · Fixed by #4808
Closed

string_lit_as_bytes lint isn't trigged when string contains escaped characters #4796

upsuper opened this issue Nov 9, 2019 · 2 comments · Fixed by #4808

Comments

@upsuper
Copy link
Contributor

upsuper commented Nov 9, 2019

I encountered a case where string_lit_as_bytes is not triggered as expected:

let bs = "a byte string\t\n".as_bytes();

If you remove \t\n, then it correctly suggests that it can use byte string literal instead, however, with either \t or \n presents, it doesn't say anything.

I'm testing using Clippy from playground which has version 0.0.212 (2019-10-28 c8e3cfb).

@upsuper
Copy link
Contributor Author

upsuper commented Nov 9, 2019

Probably not too hard to fix, but not trivial either:

} else if callsite == expanded
&& lit_content.as_str().chars().all(|c| c.is_ascii())
&& lit_content.as_str().len() <= MAX_LENGTH_BYTE_STRING_LIT
&& !args[0].span.from_expansion()

@hellow554
Copy link
Contributor

hellow554 commented Nov 12, 2019

lit_content.as_str().chars().all(|c| c.is_ascii()) should be lit_content.as_str().is_ascii() while we're at it

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 a pull request may close this issue.

2 participants