diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-03-17 13:14:26 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-17 13:14:26 +0000 |
| commit | 0a18e4355a38bd0657e2083a81198f47b76857b6 (patch) | |
| tree | 95fee89bc073a7651d99bf32540fa48fc2da948d | |
| parent | 502e30e6767ef26cf56158a92b47b3b8e9b63235 (diff) | |
| parent | 217b30568ed8dc6e11df9978a31747cb1fc9a094 (diff) | |
| download | rust-0a18e4355a38bd0657e2083a81198f47b76857b6.tar.gz rust-0a18e4355a38bd0657e2083a81198f47b76857b6.zip | |
Merge #11740
11740: Insert #[must_use] in generate_is_empty_from_len r=lnicola a=Walther Inserts `#[must_use]` for the generated `is_empty` methods. I also added the `#[must_use]` for the `len()` methods in the documentation examples and tests for this generator while at it, to make sure they too encourage the use of the annotation. From discussion in https://github.com/rust-analyzer/rust-analyzer/issues/11736 and https://github.com/rust-analyzer/rust-analyzer/pull/11738 Co-authored-by: Walther <veeti.haapsamo@gmail.com>
| -rw-r--r-- | crates/ide_assists/src/handlers/generate_is_empty_from_len.rs | 18 | ||||
| -rw-r--r-- | crates/ide_assists/src/tests/generated.rs | 3 |
2 files changed, 21 insertions, 0 deletions
diff --git a/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs b/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs index db0cfbe2ec0..bd7c85c4430 100644 --- a/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs +++ b/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs @@ -17,6 +17,7 @@ use crate::{ // struct MyStruct { data: Vec<String> } // // impl MyStruct { +// #[must_use] // p$0ub fn len(&self) -> usize { // self.data.len() // } @@ -27,10 +28,12 @@ use crate::{ // struct MyStruct { data: Vec<String> } // // impl MyStruct { +// #[must_use] // pub fn len(&self) -> usize { // self.data.len() // } // +// #[must_use] // pub fn is_empty(&self) -> bool { // self.len() == 0 // } @@ -72,6 +75,7 @@ pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext) |builder| { let code = r#" + #[must_use] pub fn is_empty(&self) -> bool { self.len() == 0 }"# @@ -129,6 +133,7 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] p$0ub fn len(&self, _i: bool) -> usize { self.data.len() } @@ -146,10 +151,12 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] p$0ub fn len(&self) -> usize { self.data.len() } + #[must_use] pub fn is_empty(&self) -> bool { self.len() == 0 } @@ -167,6 +174,7 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] p$0ub fn len(&self) -> u32 { self.data.len() } @@ -183,6 +191,7 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] p$0ub fn len(&self) -> usize { self.data.len() } @@ -192,10 +201,12 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] pub fn len(&self) -> usize { self.data.len() } + #[must_use] pub fn is_empty(&self) -> bool { self.len() == 0 } @@ -212,10 +223,12 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] pub fn new() -> Self { Self { data: 0 } } + #[must_use] p$0ub fn len(&self) -> usize { self.data.len() } @@ -229,14 +242,17 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] pub fn new() -> Self { Self { data: 0 } } + #[must_use] pub fn len(&self) -> usize { self.data.len() } + #[must_use] pub fn is_empty(&self) -> bool { self.len() == 0 } @@ -257,12 +273,14 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] p$0ub fn len(&self) -> usize { self.data.len() } } impl MyStruct { + #[must_use] pub fn is_empty(&self) -> bool { self.len() == 0 } diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs index 53e5d085909..84c130ffa86 100644 --- a/crates/ide_assists/src/tests/generated.rs +++ b/crates/ide_assists/src/tests/generated.rs @@ -1099,6 +1099,7 @@ fn doctest_generate_is_empty_from_len() { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] p$0ub fn len(&self) -> usize { self.data.len() } @@ -1108,10 +1109,12 @@ impl MyStruct { struct MyStruct { data: Vec<String> } impl MyStruct { + #[must_use] pub fn len(&self) -> usize { self.data.len() } + #[must_use] pub fn is_empty(&self) -> bool { self.len() == 0 } |
