summaryrefslogtreecommitdiffstats
path: root/tests/ui/modules
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/modules')
-rw-r--r--tests/ui/modules/auxiliary/dummy_lib.rs2
-rw-r--r--tests/ui/modules/auxiliary/two_macros_2.rs3
-rw-r--r--tests/ui/modules/issue-56411-aux.rs5
-rw-r--r--tests/ui/modules/issue-56411.rs18
-rw-r--r--tests/ui/modules/issue-56411.stderr33
-rw-r--r--tests/ui/modules/mod-inside-fn.rs13
-rw-r--r--tests/ui/modules/mod-view-items.rs14
-rw-r--r--tests/ui/modules/mod_dir_implicit.rs8
-rw-r--r--tests/ui/modules/mod_dir_implicit_aux/compiletest-ignore-dir0
-rw-r--r--tests/ui/modules/mod_dir_implicit_aux/mod.rs2
-rw-r--r--tests/ui/modules/mod_dir_path.rs23
-rw-r--r--tests/ui/modules/mod_dir_path2.rs12
-rw-r--r--tests/ui/modules/mod_dir_path3.rs11
-rw-r--r--tests/ui/modules/mod_dir_path_multi.rs17
-rw-r--r--tests/ui/modules/mod_dir_recursive.rs14
-rw-r--r--tests/ui/modules/mod_dir_simple.rs10
-rw-r--r--tests/ui/modules/mod_dir_simple/compiletest-ignore-dir0
-rw-r--r--tests/ui/modules/mod_dir_simple/load_another_mod.rs3
-rw-r--r--tests/ui/modules/mod_dir_simple/test.rs2
-rw-r--r--tests/ui/modules/mod_file.rs10
-rw-r--r--tests/ui/modules/mod_file_aux.rs4
-rw-r--r--tests/ui/modules/mod_file_with_path_attr.rs11
-rw-r--r--tests/ui/modules/module-polymorphism3-files/compiletest-ignore-dir0
-rw-r--r--tests/ui/modules/module-polymorphism3-files/float-template/inst_f32.rs3
-rw-r--r--tests/ui/modules/module-polymorphism3-files/float-template/inst_f64.rs3
-rw-r--r--tests/ui/modules/module-polymorphism3-files/float-template/inst_float.rs3
-rw-r--r--tests/ui/modules/path-invalid-form.rs4
-rw-r--r--tests/ui/modules/path-invalid-form.stderr8
-rw-r--r--tests/ui/modules/path-macro.rs8
-rw-r--r--tests/ui/modules/path-macro.stderr8
-rw-r--r--tests/ui/modules/path-no-file-name.rs7
-rw-r--r--tests/ui/modules/path-no-file-name.stderr8
-rw-r--r--tests/ui/modules/special_module_name.rs8
-rw-r--r--tests/ui/modules/special_module_name.stderr37
-rw-r--r--tests/ui/modules/special_module_name_ignore.rs9
35 files changed, 321 insertions, 0 deletions
diff --git a/tests/ui/modules/auxiliary/dummy_lib.rs b/tests/ui/modules/auxiliary/dummy_lib.rs
new file mode 100644
index 000000000..ef805c1f0
--- /dev/null
+++ b/tests/ui/modules/auxiliary/dummy_lib.rs
@@ -0,0 +1,2 @@
+#[allow(dead_code)]
+pub struct Dummy;
diff --git a/tests/ui/modules/auxiliary/two_macros_2.rs b/tests/ui/modules/auxiliary/two_macros_2.rs
new file mode 100644
index 000000000..8ad2c0f12
--- /dev/null
+++ b/tests/ui/modules/auxiliary/two_macros_2.rs
@@ -0,0 +1,3 @@
+macro_rules! macro_one { ($($t:tt)*) => ($($t)*) }
+
+macro_rules! macro_two { ($($t:tt)*) => ($($t)*) }
diff --git a/tests/ui/modules/issue-56411-aux.rs b/tests/ui/modules/issue-56411-aux.rs
new file mode 100644
index 000000000..c8e5a0598
--- /dev/null
+++ b/tests/ui/modules/issue-56411-aux.rs
@@ -0,0 +1,5 @@
+// check-pass
+
+struct T {}
+
+fn main() {}
diff --git a/tests/ui/modules/issue-56411.rs b/tests/ui/modules/issue-56411.rs
new file mode 100644
index 000000000..0a20f5fe9
--- /dev/null
+++ b/tests/ui/modules/issue-56411.rs
@@ -0,0 +1,18 @@
+macro_rules! import {
+ ( $(($path:expr, $name:ident)),* ) => {
+ $(
+ #[path = $path]
+ mod $name;
+ pub use self::$name;
+ //~^ ERROR the name `issue_56411_aux` is defined multiple times
+ //~| ERROR `issue_56411_aux` is only public within the crate, and cannot be re-exported outside
+
+ )*
+ }
+}
+
+import!(("issue-56411-aux.rs", issue_56411_aux));
+
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/tests/ui/modules/issue-56411.stderr b/tests/ui/modules/issue-56411.stderr
new file mode 100644
index 000000000..6732a8a3d
--- /dev/null
+++ b/tests/ui/modules/issue-56411.stderr
@@ -0,0 +1,33 @@
+error[E0255]: the name `issue_56411_aux` is defined multiple times
+ --> $DIR/issue-56411.rs:6:21
+ |
+LL | mod $name;
+ | ---------- previous definition of the module `issue_56411_aux` here
+LL | pub use self::$name;
+ | ^^^^^^^^^^^
+ | |
+ | `issue_56411_aux` reimported here
+ | you can use `as` to change the binding name of the import
+...
+LL | import!(("issue-56411-aux.rs", issue_56411_aux));
+ | ------------------------------------------------ in this macro invocation
+ |
+ = note: `issue_56411_aux` must be defined only once in the type namespace of this module
+ = note: this error originates in the macro `import` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0365]: `issue_56411_aux` is only public within the crate, and cannot be re-exported outside
+ --> $DIR/issue-56411.rs:6:21
+ |
+LL | pub use self::$name;
+ | ^^^^^^^^^^^ re-export of crate public `issue_56411_aux`
+...
+LL | import!(("issue-56411-aux.rs", issue_56411_aux));
+ | ------------------------------------------------ in this macro invocation
+ |
+ = note: consider declaring type or module `issue_56411_aux` with `pub`
+ = note: this error originates in the macro `import` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0255, E0365.
+For more information about an error, try `rustc --explain E0255`.
diff --git a/tests/ui/modules/mod-inside-fn.rs b/tests/ui/modules/mod-inside-fn.rs
new file mode 100644
index 000000000..93050c891
--- /dev/null
+++ b/tests/ui/modules/mod-inside-fn.rs
@@ -0,0 +1,13 @@
+// run-pass
+
+fn f() -> isize {
+ mod m {
+ pub fn g() -> isize { 720 }
+ }
+
+ m::g()
+}
+
+pub fn main() {
+ assert_eq!(f(), 720);
+}
diff --git a/tests/ui/modules/mod-view-items.rs b/tests/ui/modules/mod-view-items.rs
new file mode 100644
index 000000000..db2b30366
--- /dev/null
+++ b/tests/ui/modules/mod-view-items.rs
@@ -0,0 +1,14 @@
+// run-pass
+// Test view items inside non-file-level mods
+
+// This is a regression test for an issue where we were failing to
+// pretty-print such view items. If that happens again, this should
+// begin failing.
+
+// pretty-expanded FIXME #23616
+
+mod m {
+ pub fn f() -> Vec<isize> { Vec::new() }
+}
+
+pub fn main() { let _x = m::f(); }
diff --git a/tests/ui/modules/mod_dir_implicit.rs b/tests/ui/modules/mod_dir_implicit.rs
new file mode 100644
index 000000000..d6ea6a98b
--- /dev/null
+++ b/tests/ui/modules/mod_dir_implicit.rs
@@ -0,0 +1,8 @@
+// run-pass
+// ignore-pretty issue #37195
+
+mod mod_dir_implicit_aux;
+
+pub fn main() {
+ assert_eq!(mod_dir_implicit_aux::foo(), 10);
+}
diff --git a/tests/ui/modules/mod_dir_implicit_aux/compiletest-ignore-dir b/tests/ui/modules/mod_dir_implicit_aux/compiletest-ignore-dir
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/ui/modules/mod_dir_implicit_aux/compiletest-ignore-dir
diff --git a/tests/ui/modules/mod_dir_implicit_aux/mod.rs b/tests/ui/modules/mod_dir_implicit_aux/mod.rs
new file mode 100644
index 000000000..4f1eb85e4
--- /dev/null
+++ b/tests/ui/modules/mod_dir_implicit_aux/mod.rs
@@ -0,0 +1,2 @@
+// run-pass
+pub fn foo() -> isize { 10 }
diff --git a/tests/ui/modules/mod_dir_path.rs b/tests/ui/modules/mod_dir_path.rs
new file mode 100644
index 000000000..70f592d0c
--- /dev/null
+++ b/tests/ui/modules/mod_dir_path.rs
@@ -0,0 +1,23 @@
+// run-pass
+#![allow(unused_macros)]
+// ignore-pretty issue #37195
+
+mod mod_dir_simple {
+ #[path = "test.rs"]
+ pub mod syrup;
+}
+
+pub fn main() {
+ assert_eq!(mod_dir_simple::syrup::foo(), 10);
+
+ #[path = "auxiliary"]
+ mod foo {
+ mod two_macros_2;
+ }
+
+ #[path = "auxiliary"]
+ mod bar {
+ macro_rules! m { () => { mod two_macros_2; } }
+ m!();
+ }
+}
diff --git a/tests/ui/modules/mod_dir_path2.rs b/tests/ui/modules/mod_dir_path2.rs
new file mode 100644
index 000000000..c3e3e1d63
--- /dev/null
+++ b/tests/ui/modules/mod_dir_path2.rs
@@ -0,0 +1,12 @@
+// run-pass
+// ignore-pretty issue #37195
+
+#[path = "mod_dir_simple"]
+mod pancakes {
+ #[path = "test.rs"]
+ pub mod syrup;
+}
+
+pub fn main() {
+ assert_eq!(pancakes::syrup::foo(), 10);
+}
diff --git a/tests/ui/modules/mod_dir_path3.rs b/tests/ui/modules/mod_dir_path3.rs
new file mode 100644
index 000000000..fed70c1bc
--- /dev/null
+++ b/tests/ui/modules/mod_dir_path3.rs
@@ -0,0 +1,11 @@
+// run-pass
+// ignore-pretty issue #37195
+
+#[path = "mod_dir_simple"]
+mod pancakes {
+ pub mod test;
+}
+
+pub fn main() {
+ assert_eq!(pancakes::test::foo(), 10);
+}
diff --git a/tests/ui/modules/mod_dir_path_multi.rs b/tests/ui/modules/mod_dir_path_multi.rs
new file mode 100644
index 000000000..2b805141a
--- /dev/null
+++ b/tests/ui/modules/mod_dir_path_multi.rs
@@ -0,0 +1,17 @@
+// run-pass
+// ignore-pretty issue #37195
+
+#[path = "mod_dir_simple"]
+mod biscuits {
+ pub mod test;
+}
+
+#[path = "mod_dir_simple"]
+mod gravy {
+ pub mod test;
+}
+
+pub fn main() {
+ assert_eq!(biscuits::test::foo(), 10);
+ assert_eq!(gravy::test::foo(), 10);
+}
diff --git a/tests/ui/modules/mod_dir_recursive.rs b/tests/ui/modules/mod_dir_recursive.rs
new file mode 100644
index 000000000..b109d13d1
--- /dev/null
+++ b/tests/ui/modules/mod_dir_recursive.rs
@@ -0,0 +1,14 @@
+// run-pass
+// ignore-pretty issue #37195
+
+// Testing that the parser for each file tracks its modules
+// and paths independently. The load_another_mod module should
+// not try to reuse the 'mod_dir_simple' path.
+
+mod mod_dir_simple {
+ pub mod load_another_mod;
+}
+
+pub fn main() {
+ assert_eq!(mod_dir_simple::load_another_mod::test::foo(), 10);
+}
diff --git a/tests/ui/modules/mod_dir_simple.rs b/tests/ui/modules/mod_dir_simple.rs
new file mode 100644
index 000000000..1d92c968a
--- /dev/null
+++ b/tests/ui/modules/mod_dir_simple.rs
@@ -0,0 +1,10 @@
+// run-pass
+// ignore-pretty issue #37195
+
+mod mod_dir_simple {
+ pub mod test;
+}
+
+pub fn main() {
+ assert_eq!(mod_dir_simple::test::foo(), 10);
+}
diff --git a/tests/ui/modules/mod_dir_simple/compiletest-ignore-dir b/tests/ui/modules/mod_dir_simple/compiletest-ignore-dir
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/ui/modules/mod_dir_simple/compiletest-ignore-dir
diff --git a/tests/ui/modules/mod_dir_simple/load_another_mod.rs b/tests/ui/modules/mod_dir_simple/load_another_mod.rs
new file mode 100644
index 000000000..f96b546aa
--- /dev/null
+++ b/tests/ui/modules/mod_dir_simple/load_another_mod.rs
@@ -0,0 +1,3 @@
+// run-pass
+#[path = "test.rs"]
+pub mod test;
diff --git a/tests/ui/modules/mod_dir_simple/test.rs b/tests/ui/modules/mod_dir_simple/test.rs
new file mode 100644
index 000000000..4f1eb85e4
--- /dev/null
+++ b/tests/ui/modules/mod_dir_simple/test.rs
@@ -0,0 +1,2 @@
+// run-pass
+pub fn foo() -> isize { 10 }
diff --git a/tests/ui/modules/mod_file.rs b/tests/ui/modules/mod_file.rs
new file mode 100644
index 000000000..0ca52889e
--- /dev/null
+++ b/tests/ui/modules/mod_file.rs
@@ -0,0 +1,10 @@
+// run-pass
+// ignore-pretty issue #37195
+
+// Testing that a plain .rs file can load modules from other source files
+
+mod mod_file_aux;
+
+pub fn main() {
+ assert_eq!(mod_file_aux::foo(), 10);
+}
diff --git a/tests/ui/modules/mod_file_aux.rs b/tests/ui/modules/mod_file_aux.rs
new file mode 100644
index 000000000..6d052272e
--- /dev/null
+++ b/tests/ui/modules/mod_file_aux.rs
@@ -0,0 +1,4 @@
+// run-pass
+// ignore-test Not a test. Used by other tests
+
+pub fn foo() -> isize { 10 }
diff --git a/tests/ui/modules/mod_file_with_path_attr.rs b/tests/ui/modules/mod_file_with_path_attr.rs
new file mode 100644
index 000000000..48e253ead
--- /dev/null
+++ b/tests/ui/modules/mod_file_with_path_attr.rs
@@ -0,0 +1,11 @@
+// run-pass
+// ignore-pretty issue #37195
+
+// Testing that a plain .rs file can load modules from other source files
+
+#[path = "mod_file_aux.rs"]
+mod m;
+
+pub fn main() {
+ assert_eq!(m::foo(), 10);
+}
diff --git a/tests/ui/modules/module-polymorphism3-files/compiletest-ignore-dir b/tests/ui/modules/module-polymorphism3-files/compiletest-ignore-dir
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/ui/modules/module-polymorphism3-files/compiletest-ignore-dir
diff --git a/tests/ui/modules/module-polymorphism3-files/float-template/inst_f32.rs b/tests/ui/modules/module-polymorphism3-files/float-template/inst_f32.rs
new file mode 100644
index 000000000..49d2b3d4b
--- /dev/null
+++ b/tests/ui/modules/module-polymorphism3-files/float-template/inst_f32.rs
@@ -0,0 +1,3 @@
+// run-pass
+
+pub type T = f32;
diff --git a/tests/ui/modules/module-polymorphism3-files/float-template/inst_f64.rs b/tests/ui/modules/module-polymorphism3-files/float-template/inst_f64.rs
new file mode 100644
index 000000000..e2aad480e
--- /dev/null
+++ b/tests/ui/modules/module-polymorphism3-files/float-template/inst_f64.rs
@@ -0,0 +1,3 @@
+// run-pass
+
+pub type T = f64;
diff --git a/tests/ui/modules/module-polymorphism3-files/float-template/inst_float.rs b/tests/ui/modules/module-polymorphism3-files/float-template/inst_float.rs
new file mode 100644
index 000000000..5828718cd
--- /dev/null
+++ b/tests/ui/modules/module-polymorphism3-files/float-template/inst_float.rs
@@ -0,0 +1,3 @@
+// run-pass
+
+pub type T = float;
diff --git a/tests/ui/modules/path-invalid-form.rs b/tests/ui/modules/path-invalid-form.rs
new file mode 100644
index 000000000..713ef4a79
--- /dev/null
+++ b/tests/ui/modules/path-invalid-form.rs
@@ -0,0 +1,4 @@
+#[path = 123] //~ ERROR malformed `path` attribute
+mod foo;
+
+fn main() {}
diff --git a/tests/ui/modules/path-invalid-form.stderr b/tests/ui/modules/path-invalid-form.stderr
new file mode 100644
index 000000000..7e8aa44ef
--- /dev/null
+++ b/tests/ui/modules/path-invalid-form.stderr
@@ -0,0 +1,8 @@
+error: malformed `path` attribute input
+ --> $DIR/path-invalid-form.rs:1:1
+ |
+LL | #[path = 123]
+ | ^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/modules/path-macro.rs b/tests/ui/modules/path-macro.rs
new file mode 100644
index 000000000..ce2d1e2da
--- /dev/null
+++ b/tests/ui/modules/path-macro.rs
@@ -0,0 +1,8 @@
+macro_rules! foo {
+ () => {"bar.rs"};
+}
+
+#[path = foo!()] //~ ERROR malformed `path` attribute
+mod abc;
+
+fn main() {}
diff --git a/tests/ui/modules/path-macro.stderr b/tests/ui/modules/path-macro.stderr
new file mode 100644
index 000000000..9a2e01ea2
--- /dev/null
+++ b/tests/ui/modules/path-macro.stderr
@@ -0,0 +1,8 @@
+error: malformed `path` attribute input
+ --> $DIR/path-macro.rs:5:1
+ |
+LL | #[path = foo!()]
+ | ^^^^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/modules/path-no-file-name.rs b/tests/ui/modules/path-no-file-name.rs
new file mode 100644
index 000000000..f62cd2a9e
--- /dev/null
+++ b/tests/ui/modules/path-no-file-name.rs
@@ -0,0 +1,7 @@
+// normalize-stderr-test: "\.:.*\(" -> ".: $$ACCESS_DENIED_MSG ("
+// normalize-stderr-test: "os error \d+" -> "os error $$ACCESS_DENIED_CODE"
+
+#[path = "."]
+mod m; //~ ERROR couldn't read
+
+fn main() {}
diff --git a/tests/ui/modules/path-no-file-name.stderr b/tests/ui/modules/path-no-file-name.stderr
new file mode 100644
index 000000000..32a213c68
--- /dev/null
+++ b/tests/ui/modules/path-no-file-name.stderr
@@ -0,0 +1,8 @@
+error: couldn't read $DIR/.: $ACCESS_DENIED_MSG (os error $ACCESS_DENIED_CODE)
+ --> $DIR/path-no-file-name.rs:5:1
+ |
+LL | mod m;
+ | ^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/modules/special_module_name.rs b/tests/ui/modules/special_module_name.rs
new file mode 100644
index 000000000..15c59b2da
--- /dev/null
+++ b/tests/ui/modules/special_module_name.rs
@@ -0,0 +1,8 @@
+mod lib;
+//~^ WARN found module declaration for lib.rs
+//~| ERROR file not found for module `lib`
+mod main;
+//~^ WARN found module declaration for main.rs
+//~| ERROR file not found for module `main`
+
+fn main() {}
diff --git a/tests/ui/modules/special_module_name.stderr b/tests/ui/modules/special_module_name.stderr
new file mode 100644
index 000000000..bc4b4f1b3
--- /dev/null
+++ b/tests/ui/modules/special_module_name.stderr
@@ -0,0 +1,37 @@
+error[E0583]: file not found for module `lib`
+ --> $DIR/special_module_name.rs:1:1
+ |
+LL | mod lib;
+ | ^^^^^^^^
+ |
+ = help: to create the module `lib`, create file "$DIR/lib.rs" or "$DIR/lib/mod.rs"
+
+error[E0583]: file not found for module `main`
+ --> $DIR/special_module_name.rs:4:1
+ |
+LL | mod main;
+ | ^^^^^^^^^
+ |
+ = help: to create the module `main`, create file "$DIR/main.rs" or "$DIR/main/mod.rs"
+
+warning: found module declaration for lib.rs
+ --> $DIR/special_module_name.rs:1:1
+ |
+LL | mod lib;
+ | ^^^^^^^^
+ |
+ = note: lib.rs is the root of this crate's library target
+ = help: to refer to it from other targets, use the library's name as the path
+ = note: `#[warn(special_module_name)]` on by default
+
+warning: found module declaration for main.rs
+ --> $DIR/special_module_name.rs:4:1
+ |
+LL | mod main;
+ | ^^^^^^^^^
+ |
+ = note: a binary crate cannot be used as library
+
+error: aborting due to 2 previous errors; 2 warnings emitted
+
+For more information about this error, try `rustc --explain E0583`.
diff --git a/tests/ui/modules/special_module_name_ignore.rs b/tests/ui/modules/special_module_name_ignore.rs
new file mode 100644
index 000000000..07cea9b2b
--- /dev/null
+++ b/tests/ui/modules/special_module_name_ignore.rs
@@ -0,0 +1,9 @@
+// run-pass
+
+#[path = "auxiliary/dummy_lib.rs"]
+mod lib;
+
+#[path = "auxiliary/dummy_lib.rs"]
+mod main;
+
+fn main() {}