rust/tests/ui/suggestions/enum-method-probe.fixed

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.7 KiB
Rust
Raw Normal View History

2022-05-30 21:18:03 +00:00
//@ compile-flags: --edition=2021
2022-04-27 02:59:50 +00:00
//@ run-rustfix
2022-05-30 21:18:03 +00:00
2022-04-27 02:59:50 +00:00
#![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` in the current scope
//~| HELP use the `?` operator
Ok(())
}
2022-05-30 21:18:03 +00:00
async fn async_test_result_in_result() -> Result<(), ()> {
let res: Result<_, ()> = Ok(Foo);
res?.get();
//~^ ERROR no method named `get` found for enum `Result` 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` 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() {
2022-04-27 02:59:50 +00:00
let res: Result<_, ()> = Ok(Foo);
res.expect("REASON").get();
//~^ ERROR no method named `get` found for enum `Result` in the current scope
2022-05-30 21:18:03 +00:00
//~| HELP consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
2022-04-27 02:59:50 +00:00
}
fn test_option_in_option() -> Option<()> {
let res: Option<_> = Some(Foo);
res?.get();
//~^ ERROR no method named `get` found for enum `Option` in the current scope
//~| HELP use the `?` operator
Some(())
}
2022-05-30 21:18:03 +00:00
fn test_option_in_unit_return() {
2022-04-27 02:59:50 +00:00
let res: Option<_> = Some(Foo);
res.expect("REASON").get();
//~^ ERROR no method named `get` found for enum `Option` in the current scope
2022-05-30 21:18:03 +00:00
//~| HELP consider using `Option::expect` to unwrap the `Foo` value, panicking if the value is an `Option::None`
2022-04-27 02:59:50 +00:00
}
fn main() {}