-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Ignore const fn in or_fun_call
lint
#5682
Conversation
I don't think the constness of the function by itself will give us what we want. If the function is a const fn, but has arguments, these arguments may not be constants. An example: const fn compute_nth_prime(n: usize) -> Option<usize> {
// super heavy logic here
}
fn foo(n: usize) -> Option<usize> {
// Whether the function above is `const fn` or not has no effect on the cost
// of the work done in the `or`.
None.or(compute_nth_prime(n))
} Thus, we'll end up actually running the function at runtime, with all the runtime effort that comes with it. If you really want to do this, you'll need to analyze the entire expression and check if it is entirely const. I don't know of a reliable way to do this except to do it on MIR, which would be a major undertaking. |
This is a user-facing change, the "changelog:" line should say which false positive this fixes. |
cc @ecstatic-morse do you know how to detect if a const fn could be evaluated at compile-time. |
This is not about whether it could be evaluated at compile-time. A |
☔ The latest upstream changes (presumably #5691) made this pull request unmergeable. Please resolve the merge conflicts. |
I don't think I have enough skills to make that change. |
…arth Avoid or_fun_call for const_fn with no args Based on #5682 by @lzutao This avoids a subset of false positives, specifically those related to `const fn`s that take no arguments. For the rest, a much more involved fix would be needed, see #5682 (comment). So this does *not* solve #5658 changelog: Avoid triggering [`or_fun_call`] with `const fn`s that take no arguments. Fixes #5886
cc #1609 (comment)
Closes #5658
changelog: none