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

60 lines
1.7 KiB
Rust
Raw Normal View History

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