Skip to content

Commit 90b428e

Browse files
Cameron SteffenCameron Steffen
Cameron Steffen
authored and
Cameron Steffen
committed
move ok_expect tests
1 parent 3356d12 commit 90b428e

File tree

4 files changed

+61
-68
lines changed

4 files changed

+61
-68
lines changed

tests/ui/methods.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -393,32 +393,6 @@ fn get_unwrap() {
393393

394394
#[allow(similar_names)]
395395
fn main() {
396-
use std::io;
397-
398396
let opt = Some(0);
399397
let _ = opt.unwrap();
400-
401-
let res: Result<i32, ()> = Ok(0);
402-
let _ = res.unwrap();
403-
404-
res.ok().expect("disaster!");
405-
// the following should not warn, since `expect` isn't implemented unless
406-
// the error type implements `Debug`
407-
let res2: Result<i32, MyError> = Ok(0);
408-
res2.ok().expect("oh noes!");
409-
let res3: Result<u32, MyErrorWithParam<u8>>= Ok(0);
410-
res3.ok().expect("whoof");
411-
let res4: Result<u32, io::Error> = Ok(0);
412-
res4.ok().expect("argh");
413-
let res5: io::Result<u32> = Ok(0);
414-
res5.ok().expect("oops");
415-
let res6: Result<u32, &str> = Ok(0);
416-
res6.ok().expect("meh");
417-
}
418-
419-
struct MyError(()); // doesn't implement Debug
420-
421-
#[derive(Debug)]
422-
struct MyErrorWithParam<T> {
423-
x: T
424398
}

tests/ui/methods.stderr

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -500,50 +500,10 @@ error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and
500500
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut some_vecdeque[0]`
501501

502502
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
503-
--> $DIR/methods.rs:399:13
503+
--> $DIR/methods.rs:397:13
504504
|
505-
399 | let _ = opt.unwrap();
505+
397 | let _ = opt.unwrap();
506506
| ^^^^^^^^^^^^
507507
|
508508
= note: `-D option-unwrap-used` implied by `-D warnings`
509509

510-
error: used unwrap() on a Result value. If you don't want to handle the Err case gracefully, consider using expect() to provide a better panic message
511-
--> $DIR/methods.rs:402:13
512-
|
513-
402 | let _ = res.unwrap();
514-
| ^^^^^^^^^^^^
515-
|
516-
= note: `-D result-unwrap-used` implied by `-D warnings`
517-
518-
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
519-
--> $DIR/methods.rs:404:5
520-
|
521-
404 | res.ok().expect("disaster!");
522-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
523-
|
524-
= note: `-D ok-expect` implied by `-D warnings`
525-
526-
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
527-
--> $DIR/methods.rs:410:5
528-
|
529-
410 | res3.ok().expect("whoof");
530-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
531-
532-
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
533-
--> $DIR/methods.rs:412:5
534-
|
535-
412 | res4.ok().expect("argh");
536-
| ^^^^^^^^^^^^^^^^^^^^^^^^
537-
538-
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
539-
--> $DIR/methods.rs:414:5
540-
|
541-
414 | res5.ok().expect("oops");
542-
| ^^^^^^^^^^^^^^^^^^^^^^^^
543-
544-
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
545-
--> $DIR/methods.rs:416:5
546-
|
547-
416 | res6.ok().expect("meh");
548-
| ^^^^^^^^^^^^^^^^^^^^^^^
549-

tests/ui/ok_expect.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::io;
2+
3+
struct MyError(()); // doesn't implement Debug
4+
5+
#[derive(Debug)]
6+
struct MyErrorWithParam<T> {
7+
x: T
8+
}
9+
10+
fn main() {
11+
let res: Result<i32, ()> = Ok(0);
12+
let _ = res.unwrap();
13+
14+
res.ok().expect("disaster!");
15+
// the following should not warn, since `expect` isn't implemented unless
16+
// the error type implements `Debug`
17+
let res2: Result<i32, MyError> = Ok(0);
18+
res2.ok().expect("oh noes!");
19+
let res3: Result<u32, MyErrorWithParam<u8>>= Ok(0);
20+
res3.ok().expect("whoof");
21+
let res4: Result<u32, io::Error> = Ok(0);
22+
res4.ok().expect("argh");
23+
let res5: io::Result<u32> = Ok(0);
24+
res5.ok().expect("oops");
25+
let res6: Result<u32, &str> = Ok(0);
26+
res6.ok().expect("meh");
27+
}

tests/ui/ok_expect.stderr

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
2+
--> $DIR/ok_expect.rs:14:5
3+
|
4+
14 | res.ok().expect("disaster!");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D ok-expect` implied by `-D warnings`
8+
9+
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
10+
--> $DIR/ok_expect.rs:20:5
11+
|
12+
20 | res3.ok().expect("whoof");
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
16+
--> $DIR/ok_expect.rs:22:5
17+
|
18+
22 | res4.ok().expect("argh");
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^
20+
21+
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
22+
--> $DIR/ok_expect.rs:24:5
23+
|
24+
24 | res5.ok().expect("oops");
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^
26+
27+
error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
28+
--> $DIR/ok_expect.rs:26:5
29+
|
30+
26 | res6.ok().expect("meh");
31+
| ^^^^^^^^^^^^^^^^^^^^^^^
32+

0 commit comments

Comments
 (0)