Change depth arg to at_root.

This will facilitate a subsequent refactoring.
This commit is contained in:
Nicholas Nethercote 2023-09-29 16:47:47 +10:00
parent 2ba4eb2d49
commit 373cc2160a

View File

@ -171,7 +171,7 @@ impl<'a> Visitor<'a> for InnerItemLinter<'_> {
// Beware, this is duplicated in librustc_passes/entry.rs (with
// `rustc_hir::Item`), so make sure to keep them in sync.
fn entry_point_type(item: &ast::Item, depth: usize) -> EntryPointType {
fn entry_point_type(item: &ast::Item, at_root: bool) -> EntryPointType {
match item.kind {
ast::ItemKind::Fn(..) => {
if attr::contains_name(&item.attrs, sym::start) {
@ -179,7 +179,7 @@ fn entry_point_type(item: &ast::Item, depth: usize) -> EntryPointType {
} else if attr::contains_name(&item.attrs, sym::rustc_main) {
EntryPointType::RustcMainAttr
} else if item.ident.name == sym::main {
if depth == 0 {
if at_root {
// This is a top-level function so can be 'main'
EntryPointType::MainNamed
} else {
@ -210,7 +210,7 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
// Remove any #[rustc_main] or #[start] from the AST so it doesn't
// clash with the one we're going to add, but mark it as
// #[allow(dead_code)] to avoid printing warnings.
let item = match entry_point_type(&item, self.depth) {
let item = match entry_point_type(&item, self.depth == 0) {
EntryPointType::MainNamed | EntryPointType::RustcMainAttr | EntryPointType::Start => {
item.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
let allow_dead_code = attr::mk_attr_nested_word(