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