-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Check casting function item to usize
#5906
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
Comments
Could I give this a shot? |
Yeah sure, go ahead! Make sure to read the Basics documentation to get up and running. If you have any questions, feel free to ask here or open a WIP PR. |
Great, thank you! I asked this question on Discord but I'm not sure that was the right place to ask: I am using the master channel (following the Basics documentation) but it seems that the |
If you want to install
|
That's basically what I did. I had installed the master toolchain with: rustup-toolchain-install-master -f -n master -c rustc-dev -c llvm-tools -c rustfmt -c rust-src And I already have
How should I resolve this? |
Does |
No, and neither does |
Do you have a These are just wild guesses by me, since I can't reproduce this locally. |
Strangely enough, yes (no idea why), but removing it did not fix the issue. |
Does |
Yes, it does. And strangely enough I got the test to pass like this: diff --git a/tests/fmt.rs b/tests/fmt.rs
index 3aff8741f..9cf4df87d 100644
--- a/tests/fmt.rs
+++ b/tests/fmt.rs
@@ -8,15 +8,16 @@ fn fmt() {
}
// Skip this test if rustup nightly is unavailable
- let rustup_output = Command::new("rustup")
- .args(&["component", "list", "--toolchain", "nightly"])
- .output()
- .unwrap();
- assert!(rustup_output.status.success());
- let component_output = String::from_utf8_lossy(&rustup_output.stdout);
- if !component_output.contains("rustfmt") {
- return;
- }
+ // let rustup_output = Command::new("rustup")
+ // .args(&["component", "list", "--toolchain", "nightly"])
+ // .output()
+ // .unwrap();
+ // println!("*** OUT: {:?}", rustup_output);
+ // assert!(rustup_output.status.success());
+ // let component_output = String::from_utf8_lossy(&rustup_output.stdout);
+ // if !component_output.contains("rustfmt") {
+ // return;
+ // }
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let dev_dir = root_dir.join("clippy_dev");
@@ -24,7 +25,7 @@ fn fmt() {
let target_dir = target_dir.to_str().unwrap();
let output = Command::new("cargo")
.current_dir(dev_dir)
- .args(&["+nightly", "run", "--target-dir", target_dir, "--", "fmt", "--check"])
+ .args(&["+master", "run", "--target-dir", target_dir, "--", "fmt", "--check"])
.output()
.unwrap(); |
I think I'm just going to stick to |
Yeah, you can ignore the |
Alright. Anyway I just noticed the existing Maybe it should apply to |
I'm starting to wonder if this type of cast is intentionally supported. It is even mentioned in the Rust reference. Maybe that is because it was implemented before |
Maybe missing a row about casting function item to function pointer and/or usize address. |
@lzutao I think maybe it actually is covered? Here are the relevant lines:
Which lines do you think are missing? Just function definition --> function pointer? |
It is not that. Those are 2 types: function item != function pointer. |
Ok, I agree that should be added. |
Back to your question
Maybe, but it causes real bug in practice. This kind of bug (typo) is hard to catch by eyes. |
@lzutao I completely agree, and I'm working on a PR that implements this lint. I think that this syntax was meant for function pointers, not function items, so I'm planning to lint only against function items. |
I opened #5914 last night (at first I linked to the wrong issue by mistake). |
@Coder-256 @flip1995 Is this resolved by #7705? |
Yes, I think this should cover it. I think #5914 can now also be closed, after it was abandoned by me for so long (sorry...) |
What it does
Check a mistaken casting function item to
usize
or all other integer primitive types.Categories (optional)
What is the advantage of the recommended code over the original code
usize
instead of getting function result.This could be unnotice for a long time.
usize
.The bug appeared in real code: rust-lang/rustup@5d9d980
I was author of the bug :) .
Drawbacks
It is verbose and somewhat redundant.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: