Commit 97bfc59
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 <[email protected]>1 parent cf48d44 commit 97bfc59
1 file changed
+8
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
211 | 218 | | |
212 | 219 | | |
213 | 220 | | |
214 | 221 | | |
215 | | - | |
| |||
0 commit comments