about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCharles Lew <crlf0710@gmail.com>2021-04-26 01:09:35 +0800
committerCharles Lew <crlf0710@gmail.com>2021-04-29 08:35:08 +0800
commitd261df4a72e60e8baa0f21b67eba8f7b91cc2135 (patch)
tree4547e05f08c17033fdc8da3d03415010f213d82c /src
parent727d101561f9b1e81c6282943292d990288ca479 (diff)
downloadrust-d261df4a72e60e8baa0f21b67eba8f7b91cc2135.tar.gz
rust-d261df4a72e60e8baa0f21b67eba8f7b91cc2135.zip
Implement RFC 1260 with feature_name `imported_main`.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/async-await/issue-68523.rs1
-rw-r--r--src/test/ui/async-await/issue-68523.stderr13
-rw-r--r--src/test/ui/entry-point/auxiliary/main_functions.rs1
-rw-r--r--src/test/ui/entry-point/imported_main_conflict.rs7
-rw-r--r--src/test/ui/entry-point/imported_main_conflict.stderr18
-rw-r--r--src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs12
-rw-r--r--src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr17
-rw-r--r--src/test/ui/entry-point/imported_main_const_forbidden.rs7
-rw-r--r--src/test/ui/entry-point/imported_main_const_forbidden.stderr17
-rw-r--r--src/test/ui/entry-point/imported_main_from_extern_crate.rs9
-rw-r--r--src/test/ui/entry-point/imported_main_from_extern_crate.stderr10
-rw-r--r--src/test/ui/entry-point/imported_main_from_inner_mod.rs9
-rw-r--r--src/test/ui/entry-point/imported_main_unused_not_trigger_feature_gate.rs11
-rw-r--r--src/test/ui/feature-gates/feature-gate-imported_main.rs6
-rw-r--r--src/test/ui/feature-gates/feature-gate-imported_main.stderr12
-rw-r--r--src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs1
-rw-r--r--src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr13
-rw-r--r--src/tools/clippy/clippy_utils/src/lib.rs2
18 files changed, 141 insertions, 25 deletions
diff --git a/src/test/ui/async-await/issue-68523.rs b/src/test/ui/async-await/issue-68523.rs
index 718c597e712..7a67661a019 100644
--- a/src/test/ui/async-await/issue-68523.rs
+++ b/src/test/ui/async-await/issue-68523.rs
@@ -2,6 +2,5 @@
 
 async fn main() -> Result<i32, ()> {
 //~^ ERROR `main` function is not allowed to be `async`
-//~^^ ERROR `main` has invalid return type `impl Future`
     Ok(1)
 }
diff --git a/src/test/ui/async-await/issue-68523.stderr b/src/test/ui/async-await/issue-68523.stderr
index 6f67af04cd4..dfdf078e303 100644
--- a/src/test/ui/async-await/issue-68523.stderr
+++ b/src/test/ui/async-await/issue-68523.stderr
@@ -1,18 +1,9 @@
-error[E0277]: `main` has invalid return type `impl Future`
-  --> $DIR/issue-68523.rs:3:20
-   |
-LL | async fn main() -> Result<i32, ()> {
-   |                    ^^^^^^^^^^^^^^^ `main` can only return types that implement `Termination`
-   |
-   = help: consider using `()`, or a `Result`
-
 error[E0752]: `main` function is not allowed to be `async`
   --> $DIR/issue-68523.rs:3:1
    |
 LL | async fn main() -> Result<i32, ()> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`
 
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
-Some errors have detailed explanations: E0277, E0752.
-For more information about an error, try `rustc --explain E0277`.
+For more information about this error, try `rustc --explain E0752`.
diff --git a/src/test/ui/entry-point/auxiliary/main_functions.rs b/src/test/ui/entry-point/auxiliary/main_functions.rs
new file mode 100644
index 00000000000..cc7992a42c1
--- /dev/null
+++ b/src/test/ui/entry-point/auxiliary/main_functions.rs
@@ -0,0 +1 @@
+pub fn boilerplate() {}
diff --git a/src/test/ui/entry-point/imported_main_conflict.rs b/src/test/ui/entry-point/imported_main_conflict.rs
new file mode 100644
index 00000000000..2839688f342
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_conflict.rs
@@ -0,0 +1,7 @@
+#![feature(imported_main)]
+//~^ ERROR `main` is ambiguous (glob import vs glob import in the same module)
+mod m1 { pub(crate) fn main() {} }
+mod m2 { pub(crate) fn main() {} }
+
+use m1::*;
+use m2::*;
diff --git a/src/test/ui/entry-point/imported_main_conflict.stderr b/src/test/ui/entry-point/imported_main_conflict.stderr
new file mode 100644
index 00000000000..36cb98d94e6
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_conflict.stderr
@@ -0,0 +1,18 @@
+error[E0659]: `main` is ambiguous (glob import vs glob import in the same module)
+   |
+note: `main` could refer to the function imported here
+  --> $DIR/imported_main_conflict.rs:6: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
+   |
+LL | use m2::*;
+   |     ^^^^^
+   = help: consider adding an explicit import of `main` to disambiguate
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0659`.
diff --git a/src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs b/src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs
new file mode 100644
index 00000000000..559f10de109
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs
@@ -0,0 +1,12 @@
+#![feature(imported_main)]
+#![feature(min_type_alias_impl_trait, impl_trait_in_bindings)]
+#![allow(incomplete_features)]
+//~^^^ ERROR `main` function not found in crate
+pub mod foo {
+    type MainFn = impl Fn();
+
+    fn bar() {}
+    pub const BAR: MainFn = bar;
+}
+
+use foo::BAR as main;
diff --git a/src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr b/src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr
new file mode 100644
index 00000000000..9b879fc09f7
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr
@@ -0,0 +1,17 @@
+error[E0601]: `main` function not found in crate `imported_main_const_fn_item_type_forbidden`
+  --> $DIR/imported_main_const_fn_item_type_forbidden.rs:1:1
+   |
+LL | / #![feature(imported_main)]
+LL | | #![feature(min_type_alias_impl_trait, impl_trait_in_bindings)]
+LL | | #![allow(incomplete_features)]
+LL | |
+...  |
+LL | |
+LL | | use foo::BAR as main;
+   | |_____----------------^ consider adding a `main` function to `$DIR/imported_main_const_fn_item_type_forbidden.rs`
+   |       |
+   |       non-function item at `crate::main` is found
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0601`.
diff --git a/src/test/ui/entry-point/imported_main_const_forbidden.rs b/src/test/ui/entry-point/imported_main_const_forbidden.rs
new file mode 100644
index 00000000000..989a6c97a80
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_const_forbidden.rs
@@ -0,0 +1,7 @@
+#![feature(imported_main)]
+//~^ ERROR `main` function not found in crate
+pub mod foo {
+    pub const BAR: usize = 42;
+}
+
+use foo::BAR as main;
diff --git a/src/test/ui/entry-point/imported_main_const_forbidden.stderr b/src/test/ui/entry-point/imported_main_const_forbidden.stderr
new file mode 100644
index 00000000000..4640513c2bb
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_const_forbidden.stderr
@@ -0,0 +1,17 @@
+error[E0601]: `main` function not found in crate `imported_main_const_forbidden`
+  --> $DIR/imported_main_const_forbidden.rs:1:1
+   |
+LL | / #![feature(imported_main)]
+LL | |
+LL | | pub mod foo {
+LL | |     pub const BAR: usize = 42;
+LL | | }
+LL | |
+LL | | use foo::BAR as main;
+   | |_____----------------^ consider adding a `main` function to `$DIR/imported_main_const_forbidden.rs`
+   |       |
+   |       non-function item at `crate::main` is found
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0601`.
diff --git a/src/test/ui/entry-point/imported_main_from_extern_crate.rs b/src/test/ui/entry-point/imported_main_from_extern_crate.rs
new file mode 100644
index 00000000000..6bbf67fa540
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_from_extern_crate.rs
@@ -0,0 +1,9 @@
+// build-fail
+// aux-build:main_functions.rs
+
+#![feature(imported_main)]
+
+extern crate main_functions;
+pub use main_functions::boilerplate as main; //~ ERROR entry symbol `main` from foreign crate
+
+// FIXME: Should be run-pass
diff --git a/src/test/ui/entry-point/imported_main_from_extern_crate.stderr b/src/test/ui/entry-point/imported_main_from_extern_crate.stderr
new file mode 100644
index 00000000000..8792e1e4142
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_from_extern_crate.stderr
@@ -0,0 +1,10 @@
+error: entry symbol `main` from foreign crate is not yet supported.
+  --> $DIR/imported_main_from_extern_crate.rs:7:9
+   |
+LL | pub use main_functions::boilerplate as main;
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #28937 <https://github.com/rust-lang/rust/issues/28937> for more information
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/entry-point/imported_main_from_inner_mod.rs b/src/test/ui/entry-point/imported_main_from_inner_mod.rs
new file mode 100644
index 00000000000..45750072a7f
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_from_inner_mod.rs
@@ -0,0 +1,9 @@
+// run-pass
+#![feature(imported_main)]
+
+pub mod foo {
+    pub fn bar() {
+        println!("Hello world!");
+    }
+}
+use foo::bar as main;
diff --git a/src/test/ui/entry-point/imported_main_unused_not_trigger_feature_gate.rs b/src/test/ui/entry-point/imported_main_unused_not_trigger_feature_gate.rs
new file mode 100644
index 00000000000..4762fbb7c59
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_unused_not_trigger_feature_gate.rs
@@ -0,0 +1,11 @@
+// check-pass
+#![feature(rustc_attrs)]
+
+#[rustc_main]
+fn actual_main() {}
+
+mod foo {
+    pub(crate) fn something() {}
+}
+
+use foo::something as main;
diff --git a/src/test/ui/feature-gates/feature-gate-imported_main.rs b/src/test/ui/feature-gates/feature-gate-imported_main.rs
new file mode 100644
index 00000000000..b351d0d0e9a
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-imported_main.rs
@@ -0,0 +1,6 @@
+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/src/test/ui/feature-gates/feature-gate-imported_main.stderr b/src/test/ui/feature-gates/feature-gate-imported_main.stderr
new file mode 100644
index 00000000000..3b879fdfc6b
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-imported_main.stderr
@@ -0,0 +1,12 @@
+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
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs b/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs
index a59cacb8bde..039878af56e 100644
--- a/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs
+++ b/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs
@@ -3,6 +3,5 @@
 // Test that using a macro to replace the entire crate tree with a non-'mod' item errors out nicely.
 // `issue_59191::no_main` replaces whatever's passed in with `fn main() {}`.
 #![feature(custom_inner_attributes)]
-//~^ ERROR `main` function not found in crate `issue_59191_replace_root_with_fn` [E0601]
 #![issue_59191::no_main]
 //~^ ERROR expected crate top-level item to be a module after macro expansion, found a function
diff --git a/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr b/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr
index 5995a4891f3..579041c5259 100644
--- a/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr
+++ b/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr
@@ -1,19 +1,10 @@
 error: expected crate top-level item to be a module after macro expansion, found a function
-  --> $DIR/issue-59191-replace-root-with-fn.rs:7:1
+  --> $DIR/issue-59191-replace-root-with-fn.rs:6:1
    |
 LL | #![issue_59191::no_main]
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error[E0601]: `main` function not found in crate `issue_59191_replace_root_with_fn`
-  --> $DIR/issue-59191-replace-root-with-fn.rs:5:1
-   |
-LL | / #![feature(custom_inner_attributes)]
-LL | |
-LL | | #![issue_59191::no_main]
-   | |________________________^ consider adding a `main` function to `$DIR/issue-59191-replace-root-with-fn.rs`
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0601`.
diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs
index cd85c487798..e81a92eb74c 100644
--- a/src/tools/clippy/clippy_utils/src/lib.rs
+++ b/src/tools/clippy/clippy_utils/src/lib.rs
@@ -678,7 +678,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option<Vec
 pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool {
     cx.tcx
         .entry_fn(LOCAL_CRATE)
-        .map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id.to_def_id())
+        .map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id)
 }
 
 /// Returns `true` if the expression is in the program's `#[panic_handler]`.