mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
Clarify message for unwrap lint
This commit is contained in:
parent
377d72ae8b
commit
f93fb9a417
@ -89,15 +89,15 @@ enum UnwrappableKind {
|
|||||||
impl UnwrappableKind {
|
impl UnwrappableKind {
|
||||||
fn success_variant_pattern(self) -> &'static str {
|
fn success_variant_pattern(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
UnwrappableKind::Option => "Some(..)",
|
UnwrappableKind::Option => "Some(<item>)",
|
||||||
UnwrappableKind::Result => "Ok(..)",
|
UnwrappableKind::Result => "Ok(<item>)",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_variant_pattern(self) -> &'static str {
|
fn error_variant_pattern(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
UnwrappableKind::Option => "None",
|
UnwrappableKind::Option => "None",
|
||||||
UnwrappableKind::Result => "Err(..)",
|
UnwrappableKind::Result => "Err(<item>)",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
--> tests/ui/checked_unwrap/complex_conditionals_nested.rs:13:13
|
||||||
|
|
|
|
||||||
LL | if x.is_some() {
|
LL | if x.is_some() {
|
||||||
| -------------- help: try: `if let Some(..) = x`
|
| -------------- help: try: `if let Some(<item>) = x`
|
||||||
LL | // unnecessary
|
LL | // unnecessary
|
||||||
LL | x.unwrap();
|
LL | x.unwrap();
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:46:9
|
||||||
|
|
|
|
||||||
LL | if x.is_some() {
|
LL | if x.is_some() {
|
||||||
| -------------- help: try: `if let Some(..) = x`
|
| -------------- help: try: `if let Some(<item>) = x`
|
||||||
LL | // unnecessary
|
LL | // unnecessary
|
||||||
LL | x.unwrap();
|
LL | x.unwrap();
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:49:9
|
||||||
|
|
|
|
||||||
LL | if x.is_some() {
|
LL | if x.is_some() {
|
||||||
| -------------- help: try: `if let Some(..) = x`
|
| -------------- help: try: `if let Some(<item>) = x`
|
||||||
...
|
...
|
||||||
LL | x.expect("an error message");
|
LL | x.expect("an error message");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:65:9
|
||||||
|
|
|
|
||||||
LL | if x.is_none() {
|
LL | if x.is_none() {
|
||||||
| -------------- help: try: `if let Some(..) = x`
|
| -------------- help: try: `if let Some(<item>) = x`
|
||||||
...
|
...
|
||||||
LL | x.unwrap();
|
LL | x.unwrap();
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:13:13
|
||||||
|
|
|
|
||||||
LL | if $a.is_some() {
|
LL | if $a.is_some() {
|
||||||
| --------------- help: try: `if let Some(..) = x`
|
| --------------- help: try: `if let Some(<item>) = x`
|
||||||
LL | // unnecessary
|
LL | // unnecessary
|
||||||
LL | $a.unwrap();
|
LL | $a.unwrap();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:78:9
|
||||||
|
|
|
|
||||||
LL | if x.is_ok() {
|
LL | if x.is_ok() {
|
||||||
| ------------ help: try: `if let Ok(..) = x`
|
| ------------ help: try: `if let Ok(<item>) = x`
|
||||||
LL | // unnecessary
|
LL | // unnecessary
|
||||||
LL | x.unwrap();
|
LL | x.unwrap();
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:81:9
|
||||||
|
|
|
|
||||||
LL | if x.is_ok() {
|
LL | if x.is_ok() {
|
||||||
| ------------ help: try: `if let Ok(..) = x`
|
| ------------ help: try: `if let Ok(<item>) = x`
|
||||||
...
|
...
|
||||||
LL | x.expect("an error message");
|
LL | x.expect("an error message");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:94:9
|
||||||
|
|
|
|
||||||
LL | if x.is_ok() {
|
LL | if x.is_ok() {
|
||||||
| ------------ help: try: `if let Err(..) = x`
|
| ------------ help: try: `if let Err(<item>) = x`
|
||||||
...
|
...
|
||||||
LL | x.unwrap_err();
|
LL | x.unwrap_err();
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:102:9
|
||||||
|
|
|
|
||||||
LL | if x.is_err() {
|
LL | if x.is_err() {
|
||||||
| ------------- help: try: `if let Err(..) = x`
|
| ------------- help: try: `if let Err(<item>) = x`
|
||||||
...
|
...
|
||||||
LL | x.unwrap_err();
|
LL | x.unwrap_err();
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:106:9
|
||||||
|
|
|
|
||||||
LL | if x.is_err() {
|
LL | if x.is_err() {
|
||||||
| ------------- help: try: `if let Ok(..) = x`
|
| ------------- help: try: `if let Ok(<item>) = x`
|
||||||
...
|
...
|
||||||
LL | x.unwrap();
|
LL | x.unwrap();
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:134:9
|
||||||
|
|
|
|
||||||
LL | if option.is_some() {
|
LL | if option.is_some() {
|
||||||
| ------------------- help: try: `if let Some(..) = &option`
|
| ------------------- help: try: `if let Some(<item>) = &option`
|
||||||
LL | option.as_ref().unwrap();
|
LL | option.as_ref().unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:144:9
|
||||||
|
|
|
|
||||||
LL | if result.is_ok() {
|
LL | if result.is_ok() {
|
||||||
| ----------------- help: try: `if let Ok(..) = &result`
|
| ----------------- help: try: `if let Ok(<item>) = &result`
|
||||||
LL | result.as_ref().unwrap();
|
LL | result.as_ref().unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:153:9
|
||||||
|
|
|
|
||||||
LL | if option.is_some() {
|
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();
|
LL | option.as_mut().unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
@ -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
|
--> tests/ui/checked_unwrap/simple_conditionals.rs:162:9
|
||||||
|
|
|
|
||||||
LL | if result.is_ok() {
|
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();
|
LL | result.as_mut().unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user