-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add feature gate for mut refs in const fn #66606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
12ac49a
bb2a423
8b0f5ac
d24ae25
1f420b9
de60f72
d92e9b7
e31a136
683f5c9
681690d
5e61e4c
19ddfb5
dc0117a
416b439
e01ad6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
error[E0017]: references in statics may only refer to immutable values | ||
error[E0658]: references in statics may only refer to immutable values | ||
--> $DIR/check-static-immutable-mut-slices.rs:3:37 | ||
| | ||
LL | static TEST: &'static mut [isize] = &mut []; | ||
| ^^^^^^^ statics require immutable values | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/57349 | ||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0017`. | ||
For more information about this error, try `rustc --explain E0658`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// run-pass | ||
|
||
#![feature(const_mut_refs)] | ||
|
||
struct Foo { | ||
x: usize | ||
} | ||
|
||
const fn foo() -> Foo { | ||
Foo { x: 0 } | ||
} | ||
|
||
impl Foo { | ||
const fn bar(&mut self) -> usize { | ||
self.x = 1; | ||
self.x | ||
} | ||
|
||
} | ||
|
||
const fn baz(foo: &mut Foo) -> usize { | ||
let x = &mut foo.x; | ||
*x = 2; | ||
*x | ||
} | ||
|
||
const fn bazz(foo: &mut Foo) -> usize { | ||
foo.x = 3; | ||
foo.x | ||
} | ||
|
||
fn main() { | ||
let _: [(); foo().bar()] = [(); 1]; | ||
let _: [(); baz(&mut foo())] = [(); 2]; | ||
let _: [(); bazz(&mut foo())] = [(); 3]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
foo(&mut 5); | ||
} | ||
|
||
const fn foo(x: &mut i32) -> i32 { //~ ERROR mutable references in const fn are unstable | ||
*x + 1 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0723]: mutable references in const fn are unstable | ||
--> $DIR/feature-gate-const_mut_refs.rs:5:14 | ||
| | ||
LL | const fn foo(x: &mut i32) -> i32 { | ||
| ^ | ||
| | ||
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 | ||
= help: add `#![feature(const_fn)]` to the crate attributes to enable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... it's quite unfortunate that the wrong feature gate is suggested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes :( I'd like to fix it Edit: I think I found how to do it, working on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was able to fix it when mutable borrows are done inside constant contexts but not when they are function arguments. This is because that check is done by the const fn qualification and it always suggests the |
||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0723`. |
Uh oh!
There was an error while loading. Please reload this page.