1use rustc_span::{Symbol, sym};
23#[derive(#[automatically_derived]
impl ::core::fmt::Debug for EntryPointType {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
EntryPointType::None => "None",
EntryPointType::MainNamed => "MainNamed",
EntryPointType::RustcMainAttr => "RustcMainAttr",
EntryPointType::OtherMain => "OtherMain",
})
}
}Debug)]
4pub enum EntryPointType {
5/// This function is not an entrypoint.
6None,
7/// This is a function called `main` at the root level.
8 /// ```
9 /// fn main() {}
10 /// ```
11MainNamed,
12/// This is a function with the `#[rustc_main]` attribute.
13 /// Used by the testing harness to create the test entrypoint.
14 /// ```ignore (clashes with test entrypoint)
15 /// #[rustc_main]
16 /// fn main() {}
17 /// ```
18RustcMainAttr,
19/// This function is **not** an entrypoint but simply named `main` (not at the root).
20 /// This is only used for diagnostics.
21 /// ```
22 /// #[allow(dead_code)]
23 /// mod meow {
24 /// fn main() {}
25 /// }
26 /// ```
27OtherMain,
28}
2930pub fn entry_point_type(
31 has_rustc_main: bool,
32 at_root: bool,
33 name: Option<Symbol>,
34) -> EntryPointType {
35if has_rustc_main {
36 EntryPointType::RustcMainAttr37 } else if let Some(name) = name38 && name == sym::main39 {
40if at_root {
41// This is a top-level function so it can be `main`.
42EntryPointType::MainNamed43 } else {
44 EntryPointType::OtherMain45 }
46 } else {
47 EntryPointType::None48 }
49}