Skip to content

Commit

Permalink
Auto merge of #13253 - alex-semenyuk:fix_message_unnecessary_unwrap, …
Browse files Browse the repository at this point in the history
…r=llogiq

Clarify suggestion message for unwrap lint

Close #10217
As mentioned at #10217 message for `unwrap` uses `..` like `Some(..)` which can confuse with slice and other places mostly use `<item>` like `for (i, <item>) in target_groups_json.iter().enumerate().skip(1) {` So replace  `..` to `<item>`

changelog: [`unnecessary_unwrap`] clarify suggestion message
  • Loading branch information
bors committed Aug 13, 2024
2 parents 84e98eb + f93fb9a commit 70457f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ enum UnwrappableKind {
impl UnwrappableKind {
fn success_variant_pattern(self) -> &'static str {
match self {
UnwrappableKind::Option => "Some(..)",
UnwrappableKind::Result => "Ok(..)",
UnwrappableKind::Option => "Some(<item>)",
UnwrappableKind::Result => "Ok(<item>)",
}
}

fn error_variant_pattern(self) -> &'static str {
match self {
UnwrappableKind::Option => "None",
UnwrappableKind::Result => "Err(..)",
UnwrappableKind::Result => "Err(<item>)",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/checked_unwrap/complex_conditionals_nested.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: called `unwrap` on `x` after checking its variant with `is_some`
--> tests/ui/checked_unwrap/complex_conditionals_nested.rs:13:13
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
| -------------- help: try: `if let Some(<item>) = x`
LL | // unnecessary
LL | x.unwrap();
| ^^^^^^^^^^
Expand Down
26 changes: 13 additions & 13 deletions tests/ui/checked_unwrap/simple_conditionals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: called `unwrap` on `x` after checking its variant with `is_some`
--> tests/ui/checked_unwrap/simple_conditionals.rs:46:9
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
| -------------- help: try: `if let Some(<item>) = x`
LL | // unnecessary
LL | x.unwrap();
| ^^^^^^^^^^
Expand All @@ -17,7 +17,7 @@ error: called `expect` on `x` after checking its variant with `is_some`
--> tests/ui/checked_unwrap/simple_conditionals.rs:49:9
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
| -------------- help: try: `if let Some(<item>) = x`
...
LL | x.expect("an error message");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -59,7 +59,7 @@ error: called `unwrap` on `x` after checking its variant with `is_none`
--> tests/ui/checked_unwrap/simple_conditionals.rs:65:9
|
LL | if x.is_none() {
| -------------- help: try: `if let Some(..) = x`
| -------------- help: try: `if let Some(<item>) = x`
...
LL | x.unwrap();
| ^^^^^^^^^^
Expand All @@ -68,7 +68,7 @@ error: called `unwrap` on `x` after checking its variant with `is_some`
--> tests/ui/checked_unwrap/simple_conditionals.rs:13:13
|
LL | if $a.is_some() {
| --------------- help: try: `if let Some(..) = x`
| --------------- help: try: `if let Some(<item>) = x`
LL | // unnecessary
LL | $a.unwrap();
| ^^^^^^^^^^^
Expand All @@ -82,7 +82,7 @@ error: called `unwrap` on `x` after checking its variant with `is_ok`
--> tests/ui/checked_unwrap/simple_conditionals.rs:78:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Ok(..) = x`
| ------------ help: try: `if let Ok(<item>) = x`
LL | // unnecessary
LL | x.unwrap();
| ^^^^^^^^^^
Expand All @@ -91,7 +91,7 @@ error: called `expect` on `x` after checking its variant with `is_ok`
--> tests/ui/checked_unwrap/simple_conditionals.rs:81:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Ok(..) = x`
| ------------ help: try: `if let Ok(<item>) = x`
...
LL | x.expect("an error message");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -127,7 +127,7 @@ error: called `unwrap_err` on `x` after checking its variant with `is_ok`
--> tests/ui/checked_unwrap/simple_conditionals.rs:94:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Err(..) = x`
| ------------ help: try: `if let Err(<item>) = x`
...
LL | x.unwrap_err();
| ^^^^^^^^^^^^^^
Expand All @@ -145,7 +145,7 @@ error: called `unwrap_err` on `x` after checking its variant with `is_err`
--> tests/ui/checked_unwrap/simple_conditionals.rs:102:9
|
LL | if x.is_err() {
| ------------- help: try: `if let Err(..) = x`
| ------------- help: try: `if let Err(<item>) = x`
...
LL | x.unwrap_err();
| ^^^^^^^^^^^^^^
Expand All @@ -154,7 +154,7 @@ error: called `unwrap` on `x` after checking its variant with `is_err`
--> tests/ui/checked_unwrap/simple_conditionals.rs:106:9
|
LL | if x.is_err() {
| ------------- help: try: `if let Ok(..) = x`
| ------------- help: try: `if let Ok(<item>) = x`
...
LL | x.unwrap();
| ^^^^^^^^^^
Expand All @@ -172,7 +172,7 @@ error: called `unwrap` on `option` after checking its variant with `is_some`
--> tests/ui/checked_unwrap/simple_conditionals.rs:134:9
|
LL | if option.is_some() {
| ------------------- help: try: `if let Some(..) = &option`
| ------------------- help: try: `if let Some(<item>) = &option`
LL | option.as_ref().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -189,7 +189,7 @@ error: called `unwrap` on `result` after checking its variant with `is_ok`
--> tests/ui/checked_unwrap/simple_conditionals.rs:144:9
|
LL | if result.is_ok() {
| ----------------- help: try: `if let Ok(..) = &result`
| ----------------- help: try: `if let Ok(<item>) = &result`
LL | result.as_ref().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -206,7 +206,7 @@ error: called `unwrap` on `option` after checking its variant with `is_some`
--> tests/ui/checked_unwrap/simple_conditionals.rs:153:9
|
LL | if option.is_some() {
| ------------------- help: try: `if let Some(..) = &mut option`
| ------------------- help: try: `if let Some(<item>) = &mut option`
LL | option.as_mut().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -223,7 +223,7 @@ error: called `unwrap` on `result` after checking its variant with `is_ok`
--> tests/ui/checked_unwrap/simple_conditionals.rs:162:9
|
LL | if result.is_ok() {
| ----------------- help: try: `if let Ok(..) = &mut result`
| ----------------- help: try: `if let Ok(<item>) = &mut result`
LL | result.as_mut().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit 70457f6

Please sign in to comment.