Change depth
arg to at_root
.
This will facilitate a subsequent refactoring.
This commit is contained in:
parent
2ba4eb2d49
commit
373cc2160a
1 changed files with 3 additions and 3 deletions
|
@ -171,7 +171,7 @@ impl<'a> Visitor<'a> for InnerItemLinter<'_> {
|
||||||
|
|
||||||
// Beware, this is duplicated in librustc_passes/entry.rs (with
|
// Beware, this is duplicated in librustc_passes/entry.rs (with
|
||||||
// `rustc_hir::Item`), so make sure to keep them in sync.
|
// `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 {
|
match item.kind {
|
||||||
ast::ItemKind::Fn(..) => {
|
ast::ItemKind::Fn(..) => {
|
||||||
if attr::contains_name(&item.attrs, sym::start) {
|
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) {
|
} else if attr::contains_name(&item.attrs, sym::rustc_main) {
|
||||||
EntryPointType::RustcMainAttr
|
EntryPointType::RustcMainAttr
|
||||||
} else if item.ident.name == sym::main {
|
} else if item.ident.name == sym::main {
|
||||||
if depth == 0 {
|
if at_root {
|
||||||
// This is a top-level function so can be 'main'
|
// This is a top-level function so can be 'main'
|
||||||
EntryPointType::MainNamed
|
EntryPointType::MainNamed
|
||||||
} else {
|
} else {
|
||||||
|
@ -210,7 +210,7 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
|
||||||
// Remove any #[rustc_main] or #[start] from the AST so it doesn't
|
// 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
|
// clash with the one we're going to add, but mark it as
|
||||||
// #[allow(dead_code)] to avoid printing warnings.
|
// #[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 => {
|
EntryPointType::MainNamed | EntryPointType::RustcMainAttr | EntryPointType::Start => {
|
||||||
item.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
|
item.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
|
||||||
let allow_dead_code = attr::mk_attr_nested_word(
|
let allow_dead_code = attr::mk_attr_nested_word(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue