mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Remove #[main] attribute.
This commit is contained in:
parent
9c3b66cff7
commit
fc357039f9
@ -366,16 +366,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
over time"
|
||||
);
|
||||
}
|
||||
if self.sess.contains_name(&i.attrs[..], sym::main) {
|
||||
gate_feature_post!(
|
||||
&self,
|
||||
main,
|
||||
i.span,
|
||||
"declaration of a non-standard `#[main]` \
|
||||
function may change over time, for now \
|
||||
a top-level `fn main()` is required"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ast::ItemKind::Struct(..) => {
|
||||
|
@ -142,7 +142,7 @@ fn entry_point_type(sess: &Session, item: &ast::Item, depth: usize) -> EntryPoin
|
||||
ast::ItemKind::Fn(..) => {
|
||||
if sess.contains_name(&item.attrs, sym::start) {
|
||||
EntryPointType::Start
|
||||
} else if sess.contains_name(&item.attrs, sym::main) {
|
||||
} else if sess.contains_name(&item.attrs, sym::rustc_main) {
|
||||
EntryPointType::MainAttr
|
||||
} else if item.ident.name == sym::main {
|
||||
if depth == 1 {
|
||||
@ -187,7 +187,7 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
|
||||
let attrs = attrs
|
||||
.into_iter()
|
||||
.filter(|attr| {
|
||||
!self.sess.check_name(attr, sym::main)
|
||||
!self.sess.check_name(attr, sym::rustc_main)
|
||||
&& !self.sess.check_name(attr, sym::start)
|
||||
})
|
||||
.chain(iter::once(allow_dead_code))
|
||||
@ -220,7 +220,7 @@ fn generate_test_harness(
|
||||
let expn_id = ext_cx.resolver.expansion_for_ast_pass(
|
||||
DUMMY_SP,
|
||||
AstPass::TestHarness,
|
||||
&[sym::main, sym::test, sym::rustc_attrs],
|
||||
&[sym::test, sym::rustc_attrs],
|
||||
None,
|
||||
);
|
||||
let def_site = DUMMY_SP.with_def_site_ctxt(expn_id);
|
||||
@ -247,7 +247,7 @@ fn generate_test_harness(
|
||||
/// By default this expands to
|
||||
///
|
||||
/// ```
|
||||
/// #[main]
|
||||
/// #[rustc_main]
|
||||
/// pub fn main() {
|
||||
/// extern crate test;
|
||||
/// test::test_main_static(&[
|
||||
@ -297,8 +297,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
||||
let test_extern_stmt =
|
||||
ecx.stmt_item(sp, ecx.item(sp, test_id, vec![], ast::ItemKind::ExternCrate(None)));
|
||||
|
||||
// #[main]
|
||||
let main_meta = ecx.meta_word(sp, sym::main);
|
||||
// #[rustc_main]
|
||||
let main_meta = ecx.meta_word(sp, sym::rustc_main);
|
||||
let main_attr = ecx.attribute(main_meta);
|
||||
|
||||
// pub fn main() { ... }
|
||||
|
@ -1,8 +1,10 @@
|
||||
#### Note: this error code is no longer emitted by the compiler.
|
||||
|
||||
More than one function was declared with the `#[main]` attribute.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0137
|
||||
```compile_fail
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
@ -16,7 +18,7 @@ This error indicates that the compiler found multiple functions with the
|
||||
`#[main]` attribute. This is an error because there must be a unique entry
|
||||
point into a Rust program. Example:
|
||||
|
||||
```
|
||||
```compile_fail
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
|
@ -134,9 +134,6 @@ declare_features! (
|
||||
/// Allows using the `box $expr` syntax.
|
||||
(active, box_syntax, "1.0.0", Some(49733), None),
|
||||
|
||||
/// Allows using `#[main]` to replace the entrypoint `#[lang = "start"]` calls.
|
||||
(active, main, "1.0.0", Some(29634), None),
|
||||
|
||||
/// Allows using `#[start]` on a function indicating that it is the program entrypoint.
|
||||
(active, start, "1.0.0", Some(29633), None),
|
||||
|
||||
|
@ -536,6 +536,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
rustc_specialization_trait, Normal, template!(Word),
|
||||
"the `#[rustc_specialization_trait]` attribute is used to check specializations"
|
||||
),
|
||||
rustc_attr!(
|
||||
rustc_main, Normal, template!(Word),
|
||||
"the `#[rustc_main]` attribute is used internally to specify test entry point function",
|
||||
),
|
||||
|
||||
// ==========================================================================
|
||||
// Internal attributes, Testing:
|
||||
|
@ -132,6 +132,8 @@ declare_features! (
|
||||
(removed, link_args, "1.53.0", Some(29596), None,
|
||||
Some("removed in favor of using `-C link-arg=ARG` on command line, \
|
||||
which is available from cargo build scripts with `cargo:rustc-link-arg` now")),
|
||||
/// Allows using `#[main]` to replace the entrypoint `#[lang = "start"]` calls.
|
||||
(removed, main, "1.53.0", Some(29634), None, None),
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// feature-group-end: removed features
|
||||
|
@ -1489,7 +1489,7 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
|
||||
sym::path,
|
||||
sym::automatically_derived,
|
||||
sym::start,
|
||||
sym::main,
|
||||
sym::rustc_main,
|
||||
];
|
||||
|
||||
for attr in attrs {
|
||||
|
@ -84,7 +84,7 @@ fn entry_point_type(ctxt: &EntryContext<'_, '_>, item: &Item<'_>, at_root: bool)
|
||||
let attrs = ctxt.map.attrs(item.hir_id());
|
||||
if ctxt.session.contains_name(attrs, sym::start) {
|
||||
EntryPointType::Start
|
||||
} else if ctxt.session.contains_name(attrs, sym::main) {
|
||||
} else if ctxt.session.contains_name(attrs, sym::rustc_main) {
|
||||
EntryPointType::MainAttr
|
||||
} else if item.ident.name == sym::main {
|
||||
if at_root {
|
||||
@ -111,8 +111,8 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
|
||||
if let Some(attr) = ctxt.session.find_by_name(attrs, sym::start) {
|
||||
throw_attr_err(&ctxt.session, attr.span, "start");
|
||||
}
|
||||
if let Some(attr) = ctxt.session.find_by_name(attrs, sym::main) {
|
||||
throw_attr_err(&ctxt.session, attr.span, "main");
|
||||
if let Some(attr) = ctxt.session.find_by_name(attrs, sym::rustc_main) {
|
||||
throw_attr_err(&ctxt.session, attr.span, "rustc_main");
|
||||
}
|
||||
}
|
||||
EntryPointType::MainNamed => {
|
||||
@ -193,10 +193,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
|
||||
err.span_note(span, "here is a function named `main`");
|
||||
}
|
||||
err.note("you have one or more functions named `main` not defined at the crate level");
|
||||
err.help(
|
||||
"either move the `main` function definitions or attach the `#[main]` attribute \
|
||||
to one of them",
|
||||
);
|
||||
err.help("consider moving the `main` function definitions");
|
||||
// There were some functions named `main` though. Try to give the user a hint.
|
||||
format!(
|
||||
"the main function must be defined at the crate level{}",
|
||||
|
@ -1008,6 +1008,7 @@ symbols! {
|
||||
rustc_layout_scalar_valid_range_start,
|
||||
rustc_legacy_const_generics,
|
||||
rustc_macro_transparency,
|
||||
rustc_main,
|
||||
rustc_mir,
|
||||
rustc_nonnull_optimization_guaranteed,
|
||||
rustc_object_lifetime_default,
|
||||
|
@ -1,11 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(main)]
|
||||
|
||||
pub fn main() {
|
||||
panic!()
|
||||
}
|
||||
|
||||
#[main]
|
||||
fn foo() {
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
// run-pass
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
fn foo() {
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
// run-pass
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
fn foo() {
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
fn foo() {}
|
||||
|
||||
#[main]
|
||||
fn f() {}
|
||||
//~^ ERROR E0137
|
@ -1,12 +0,0 @@
|
||||
error[E0137]: multiple functions with a `#[main]` attribute
|
||||
--> $DIR/E0137.rs:7:1
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ----------- first `#[main]` function
|
||||
...
|
||||
LL | fn f() {}
|
||||
| ^^^^^^^^^ additional `#[main]` function
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0137`.
|
@ -1,2 +0,0 @@
|
||||
#[main]
|
||||
fn foo() {} //~ ERROR: declaration of a non-standard `#[main]` function may change over time
|
@ -1,12 +0,0 @@
|
||||
error[E0658]: declaration of a non-standard `#[main]` function may change over time, for now a top-level `fn main()` is required
|
||||
--> $DIR/feature-gate-main.rs:2:1
|
||||
|
|
||||
LL | fn foo() {}
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #29634 <https://github.com/rust-lang/rust/issues/29634> for more information
|
||||
= help: add `#![feature(main)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
@ -11,8 +11,8 @@
|
||||
|
||||
#![macro_export]
|
||||
//~^ ERROR: `macro_export` attribute cannot be used at crate level
|
||||
#![main]
|
||||
//~^ ERROR: `main` attribute cannot be used at crate level
|
||||
#![rustc_main] //~ ERROR: the `#[rustc_main]` attribute is used internally to specify
|
||||
//~^ ERROR: `rustc_main` attribute cannot be used at crate level
|
||||
#![start]
|
||||
//~^ ERROR: `start` attribute cannot be used at crate level
|
||||
#![repr()]
|
||||
@ -106,24 +106,6 @@ mod export_name {
|
||||
//~| NOTE not a function or static
|
||||
}
|
||||
|
||||
#[main]
|
||||
//~^ ERROR: `main` attribute can only be used on functions
|
||||
mod main {
|
||||
mod inner { #![main] }
|
||||
//~^ ERROR: `main` attribute can only be used on functions
|
||||
|
||||
// for `fn f()` case, see feature-gate-main.rs
|
||||
|
||||
#[main] struct S;
|
||||
//~^ ERROR: `main` attribute can only be used on functions
|
||||
|
||||
#[main] type T = S;
|
||||
//~^ ERROR: `main` attribute can only be used on functions
|
||||
|
||||
#[main] impl S { }
|
||||
//~^ ERROR: `main` attribute can only be used on functions
|
||||
}
|
||||
|
||||
#[start]
|
||||
//~^ ERROR: `start` attribute can only be used on functions
|
||||
mod start {
|
||||
|
@ -1,3 +1,11 @@
|
||||
error[E0658]: the `#[rustc_main]` attribute is used internally to specify test entry point function
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:14:1
|
||||
|
|
||||
LL | #![rustc_main]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
|
||||
|
||||
error: attribute must be of the form `#[inline]` or `#[inline(always|never)]`
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:40:5
|
||||
|
|
||||
@ -8,62 +16,32 @@ LL | #[inline = "2100"] fn f() { }
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
|
||||
|
||||
error: `main` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:1
|
||||
|
|
||||
LL | #[main]
|
||||
| ^^^^^^^
|
||||
|
||||
error: `main` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:112:17
|
||||
|
|
||||
LL | mod inner { #![main] }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `main` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:117:5
|
||||
|
|
||||
LL | #[main] struct S;
|
||||
| ^^^^^^^
|
||||
|
||||
error: `main` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:120:5
|
||||
|
|
||||
LL | #[main] type T = S;
|
||||
| ^^^^^^^
|
||||
|
||||
error: `main` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:5
|
||||
|
|
||||
LL | #[main] impl S { }
|
||||
| ^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:1
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:1
|
||||
|
|
||||
LL | #[start]
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:130:17
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:112:17
|
||||
|
|
||||
LL | mod inner { #![start] }
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:135:5
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:117:5
|
||||
|
|
||||
LL | #[start] struct S;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:138:5
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:120:5
|
||||
|
|
||||
LL | #[start] type T = S;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `start` attribute can only be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:141:5
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:5
|
||||
|
|
||||
LL | #[start] impl S { }
|
||||
| ^^^^^^^^
|
||||
@ -137,11 +115,11 @@ error: `macro_export` attribute cannot be used at crate level
|
||||
LL | #![macro_export]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `main` attribute cannot be used at crate level
|
||||
error: `rustc_main` attribute cannot be used at crate level
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:14:1
|
||||
|
|
||||
LL | #![main]
|
||||
| ^^^^^^^^
|
||||
LL | #![rustc_main]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: `start` attribute cannot be used at crate level
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1
|
||||
@ -245,6 +223,7 @@ error: attribute should be applied to a function or static
|
||||
LL | #[export_name = "2200"] impl S { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a function or static
|
||||
|
||||
error: aborting due to 36 previous errors
|
||||
error: aborting due to 32 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0518`.
|
||||
Some errors have detailed explanations: E0518, E0658.
|
||||
For more information about an error, try `rustc --explain E0518`.
|
||||
|
@ -1,7 +1,7 @@
|
||||
// run-pass
|
||||
// ignore-wasm32-bare seems not important to test here
|
||||
|
||||
#![feature(intrinsics, main)]
|
||||
#![feature(intrinsics)]
|
||||
|
||||
mod rusti {
|
||||
extern "rust-intrinsic" {
|
||||
@ -21,7 +21,6 @@ mod rusti {
|
||||
target_os = "solaris",
|
||||
target_os = "vxworks"))]
|
||||
mod m {
|
||||
#[main]
|
||||
#[cfg(target_arch = "x86")]
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
@ -30,7 +29,6 @@ mod m {
|
||||
}
|
||||
}
|
||||
|
||||
#[main]
|
||||
#[cfg(not(target_arch = "x86"))]
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
@ -42,7 +40,6 @@ mod m {
|
||||
|
||||
#[cfg(target_env = "sgx")]
|
||||
mod m {
|
||||
#[main]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
@ -54,7 +51,6 @@ mod m {
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod m {
|
||||
#[main]
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
assert_eq!(::rusti::pref_align_of::<u64>(), 8);
|
||||
@ -62,3 +58,7 @@ mod m {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
m::main();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![allow(unused_variables)]
|
||||
#![deny(dead_code)]
|
||||
#![feature(main, start)]
|
||||
#![feature(rustc_attrs, start)]
|
||||
|
||||
struct Foo;
|
||||
|
||||
@ -21,7 +21,7 @@ fn live_fn() {}
|
||||
|
||||
fn dead_fn() {} //~ ERROR: function is never used
|
||||
|
||||
#[main]
|
||||
#[rustc_main]
|
||||
fn dead_fn2() {} //~ ERROR: function is never used
|
||||
|
||||
fn used_fn() {}
|
||||
|
@ -1,6 +1,6 @@
|
||||
mod m {
|
||||
//~^ ERROR `main` function not found
|
||||
// An inferred main entry point (that doesn't use #[main])
|
||||
// An inferred main entry point
|
||||
// must appear at the top of the crate
|
||||
fn main() { }
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ error[E0601]: `main` function not found in crate `main_wrong_location`
|
||||
|
|
||||
LL | / mod m {
|
||||
LL | |
|
||||
LL | | // An inferred main entry point (that doesn't use #[main])
|
||||
LL | | // An inferred main entry point
|
||||
LL | | // must appear at the top of the crate
|
||||
LL | | fn main() { }
|
||||
LL | | }
|
||||
@ -15,7 +15,7 @@ note: here is a function named `main`
|
||||
LL | fn main() { }
|
||||
| ^^^^^^^^^^^^^
|
||||
= note: you have one or more functions named `main` not defined at the crate level
|
||||
= help: either move the `main` function definitions or attach the `#[main]` attribute to one of them
|
||||
= help: consider moving the `main` function definitions
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
fn bar() {
|
||||
}
|
||||
|
||||
#[main]
|
||||
fn foo() { //~ ERROR multiple functions with a `#[main]` attribute
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
error[E0137]: multiple functions with a `#[main]` attribute
|
||||
--> $DIR/multiple-main-2.rs:8:1
|
||||
|
|
||||
LL | / fn bar() {
|
||||
LL | | }
|
||||
| |_- first `#[main]` function
|
||||
...
|
||||
LL | / fn foo() {
|
||||
LL | | }
|
||||
| |_^ additional `#[main]` function
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0137`.
|
@ -1,11 +0,0 @@
|
||||
#![feature(main)]
|
||||
|
||||
#[main]
|
||||
fn main1() {
|
||||
}
|
||||
|
||||
mod foo {
|
||||
#[main]
|
||||
fn main2() { //~ ERROR multiple functions with a `#[main]` attribute
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
error[E0137]: multiple functions with a `#[main]` attribute
|
||||
--> $DIR/multiple-main-3.rs:9:5
|
||||
|
|
||||
LL | / fn main1() {
|
||||
LL | | }
|
||||
| |_- first `#[main]` function
|
||||
...
|
||||
LL | / fn main2() {
|
||||
LL | | }
|
||||
| |_____^ additional `#[main]` function
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0137`.
|
@ -1,9 +1,9 @@
|
||||
// run-pass
|
||||
// compile-flags: --test
|
||||
|
||||
#![feature(main)]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#![deny(dead_code)]
|
||||
|
||||
#[main]
|
||||
#[rustc_main]
|
||||
fn foo() { panic!(); }
|
||||
|
@ -1,14 +1,14 @@
|
||||
// run-pass
|
||||
// compile-flags: --test
|
||||
|
||||
#![feature(main)]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
mod a {
|
||||
fn b() {
|
||||
(|| {
|
||||
#[main]
|
||||
#[rustc_main]
|
||||
fn c() { panic!(); }
|
||||
})();
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
// ignore-macos
|
||||
// ignore-windows
|
||||
|
||||
#![feature(main)]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[warn(clippy::main_recursion)]
|
||||
#[allow(unconditional_recursion)]
|
||||
#[main]
|
||||
#[rustc_main]
|
||||
fn a() {
|
||||
println!("Hello, World!");
|
||||
a();
|
||||
|
Loading…
Reference in New Issue
Block a user