-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Calling main
#333
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
The admin of the German Rust Forum told me he wanted to try this one. |
… commit: the remaining changes)
@thomanski It's been a while and I just saw the commit in your fork, would you like to continue with it and open a PR? |
Nope, thanks, I think @oli-obk <https://github.com/oli-obk> was last
looking into that. I wish I'd have more time for Rust but still just don't.
…On 14 April 2018 at 13:04, Philipp Hansch ***@***.***> wrote:
@thomanski <https://github.com/thomanski> It's been a while and I just
saw the commit in your fork, would you like to continue with it and open a
PR?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#333 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMwtIPdpINAgWenDTT1R_JfGGq6e6NlKks5todfXgaJpZM4F-O9Y>
.
|
Hello, is this issue still relevant? |
I would like to add this lint. Where should I add it? (I mean in which file ?). |
Oh sorry, I missed your previous comment. Yes, this is still relevant.
Taking a closer look at this module, it does not fit in there. So just create a new file for this lint. |
OK, no worries. |
I have looked into how to check functions and macros. But in order to disable this lint, I need a state for whether the no_std macro is found or not. |
struct MainCall {
has_no_std: bool
}
impl_lint_pass!(..)
impl EarlyLintPass for MainCall {
fn check_crate(.., krate: &Crate) {
self.has_no_std = krate.attrs.iter().any(/*check if no_std*/);
}
fn check_expr(..) { ... }
} |
I am looking for a way to test that "main" recursion. I cannot figure a way to have a no_std and an std version of a test working...
in the code above there is no exit from the recursion... |
You have to create two testfiles for this. These can be identical (except for the
use core::sync::atomic::{AtomicUsize, Ordering};
static N: AtomicUsize = AtomicUsize::new(0);
fn main() {
let x = N.load(Ordering::Relaxed);
N.store(x + 1, Ordering::Relaxed);
println!("{}", x);
if x < 3 {
main();
}
} Internal mutability to the rescue. Clippy tests never get executed, but only compiled (=> just allow |
oh, alright. Thank you ! |
After many tries for the no_std part, I have a cc link issue:
where my test look like this:
|
See rust-lang/rust#17346, especially the last 2 comments. Please try this and report back here. (Your code get's build successfully on the playground) |
Those lines did the trick. |
I have started to get crate symbols checked:
This code seems to works.
I get |
The first function can be done more efficient with an iterator: self.has_no_std_attr = krate.attrs.iter().any(|attr| attr.path == sym::no_std); This should work: if_chain! {
if let ExprKind::Call(func) = &expr.node;
if let ExprKind::Path(_, path) = &func.node;
if path == sym::main;
then {
// report your lint here
}
} https://doc.rust-lang.org/nightly/nightly-rustc/syntax/symbol/sym/index.html |
So I don't need to use the
I learned something new today. |
I kind of lost track about the symbol back and forth in rustc/Clippy. But IIUC since This is pretty much the output of the |
Add recursion check on main function Changes: - Add MainRecursion lint to Clippy - Check for no-std setup fixes #333 changelog: Add `main_recursion` lint
Add recursion check on main function Changes: - Add MainRecursion lint to Clippy - Check for no-std setup fixes #333 changelog: Add `main_recursion` lint
Apart from special setups (which we could detect following attributes like
#![no_std]
), recursing intomain()
seems like an unintuitive antipattern we should be able to detect.The text was updated successfully, but these errors were encountered: