rust-lang / rust-lang/rust-clippy
Incorrect hints from trivial_regex for bytes regexes
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
The trivial_regex lint does not seem to make any difference between regex::Regex and regex::bytes::Regex when giving hints. I am not sure what should be used for non-anchored regexes, maybe the memchr crate, for anchored it should suggest slice::starts_with and slice::ends_with.
warning: trivial regex
--> src/bin/foo.rs:2:30
|
2 | regex::bytes::Regex::new("foo").unwrap();
| ^^^^^
|
= note: #[warn(clippy::trivial_regex)] on by default
= help: consider using `str::contains`
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#trivial_regex
warning: trivial regex
--> src/bin/foo.rs:3:30
|
3 | regex::bytes::Regex::new("^bar").unwrap();
| ^^^^^^
|
= help: consider using `str::starts_with`
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#trivial_regex
Version: clippy 0.0.212 (2e26fdc 2018-11-22)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the trivial_regex lint with the regex::bytes::Regex examples in src/bin/foo.rs, including the unanchored and ^bar patterns. Locate the lint implementation and its tests, then verify that byte regexes receive appropriate hints and that anchored patterns suggest slice::starts_with or slice::ends_with.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100