Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(within_macro_span, "due to this macro variable");
}
self.suggest_valid_traits(&mut err, item_name, out_of_scope_traits, true);
self.suggest_unwrapping_inner_self(&mut err, source, rcvr_ty, item_name);
err.emit()
}

Expand Down
7 changes: 7 additions & 0 deletions tests/ui/suggestions/enum-method-probe.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@ fn test_option_in_unit_return() {
//~| 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() {}
7 changes: 7 additions & 0 deletions tests/ui/suggestions/enum-method-probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@ fn test_option_in_unit_return() {
//~| 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.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() {}
21 changes: 19 additions & 2 deletions tests/ui/suggestions/enum-method-probe.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ help: consider using `Option::expect` to unwrap the `Foo` value, panicking if th
LL | res.expect("REASON").get();
| +++++++++++++++++

error: aborting due to 6 previous errors
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

For more information about this error, try `rustc --explain E0599`.
Some errors have detailed explanations: E0599, E0624.
For more information about an error, try `rustc --explain E0599`.
Loading