-
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
Add initial version of const_fn lint #3648
Conversation
Soo... some questions:
|
Lots of CI failures, so I'm going to have to do some more work first before it's ready for review. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Add initial version of const_fn lint This adds an initial version of a lint that can tell if a function could be `const`. TODO: - [x] Finish up the docs - [ ] Fix the ICE cc #2440
This comment has been minimized.
This comment has been minimized.
return; | ||
} | ||
}, | ||
FnKind::Method(ident, sig, _vis, attrs) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will also trigger on methods in traits with default bodies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that matter though? Trait methods with default bodies can't be const anyway , according to the RFC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, what I meant was that the code looks to me like it will suggest to make trait methods with default bodies const fn
This is causing issues with a new Clippy lint that will be able to detect possible const functions. As per rust-lang/rust-clippy#3648 (comment)
Remove delay_span_bug from qualify_min_const_fn This is causing issues with a new Clippy lint that will be able to detect possible const functions. As per rust-lang/rust-clippy#3648 (comment) r? @oli-obk
fdc3f46
to
cadac5b
Compare
I think this is ready for another review now |
/// | ||
/// **Why is this bad?** | ||
/// | ||
/// Not using `const` is a missed optimization. Instead of having the function execute at runtime, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not quite true. This optimization will still happen for non-const fn. The major use case is crates forgetting to use const fn
will unnecessarily limit their consumers in what they can do. This is similar to forgetting to implement PartialEq
or similar things on types where it might be helpful to have that.
r=me with documentation nit addressed |
☔ The latest upstream changes (presumably #3582) made this pull request unmergeable. Please resolve the merge conflicts. |
9de367d
to
101d96d
Compare
97653e0
to
0bec822
Compare
* `const_transmute` currently also seems to depend on the `const_fn` feature. * Only `Sized` is currently allowed as a bound, not Copy.
0bec822
to
92bb817
Compare
92bb817
to
d0d7c5e
Compare
oh I missed that comment 👀 @bors r=oli-obk |
📌 Commit d0d7c5e has been approved by |
Add initial version of const_fn lint This adds an initial version of a lint that can tell if a function could be `const`. TODO: - [x] Finish up the docs - [x] Fix the ICE cc #2440
☀️ Test successful - checks-travis, status-appveyor |
This is causing issues with a new Clippy lint that will be able to detect possible const functions. As per rust-lang/rust-clippy#3648 (comment)
This adds an initial version of a lint that can tell if a function could be
const
.TODO:
cc #2440