about summary refs log tree commit diff
path: root/tests/ui/suggestions/enum-method-probe.fixed
blob: 1ce6a943c5bbab8238b662360ba0d84d32059372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//@ edition: 2021
//@ run-rustfix

#![allow(unused)]

struct Foo;

impl Foo {
    fn get(&self) -> u8 {
        42
    }
}

fn test_result_in_result() -> Result<(), ()> {
    let res: Result<_, ()> = Ok(Foo);
    res?.get();
    //~^ ERROR no method named `get` found for enum `Result<T, E>` in the current scope
    //~| HELP use the `?` operator
    Ok(())
}

async fn async_test_result_in_result() -> Result<(), ()> {
    let res: Result<_, ()> = Ok(Foo);
    res?.get();
    //~^ ERROR no method named `get` found for enum `Result<T, E>` in the current scope
    //~| HELP use the `?` operator
    Ok(())
}

fn test_result_in_unit_return() {
    let res: Result<_, ()> = Ok(Foo);
    res.expect("REASON").get();
    //~^ ERROR no method named `get` found for enum `Result<T, E>` in the current scope
    //~| HELP consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
}

async fn async_test_result_in_unit_return() {
    let res: Result<_, ()> = Ok(Foo);
    res.expect("REASON").get();
    //~^ ERROR no method named `get` found for enum `Result<T, E>` in the current scope
    //~| HELP consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
}

fn test_option_in_option() -> Option<()> {
    let res: Option<_> = Some(Foo);
    res?.get();
    //~^ ERROR no method named `get` found for enum `Option<T>` in the current scope
    //~| HELP use the `?` operator
    Some(())
}

fn test_option_in_unit_return() {
    let res: Option<_> = Some(Foo);
    res.expect("REASON").get();
    //~^ ERROR no method named `get` found for enum `Option<T>` in the current scope
    //~| HELP consider using `Option::expect` to unwrap the `Foo` value, panicking if the value is an `Option::None`
}

fn test_option_private_method() {
    let res: Option<_> = Some(vec![1, 2, 3]);
    res.expect("REASON").len();
    //~^ ERROR method `len` is private
    //~| HELP consider using `Option::expect` to unwrap the `Vec<{integer}>` value, panicking if the value is an `Option::None`
}

fn main() {}