-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Suggest const_mut_refs
, not const_fn
for mutable references in const fn
#77136
Conversation
I would have thought we could remove |
I browsed the In other news, we need more |
@bors r+ |
📌 Commit e5e5e64 has been approved by |
@bors rollup |
…as-schievink Rollup of 15 pull requests Successful merges: - rust-lang#75438 (Use adaptive SVG favicon for rustdoc like other rust sites) - rust-lang#76304 (Make delegation methods of `std::net::IpAddr` unstably const) - rust-lang#76724 (Allow a unique name to be assigned to dataflow graphviz output) - rust-lang#76978 (Documented From impls in std/sync/mpsc/mod.rs) - rust-lang#77044 (Liballoc bench vec use mem take not replace) - rust-lang#77050 (Typo fix: "satsify" -> "satisfy") - rust-lang#77074 (add array::from_ref) - rust-lang#77078 (Don't use an if guard to check equality with a constant) - rust-lang#77079 (Use `Self` in docs when possible) - rust-lang#77081 (Merge two almost identical match arms) - rust-lang#77121 (Updated html_root_url for compiler crates) - rust-lang#77136 (Suggest `const_mut_refs`, not `const_fn` for mutable references in `const fn`) - rust-lang#77160 (Suggest `const_fn_transmute`, not `const_fn`) - rust-lang#77164 (Remove workaround for deref issue that no longer exists.) - rust-lang#77165 (Followup to rust-lang#76673) Failed merges: r? `@ghost`
Resolves #77134.
Prior to #76850, most uses of
&mut
inconst fn
requiredinvolved two feature gates,const_mut_refs
andconst_fn
. The first allowed all mutable borrows of locals. The second allowed only locals, arguments and return values whose types contained&mut
. I switched the second check to theconst_mut_refs
gate. However, I forgot update the error message with the new suggestion.Alternatively, we could revert to having two different feature gates for this. OP's code never borrows anything mutably, so it didn't need
const_mut_refs
in the past, onlyconst_fn
. I'd prefer to keep everything under a single gate, however.r? @oli-obk