rustc_ast/entry.rs
1use rustc_span::{Symbol, sym};
2
3#[derive(Debug)]
4pub enum EntryPointType {
5 /// This function is not an entrypoint.
6 None,
7 /// This is a function called `main` at the root level.
8 /// ```
9 /// fn main() {}
10 /// ```
11 MainNamed,
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 /// ```
18 RustcMainAttr,
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 /// ```
27 OtherMain,
28}
29
30pub fn entry_point_type(
31 has_rustc_main: bool,
32 at_root: bool,
33 name: Option<Symbol>,
34) -> EntryPointType {
35 if has_rustc_main {
36 EntryPointType::RustcMainAttr
37 } else if let Some(name) = name
38 && name == sym::main
39 {
40 if at_root {
41 // This is a top-level function so it can be `main`.
42 EntryPointType::MainNamed
43 } else {
44 EntryPointType::OtherMain
45 }
46 } else {
47 EntryPointType::None
48 }
49}