-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Function pointer signature containing &mut T
should work in const context
#114994
Comments
Cc @rust-lang/wg-const-eval Fixing this requires changing this logic to skip traversing things inside function pointers. I'm not sure what the best way to achieve that is. |
@rustbot claim |
- add new testcase for TypeVisitor on const-eval mutable ref check
const_eval: allow function pointer signatures containing &mut T in const contexts potentially fixes rust-lang#114994 We utilize a `TypeVisitor` here in order to more easily handle control flow. - In the event the typekind the Visitor sees is a function pointer, we skip over it - However, otherwise we do one of two things: - If we find a mutable reference, check it, then continue visiting types - If we find any other type, continue visiting types This means we will check if the function pointer _itself_ is mutable, but not if any of the types _within_ are.
Is there any reason returning a function trait object (e.g. fn something(_s: &mut String) {
}
const fn unwrap_cool() -> &'static dyn Fn(&mut String) {
&something
} |
We didn't exhaustively look through all cases that we can exempt here. Anyway, |
Proposing to extract this from #57349.
The following examples shouldn't error:
While this has been considered part of #57349 for a while, it's also been acknowledged as a bug and suggested by @RalfJung to address separately ahead of stabilizing
const_mut_refs
. Indeed it's surprising for users that this would count as handling a mutable reference in const contexts.See:
#57349 (comment)
#57349 (comment)
The text was updated successfully, but these errors were encountered: