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

Main function recognition #95

Closed
plasticartsshow opened this issue Apr 9, 2023 · 1 comment · Fixed by #96
Closed

Main function recognition #95

plasticartsshow opened this issue Apr 9, 2023 · 1 comment · Fixed by #96
Labels
bug Something isn't working

Comments

@plasticartsshow
Copy link

plasticartsshow commented Apr 9, 2023

Description

If I add a space after the function identifier main rust-script will not use the function.

Example

  • This example was taken from the example script in this repository's main readme.
  • The only change was that I added a space between main and ():
#!/usr/bin/env rust-script
//! Dependencies can be specified in the script file itself as follows:
//!
//! ```cargo
//! [dependencies]
//! rand = "0.8.0"
//! ```

use rand::prelude::*;

fn main () {
    let x: u64 = random();
    println!("A random number: {}", x);
}

This can be seen this in the following compiler warnings:

» rust-script script2.rs
warning: unused doc comment
  --> script2.rs:3:5
   |
2  | /      {
3  | |      //! Dependencies can be specified in the script file itself as follows:
   | | _____^
4  | || //!
5  | || //! ```cargo
6  | || //! [dependencies]
7  | || //! rand = "0.8.0"
8  | || //! ```
   | ||_______^
...  |
15 | |  }
16 | |      }
   | |______- rustdoc does not generate documentation for expressions
   |
   = help: use `//` for a plain comment
   = note: `#[warn(unused_doc_comments)]` on by default

warning: function `main` is never used
  --> script2.rs:12:4
   |
12 | fn main () {
   |    ^^^^
   |
   = note: `#[warn(dead_code)]` on by default

Why is this an issue?

In my case, I generate rust scripts externally using quote, which injects these errant spaces into the output TokenStream.

As seen above, this is valid Rust code. I am opening this issue here because I assume it's relevant, but please let me know if I should close it and look somewhere else.

Notes

If you feel this is worth changing, I can try to fix it and open a PR. I'm not sure where to look for this problem though, tbh.

fornwall added a commit that referenced this issue Apr 10, 2023
fornwall added a commit that referenced this issue Apr 10, 2023
@fornwall fornwall added the bug Something isn't working label Apr 10, 2023
@fornwall
Copy link
Owner

@plasticartsshow Thanks! This should be fixed by #96, which is a part of the just released 0.25.0 version.

Let me know how it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants