Commit 36404ce
committed
Allow coercions from never-type when ref binding is involved
When we type-check a binding that uses ref patterns, we do not
perform coercions between the expression type and the pattern type.
However, this has the unfortunate result of disallow code like:
`let Foo { ref my_field } = diverging_expr();`. This code is accepted
without the `ref` keyword.
We now explicitly allow coercions when the expression type is !
In all other cases, we still avoid performing coersions.
This avoids causing broader changes in type-checking (with potential
soundness implications for 'ref mut'),1 parent 42ae1a7 commit 36404ce
File tree
3 files changed
+23
-2
lines changed- compiler/rustc_hir_typeck/src
- fn_ctxt
- tests/ui/pattern
3 files changed
+23
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1444 | 1444 | | |
1445 | 1445 | | |
1446 | 1446 | | |
1447 | | - | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
1448 | 1459 | | |
1449 | 1460 | | |
1450 | 1461 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments