-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 recursion check on main function #4203
Conversation
Documentation on the way |
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.
This LGTM overall!
Can you remove the tests/ui/crate_level_checks/no_std_main_recursion.stderr
file?
Should we have a testcase with the #![feature(main)]
#[main]
fn a() {
println!("hello from our new main method");
} |
Good point. Do you know how we can query the name of the |
Hmm, maybe this can help? rust-lang/rust@b7cefd0 |
That commit is from Jan 2013, so way before Rust 1.0. I don't think any of this code still exists :D Maybe this: @Urriel if you want to look into that, feel free to do so. Otherwise we can leave this to future work. |
You could try using rust-clippy/clippy_lints/src/utils/mod.rs Line 397 in 0814207
|
I don't think it should say "changelog: none" here :) |
I need to add the documentation to the code too :) |
I cannot make a test compiling around this, are you sure it is not the |
There is both |
"No main function was detected, so your code was compiled but not run. If you'd like to execute your code, please add a main function." So the |
It seems that this works on playground once the proper run-mode is selected! |
The code above does not seem to find the error here:
I feel like I'm spamming dumb questions since the beginning of this PR -_- |
Can you post the output of dbg!(func.hir_id.owner_def_id());
dbg!(expr.hir_id.owner_def_id());
There are no dumb questions! And we all needed to learn once. So please keep asking (and contributing 😉)! |
Also I found out I cannot register my lint for both early and late pass... |
Yeah, a lint can only be either of them. Just register it as a Oh, I meant the debug information when you run it on this code:
|
yes I can remove the |
Oh sorry, I didn't realized the
The closest "item-like" is the main()/a()-function. This function is an entry point, so What you want to do, is to get the
From there you can get the |
Do you have a specific format for the changelog tag in this pull request? |
9f82260
to
73978a1
Compare
Not really. Just changelog: short description of what was changed. You practically already wrote it: changelog: Add |
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.
Only some minor things to fix and this should be good to go.
73978a1
to
992b821
Compare
clippy_lints/src/main_recursion.rs
Outdated
impl_lint_pass!(MainRecursion => [MAIN_RECURSION]); | ||
|
||
impl MainRecursion { | ||
pub fn new() -> MainRecursion { |
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.
Now you can remove the new()
function and use ::default()
in lib.rs
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, I saw this one above!
542ed89
to
e6b42fe
Compare
it seems like the code for building the no_std on linux does not work elsewhere |
Hmmm. Could you try adding #![cfg(target_os = "linux")] to the top of the file? |
e6b42fe
to
fa2657f
Compare
Oh sorry, I didn't get a ping for your last change. Sooo, adding I took a closer look on compiletest-rs and it seems you can add
to the top of the file and the test should be ignored on these platforms. Keep in mind that you have to run |
fa2657f
to
d456959
Compare
It seems that github doesn't notify you on force pushes to a pull request 🤔 Reopening for travis run |
Oh alright, let me know :) |
You have to run |
Changes: - Add MainRecursion lint to clippy - Check for no-std setup fixes rust-lang#333
Changes: - Move from EarlyLintPass - Fix entrypoint check with function path def_id.
d456959
to
a922f80
Compare
@bors r+ |
📌 Commit a922f80 has been approved by |
Add recursion check on main function Changes: - Add MainRecursion lint to Clippy - Check for no-std setup fixes #333 changelog: Add `main_recursion` lint
💔 Test failed - status-appveyor |
Oh sorry, I forgot about this, do we still need to reformat ? |
The test |
@bors r+ |
📌 Commit dabf599 has been approved by |
Add recursion check on main function Changes: - Add MainRecursion lint to Clippy - Check for no-std setup fixes #333 changelog: Add `main_recursion` lint
☀️ Test successful - checks-travis, status-appveyor |
Changes:
fixes #333
changelog: Add
main_recursion
lint