Rollup merge of #122060 - clubby789:stabilize-imported-main, r=lcnr

Stabilize `imported_main`

FCP: https://github.com/rust-lang/rust/issues/28937#issuecomment-1977822831
Docs: https://github.com/rust-lang/reference/pull/1461
This commit is contained in:
Matthias Krüger 2024-03-18 22:24:37 +01:00 committed by GitHub
commit b19c67c0fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 7 additions and 51 deletions

View File

@ -203,6 +203,8 @@ macro_rules! declare_features {
(accepted, impl_header_lifetime_elision, "1.31.0", Some(15872)),
/// Allows referencing `Self` and projections in impl-trait.
(accepted, impl_trait_projections, "1.74.0", Some(103532)),
/// Allows using imported `main` function
(accepted, imported_main, "CURRENT_RUSTC_VERSION", Some(28937)),
/// Allows using `a..=b` and `..=b` as inclusive range syntaxes.
(accepted, inclusive_range_syntax, "1.26.0", Some(28237)),
/// Allows inferring outlives requirements (RFC 2093).

View File

@ -495,8 +495,6 @@ pub fn internal(&self, feature: Symbol) -> bool {
(unstable, impl_trait_in_assoc_type, "1.70.0", Some(63063)),
/// Allows `impl Trait` as output type in `Fn` traits in return position of functions.
(unstable, impl_trait_in_fn_trait_return, "1.64.0", Some(99697)),
/// Allows using imported `main` function
(unstable, imported_main, "1.53.0", Some(28937)),
/// Allows associated types in inherent impls.
(incomplete, inherent_associated_types, "1.52.0", Some(8995)),
/// Allow anonymous constants from an inline `const` block

View File

@ -7,7 +7,6 @@
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{sigpipe, CrateType, EntryFnType};
use rustc_session::parse::feature_err;
use rustc_span::symbol::sym;
use rustc_span::{Span, Symbol};
@ -133,16 +132,6 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
return None;
}
if main_def.is_import && !tcx.features().imported_main {
let span = main_def.span;
feature_err(
&tcx.sess,
sym::imported_main,
span,
"using an imported function as entry point `main` is experimental",
)
.emit();
}
return Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx, def_id) }));
}
no_main_err(tcx, visitor);

View File

@ -1,3 +1 @@
#![feature(imported_main)]
use cargo_miri_test::main;

View File

@ -1,5 +1,3 @@
#![feature(imported_main)]
pub mod foo {
pub fn mymain() {
println!("Hello, world!");

View File

@ -1,5 +1,3 @@
#![feature(imported_main)]
mod foo {
pub(crate) fn bar() {}
}

View File

@ -1,5 +1,4 @@
#![feature(imported_main)]
//~^ ERROR `main` is ambiguous
//~ ERROR `main` is ambiguous
mod m1 { pub(crate) fn main() {} }
mod m2 { pub(crate) fn main() {} }

View File

@ -2,13 +2,13 @@ error[E0659]: `main` is ambiguous
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `main` could refer to the function imported here
--> $DIR/imported_main_conflict.rs:6:5
--> $DIR/imported_main_conflict.rs:5:5
|
LL | use m1::*;
| ^^^^^
= help: consider adding an explicit import of `main` to disambiguate
note: `main` could also refer to the function imported here
--> $DIR/imported_main_conflict.rs:7:5
--> $DIR/imported_main_conflict.rs:6:5
|
LL | use m2::*;
| ^^^^^

View File

@ -1,4 +1,3 @@
#![feature(imported_main)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
pub mod foo {

View File

@ -1,5 +1,5 @@
error[E0601]: `main` function not found in crate `imported_main_const_fn_item_type_forbidden`
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:11:22
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:10:22
|
LL | use foo::BAR as main;
| ---------------- ^ consider adding a `main` function to `$DIR/imported_main_const_fn_item_type_forbidden.rs`

View File

@ -1,4 +1,3 @@
#![feature(imported_main)]
pub mod foo {
pub const BAR: usize = 42;
}

View File

@ -1,5 +1,5 @@
error[E0601]: `main` function not found in crate `imported_main_const_forbidden`
--> $DIR/imported_main_const_forbidden.rs:6:22
--> $DIR/imported_main_const_forbidden.rs:5:22
|
LL | use foo::BAR as main;
| ---------------- ^ consider adding a `main` function to `$DIR/imported_main_const_forbidden.rs`

View File

@ -1,7 +1,5 @@
//@ run-pass
//@ aux-build:main_functions.rs
#![feature(imported_main)]
extern crate main_functions;
pub use main_functions::boilerplate as main;

View File

@ -1,6 +1,4 @@
//@ aux-build:bad_main_functions.rs
#![feature(imported_main)]
extern crate bad_main_functions;
pub use bad_main_functions::boilerplate as main;

View File

@ -1,5 +1,4 @@
//@ run-pass
#![feature(imported_main)]
pub mod foo {
pub fn bar() {

View File

@ -1,6 +0,0 @@
pub mod foo {
pub fn bar() {
println!("Hello world!");
}
}
use foo::bar as main; //~ ERROR using an imported function as entry point

View File

@ -1,13 +0,0 @@
error[E0658]: using an imported function as entry point `main` is experimental
--> $DIR/feature-gate-imported_main.rs:6:5
|
LL | use foo::bar as main;
| ^^^^^^^^^^^^^^^^
|
= note: see issue #28937 <https://github.com/rust-lang/rust/issues/28937> for more information
= help: add `#![feature(imported_main)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0658`.