Skip to content

mention expect if we try to unwrap("string lit") #155502

@matthiaskrgr

Description

@matthiaskrgr

Code

fn main() {
    let x = Some(());
    x.unwrap("oh no");
}

Current output

error[E0061]: this method takes 0 arguments but 1 argument was supplied
    --> src/main.rs:3:7
     |
   3 |     x.unwrap("oh no");
     |       ^^^^^^ ------- unexpected argument of type `&'static str`
     |
note: method defined here
    --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1013:18
     |
1013 |     pub const fn unwrap(self) -> T {
     |                  ^^^^^^
help: remove the extra argument
     |
   3 -     x.unwrap("oh no");
   3 +     x.unwrap();
     |

For more information about this error, try `rustc --explain E0061`.

Desired output

...
help: did you mean to use 'expect'?
     |
   3 -     x.unwrap("oh no");
   3 +     x.expect("oh no");
     |

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.97.0-nightly (e9e32aca5 2026-04-17)
binary: rustc
commit-hash: e9e32aca5a4ffd08cbc29547b039d64b92a2c03b
commit-date: 2026-04-17
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions