Commit 479cb33
committed
gccrs: Emit error when borrowing immutable variable as mutable
Fixes #4289
Rust rules strictly forbid creating a mutable reference ('&mut T') to an
immutable binding. Previously, the compiler failed to validate the
mutability of the source variable when using a 'ref mut' pattern.
This patch adds verification logic to TypeCheckStmt to check the
mutability status of the variable definition.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit):
Add check to ensure 'ref mut' patterns bind to mutable variables.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4289.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>1 parent 32622b7 commit 479cb33
File tree
2 files changed
+43
-0
lines changed- gcc
- rust/typecheck
- testsuite/rust/compile
2 files changed
+43
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
91 | 124 | | |
92 | 125 | | |
93 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments