
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
use rustc_span::{Symbol, sym};
|
|
|
|
use crate::attr::{self, AttributeExt};
|
|
|
|
#[derive(Debug)]
|
|
pub enum EntryPointType {
|
|
/// This function is not an entrypoint.
|
|
None,
|
|
/// This is a function called `main` at the root level.
|
|
/// ```
|
|
/// fn main() {}
|
|
/// ```
|
|
MainNamed,
|
|
/// 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() {}
|
|
/// ```
|
|
RustcMainAttr,
|
|
/// This is a function with the `#[start]` attribute.
|
|
/// ```ignore (clashes with test entrypoint)
|
|
/// #[start]
|
|
/// fn main() {}
|
|
/// ```
|
|
Start,
|
|
/// 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,
|
|
}
|
|
|
|
pub fn entry_point_type(
|
|
attrs: &[impl AttributeExt],
|
|
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
|
|
}
|
|
}
|