about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-06-24 19:54:23 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-06-30 01:53:32 +0300
commit99ecdb3f5fc49efb3eccdd10fbe12dc98623a938 (patch)
tree7c82e4221bf6f94e44ca58399c873b2b9eb29a25 /src/test
parent09856c85b73feff1db93990cd3d80f2c585b40c4 (diff)
downloadrust-99ecdb3f5fc49efb3eccdd10fbe12dc98623a938.tar.gz
rust-99ecdb3f5fc49efb3eccdd10fbe12dc98623a938.zip
hygiene: Implement transparent marks
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/hygiene/auxiliary/intercrate.rs6
-rw-r--r--src/test/ui/hygiene/auxiliary/transparent-basic.rs16
-rw-r--r--src/test/ui/hygiene/dollar-crate-modern.rs22
-rw-r--r--src/test/ui/hygiene/generate-mod.rs24
-rw-r--r--src/test/ui/hygiene/generate-mod.stderr17
-rw-r--r--src/test/ui/hygiene/transparent-basic.rs53
6 files changed, 138 insertions, 0 deletions
diff --git a/src/test/ui/hygiene/auxiliary/intercrate.rs b/src/test/ui/hygiene/auxiliary/intercrate.rs
index aa67e5c5f4d..244a9903e31 100644
--- a/src/test/ui/hygiene/auxiliary/intercrate.rs
+++ b/src/test/ui/hygiene/auxiliary/intercrate.rs
@@ -19,3 +19,9 @@ pub mod foo {
         }
     }
 }
+
+pub struct SomeType;
+
+pub macro uses_dollar_crate() {
+    type Alias = $crate::SomeType;
+}
diff --git a/src/test/ui/hygiene/auxiliary/transparent-basic.rs b/src/test/ui/hygiene/auxiliary/transparent-basic.rs
new file mode 100644
index 00000000000..ba65c5f4da8
--- /dev/null
+++ b/src/test/ui/hygiene/auxiliary/transparent-basic.rs
@@ -0,0 +1,16 @@
+// Copyright 2018 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, rustc_attrs)]
+
+#[rustc_transparent_macro]
+pub macro dollar_crate() {
+    let s = $crate::S;
+}
diff --git a/src/test/ui/hygiene/dollar-crate-modern.rs b/src/test/ui/hygiene/dollar-crate-modern.rs
new file mode 100644
index 00000000000..f4b24d0c5b4
--- /dev/null
+++ b/src/test/ui/hygiene/dollar-crate-modern.rs
@@ -0,0 +1,22 @@
+// Copyright 2018 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.
+
+// Make sure `$crate` works in `macro` macros.
+
+// compile-pass
+// aux-build:intercrate.rs
+
+#![feature(use_extern_macros)]
+
+extern crate intercrate;
+
+intercrate::uses_dollar_crate!();
+
+fn main() {}
diff --git a/src/test/ui/hygiene/generate-mod.rs b/src/test/ui/hygiene/generate-mod.rs
new file mode 100644
index 00000000000..90409857dea
--- /dev/null
+++ b/src/test/ui/hygiene/generate-mod.rs
@@ -0,0 +1,24 @@
+// Copyright 2018 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.
+
+// This is an equivalent of issue #50504, but for declarative macros.
+
+#![feature(decl_macro, rustc_attrs)]
+
+#[rustc_transparent_macro]
+macro genmod() {
+    mod m {
+        type A = S; //~ ERROR cannot find type `S` in this scope
+    }
+}
+
+struct S;
+
+genmod!();
diff --git a/src/test/ui/hygiene/generate-mod.stderr b/src/test/ui/hygiene/generate-mod.stderr
new file mode 100644
index 00000000000..e79f8528c2c
--- /dev/null
+++ b/src/test/ui/hygiene/generate-mod.stderr
@@ -0,0 +1,17 @@
+error[E0412]: cannot find type `S` in this scope
+  --> $DIR/generate-mod.rs:18:18
+   |
+LL |         type A = S; //~ ERROR cannot find type `S` in this scope
+   |                  ^ did you mean `A`?
+...
+LL | genmod!();
+   | ---------- in this macro invocation
+
+error[E0601]: `main` function not found in crate `generate_mod`
+   |
+   = note: consider adding a `main` function to `$DIR/generate-mod.rs`
+
+error: aborting due to 2 previous errors
+
+Some errors occurred: E0412, E0601.
+For more information about an error, try `rustc --explain E0412`.
diff --git a/src/test/ui/hygiene/transparent-basic.rs b/src/test/ui/hygiene/transparent-basic.rs
new file mode 100644
index 00000000000..81ece1f11bc
--- /dev/null
+++ b/src/test/ui/hygiene/transparent-basic.rs
@@ -0,0 +1,53 @@
+// Copyright 2018 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.
+
+// compile-pass
+// aux-build:transparent-basic.rs
+
+#![feature(decl_macro, rustc_attrs)]
+
+extern crate transparent_basic;
+
+#[rustc_transparent_macro]
+macro binding() {
+    let x = 10;
+}
+
+#[rustc_transparent_macro]
+macro label() {
+    break 'label
+}
+
+macro_rules! legacy {
+    () => {
+        binding!();
+        let y = x;
+    }
+}
+
+fn legacy_interaction1() {
+    legacy!();
+}
+
+struct S;
+
+fn check_dollar_crate() {
+    // `$crate::S` inside the macro resolves to `S` from this crate.
+    transparent_basic::dollar_crate!();
+}
+
+fn main() {
+    binding!();
+    let y = x;
+
+    'label: loop {
+        label!();
+    }
+}