Skip to content

Commit 94477e3

Browse files
committed
Fixup missing renames from #[main] to #[rustc_main]
In fc35703 `#[main]` was removed and replaced with `#[rustc_main]`. In some place 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.
1 parent 6ec3993 commit 94477e3

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

compiler/rustc_ast/src/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pub enum EntryPointType {
33
None,
44
MainNamed,
5-
MainAttr,
5+
RustcMainAttr,
66
Start,
77
OtherMain, // Not an entry point, but some other function named main
88
}

compiler/rustc_builtin_macros/src/test_harness.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn entry_point_type(sess: &Session, item: &ast::Item, depth: usize) -> EntryPoin
147147
if sess.contains_name(&item.attrs, sym::start) {
148148
EntryPointType::Start
149149
} else if sess.contains_name(&item.attrs, sym::rustc_main) {
150-
EntryPointType::MainAttr
150+
EntryPointType::RustcMainAttr
151151
} else if item.ident.name == sym::main {
152152
if depth == 0 {
153153
// This is a top-level function so can be 'main'
@@ -177,12 +177,12 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
177177
let item = noop_flat_map_item(i, self).expect_one("noop did something");
178178
self.depth -= 1;
179179

180-
// Remove any #[main] or #[start] from the AST so it doesn't
180+
// Remove any #[rustc_main] or #[start] from the AST so it doesn't
181181
// clash with the one we're going to add, but mark it as
182182
// #[allow(dead_code)] to avoid printing warnings.
183183
let item = match entry_point_type(self.sess, &item, self.depth) {
184-
EntryPointType::MainNamed | EntryPointType::MainAttr | EntryPointType::Start => item
185-
.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
184+
EntryPointType::MainNamed | EntryPointType::RustcMainAttr | EntryPointType::Start => {
185+
item.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
186186
let allow_ident = Ident::new(sym::allow, self.def_site);
187187
let dc_nested =
188188
attr::mk_nested_word_item(Ident::new(sym::dead_code, self.def_site));
@@ -197,7 +197,8 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
197197
.collect();
198198

199199
ast::Item { id, ident, attrs, kind, vis, span, tokens }
200-
}),
200+
})
201+
}
201202
EntryPointType::None | EntryPointType::OtherMain => item,
202203
};
203204

compiler/rustc_passes/src/entry.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn entry_point_type(ctxt: &EntryContext<'_>, id: ItemId, at_root: bool) -> Entry
5656
if ctxt.tcx.sess.contains_name(attrs, sym::start) {
5757
EntryPointType::Start
5858
} else if ctxt.tcx.sess.contains_name(attrs, sym::rustc_main) {
59-
EntryPointType::MainAttr
59+
EntryPointType::RustcMainAttr
6060
} else {
6161
if let Some(name) = ctxt.tcx.opt_item_name(id.def_id.to_def_id())
6262
&& name == sym::main {
@@ -95,21 +95,21 @@ fn find_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
9595
EntryPointType::OtherMain => {
9696
ctxt.non_main_fns.push(ctxt.tcx.def_span(id.def_id));
9797
}
98-
EntryPointType::MainAttr => {
98+
EntryPointType::RustcMainAttr => {
9999
if ctxt.attr_main_fn.is_none() {
100100
ctxt.attr_main_fn = Some((id.def_id, ctxt.tcx.def_span(id.def_id.to_def_id())));
101101
} else {
102102
struct_span_err!(
103103
ctxt.tcx.sess,
104104
ctxt.tcx.def_span(id.def_id.to_def_id()),
105105
E0137,
106-
"multiple functions with a `#[main]` attribute"
106+
"multiple functions with a `#[rustc_main]` attribute"
107107
)
108108
.span_label(
109109
ctxt.tcx.def_span(id.def_id.to_def_id()),
110-
"additional `#[main]` function",
110+
"additional `#[rustc_main]` function",
111111
)
112-
.span_label(ctxt.attr_main_fn.unwrap().1, "first `#[main]` function")
112+
.span_label(ctxt.attr_main_fn.unwrap().1, "first `#[rustc_main]` function")
113113
.emit();
114114
}
115115
}

0 commit comments

Comments
 (0)