about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-08-17 21:15:48 +0000
committerbors <bors@rust-lang.org>2021-08-17 21:15:48 +0000
commit1fc1aee7be6e7e71f12eacd60b9b1040e7640fe4 (patch)
tree008276c6d2c7a85574eb446235521fe4f7facc29 /src/test/codegen
parentcde7e6b8d3502f6eb6a11ba85af812161c2ac03a (diff)
parentaab3267412bd23cae4fd58e860b6b9a36de42448 (diff)
downloadrust-1fc1aee7be6e7e71f12eacd60b9b1040e7640fe4.tar.gz
rust-1fc1aee7be6e7e71f12eacd60b9b1040e7640fe4.zip
Auto merge of #7565 - Jarcho:manual_split_once, r=llogiq
New lint `manual_split_once`

This is a WIP because it still needs to recognize more patterns. Currently handles:

```rust
s.splitn(2, ' ').next();
s.splitn(2, ' ').nth(0)
s.splitn(2, ' ').nth(1);
s.splitn(2, ' ').skip(0).next();
s.splitn(2, ' ').skip(1).next();
s.splitn(2, ' ').next_tuple(); // from itertools

// as well as `unwrap()` and `?` forms
```

Still to do:

```rust
let mut iter = s.splitn(2, ' ');
(iter.next().unwrap(), iter.next()?)

let mut iter = s.splitn(2, ' ');
let key = iter.next().unwrap();
let value = iter.next()?;
```

Suggestions on other patterns to check for would be useful. I've done a search on github for uses of `splitn`. Still have yet to actually look through the results.

There's also the question of whether the lint shouold trigger on all uses of `splitn` with two values, or only on recognized usages. The former could have false positives where it couldn't be replaced, but I'm not sure how common that would be.

changelog: Add lint `manual_split_once`
Diffstat (limited to 'src/test/codegen')
0 files changed, 0 insertions, 0 deletions