![](/style/images/good.png)
7
![](/style/images/bad.png)
Github Add lint `manual_str_repeat` by Jarcho · Pull Request #7265 · rust-lang/r...
source link: https://github.com/rust-lang/rust-clippy/pull/7265
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
I tested this lint against a lot of crates and it worked perfectly.
Some of the type checks could be tightened up through because it can get confused by custom implementations of FromIterator
. An example is below. I couldn't find an actual example of this in real code.
#![warn(clippy::manual_str_repeat)]
use core::iter;
use core::iter::FromIterator;
#[derive(Clone)]
struct S {}
impl FromIterator<Box<S>> for String {
fn from_iter<I: IntoIterator<Item = Box<S>>>(_: I) -> String {
"abc".to_string()
}
}
fn main() {
let _: String = iter::repeat(Box::new(S {})).take(3).collect();
//Bad suggestion:
//let _ = (&Box::new(S {})).repeat(3);
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK