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 {
|
|
|
|
None,
|
|
|
|
MainNamed,
|
2022-06-22 16:23:21 +00:00
|
|
|
RustcMainAttr,
|
2015-08-23 18:12:39 +00:00
|
|
|
Start,
|
|
|
|
OtherMain, // Not an entry point, but some other function named main
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|