// run-rustfix
#![allow(dead_code)]
+#![allow(unused_variables)]
fn option_unwrap_or() {
// int case
fn result_unwrap_or() {
// int case
+ Ok::<i32, &str>(1).unwrap_or(42);
+
+ // int case, suggestion must surround with parenthesis
(Ok(1) as Result<i32, &str>).unwrap_or(42);
// int case reversed
- (Ok(1) as Result<i32, &str>).unwrap_or(42);
+ Ok::<i32, &str>(1).unwrap_or(42);
// richer none expr
- (Ok(1) as Result<i32, &str>).unwrap_or(1 + 42);
+ Ok::<i32, &str>(1).unwrap_or(1 + 42);
// multiline case
#[rustfmt::skip]
- (Ok(1) as Result<i32, &str>).unwrap_or({
+ Ok::<i32, &str>(1).unwrap_or({
42 + 42
+ 42 + 42 + 42
+ 42 + 42 + 42
});
// string case
- (Ok("Bob") as Result<&str, &str>).unwrap_or("Alice");
+ Ok::<&str, &str>("Bob").unwrap_or("Alice");
// don't lint
- match Ok(1) as Result<i32, &str> {
+ match Ok::<i32, &str>(1) {
Ok(i) => i + 2,
Err(_) => 42,
};
- match Ok(1) as Result<i32, &str> {
+ match Ok::<i32, &str>(1) {
Ok(i) => i,
Err(_) => return,
};
for j in 0..4 {
- match Ok(j) as Result<i32, &str> {
+ match Ok::<i32, &str>(j) {
Ok(i) => i,
Err(_) => continue,
};
- match Ok(j) as Result<i32, &str> {
+ match Ok::<i32, &str>(j) {
Ok(i) => i,
Err(_) => break,
};
}
+
+ // don't lint, Err value is used
+ match Ok::<&str, &str>("Alice") {
+ Ok(s) => s,
+ Err(s) => s,
+ };
+ // could lint, but unused_variables takes care of it
+ match Ok::<&str, &str>("Alice") {
+ Ok(s) => s,
+ Err(s) => "Bob",
+ };
}
fn main() {}
// run-rustfix
#![allow(dead_code)]
+#![allow(unused_variables)]
fn option_unwrap_or() {
// int case
fn result_unwrap_or() {
// int case
+ match Ok::<i32, &str>(1) {
+ Ok(i) => i,
+ Err(_) => 42,
+ };
+
+ // int case, suggestion must surround with parenthesis
match Ok(1) as Result<i32, &str> {
Ok(i) => i,
Err(_) => 42,
};
// int case reversed
- match Ok(1) as Result<i32, &str> {
+ match Ok::<i32, &str>(1) {
Err(_) => 42,
Ok(i) => i,
};
// richer none expr
- match Ok(1) as Result<i32, &str> {
+ match Ok::<i32, &str>(1) {
Ok(i) => i,
Err(_) => 1 + 42,
};
// multiline case
#[rustfmt::skip]
- match Ok(1) as Result<i32, &str> {
+ match Ok::<i32, &str>(1) {
Ok(i) => i,
Err(_) => {
42 + 42
};
// string case
- match Ok("Bob") as Result<&str, &str> {
+ match Ok::<&str, &str>("Bob") {
Ok(i) => i,
Err(_) => "Alice",
};
// don't lint
- match Ok(1) as Result<i32, &str> {
+ match Ok::<i32, &str>(1) {
Ok(i) => i + 2,
Err(_) => 42,
};
- match Ok(1) as Result<i32, &str> {
+ match Ok::<i32, &str>(1) {
Ok(i) => i,
Err(_) => return,
};
for j in 0..4 {
- match Ok(j) as Result<i32, &str> {
+ match Ok::<i32, &str>(j) {
Ok(i) => i,
Err(_) => continue,
};
- match Ok(j) as Result<i32, &str> {
+ match Ok::<i32, &str>(j) {
Ok(i) => i,
Err(_) => break,
};
}
+
+ // don't lint, Err value is used
+ match Ok::<&str, &str>("Alice") {
+ Ok(s) => s,
+ Err(s) => s,
+ };
+ // could lint, but unused_variables takes care of it
+ match Ok::<&str, &str>("Alice") {
+ Ok(s) => s,
+ Err(s) => "Bob",
+ };
}
fn main() {}
error: this pattern reimplements `Option::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:6:5
+ --> $DIR/manual_unwrap_or.rs:7:5
|
LL | / match Some(1) {
LL | | Some(i) => i,
= note: `-D clippy::manual-unwrap-or` implied by `-D warnings`
error: this pattern reimplements `Option::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:12:5
+ --> $DIR/manual_unwrap_or.rs:13:5
|
LL | / match Some(1) {
LL | | None => 42,
| |_____^ help: replace with: `Some(1).unwrap_or(42)`
error: this pattern reimplements `Option::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:18:5
+ --> $DIR/manual_unwrap_or.rs:19:5
|
LL | / match Some(1) {
LL | | Some(i) => i,
| |_____^ help: replace with: `Some(1).unwrap_or(1 + 42)`
error: this pattern reimplements `Option::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:25:5
+ --> $DIR/manual_unwrap_or.rs:26:5
|
LL | / match Some(1) {
LL | | Some(i) => i,
|
error: this pattern reimplements `Option::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:35:5
+ --> $DIR/manual_unwrap_or.rs:36:5
|
LL | / match Some("Bob") {
LL | | Some(i) => i,
| |_____^ help: replace with: `Some("Bob").unwrap_or("Alice")`
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:85:5
+ --> $DIR/manual_unwrap_or.rs:86:5
+ |
+LL | / match Ok::<i32, &str>(1) {
+LL | | Ok(i) => i,
+LL | | Err(_) => 42,
+LL | | };
+ | |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(42)`
+
+error: this pattern reimplements `Result::unwrap_or`
+ --> $DIR/manual_unwrap_or.rs:92:5
|
LL | / match Ok(1) as Result<i32, &str> {
LL | | Ok(i) => i,
| |_____^ help: replace with: `(Ok(1) as Result<i32, &str>).unwrap_or(42)`
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:91:5
+ --> $DIR/manual_unwrap_or.rs:98:5
|
-LL | / match Ok(1) as Result<i32, &str> {
+LL | / match Ok::<i32, &str>(1) {
LL | | Err(_) => 42,
LL | | Ok(i) => i,
LL | | };
- | |_____^ help: replace with: `(Ok(1) as Result<i32, &str>).unwrap_or(42)`
+ | |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(42)`
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:97:5
+ --> $DIR/manual_unwrap_or.rs:104:5
|
-LL | / match Ok(1) as Result<i32, &str> {
+LL | / match Ok::<i32, &str>(1) {
LL | | Ok(i) => i,
LL | | Err(_) => 1 + 42,
LL | | };
- | |_____^ help: replace with: `(Ok(1) as Result<i32, &str>).unwrap_or(1 + 42)`
+ | |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(1 + 42)`
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:104:5
+ --> $DIR/manual_unwrap_or.rs:111:5
|
-LL | / match Ok(1) as Result<i32, &str> {
+LL | / match Ok::<i32, &str>(1) {
LL | | Ok(i) => i,
LL | | Err(_) => {
LL | | 42 + 42
|
help: replace with
|
-LL | (Ok(1) as Result<i32, &str>).unwrap_or({
+LL | Ok::<i32, &str>(1).unwrap_or({
LL | 42 + 42
LL | + 42 + 42 + 42
LL | + 42 + 42 + 42
|
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:114:5
+ --> $DIR/manual_unwrap_or.rs:121:5
|
-LL | / match Ok("Bob") as Result<&str, &str> {
+LL | / match Ok::<&str, &str>("Bob") {
LL | | Ok(i) => i,
LL | | Err(_) => "Alice",
LL | | };
- | |_____^ help: replace with: `(Ok("Bob") as Result<&str, &str>).unwrap_or("Alice")`
+ | |_____^ help: replace with: `Ok::<&str, &str>("Bob").unwrap_or("Alice")`
-error: aborting due to 10 previous errors
+error: aborting due to 11 previous errors