-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant 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.
Description
Code
use std::sync::Arc;
fn main() {
let x = Box::new(Some(1));
let test: Option<i32> = x as Box<Option<i32>>;
}Current output
error[E0308]: mismatched types
--> src/main.rs:5:29
|
5 | let test: Option<i32> = x as Box<Option<i32>>;
| ----------- ^^^^^^^^^^^^^^^^^^^^^ expected `Option<i32>`, found `Box<Option<i32>>`
| |
| expected due to this
|
= note: expected enum `Option<_>`
found struct `Box<Option<_>>`
help: consider unboxing the value
|
5 | let test: Option<i32> = *x as Box<Option<i32>>;
| +Desired output
error[E0308]: mismatched types
--> src/main.rs:5:29
|
5 | let test: Option<i32> = x as Box<Option<i32>>;
| ----------- ^^^^^^^^^^^^^^^^^^^^^ expected `Option<i32>`, found `Box<Option<i32>>`
| |
| expected due to this
|
= note: expected enum `Option<_>`
found struct `Box<Option<_>>`
help: consider unboxing the value
|
5 | let test: Option<i32> = *(x as Box<Option<i32>>);
| ++ +Rationale and extra context
The current output is incorrect, and leads to the same suggestion over and over again if we keep applying it. The relevant code is
| "unboxing the value" |
See
| let needs_parens = match expr.kind { |
Other cases
Rust Version
rustc 1.84.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.84.0-dev
LLVM version: 19.1.3
----
Tested on commit 42b24963202f31d417a972e56e48a17e916b279bAnything else?
No response
linyihai
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant 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.