about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-30 09:19:21 +0000
committerbors <bors@rust-lang.org>2018-06-30 09:19:21 +0000
commitbfc1ee4968ff5778cd80e12150f379ddfe6c2767 (patch)
tree1e61b5ce7879de8613a142ffd6c029f8866bf70a /src/test/ui
parentacf50b79beb5909c16861cc7c91e8226b7f78272 (diff)
parent84f1bc8b662da4ceb0e448bf0d24ce627e6a462b (diff)
Auto merge of #51762 - petrochenkov:oh-hi-mark, r=oli-obk
hygiene: Implement transparent marks and use them for call-site hygiene in proc-macros

Fixes https://github.com/rust-lang/rust/issues/50050
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/hygiene/auxiliary/intercrate.rs35
-rw-r--r--src/test/ui/hygiene/auxiliary/transparent-basic.rs16
-rw-r--r--src/test/ui/hygiene/dollar-crate-modern.rs35
-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, 180 insertions, 0 deletions
diff --git a/src/test/ui/hygiene/auxiliary/intercrate.rs b/src/test/ui/hygiene/auxiliary/intercrate.rs
index aa67e5c5f4d..f917fabbe0c 100644
--- a/src/test/ui/hygiene/auxiliary/intercrate.rs
+++ b/src/test/ui/hygiene/auxiliary/intercrate.rs
@@ -19,3 +19,38 @@ pub mod foo {
         }
     }
 }
+
+pub struct SomeType;
+
+// `$crate`
+pub macro uses_dollar_crate_modern() {
+    type Alias = $crate::SomeType;
+}
+
+pub macro define_uses_dollar_crate_modern_nested($uses_dollar_crate_modern_nested: ident) {
+    macro $uses_dollar_crate_modern_nested() {
+        type AliasCrateModernNested = $crate::SomeType;
+    }
+}
+
+#[macro_export]
+macro_rules! define_uses_dollar_crate_legacy_nested {
+    () => {
+        macro_rules! uses_dollar_crate_legacy_nested {
+            () => {
+                type AliasLegacyNested = $crate::SomeType;
+            }
+        }
+    }
+}
+
+// `crate`
+pub macro uses_crate_modern() {
+    type AliasCrate = crate::SomeType;
+}
+
+pub macro define_uses_crate_modern_nested($uses_crate_modern_nested: ident) {
+    macro $uses_crate_modern_nested() {
+        type AliasCrateModernNested = 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..6e536ab1422
--- /dev/null
+++ b/src/test/ui/hygiene/dollar-crate-modern.rs
@@ -0,0 +1,35 @@
+// 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` and `crate` work in for basic cases of nested macros.
+
+// compile-pass
+// aux-build:intercrate.rs
+
+#![feature(decl_macro, crate_in_paths)]
+
+extern crate intercrate;
+
+// `$crate`
+intercrate::uses_dollar_crate_modern!();
+
+intercrate::define_uses_dollar_crate_modern_nested!(uses_dollar_crate_modern_nested);
+uses_dollar_crate_modern_nested!();
+
+intercrate::define_uses_dollar_crate_legacy_nested!();
+uses_dollar_crate_legacy_nested!();
+
+// `crate`
+intercrate::uses_crate_modern!();
+
+intercrate::define_uses_crate_modern_nested!(uses_crate_modern_nested);
+uses_crate_modern_nested!();
+
+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!();
+    }
+}