Uh oh!
There was an error while loading. Please reload this page.
Suggest single quotes when char expected, str provided - #92507
Conversation
rust-highfive
commented
Jan 3, 2022
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. Please see the contribution instructions for more information. |
joshtriplett
commented
Jan 3, 2022
@chordtoll Could you please add a test that demonstrates the new suggestion? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
petrochenkov
commented
Jan 4, 2022
Looks like we actually do not. |
petrochenkov
commented
Jan 4, 2022
r=me after squashing commits. |
0edffee to
3087c4dComparepetrochenkov
commented
Jan 4, 2022
@bors r+ |
bors
commented
Jan 4, 2022
📌 Commit 3087c4d has been approved by |
| if let Some(code) = | ||
| code.strip_prefix('"').and_then(|s| s.strip_suffix('"')) | ||
| { | ||
| if code.chars().nth(1).is_none() { |
There was a problem hiding this comment.
Oh no, I think my suggestion also fires for empty string literals "", sorry 😟! I think it's too late to change in this PR since it's already approved.
| if code.chars().nth(1).is_none(){ | |
| if code.chars().nth(1).is_none()&& !code.is_empty(){ |
Hmm that code is not that self-explanatory.
There was a problem hiding this comment.
Good point- I'll open another PR to add the 0-character check
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#91754 (Modifications to `std::io::Stdin` on Windows so that there is no longer a 4-byte buffer minimum in read().) - rust-lang#91884 (Constify `Box<T, A>` methods) - rust-lang#92107 (Actually set IMAGE_SCN_LNK_REMOVE for .rmeta) - rust-lang#92456 (Make the documentation of builtin macro attributes accessible) - rust-lang#92507 (Suggest single quotes when char expected, str provided) - rust-lang#92525 (intra-doc: Make `Receiver::into_iter` into a clickable link) - rust-lang#92532 (revert rust-lang#92254 "Bump gsgdt to 0.1.3") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Do not suggest char literal for zero-length strings PR rust-lang#92507 adds a hint to switch to single quotes when a char is expected and a single-character string literal is provided. The check to ensure the string literal is one character long missed the 0-char case, and would incorrectly offer the hint. This PR adds the missing check, and a test case to confirm the new behavior.
Do not suggest char literal for zero-length strings PR rust-lang#92507 adds a hint to switch to single quotes when a char is expected and a single-character string literal is provided. The check to ensure the string literal is one character long missed the 0-char case, and would incorrectly offer the hint. This PR adds the missing check, and a test case to confirm the new behavior.
If a type mismatch occurs where a char is expected and a string literal is provided, suggest changing the double quotes to single quotes.
We already provide this suggestion in the other direction ( ' -> " ).
Especially useful for new rust devs used to a language in which single/double quotes are interchangeable.
Fixes#92479.