2023-09-29 06:54:48 +00:00
|
|
|
use crate::{attr, Attribute};
|
|
|
|
use rustc_span::symbol::sym;
|
|
|
|
use rustc_span::Symbol;
|
|
|
|
|
2021-06-10 03:11:35 +00:00
|
|
|
#[derive(Debug)]
|
2015-08-23 18:12:39 +00:00
|
|
|
pub enum EntryPointType {
|
2024-05-01 15:37:22 +00:00
|
|
|
/// This function is not an entrypoint.
|
2015-08-23 18:12:39 +00:00
|
|
|
None,
|
2024-05-01 15:37:22 +00:00
|
|
|
/// This is a function called `main` at the root level.
|
|
|
|
/// ```
|
|
|
|
/// fn main() {}
|
|
|
|
/// ```
|
2015-08-23 18:12:39 +00:00
|
|
|
MainNamed,
|
2024-05-01 15:37:22 +00:00
|
|
|
/// This is a function with the `#[rustc_main]` attribute.
|
|
|
|
/// Used by the testing harness to create the test entrypoint.
|
|
|
|
/// ```ignore (clashes with test entrypoint)
|
|
|
|
/// #[rustc_main]
|
|
|
|
/// fn main() {}
|
|
|
|
/// ```
|
2022-06-22 16:23:21 +00:00
|
|
|
RustcMainAttr,
|
2024-05-01 15:37:22 +00:00
|
|
|
/// This is a function with the `#[start]` attribute.
|
|
|
|
/// ```ignore (clashes with test entrypoint)
|
|
|
|
/// #[start]
|
|
|
|
/// fn main() {}
|
|
|
|
/// ```
|
2015-08-23 18:12:39 +00:00
|
|
|
Start,
|
2024-05-01 15:37:22 +00:00
|
|
|
/// This function is **not** an entrypoint but simply named `main` (not at the root).
|
|
|
|
/// This is only used for diagnostics.
|
|
|
|
/// ```
|
|
|
|
/// #[allow(dead_code)]
|
|
|
|
/// mod meow {
|
|
|
|
/// fn main() {}
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
OtherMain,
|
2015-08-23 18:12:39 +00:00
|
|
|
}
|
2023-09-29 06:54:48 +00:00
|
|
|
|
|
|
|
pub fn entry_point_type(
|
|
|
|
attrs: &[Attribute],
|
|
|
|
at_root: bool,
|
|
|
|
name: Option<Symbol>,
|
|
|
|
) -> EntryPointType {
|
|
|
|
if attr::contains_name(attrs, sym::start) {
|
|
|
|
EntryPointType::Start
|
|
|
|
} else if attr::contains_name(attrs, sym::rustc_main) {
|
|
|
|
EntryPointType::RustcMainAttr
|
|
|
|
} else {
|
|
|
|
if let Some(name) = name
|
|
|
|
&& name == sym::main
|
|
|
|
{
|
|
|
|
if at_root {
|
|
|
|
// This is a top-level function so it can be `main`.
|
|
|
|
EntryPointType::MainNamed
|
|
|
|
} else {
|
|
|
|
EntryPointType::OtherMain
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EntryPointType::None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|