-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add parentheses when unboxing suggestion needed
- Loading branch information
Showing
3 changed files
with
82 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/ui/coercion/unboxing-needing-parenthases-issue-132924.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ check-fail | ||
fn main() { | ||
let x = Box::new(Some(1)); | ||
|
||
let test: Option<i32> = x; | ||
//~^ ERROR mismatched types | ||
let x = Box::new(Some(1)); | ||
let test: Option<i32> = { x as Box<Option<i32>> }; | ||
//~^ ERROR mismatched types | ||
|
||
let x = Box::new(Some(1)); | ||
let test: Option<i32> = if true { x as Box<Option<i32>> } else { None }; | ||
//~^ ERROR mismatched types | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/ui/coercion/unboxing-needing-parenthases-issue-132924.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/unboxing-needing-parenthases-issue-132924.rs:5:29 | ||
| | ||
LL | let test: Option<i32> = x; | ||
| ----------- ^ expected `Option<i32>`, found `Box<Option<{integer}>>` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected enum `Option<i32>` | ||
found struct `Box<Option<{integer}>>` | ||
help: consider unboxing the value | ||
| | ||
LL | let test: Option<i32> = *x; | ||
| + | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/unboxing-needing-parenthases-issue-132924.rs:8:31 | ||
| | ||
LL | let test: Option<i32> = { x as Box<Option<i32>> }; | ||
| ^^^^^^^^^^^^^^^^^^^^^ expected `Option<i32>`, found `Box<Option<i32>>` | ||
| | ||
= note: expected enum `Option<_>` | ||
found struct `Box<Option<_>>` | ||
help: consider unboxing the value | ||
| | ||
LL | let test: Option<i32> = { *(x as Box<Option<i32>>) }; | ||
| ++ + | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/unboxing-needing-parenthases-issue-132924.rs:12:39 | ||
| | ||
LL | let test: Option<i32> = if true { x as Box<Option<i32>> } else { None }; | ||
| ^^^^^^^^^^^^^^^^^^^^^ expected `Option<i32>`, found `Box<Option<i32>>` | ||
| | ||
= note: expected enum `Option<_>` | ||
found struct `Box<Option<_>>` | ||
help: consider unboxing the value | ||
| | ||
LL | let test: Option<i32> = if true { *(x as Box<Option<i32>>) } else { None }; | ||
| ++ + | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |