Skip to content
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

False Suggestion for const fn #5192

Closed
Demonstrandum opened this issue Feb 18, 2020 · 3 comments · Fixed by #5216
Closed

False Suggestion for const fn #5192

Demonstrandum opened this issue Feb 18, 2020 · 3 comments · Fixed by #5216
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy T-const-generics Type: Issues related to const generics

Comments

@Demonstrandum
Copy link

cargo clippy -V
#=> clippy 0.0.212 (07f1736 2020-02-11)
warning: this could be a `const fn`
  --> src/vm/unmarshal.rs:23:1
   |
23 | / fn fix_slice_size<T, const N : usize>(slice : &[T]) -> &[T; N] {
24 | |     let ptr = slice.as_ptr() as *const [T; N];
25 | |     unsafe { &*ptr }
26 | | }
   | |_^
   |

This is a false suggestion, since const parameters are not permitted in const fn.

@flip1995 flip1995 added C-bug Category: Clippy is not doing the correct thing T-const-generics Type: Issues related to const generics labels Feb 18, 2020
@flip1995
Copy link
Member

cc @phansch

@phansch phansch self-assigned this Feb 18, 2020
@phansch
Copy link
Member

phansch commented Feb 20, 2020

This seems easy to fix, if someone wants to take it. We should be able to handle this by copying the conditional from here:

https://github.com/rust-lang/rust/blob/183e893aaae581bd0ab499ba56b6c5e118557dc7/src/librustc_ast_passes/ast_validation.rs#L570-L573

        if let Const::Yes(const_span) = sig.header.constness {
            // Look for const generics and error if we find any.
            for param in &generics.params {
                if let GenericParamKind::Const { .. } = param.kind {

and return early instead of linting here:

FnKind::ItemFn(_, _, header, ..) => {
if already_const(header) {
return;

@phansch phansch added the good-first-issue These issues are a good way to get started with Clippy label Feb 20, 2020
@phansch phansch removed their assignment Feb 20, 2020
@krishna-veerareddy
Copy link
Contributor

I can work on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy T-const-generics Type: Issues related to const generics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants