Closed
Description
Code
const fn foo() {
let i = 0;
let _ = || {
i = 1;
};
}
Current output
error[E0492]: constant functions cannot refer to interior mutable data
--> src/lib.rs:5:13
|
5 | let _ = || {
| _____________^
6 | | i = 1;
7 | | };
| |_____^ this borrow of an interior mutable value may end up in the final value
error[E0594]: cannot assign to `i`, as it is not declared as mutable
--> src/lib.rs:6:9
|
4 | let i = 0;
| - help: consider changing this to be mutable: `mut i`
5 | let _ = || {
6 | i = 1;
| ^^^^^ cannot assign
Desired output
error[E0658]: mutable references are not allowed in constant functions
--> src/lib.rs:5:13
|
5 | let _ = || {
| _____________^
6 | | i = 1;
7 | | };
| |_____^
error[E0594]: cannot assign to `i`, as it is not declared as mutable
--> src/lib.rs:6:9
|
4 | let i = 0;
| - help: consider changing this to be mutable: `mut i`
5 | let _ = || {
6 | i = 1;
| ^^^^^ cannot assign
Rationale and extra context
Apparently there's no interior mutability involved. So we should just output we cannot mutable borrow i
in const context.
Incidentally(?) fixed by #112119. Still needs test though.
@rustbot label E-needs-test
Other cases
No response
Anything else?
rustc version
rustc +stable --version
rustc 1.70.0 (90c541806 2023-05-31)