Skip to content

does not support #![feature(main)] #503

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

Closed
matthiaskrgr opened this issue Jun 13, 2019 · 2 comments
Closed

does not support #![feature(main)] #503

matthiaskrgr opened this issue Jun 13, 2019 · 2 comments
Labels

Comments

@matthiaskrgr
Copy link
Member

#![feature(main)]

#[main]
fn a() {
    println!("hi");
}

When I run it locally, I get a "hi", but playground says

   Compiling playground v0.0.1 (/playground)
warning: function is never used: `a`
 --> src/lib.rs:6:1
  |
6 | fn a() {
  | ^^^^^^
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 1.43s

Warnings

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.

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=7ff692f07c7c3562df289936dbc97eda

@shepmaster
Copy link
Member

Yes, the automatic detection of whether to run cargo run / cargo build / cargo test is based on a simple regex match. You don't have fn main() so the regex isn't triggered. You need to expressly request to run the code:

image

You'll note that the button says "build" not "run" before you do this.

@matthiaskrgr
Copy link
Member Author

Thanks for clarifying! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants