summaryrefslogtreecommitdiffstats
path: root/src/test/ui/entry-point
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/entry-point
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/entry-point')
-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.stderr19
-rw-r--r--src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs11
-rw-r--r--src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr11
-rw-r--r--src/test/ui/entry-point/imported_main_const_forbidden.rs6
-rw-r--r--src/test/ui/entry-point/imported_main_const_forbidden.stderr11
-rw-r--r--src/test/ui/entry-point/imported_main_from_extern_crate.rs7
-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
10 files changed, 93 insertions, 0 deletions
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 000000000..cc7992a42
--- /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 000000000..e8c70b065
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_conflict.rs
@@ -0,0 +1,7 @@
+#![feature(imported_main)]
+//~^ ERROR `main` is ambiguous
+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 000000000..8fadd0e19
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_conflict.stderr
@@ -0,0 +1,19 @@
+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
+ |
+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 000000000..405d6e2a9
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs
@@ -0,0 +1,11 @@
+#![feature(imported_main)]
+#![feature(type_alias_impl_trait)]
+#![allow(incomplete_features)]
+pub mod foo {
+ type MainFn = impl Fn();
+
+ fn bar() {}
+ pub const BAR: MainFn = bar;
+}
+
+use foo::BAR as main; //~ ERROR `main` function not found in crate
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 000000000..fabb6ffb0
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr
@@ -0,0 +1,11 @@
+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
+ |
+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 000000000..1508280c0
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_const_forbidden.rs
@@ -0,0 +1,6 @@
+#![feature(imported_main)]
+pub mod foo {
+ pub const BAR: usize = 42;
+}
+
+use foo::BAR as main; //~ ERROR `main` function not found in crate
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 000000000..9d8b40dc3
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_const_forbidden.stderr
@@ -0,0 +1,11 @@
+error[E0601]: `main` function not found in crate `imported_main_const_forbidden`
+ --> $DIR/imported_main_const_forbidden.rs:6:22
+ |
+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 000000000..4fddfc44a
--- /dev/null
+++ b/src/test/ui/entry-point/imported_main_from_extern_crate.rs
@@ -0,0 +1,7 @@
+// run-pass
+// aux-build:main_functions.rs
+
+#![feature(imported_main)]
+
+extern crate main_functions;
+pub use main_functions::boilerplate as main;
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 000000000..45750072a
--- /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 000000000..4762fbb7c
--- /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;