1
Fork 0

Factor out the two entry_point_type functions.

They are very similar, and each one has a comment about the importance
of being kept in sync with the other. This commit removes the
duplication.
This commit is contained in:
Nicholas Nethercote 2023-09-29 16:54:48 +10:00
parent 373cc2160a
commit 7326cd98b9
3 changed files with 36 additions and 42 deletions

View file

@ -1,3 +1,7 @@
use crate::{attr, Attribute};
use rustc_span::symbol::sym;
use rustc_span::Symbol;
#[derive(Debug)]
pub enum EntryPointType {
None,
@ -6,3 +10,26 @@ pub enum EntryPointType {
Start,
OtherMain, // Not an entry point, but some other function named main
}
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
}
}
}