]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/repeat_once.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / repeat_once.txt
1 ### What it does
2 Checks for usage of `.repeat(1)` and suggest the following method for each types.
3 - `.to_string()` for `str`
4 - `.clone()` for `String`
5 - `.to_vec()` for `slice`
6
7 The lint will evaluate constant expressions and values as arguments of `.repeat(..)` and emit a message if
8 they are equivalent to `1`. (Related discussion in [rust-clippy#7306](https://github.com/rust-lang/rust-clippy/issues/7306))
9
10 ### Why is this bad?
11 For example, `String.repeat(1)` is equivalent to `.clone()`. If cloning
12 the string is the intention behind this, `clone()` should be used.
13
14 ### Example
15 ```
16 fn main() {
17     let x = String::from("hello world").repeat(1);
18 }
19 ```
20 Use instead:
21 ```
22 fn main() {
23     let x = String::from("hello world").clone();
24 }
25 ```