Skip to content

fn main in multiline comment causes errors #1167

@ChaiTRex

Description

@ChaiTRex

Putting a main function in a multiline comment (this does not happen when using // commenting syntax on each line of main) causes the playground to mistakenly show a Run button rather than a Build button. This causes errors when the Run button is pressed.

/*
fn main() {}
*/

produces:

   Compiling playground v0.0.1 (/playground)
error[E0601]: `main` function not found in crate `playground`
 --> src/main.rs:3:3
  |
3 | */
  |   ^ consider adding a `main` function to `src/main.rs`

For more information about this error, try `rustc --explain E0601`.
error: could not compile `playground` (bin "playground") due to 1 previous error

This also causes a much more difficult to debug error message when you're trying to check that some functions work under #![no_std] and you comment out the main function:

#![no_std]

/*
fn main()
*/

produces:

   Compiling playground v0.0.1 (/playground)
error: `#[panic_handler]` function required, but not found

error: unwinding panics are not supported without std
  |
  = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
  = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem

error[E0601]: `main` function not found in crate `playground`
 --> src/main.rs:1:11
  |
1 | #![no_std]
  |           ^ consider adding a `main` function to `src/main.rs`

For more information about this error, try `rustc --explain E0601`.
error: could not compile `playground` (bin "playground") due to 3 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething new the playground could dohelp wantedNot immediately going to be prioritized — ask for mentoring instructions!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions