rust/tests/ui/suggestions/enum-method-probe.stderr
Esteban Küber 78fc7c351d Suggest unwrapping when private method name is available in inner type
Given

```rust
fn main() {
    let maybe_vec = Some(vec![1,2,3]);
    assert_eq!(maybe_vec.len(), 3);
}
```

suggest unwraping `maybe_vec` to call `.len()` on the `Vec<_>`.

```
error[E0624]: method `len` is private
  --> $DIR/enum-method-probe.rs:61:9
   |
LL |     res.len();
   |         ^^^ private method
  --> $SRC_DIR/core/src/option.rs:LL:COL
   |
   = note: private method defined here
   |
note: the method `len` exists on the type `Vec<{integer}>`
  --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
help: consider using `Option::expect` to unwrap the `Vec<{integer}>` value, panicking if the value is an `Option::None`
   |
LL |     res.expect("REASON").len();
   |        +++++++++++++++++
```
2025-07-23 19:23:49 +00:00

116 lines
3.7 KiB
Text

error[E0599]: no method named `get` found for enum `Result` in the current scope
--> $DIR/enum-method-probe.rs:24:9
|
LL | res.get();
| ^^^ method not found in `Result<Foo, ()>`
|
note: the method `get` exists on the type `Foo`
--> $DIR/enum-method-probe.rs:9:5
|
LL | fn get(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^
help: use the `?` operator to extract the `Foo` value, propagating a `Result::Err` value to the caller
|
LL | res?.get();
| +
error[E0599]: no method named `get` found for enum `Result` in the current scope
--> $DIR/enum-method-probe.rs:39:9
|
LL | res.get();
| ^^^ method not found in `Result<Foo, ()>`
|
note: the method `get` exists on the type `Foo`
--> $DIR/enum-method-probe.rs:9:5
|
LL | fn get(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^
help: consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
|
LL | res.expect("REASON").get();
| +++++++++++++++++
error[E0599]: no method named `get` found for enum `Result` in the current scope
--> $DIR/enum-method-probe.rs:16:9
|
LL | res.get();
| ^^^ method not found in `Result<Foo, ()>`
|
note: the method `get` exists on the type `Foo`
--> $DIR/enum-method-probe.rs:9:5
|
LL | fn get(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^
help: use the `?` operator to extract the `Foo` value, propagating a `Result::Err` value to the caller
|
LL | res?.get();
| +
error[E0599]: no method named `get` found for enum `Result` in the current scope
--> $DIR/enum-method-probe.rs:32:9
|
LL | res.get();
| ^^^ method not found in `Result<Foo, ()>`
|
note: the method `get` exists on the type `Foo`
--> $DIR/enum-method-probe.rs:9:5
|
LL | fn get(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^
help: consider using `Result::expect` to unwrap the `Foo` value, panicking if the value is a `Result::Err`
|
LL | res.expect("REASON").get();
| +++++++++++++++++
error[E0599]: no method named `get` found for enum `Option` in the current scope
--> $DIR/enum-method-probe.rs:46:9
|
LL | res.get();
| ^^^ method not found in `Option<Foo>`
|
note: the method `get` exists on the type `Foo`
--> $DIR/enum-method-probe.rs:9:5
|
LL | fn get(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^
help: use the `?` operator to extract the `Foo` value, propagating an `Option::None` value to the caller
|
LL | res?.get();
| +
error[E0599]: no method named `get` found for enum `Option` in the current scope
--> $DIR/enum-method-probe.rs:54:9
|
LL | res.get();
| ^^^ method not found in `Option<Foo>`
|
note: the method `get` exists on the type `Foo`
--> $DIR/enum-method-probe.rs:9:5
|
LL | fn get(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^
help: consider using `Option::expect` to unwrap the `Foo` value, panicking if the value is an `Option::None`
|
LL | res.expect("REASON").get();
| +++++++++++++++++
error[E0624]: method `len` is private
--> $DIR/enum-method-probe.rs:61:9
|
LL | res.len();
| ^^^ private method
--> $SRC_DIR/core/src/option.rs:LL:COL
|
= note: private method defined here
|
note: the method `len` exists on the type `Vec<{integer}>`
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
help: consider using `Option::expect` to unwrap the `Vec<{integer}>` value, panicking if the value is an `Option::None`
|
LL | res.expect("REASON").len();
| +++++++++++++++++
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0599, E0624.
For more information about an error, try `rustc --explain E0599`.