]> git.lizzy.rs Git - rust.git/commitdiff
Add tests.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Sat, 25 Mar 2017 02:37:55 +0000 (02:37 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 25 May 2017 05:52:12 +0000 (05:52 +0000)
15 files changed:
src/test/compile-fail/feature-gate-decl_macro.rs [new file with mode: 0644]
src/test/compile-fail/hygiene/globs.rs [new file with mode: 0644]
src/test/compile-fail/hygiene/nested_macro_privacy.rs [new file with mode: 0644]
src/test/compile-fail/hygiene/no_implicit_prelude.rs [new file with mode: 0644]
src/test/compile-fail/hygiene/privacy.rs [new file with mode: 0644]
src/test/compile-fail/hygiene/trait_items.rs [new file with mode: 0644]
src/test/run-pass/hygiene/arguments.rs [new file with mode: 0644]
src/test/run-pass/hygiene/auxiliary/intercrate.rs [new file with mode: 0644]
src/test/run-pass/hygiene/fields.rs [new file with mode: 0644]
src/test/run-pass/hygiene/impl_items.rs [new file with mode: 0644]
src/test/run-pass/hygiene/intercrate.rs [new file with mode: 0644]
src/test/run-pass/hygiene/items.rs [new file with mode: 0644]
src/test/run-pass/hygiene/lexical.rs [new file with mode: 0644]
src/test/run-pass/hygiene/trait_items.rs [new file with mode: 0644]
src/test/run-pass/hygiene/ty_params.rs [new file with mode: 0644]

diff --git a/src/test/compile-fail/feature-gate-decl_macro.rs b/src/test/compile-fail/feature-gate-decl_macro.rs
new file mode 100644 (file)
index 0000000..af7d5fe
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+macro m() {} //~ ERROR `macro` is experimental (see issue #39412)
+//~| HELP add #![feature(decl_macro)] to the crate attributes to enable
+
+fn main() {}
diff --git a/src/test/compile-fail/hygiene/globs.rs b/src/test/compile-fail/hygiene/globs.rs
new file mode 100644 (file)
index 0000000..7ba2170
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+mod foo {
+    pub fn f() {}
+}
+
+mod bar {
+    pub fn g() {}
+}
+
+macro m($($t:tt)*) {
+    $($t)*
+    use foo::*;
+    f();
+    g(); //~ ERROR cannot find function `g` in this scope
+}
+
+fn main() {
+    m! {
+        use bar::*;
+        g();
+        f(); //~ ERROR cannot find function `f` in this scope
+    }
+}
+
+n!(f);
+macro n($i:ident) {
+    mod foo {
+        pub fn $i() -> u32 { 0 }
+        pub fn f() {}
+
+        mod test {
+            use super::*;
+            fn g() {
+                let _: u32 = $i();
+                let _: () = f();
+            }
+        }
+
+        macro n($j:ident) {
+            mod test {
+                use super::*;
+                fn g() {
+                    let _: u32 = $i();
+                    let _: () = f();
+                    $j();
+                }
+            }
+        }
+
+        n!(f);
+        mod test2 {
+            super::n! {
+                f //~ ERROR cannot find function `f` in this scope
+            }
+        }
+    }
+}
diff --git a/src/test/compile-fail/hygiene/nested_macro_privacy.rs b/src/test/compile-fail/hygiene/nested_macro_privacy.rs
new file mode 100644 (file)
index 0000000..6612359
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+macro n($foo:ident, $S:ident, $i:ident, $m:ident) {
+    mod $foo {
+        #[derive(Default)]
+        pub struct $S { $i: u32 }
+        pub macro $m($e:expr) { $e.$i }
+    }
+}
+
+n!(foo, S, i, m);
+
+fn main() {
+    use foo::{S, m};
+    S::default().i; //~ ERROR field `i` of struct `foo::S` is private
+    m!(S::default()); // ok
+}
diff --git a/src/test/compile-fail/hygiene/no_implicit_prelude.rs b/src/test/compile-fail/hygiene/no_implicit_prelude.rs
new file mode 100644 (file)
index 0000000..c90c7b3
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+mod foo {
+    pub macro m() { Vec::new(); ().clone() }
+    fn f() { ::bar::m!(); }
+}
+
+#[no_implicit_prelude]
+mod bar {
+    pub macro m() {
+        Vec::new(); //~ ERROR failed to resolve
+        ().clone() //~ ERROR no method named `clone` found
+    }
+    fn f() { ::foo::m!(); }
+}
diff --git a/src/test/compile-fail/hygiene/privacy.rs b/src/test/compile-fail/hygiene/privacy.rs
new file mode 100644 (file)
index 0000000..987cad1
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+mod foo {
+    fn f() {}
+
+    pub macro m($e:expr) {
+        f();
+        self::f();
+        ::foo::f();
+        $e
+    }
+}
+
+fn main() {
+    foo::m!(
+        foo::f() //~ ERROR `f` is private
+    );
+}
diff --git a/src/test/compile-fail/hygiene/trait_items.rs b/src/test/compile-fail/hygiene/trait_items.rs
new file mode 100644 (file)
index 0000000..3bd19cb
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+mod foo {
+    pub trait T {
+        fn f(&self) {}
+    }
+    impl T for () {}
+}
+
+mod bar {
+    use foo::*;
+    pub macro m() { ().f() }
+    fn f() { ::baz::m!(); }
+}
+
+mod baz {
+    pub macro m() { ().f() } //~ ERROR no method named `f` found for type `()` in the current scope
+    fn f() { ::bar::m!(); }
+}
+
+fn main() {}
diff --git a/src/test/run-pass/hygiene/arguments.rs b/src/test/run-pass/hygiene/arguments.rs
new file mode 100644 (file)
index 0000000..19fd08c
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+macro m($t:ty, $e:expr) {
+    mod foo {
+        #[allow(unused)]
+        struct S;
+        pub(super) fn f(_: $t) {}
+    }
+    foo::f($e);
+}
+
+fn main() {
+    struct S;
+    m!(S, S);
+}
diff --git a/src/test/run-pass/hygiene/auxiliary/intercrate.rs b/src/test/run-pass/hygiene/auxiliary/intercrate.rs
new file mode 100644 (file)
index 0000000..aa67e5c
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+pub mod foo {
+    pub use self::bar::m;
+    mod bar {
+        fn f() -> u32 { 1 }
+        pub macro m() {
+            f();
+        }
+    }
+}
diff --git a/src/test/run-pass/hygiene/fields.rs b/src/test/run-pass/hygiene/fields.rs
new file mode 100644 (file)
index 0000000..6768753
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+mod foo {
+    struct S { x: u32 }
+    struct T(u32);
+
+    pub macro m($S:ident, $x:ident) {{
+        struct $S {
+            $x: u32,
+            x: i32,
+        }
+
+        let s = S { x: 0 };
+        let _ = s.x;
+
+        let t = T(0);
+        let _ = t.0;
+
+        let s = $S { $x: 0, x: 1 };
+        assert_eq!((s.$x, s.x), (0, 1));
+        s
+    }}
+}
+
+fn main() {
+    let s = foo::m!(S, x);
+    assert_eq!(s.x, 0);
+}
diff --git a/src/test/run-pass/hygiene/impl_items.rs b/src/test/run-pass/hygiene/impl_items.rs
new file mode 100644 (file)
index 0000000..01b8e22
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+mod foo {
+    struct S;
+    impl S {
+        fn f(&self) {}
+    }
+
+    pub macro m() {
+        let _: () = S.f();
+    }
+}
+
+struct S;
+
+macro m($f:ident) {
+    impl S {
+        fn f(&self) -> u32 { 0 }
+        fn $f(&self) -> i32 { 0 }
+    }
+    fn f() {
+        let _: u32 = S.f();
+        let _: i32 = S.$f();
+    }
+}
+
+m!(f);
+
+fn main() {
+    let _: i32 = S.f();
+    foo::m!();
+}
diff --git a/src/test/run-pass/hygiene/intercrate.rs b/src/test/run-pass/hygiene/intercrate.rs
new file mode 100644 (file)
index 0000000..6550b64
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:intercrate.rs
+
+#![feature(decl_macro)]
+
+extern crate intercrate;
+
+fn main() {
+    assert_eq!(intercrate::foo::m!(), 1);
+}
diff --git a/src/test/run-pass/hygiene/items.rs b/src/test/run-pass/hygiene/items.rs
new file mode 100644 (file)
index 0000000..1fc51ee
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+pub macro m($foo:ident, $f:ident, $e:expr) {
+    mod foo {
+        pub fn f() -> u32 { 0 }
+        pub fn $f() -> u64 { 0 }
+    }
+
+    mod $foo {
+        pub fn f() -> i32 { 0 }
+        pub fn $f() -> i64 { 0  }
+    }
+
+    let _: u32 = foo::f();
+    let _: u64 = foo::$f();
+    let _: i32 = $foo::f();
+    let _: i64 = $foo::$f();
+    let _: i64 = $e;
+}
+
+fn main() {
+    m!(foo, f, foo::f());
+    let _: i64 = foo::f();
+}
diff --git a/src/test/run-pass/hygiene/lexical.rs b/src/test/run-pass/hygiene/lexical.rs
new file mode 100644 (file)
index 0000000..4068391
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+mod bar {
+    mod baz {
+        pub fn f() {}
+    }
+
+    pub macro m($f:ident) {
+        baz::f();
+        let _: i32 = $f();
+        {
+            fn $f() -> u32 { 0 }
+            let _: u32 = $f();
+        }
+    }
+}
+
+fn main() {
+    fn f() -> i32 { 0 }
+    bar::m!(f);
+}
diff --git a/src/test/run-pass/hygiene/trait_items.rs b/src/test/run-pass/hygiene/trait_items.rs
new file mode 100644 (file)
index 0000000..ed57d6d
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+macro m($T:ident, $f:ident) {
+    pub trait $T {
+        fn f(&self) -> u32 { 0 }
+        fn $f(&self) -> i32 { 0 }
+    }
+    impl $T for () {}
+
+    let _: u32 = ().f();
+    let _: i32 = ().$f();
+}
+
+fn main() {
+    m!(T, f);
+    let _: i32 = ().f();
+}
diff --git a/src/test/run-pass/hygiene/ty_params.rs b/src/test/run-pass/hygiene/ty_params.rs
new file mode 100644 (file)
index 0000000..f41c365
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(decl_macro)]
+
+macro m($T:ident) {
+    fn f<T, $T>(t: T, t2: $T) -> (T, $T) {
+        (t, t2)
+    }
+}
+
+m!(T);
+
+fn main() {}