Skip to content

Incorrect hints from trivial_regex for bytes regexes  #3647

Open
@jeltz

Description

@jeltz

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions