rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.44k stars 1.54k forks source link

Suggest replacing str::split with empty pattern with str::chars #12311

Open Ravenslofty opened 8 months ago

Ravenslofty commented 8 months ago

What it does

I was helping a friend learn Rust by going through Advent of Code 2020, and they needed to split a &str into a Vec<char>. They found the str::split method, and wrote string.split("").collect::<Vec<char>>(). While reviewing their code, this tripped me up a bit, since I would think of string.chars().collect::<Vec<char>>() instead. I think this would be a good candidate for a lint.

Advantage

Drawbacks

Example

"hello world".split(""); 

The above should trigger a suggestion of replacing with

"hello world".chars();
Vrajs16 commented 6 months ago

@rustbot claim