bors
7b566c214e
Auto merge of #13336 - nyurik:ref-option-sig, r=llogiq
...
Suggest `Option<&T>` instead of `&Option<T>`
closes #13054
```rust
// bad code
fn foo(a: &Option<T>) {}
fn bar(&self) -> &Option<T> {}
// Use instead
fn foo(a: Option<&T>) {}
fn bar(&self) -> Option<&T> {}
```
Handles argument types and return types in functions, methods, and closures with explicit types. Honors `avoid_breaking_exported_api` parameter.
See this great [YouTube video](https://www.youtube.com/watch?v=6c7pZYP_iIE ) with the in-depth explanation.
### Open Questions
These are not blocking, and could be done in separate PRs if needed.
* [ ] Should `&Option<Box<T>>` be suggested as `Option<&T>` -- without the box? Handled by [clippy::borrowed_box](https://rust-lang.github.io/rust-clippy/master/index.html#/borrowed_box )
* [ ] Should `&Option<String>` be suggested as `Option<&str>` -- using de-refed type?
### Possible Future Improvements
These cases might also be good to handle, probably in a separate PR.
```rust
fn lambdas() {
let x = |a: &Option<String>| {};
let x = |a: &Option<String>| -> &Option<String> { todo!() };
}
fn mut_ref_to_ref(a: &mut &Option<u8>) {}
```
changelog: [`ref_option`]: Suggest `Option<&T>` instead of `&Option<T>`
2024-09-28 20:16:10 +00:00
..
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-13 14:10:56 +03:00
2024-09-12 16:32:56 +02:00
2024-09-09 17:05:31 +02:00
2024-09-22 20:52:15 +02:00
2024-09-23 17:56:32 +02:00
2024-09-15 09:51:32 +02:00
2024-09-28 11:57:34 -04:00
2024-09-22 21:10:16 +02:00
2024-09-22 21:10:16 +02:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-23 15:39:02 +00:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-22 21:29:32 +02:00
2024-09-22 21:29:32 +02:00
2024-09-22 21:29:32 +02:00
2024-09-09 17:05:31 +02:00
2024-09-23 15:39:02 +00:00
2024-09-12 11:49:16 +05:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-09-14 16:12:00 +05:30
2024-09-22 20:52:15 +02:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-09 21:48:12 +08:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-17 23:19:29 +02:00
2024-09-17 23:19:29 +02:00
2024-09-17 23:19:29 +02:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-08-29 20:20:13 +02:00
2024-08-29 20:20:13 +02:00
2024-09-22 20:52:15 +02:00
2024-09-24 15:17:52 -04:00
2024-09-24 15:17:52 -04:00
2024-09-24 15:17:52 -04:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-08-29 20:20:13 +02:00
2024-08-29 20:20:13 +02:00
2024-08-29 20:20:13 +02:00
2024-08-29 20:20:13 +02:00
2024-09-06 00:55:42 +02:00
2024-09-06 00:55:42 +02:00
2024-09-06 00:55:42 +02:00
2024-09-06 00:55:42 +02:00
2024-09-06 00:55:42 +02:00
2024-09-06 00:55:42 +02:00
2024-09-05 18:38:12 -07:00
2024-09-05 18:38:12 -07:00
2024-09-05 18:38:12 -07:00
2024-09-04 21:22:28 +00:00
2024-09-04 21:22:28 +00:00
2024-09-04 21:22:28 +00:00
2024-09-04 21:22:28 +00:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-09-13 14:10:56 +03:00
2024-09-13 14:10:56 +03:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-13 14:10:56 +03:00
2024-09-22 20:52:15 +02:00
2024-08-31 15:35:42 +03:00
2024-09-12 16:32:56 +02:00
2024-09-18 06:10:51 +00:00
2024-09-18 06:10:51 +00:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-09-22 20:52:15 +02:00
2024-09-07 13:21:14 +05:30
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-07 13:21:14 +05:30
2024-09-11 13:58:05 -03:00
2024-09-03 18:58:05 +02:00
2024-09-03 18:58:05 +02:00
2024-09-13 18:26:29 +02:00
2024-09-13 18:26:29 +02:00
2024-09-09 10:18:31 +02:00
2024-09-09 10:18:31 +02:00
2024-09-09 10:18:31 +02:00
2024-09-13 14:10:56 +03:00
2024-09-13 14:10:56 +03:00
2024-09-13 14:10:56 +03:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-09-06 23:10:42 +08:00
2024-08-31 05:25:59 +08:00
2024-09-06 23:10:42 +08:00
2024-09-22 20:52:15 +02:00
2024-09-22 20:52:15 +02:00
2024-09-06 23:10:42 +08:00
2024-09-22 20:52:15 +02:00
2024-09-12 23:33:22 +00:00
2024-09-12 23:33:22 +00:00
2024-09-09 17:05:31 +02:00
2024-09-09 17:05:31 +02:00
2024-09-22 20:52:15 +02:00
2024-09-01 12:38:59 +02:00
2024-09-01 12:38:59 +02:00
2024-09-01 12:38:59 +02:00
2024-09-22 20:52:15 +02:00
2024-09-01 12:38:59 +02:00
2024-09-01 12:38:59 +02:00
2024-09-07 17:18:55 +02:00
2024-09-07 17:18:55 +02:00
2024-09-19 21:27:39 +02:00
2024-09-19 21:27:39 +02:00
2024-09-19 21:27:39 +02:00
2024-09-09 21:48:12 +08:00
2024-09-27 21:44:19 +00:00
2024-09-27 21:44:19 +00:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-23 15:39:02 +00:00
2024-09-21 00:57:47 +01:00
2024-09-21 00:57:47 +01:00
2024-09-21 00:57:47 +01:00
2024-09-13 14:10:56 +03:00
2024-09-13 14:10:56 +03:00
2024-09-13 14:10:56 +03:00
2024-09-25 13:12:19 -05:00
2024-09-25 13:12:19 -05:00