Rollup merge of #98394 - Enselic:fixup-rustc_main-renames, r=petrochenkov
Fixup missing renames from `#[main]` to `#[rustc_main]` In #84217 `#[main]` was removed and replaced with `#[rustc_main]`. In some places the rename was forgotten, which makes the current code confusing, because at first glance it seems that `#[main]` is still around. Perform the renames also in these places. I noticed this (after first being confused by it) when working on #97802. r? `@petrochenkov` (since you reviewed the other PR)
This commit is contained in:
commit
f3078d0f44
3 changed files with 12 additions and 11 deletions
|
@ -2,7 +2,7 @@
|
||||||
pub enum EntryPointType {
|
pub enum EntryPointType {
|
||||||
None,
|
None,
|
||||||
MainNamed,
|
MainNamed,
|
||||||
MainAttr,
|
RustcMainAttr,
|
||||||
Start,
|
Start,
|
||||||
OtherMain, // Not an entry point, but some other function named main
|
OtherMain, // Not an entry point, but some other function named main
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ fn entry_point_type(sess: &Session, item: &ast::Item, depth: usize) -> EntryPoin
|
||||||
if sess.contains_name(&item.attrs, sym::start) {
|
if sess.contains_name(&item.attrs, sym::start) {
|
||||||
EntryPointType::Start
|
EntryPointType::Start
|
||||||
} else if sess.contains_name(&item.attrs, sym::rustc_main) {
|
} else if sess.contains_name(&item.attrs, sym::rustc_main) {
|
||||||
EntryPointType::MainAttr
|
EntryPointType::RustcMainAttr
|
||||||
} else if item.ident.name == sym::main {
|
} else if item.ident.name == sym::main {
|
||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
// This is a top-level function so can be 'main'
|
// This is a top-level function so can be 'main'
|
||||||
|
@ -177,12 +177,12 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
|
||||||
let item = noop_flat_map_item(i, self).expect_one("noop did something");
|
let item = noop_flat_map_item(i, self).expect_one("noop did something");
|
||||||
self.depth -= 1;
|
self.depth -= 1;
|
||||||
|
|
||||||
// Remove any #[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(self.sess, &item, self.depth) {
|
let item = match entry_point_type(self.sess, &item, self.depth) {
|
||||||
EntryPointType::MainNamed | EntryPointType::MainAttr | EntryPointType::Start => item
|
EntryPointType::MainNamed | EntryPointType::RustcMainAttr | EntryPointType::Start => {
|
||||||
.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
|
item.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
|
||||||
let allow_ident = Ident::new(sym::allow, self.def_site);
|
let allow_ident = Ident::new(sym::allow, self.def_site);
|
||||||
let dc_nested =
|
let dc_nested =
|
||||||
attr::mk_nested_word_item(Ident::new(sym::dead_code, self.def_site));
|
attr::mk_nested_word_item(Ident::new(sym::dead_code, self.def_site));
|
||||||
|
@ -197,7 +197,8 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
ast::Item { id, ident, attrs, kind, vis, span, tokens }
|
ast::Item { id, ident, attrs, kind, vis, span, tokens }
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
EntryPointType::None | EntryPointType::OtherMain => item,
|
EntryPointType::None | EntryPointType::OtherMain => item,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ fn entry_point_type(ctxt: &EntryContext<'_>, id: ItemId, at_root: bool) -> Entry
|
||||||
if ctxt.tcx.sess.contains_name(attrs, sym::start) {
|
if ctxt.tcx.sess.contains_name(attrs, sym::start) {
|
||||||
EntryPointType::Start
|
EntryPointType::Start
|
||||||
} else if ctxt.tcx.sess.contains_name(attrs, sym::rustc_main) {
|
} else if ctxt.tcx.sess.contains_name(attrs, sym::rustc_main) {
|
||||||
EntryPointType::MainAttr
|
EntryPointType::RustcMainAttr
|
||||||
} else {
|
} else {
|
||||||
if let Some(name) = ctxt.tcx.opt_item_name(id.def_id.to_def_id())
|
if let Some(name) = ctxt.tcx.opt_item_name(id.def_id.to_def_id())
|
||||||
&& name == sym::main {
|
&& name == sym::main {
|
||||||
|
@ -95,7 +95,7 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
|
||||||
EntryPointType::OtherMain => {
|
EntryPointType::OtherMain => {
|
||||||
ctxt.non_main_fns.push(ctxt.tcx.def_span(id.def_id));
|
ctxt.non_main_fns.push(ctxt.tcx.def_span(id.def_id));
|
||||||
}
|
}
|
||||||
EntryPointType::MainAttr => {
|
EntryPointType::RustcMainAttr => {
|
||||||
if ctxt.attr_main_fn.is_none() {
|
if ctxt.attr_main_fn.is_none() {
|
||||||
ctxt.attr_main_fn = Some((id.def_id, ctxt.tcx.def_span(id.def_id.to_def_id())));
|
ctxt.attr_main_fn = Some((id.def_id, ctxt.tcx.def_span(id.def_id.to_def_id())));
|
||||||
} else {
|
} else {
|
||||||
|
@ -103,13 +103,13 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
|
||||||
ctxt.tcx.sess,
|
ctxt.tcx.sess,
|
||||||
ctxt.tcx.def_span(id.def_id.to_def_id()),
|
ctxt.tcx.def_span(id.def_id.to_def_id()),
|
||||||
E0137,
|
E0137,
|
||||||
"multiple functions with a `#[main]` attribute"
|
"multiple functions with a `#[rustc_main]` attribute"
|
||||||
)
|
)
|
||||||
.span_label(
|
.span_label(
|
||||||
ctxt.tcx.def_span(id.def_id.to_def_id()),
|
ctxt.tcx.def_span(id.def_id.to_def_id()),
|
||||||
"additional `#[main]` function",
|
"additional `#[rustc_main]` function",
|
||||||
)
|
)
|
||||||
.span_label(ctxt.attr_main_fn.unwrap().1, "first `#[main]` function")
|
.span_label(ctxt.attr_main_fn.unwrap().1, "first `#[rustc_main]` function")
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue