Open
Description
openedon Oct 5, 2024
Code
use std::cell::RefCell;
struct Foo {
content: RefCell::<Option<u64>>,
}
fn main() {
let foo = Foo {
content: RefCell::new(Some(5)),
};
if let Some(_content) = foo.content.borrow_mut() {
};
}
Current output
error[E0308]: mismatched types
--> src/main.rs:12:12
|
12 | if let Some(_content) = foo.content.borrow_mut() {
| ^^^^^^^^^^^^^^ ------------------------ this expression has type `RefMut<'_, Option<u64>>`
| |
| expected `RefMut<'_, Option<u64>>`, found `Option<_>`
|
= note: expected struct `RefMut<'_, Option<u64>, >`
found enum `Option<_>`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `check_ice` (bin "check_ice") due to 1 previous error
Desired output
It can suggest to deref the RefMut:
if let Some(_content) = *foo.content.borrow_mut()
Rationale and extra context
No response
Other cases
No response
Rust Version
rustc 1.83.0-nightly (7042c269c 2024-09-23)
binary: rustc
commit-hash: 7042c269c166191cd5d8daf0409890903df7af57
commit-date: 2024-09-23
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0
Anything else?
No response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.