rust-lang / rust-lang/rust-clippy

Incorrect hints from trivial_regex for bytes regexes

Open
#3,647 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.