]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/entry.rs
Rename `Item.node` to `Item.kind`
[rust.git] / src / libsyntax / entry.rs
1 use crate::attr;
2 use crate::ast::{Item, ItemKind};
3 use crate::symbol::sym;
4
5 pub enum EntryPointType {
6     None,
7     MainNamed,
8     MainAttr,
9     Start,
10     OtherMain, // Not an entry point, but some other function named main
11 }
12
13 // Beware, this is duplicated in librustc/middle/entry.rs, make sure to keep
14 // them in sync.
15 pub fn entry_point_type(item: &Item, depth: usize) -> EntryPointType {
16     match item.kind {
17         ItemKind::Fn(..) => {
18             if attr::contains_name(&item.attrs, sym::start) {
19                 EntryPointType::Start
20             } else if attr::contains_name(&item.attrs, sym::main) {
21                 EntryPointType::MainAttr
22             } else if item.ident.name == sym::main {
23                 if depth == 1 {
24                     // This is a top-level function so can be 'main'
25                     EntryPointType::MainNamed
26                 } else {
27                     EntryPointType::OtherMain
28                 }
29             } else {
30                 EntryPointType::None
31             }
32         }
33         _ => EntryPointType::None,
34     }
35 }