From c7030e9b9105e8def0d4753f69f15ae8168a6f30 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Tue, 30 Jan 2024 18:41:43 +0000 Subject: [PATCH] Stabilize `imported_main` --- compiler/rustc_feature/src/accepted.rs | 2 ++ compiler/rustc_feature/src/unstable.rs | 2 -- compiler/rustc_passes/src/entry.rs | 11 ----------- src/tools/miri/test-cargo-miri/tests/main.rs | 2 -- src/tools/miri/tests/pass/imported_main.rs | 2 -- src/tools/miri/tests/pass/main_fn.rs | 2 -- tests/ui/entry-point/imported_main_conflict.rs | 3 +-- tests/ui/entry-point/imported_main_conflict.stderr | 4 ++-- .../imported_main_const_fn_item_type_forbidden.rs | 1 - ...mported_main_const_fn_item_type_forbidden.stderr | 2 +- .../ui/entry-point/imported_main_const_forbidden.rs | 1 - .../imported_main_const_forbidden.stderr | 2 +- .../entry-point/imported_main_from_extern_crate.rs | 2 -- .../imported_main_from_extern_crate_wrong_type.rs | 2 -- .../ui/entry-point/imported_main_from_inner_mod.rs | 1 - .../ui/feature-gates/feature-gate-imported_main.rs | 6 ------ .../feature-gates/feature-gate-imported_main.stderr | 13 ------------- 17 files changed, 7 insertions(+), 51 deletions(-) delete mode 100644 tests/ui/feature-gates/feature-gate-imported_main.rs delete mode 100644 tests/ui/feature-gates/feature-gate-imported_main.stderr diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 1b2993dabdb83..5302a761817f2 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -201,6 +201,8 @@ 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). diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 17c4d81474e27..29c411a06821d 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -489,8 +489,6 @@ declare_features! ( (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 diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 97c70e327f0fe..b3d35a18a478b 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -7,7 +7,6 @@ use rustc_hir::{ItemId, Node, CRATE_HIR_ID}; 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}; @@ -132,16 +131,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); diff --git a/src/tools/miri/test-cargo-miri/tests/main.rs b/src/tools/miri/test-cargo-miri/tests/main.rs index bb94c8f37876c..72224e2961947 100644 --- a/src/tools/miri/test-cargo-miri/tests/main.rs +++ b/src/tools/miri/test-cargo-miri/tests/main.rs @@ -1,3 +1 @@ -#![feature(imported_main)] - use cargo_miri_test::main; diff --git a/src/tools/miri/tests/pass/imported_main.rs b/src/tools/miri/tests/pass/imported_main.rs index 32b39152f7839..eb93cd11d3852 100644 --- a/src/tools/miri/tests/pass/imported_main.rs +++ b/src/tools/miri/tests/pass/imported_main.rs @@ -1,5 +1,3 @@ -#![feature(imported_main)] - pub mod foo { pub fn mymain() { println!("Hello, world!"); diff --git a/src/tools/miri/tests/pass/main_fn.rs b/src/tools/miri/tests/pass/main_fn.rs index 3b84d1abe6f3d..4cdd034f30eea 100644 --- a/src/tools/miri/tests/pass/main_fn.rs +++ b/src/tools/miri/tests/pass/main_fn.rs @@ -1,5 +1,3 @@ -#![feature(imported_main)] - mod foo { pub(crate) fn bar() {} } diff --git a/tests/ui/entry-point/imported_main_conflict.rs b/tests/ui/entry-point/imported_main_conflict.rs index e8c70b06513c2..06178dbeff72d 100644 --- a/tests/ui/entry-point/imported_main_conflict.rs +++ b/tests/ui/entry-point/imported_main_conflict.rs @@ -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() {} } diff --git a/tests/ui/entry-point/imported_main_conflict.stderr b/tests/ui/entry-point/imported_main_conflict.stderr index 783e9345acf69..3ef34962524af 100644 --- a/tests/ui/entry-point/imported_main_conflict.stderr +++ b/tests/ui/entry-point/imported_main_conflict.stderr @@ -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::*; | ^^^^^ diff --git a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs index 405d6e2a9f560..d0be240e07ba6 100644 --- a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs +++ b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs @@ -1,4 +1,3 @@ -#![feature(imported_main)] #![feature(type_alias_impl_trait)] #![allow(incomplete_features)] pub mod foo { diff --git a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr index 1e7d82a73bc93..50e4cd7d39f79 100644 --- a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr +++ b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr @@ -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` diff --git a/tests/ui/entry-point/imported_main_const_forbidden.rs b/tests/ui/entry-point/imported_main_const_forbidden.rs index 1508280c0fa57..c478e004603c0 100644 --- a/tests/ui/entry-point/imported_main_const_forbidden.rs +++ b/tests/ui/entry-point/imported_main_const_forbidden.rs @@ -1,4 +1,3 @@ -#![feature(imported_main)] pub mod foo { pub const BAR: usize = 42; } diff --git a/tests/ui/entry-point/imported_main_const_forbidden.stderr b/tests/ui/entry-point/imported_main_const_forbidden.stderr index 6f34015a2cd57..eb768b1b2506e 100644 --- a/tests/ui/entry-point/imported_main_const_forbidden.stderr +++ b/tests/ui/entry-point/imported_main_const_forbidden.stderr @@ -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` diff --git a/tests/ui/entry-point/imported_main_from_extern_crate.rs b/tests/ui/entry-point/imported_main_from_extern_crate.rs index abcf2cbc05bfb..6d1c497052e9f 100644 --- a/tests/ui/entry-point/imported_main_from_extern_crate.rs +++ b/tests/ui/entry-point/imported_main_from_extern_crate.rs @@ -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; diff --git a/tests/ui/entry-point/imported_main_from_extern_crate_wrong_type.rs b/tests/ui/entry-point/imported_main_from_extern_crate_wrong_type.rs index 82d81a93d9d9a..d8ae12d200f40 100644 --- a/tests/ui/entry-point/imported_main_from_extern_crate_wrong_type.rs +++ b/tests/ui/entry-point/imported_main_from_extern_crate_wrong_type.rs @@ -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; diff --git a/tests/ui/entry-point/imported_main_from_inner_mod.rs b/tests/ui/entry-point/imported_main_from_inner_mod.rs index 7212dd6182c5b..cede1766118dd 100644 --- a/tests/ui/entry-point/imported_main_from_inner_mod.rs +++ b/tests/ui/entry-point/imported_main_from_inner_mod.rs @@ -1,5 +1,4 @@ //@ run-pass -#![feature(imported_main)] pub mod foo { pub fn bar() { diff --git a/tests/ui/feature-gates/feature-gate-imported_main.rs b/tests/ui/feature-gates/feature-gate-imported_main.rs deleted file mode 100644 index b351d0d0e9a50..0000000000000 --- a/tests/ui/feature-gates/feature-gate-imported_main.rs +++ /dev/null @@ -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 diff --git a/tests/ui/feature-gates/feature-gate-imported_main.stderr b/tests/ui/feature-gates/feature-gate-imported_main.stderr deleted file mode 100644 index 987bda7059c86..0000000000000 --- a/tests/ui/feature-gates/feature-gate-imported_main.stderr +++ /dev/null @@ -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 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`.