-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Lint single-character strings as P: Pattern args #669
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
Conversation
let hint = snippet(cx, expr.span, "..").replace(&format!("\"{}\"", r), &format!("'{}'", r)); | ||
span_lint_and_then(cx, | ||
SINGLE_CHAR_PATTERN, | ||
expr.span, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That one should be arg.span
.
New commit pushed with @mcarton's nits fixed. |
char is faster, proven by benchmark.
|
||
// Not yet testing for multi-byte characters | ||
// Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_single_char_pattern` | ||
// should have done this but produced an ICE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a bug open for that ICE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find one, although there may be (there are a lot of issues on rustc to filter through). It seems to happen here, on outputting the hint for x.split("💣");
:
tests/compile-fail/methods.rs:377:13: 377:16 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#single_char_pattern
tests/compile-fail/methods.rs:378:13: 378:16 error: single-character string constant used as pattern
tests/compile-fail/methods.rs:378 x.split("💣");
^~~
tests/compile-fail/methods.rs:4:9: 4:15 note: lint level defined here
tests/compile-fail/methods.rs:4 #![deny(clippy, clippy_pedantic)]
^~~~~~
tests/compile-fail/methods.rs:378:5: 378:17 help: try using a char instead:
error: internal compiler error: Error constructed but not emitted
thread panicked while panicking. aborting.
Probably related, the formatting on the hint output gets broken on multibyte chars, e.g.:
tests/compile-fail/methods.rs:377:13: 377:16 error: single-character string constant used as pattern
tests/compile-fail/methods.rs:377 x.split("ℝ");
^~~
tests/compile-fail/methods.rs:4:9: 4:15 note: lint level defined here
tests/compile-fail/methods.rs:4 #![deny(clippy, clippy_pedantic)]
^~~~~~
tests/compile-fail/methods.rs:377:5: 377:17 help: try using a char instead:
tests/compile-fail/methods.rs: x.split('ℝ')");
Lint single-character strings as P: Pattern args
Fixes #650