Skip to content

Main function recognition #95

Closed
@plasticartsshow

Description

@plasticartsshow

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions