-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[missing_const_for_fn
]: fix suggestions for fn with abi that requires const_extern_fn
feature
#13037
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
Merged
Merged
[missing_const_for_fn
]: fix suggestions for fn with abi that requires const_extern_fn
feature
#13037
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.fixed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![warn(clippy::missing_const_for_fn)] | ||
#![allow(unsupported_calling_conventions)] | ||
#![feature(const_extern_fn)] | ||
|
||
const extern "C-unwind" fn c_unwind() {} | ||
//~^ ERROR: this could be a `const fn` | ||
const extern "system" fn system() {} | ||
//~^ ERROR: this could be a `const fn` | ||
const extern "system-unwind" fn system_unwind() {} | ||
//~^ ERROR: this could be a `const fn` | ||
pub const extern "stdcall" fn std_call() {} | ||
//~^ ERROR: this could be a `const fn` | ||
pub const extern "stdcall-unwind" fn std_call_unwind() {} | ||
//~^ ERROR: this could be a `const fn` |
14 changes: 14 additions & 0 deletions
14
tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![warn(clippy::missing_const_for_fn)] | ||
#![allow(unsupported_calling_conventions)] | ||
#![feature(const_extern_fn)] | ||
|
||
extern "C-unwind" fn c_unwind() {} | ||
//~^ ERROR: this could be a `const fn` | ||
extern "system" fn system() {} | ||
//~^ ERROR: this could be a `const fn` | ||
extern "system-unwind" fn system_unwind() {} | ||
//~^ ERROR: this could be a `const fn` | ||
pub extern "stdcall" fn std_call() {} | ||
//~^ ERROR: this could be a `const fn` | ||
pub extern "stdcall-unwind" fn std_call_unwind() {} | ||
//~^ ERROR: this could be a `const fn` |
59 changes: 59 additions & 0 deletions
59
tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
error: this could be a `const fn` | ||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:5:1 | ||
| | ||
LL | extern "C-unwind" fn c_unwind() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::missing-const-for-fn` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::missing_const_for_fn)]` | ||
help: make the function `const` | ||
| | ||
LL | const extern "C-unwind" fn c_unwind() {} | ||
| +++++ | ||
|
||
error: this could be a `const fn` | ||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:7:1 | ||
| | ||
LL | extern "system" fn system() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: make the function `const` | ||
| | ||
LL | const extern "system" fn system() {} | ||
| +++++ | ||
|
||
error: this could be a `const fn` | ||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:9:1 | ||
| | ||
LL | extern "system-unwind" fn system_unwind() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: make the function `const` | ||
| | ||
LL | const extern "system-unwind" fn system_unwind() {} | ||
| +++++ | ||
|
||
error: this could be a `const fn` | ||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:11:1 | ||
| | ||
LL | pub extern "stdcall" fn std_call() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: make the function `const` | ||
| | ||
LL | pub const extern "stdcall" fn std_call() {} | ||
| +++++ | ||
|
||
error: this could be a `const fn` | ||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:13:1 | ||
| | ||
LL | pub extern "stdcall-unwind" fn std_call_unwind() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: make the function `const` | ||
| | ||
LL | pub const extern "stdcall-unwind" fn std_call_unwind() {} | ||
| +++++ | ||
|
||
error: aborting due to 5 previous errors | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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'm a little bit unsure should we report these with help messages like "if your are on nightly toolchain, enable
const_extern_fn
feature with#![feature(const_extern_fn)]
" instead of just skip them, it surely will make some noise tho.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.
If you really want to add that and can detect that a nightly toolchain is a build requirement (for example via a toolchain file), I'm not opposed to it.
Uh oh!
There was an error while loading. Please reload this page.
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.
Oh, that reminds me I probably (???) could use this
cx.sess().is_nightly_build
to check that but I assume it will be useless in our test cases, since it will betrue
in all of them...Well, I'll keep this in mind for future reference, maybe we could have some attribute like
#[clippy::toolchain = "nightly"]
in the future if that function turns out to be useful, but for now this might be fine (I think)~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.
For the record, the problem with
is_nightly_build
is that it's true when compiled on nightly. This is the wrong criteria, the code might still accept compiling on stable.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.
oh right... I see, that'll made the users having to force nightly toolchain if they only follow the suggestion once...
hmmm, I understand why you mentioned "via a toolchain file" now, as it seems like the only sensible way here. But doing so would require clippy to have some basic de-serializer written to match that file, and I saw there's a security flaw with that file on this rustup issue, so I'm expecting
rustup
to make some changes regarding that file, meaning that we'll have to change them too~For these reasons I think it might not worth the efforts, and lets just call this perfect imperfection :D