about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-08-28 10:45:28 +0000
committerbors <bors@rust-lang.org>2021-08-28 10:45:28 +0000
commit05cccdc9b321e6565b3e62e8b52aec53d106ef2f (patch)
treed6d123da95741a6b5bad6f4e6288805fa500f174 /src/test
parent2031fd6e46fbe4da271bb23d55c211b2e16dd91f (diff)
parentb5a41418f84b4d54b9137fe9c83c50f015161063 (diff)
Auto merge of #88019 - inquisitivecrystal:macro-def, r=cjgillot
Treat macros as HIR items

Macros have historically been treated differently from other items at the HIR level. This PR makes them just like normal items. There are a few special cases left over, which I've attempted to lay out below. By normalizing the treatment of macro items, this PR simplifies a fair bit of code and fixes some bugs at the same time. For more information, see #87406.

r? `@cjgillot`

## Backwards incompatibility

This is backwards incompatible in one small way. Due to a mistake, it was previously possible to apply stability attributes to an exported macro, even without enabling the `staged_api` feature. This never should have worked. After this PR, it will error, as it should. We could make it a warning instead, but that would require a special case for a feature that shouldn't ever have worked and is likely used by no or very few crates, so I'm not thrilled about the idea.

## Notes for reviewers
### Commit seperation

I'd recommend reviewing this PR commit by commit. The commit chunking wasn't perfect, but it's better than looking at the combined diff, which is quite overwhelming. The compiler and standard library build after each commit, although tests do not necessarily pass and tools do not necessarily build till the end of the series.

### Special cases
There are a few special cases that remain after this change. Here are the notable ones I remember:

1. Visibility works a bit differently for `macro_rules!` macros than other items, since they aren't generally marked with `pub` but instead with `#[macro_export]`.
2. Since `#[macro_export]` macros always have paths at the top level of the crate, some additional handling needs to be done on the reexport to top level.
### Performance impact

I don't know for sure, but theses changes may slightly hurt performance. They create more work for the compiler in a few places. For instance, some operations that were previously run only for exported macros are now run for all macros. A perf run is probably advisable. For all I know we'll see performance improvements instead. :)

## Issues resolved

This resolves #87406 (the tracking issue for this change). It also fixes several bugs:

Fixes #59306.
Fixes #73754.
Fixes #87257.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/rustdoc-ui/deny-missing-docs-macro.stderr2
-rw-r--r--src/test/rustdoc/macro-document-private-duplicate.rs23
-rw-r--r--src/test/rustdoc/macro-document-private.rs19
-rw-r--r--src/test/rustdoc/macro-indirect-use.rs16
-rw-r--r--src/test/ui/lint/lint-level-macro-def-mod.rs17
-rw-r--r--src/test/ui/lint/lint-level-macro-def.rs17
-rw-r--r--src/test/ui/lint/missing-doc-private-macro.rs4
-rw-r--r--src/test/ui/lint/missing-doc-private-macro.stderr4
-rw-r--r--src/test/ui/macros/macro-stability-rpass.rs3
9 files changed, 99 insertions, 6 deletions
diff --git a/src/test/rustdoc-ui/deny-missing-docs-macro.stderr b/src/test/rustdoc-ui/deny-missing-docs-macro.stderr
index a564006e74f..0867b08183e 100644
--- a/src/test/rustdoc-ui/deny-missing-docs-macro.stderr
+++ b/src/test/rustdoc-ui/deny-missing-docs-macro.stderr
@@ -1,4 +1,4 @@
-error: missing documentation for macro
+error: missing documentation for a macro
   --> $DIR/deny-missing-docs-macro.rs:6:1
    |
 LL | macro_rules! foo {
diff --git a/src/test/rustdoc/macro-document-private-duplicate.rs b/src/test/rustdoc/macro-document-private-duplicate.rs
new file mode 100644
index 00000000000..460785ed979
--- /dev/null
+++ b/src/test/rustdoc/macro-document-private-duplicate.rs
@@ -0,0 +1,23 @@
+// FIXME: If two macros in the same module have the same name
+// (yes, that's a thing), rustdoc lists both of them on the index page,
+// but only documents the first one on the page for the macro.
+// Fortunately, this can only happen in document private items mode,
+// but it still isn't ideal beahvior.
+//
+// See https://github.com/rust-lang/rust/pull/88019#discussion_r693920453
+//
+// compile-flags: --document-private-items
+
+// @has macro_document_private_duplicate/index.html 'Doc 1.'
+// @has macro_document_private_duplicate/macro.a_macro.html 'Doc 1.'
+/// Doc 1.
+macro_rules! a_macro {
+    () => ()
+}
+
+// @has macro_document_private_duplicate/index.html 'Doc 2.'
+// @!has macro_document_private_duplicate/macro.a_macro.html 'Doc 2.'
+/// Doc 2.
+macro_rules! a_macro {
+    () => ()
+}
diff --git a/src/test/rustdoc/macro-document-private.rs b/src/test/rustdoc/macro-document-private.rs
new file mode 100644
index 00000000000..d2496913ffc
--- /dev/null
+++ b/src/test/rustdoc/macro-document-private.rs
@@ -0,0 +1,19 @@
+// Checks that private macros are documented when `--document-private-items`
+// is present.
+//
+// This is a regression test for issue #73754.
+//
+// compile-flags: --document-private-items
+
+#![feature(decl_macro)]
+
+
+// @has macro_document_private/macro.some_macro.html
+macro some_macro {
+    (a: tt) => {}
+}
+
+// @has macro_document_private/macro.another_macro.html
+macro_rules! another_macro {
+    (a: tt) => {}
+}
diff --git a/src/test/rustdoc/macro-indirect-use.rs b/src/test/rustdoc/macro-indirect-use.rs
new file mode 100644
index 00000000000..b2d9336cffc
--- /dev/null
+++ b/src/test/rustdoc/macro-indirect-use.rs
@@ -0,0 +1,16 @@
+// Checks that it is possible to make a macro public through a `pub use` of its
+// parent module.
+//
+// This is a regression test for issue #87257.
+
+#![feature(decl_macro)]
+
+mod outer {
+    pub mod inner {
+        pub macro some_macro() {}
+    }
+}
+
+// @has macro_indirect_use/inner/index.html
+// @has macro_indirect_use/inner/macro.some_macro.html
+pub use outer::inner;
diff --git a/src/test/ui/lint/lint-level-macro-def-mod.rs b/src/test/ui/lint/lint-level-macro-def-mod.rs
new file mode 100644
index 00000000000..79f7d1206df
--- /dev/null
+++ b/src/test/ui/lint/lint-level-macro-def-mod.rs
@@ -0,0 +1,17 @@
+// This checks that exported macros lint as part of their module of origin, not
+// the root module.
+//
+// check-pass
+
+//! Top level documentation
+#![deny(missing_docs)]
+
+#[allow(missing_docs)]
+mod module {
+    #[macro_export]
+    macro_rules! hello {
+        () => ()
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/lint/lint-level-macro-def.rs b/src/test/ui/lint/lint-level-macro-def.rs
new file mode 100644
index 00000000000..720f4b453ab
--- /dev/null
+++ b/src/test/ui/lint/lint-level-macro-def.rs
@@ -0,0 +1,17 @@
+// Checks that you can set a lint level specficially for a macro definition.
+//
+// This is a regression test for issue #59306.
+//
+// check-pass
+
+
+#[deny(missing_docs)]
+mod module {
+    #[allow(missing_docs)]
+    #[macro_export]
+    macro_rules! hello {
+        () => ()
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/lint/missing-doc-private-macro.rs b/src/test/ui/lint/missing-doc-private-macro.rs
index 8d1d5c56880..0d4332ed08b 100644
--- a/src/test/ui/lint/missing-doc-private-macro.rs
+++ b/src/test/ui/lint/missing-doc-private-macro.rs
@@ -29,13 +29,13 @@ mod submodule {
 
     #[macro_export]
     macro_rules! exported_to_top_level {
-        //~^ ERROR missing documentation for macro
+        //~^ ERROR missing documentation for a macro
         () => ()
     }
 }
 
 pub macro top_level_pub_macro {
-    //~^ ERROR missing documentation for macro
+    //~^ ERROR missing documentation for a macro
     () => ()
 }
 
diff --git a/src/test/ui/lint/missing-doc-private-macro.stderr b/src/test/ui/lint/missing-doc-private-macro.stderr
index a5d39faf405..979b007d0ec 100644
--- a/src/test/ui/lint/missing-doc-private-macro.stderr
+++ b/src/test/ui/lint/missing-doc-private-macro.stderr
@@ -1,4 +1,4 @@
-error: missing documentation for macro
+error: missing documentation for a macro
   --> $DIR/missing-doc-private-macro.rs:31:5
    |
 LL |     macro_rules! exported_to_top_level {
@@ -10,7 +10,7 @@ note: the lint level is defined here
 LL | #![deny(missing_docs)]
    |         ^^^^^^^^^^^^
 
-error: missing documentation for macro
+error: missing documentation for a macro
   --> $DIR/missing-doc-private-macro.rs:37:1
    |
 LL | pub macro top_level_pub_macro {
diff --git a/src/test/ui/macros/macro-stability-rpass.rs b/src/test/ui/macros/macro-stability-rpass.rs
index a5f538ba6b3..2d02b95288d 100644
--- a/src/test/ui/macros/macro-stability-rpass.rs
+++ b/src/test/ui/macros/macro-stability-rpass.rs
@@ -1,7 +1,8 @@
 // run-pass
 // aux-build:unstable-macros.rs
 
-#![feature(unstable_macros, local_unstable)]
+#![unstable(feature = "one_two_three_testing", issue = "none")]
+#![feature(staged_api, unstable_macros, local_unstable)]
 
 #[macro_use] extern crate unstable_macros;