diff options
Diffstat (limited to 'tests/ui/entry-point')
10 files changed, 93 insertions, 0 deletions
diff --git a/tests/ui/entry-point/auxiliary/main_functions.rs b/tests/ui/entry-point/auxiliary/main_functions.rs new file mode 100644 index 000000000..cc7992a42 --- /dev/null +++ b/tests/ui/entry-point/auxiliary/main_functions.rs @@ -0,0 +1 @@ +pub fn boilerplate() {} diff --git a/tests/ui/entry-point/imported_main_conflict.rs b/tests/ui/entry-point/imported_main_conflict.rs new file mode 100644 index 000000000..e8c70b065 --- /dev/null +++ b/tests/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/tests/ui/entry-point/imported_main_conflict.stderr b/tests/ui/entry-point/imported_main_conflict.stderr new file mode 100644 index 000000000..8fadd0e19 --- /dev/null +++ b/tests/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/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 new file mode 100644 index 000000000..405d6e2a9 --- /dev/null +++ b/tests/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/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 new file mode 100644 index 000000000..fabb6ffb0 --- /dev/null +++ b/tests/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/tests/ui/entry-point/imported_main_const_forbidden.rs b/tests/ui/entry-point/imported_main_const_forbidden.rs new file mode 100644 index 000000000..1508280c0 --- /dev/null +++ b/tests/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/tests/ui/entry-point/imported_main_const_forbidden.stderr b/tests/ui/entry-point/imported_main_const_forbidden.stderr new file mode 100644 index 000000000..9d8b40dc3 --- /dev/null +++ b/tests/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/tests/ui/entry-point/imported_main_from_extern_crate.rs b/tests/ui/entry-point/imported_main_from_extern_crate.rs new file mode 100644 index 000000000..4fddfc44a --- /dev/null +++ b/tests/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/tests/ui/entry-point/imported_main_from_inner_mod.rs b/tests/ui/entry-point/imported_main_from_inner_mod.rs new file mode 100644 index 000000000..45750072a --- /dev/null +++ b/tests/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/tests/ui/entry-point/imported_main_unused_not_trigger_feature_gate.rs b/tests/ui/entry-point/imported_main_unused_not_trigger_feature_gate.rs new file mode 100644 index 000000000..4762fbb7c --- /dev/null +++ b/tests/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; |