-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Support pub
on macro_rules
#78166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+184
−35
Closed
Support pub
on macro_rules
#78166
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pub macro_rules! m1 { () => {} } //~ ERROR `pub` on `macro_rules` items is unstable | ||
|
||
#[cfg(FALSE)] | ||
pub macro_rules! m2 { () => {} } //~ ERROR `pub` on `macro_rules` items is unstable | ||
|
||
pub(crate) macro_rules! m3 { () => {} } //~ ERROR `pub` on `macro_rules` items is unstable | ||
|
||
pub(in self) macro_rules! m4 { () => {} } //~ ERROR `pub` on `macro_rules` items is unstable | ||
|
||
fn main() {} |
39 changes: 39 additions & 0 deletions
39
src/test/ui/feature-gates/feature-gate-pub_macro_rules.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error[E0658]: `pub` on `macro_rules` items is unstable | ||
--> $DIR/feature-gate-pub_macro_rules.rs:1:1 | ||
| | ||
LL | pub macro_rules! m1 { () => {} } | ||
| ^^^ | ||
| | ||
= note: see issue #78855 <https://github.com/rust-lang/rust/issues/78855> for more information | ||
= help: add `#![feature(pub_macro_rules)]` to the crate attributes to enable | ||
|
||
error[E0658]: `pub` on `macro_rules` items is unstable | ||
--> $DIR/feature-gate-pub_macro_rules.rs:4:1 | ||
| | ||
LL | pub macro_rules! m2 { () => {} } | ||
| ^^^ | ||
| | ||
= note: see issue #78855 <https://github.com/rust-lang/rust/issues/78855> for more information | ||
= help: add `#![feature(pub_macro_rules)]` to the crate attributes to enable | ||
|
||
error[E0658]: `pub` on `macro_rules` items is unstable | ||
--> $DIR/feature-gate-pub_macro_rules.rs:6:1 | ||
| | ||
LL | pub(crate) macro_rules! m3 { () => {} } | ||
| ^^^^^^^^^^ | ||
| | ||
= note: see issue #78855 <https://github.com/rust-lang/rust/issues/78855> for more information | ||
= help: add `#![feature(pub_macro_rules)]` to the crate attributes to enable | ||
|
||
error[E0658]: `pub` on `macro_rules` items is unstable | ||
--> $DIR/feature-gate-pub_macro_rules.rs:8:1 | ||
| | ||
LL | pub(in self) macro_rules! m4 { () => {} } | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: see issue #78855 <https://github.com/rust-lang/rust/issues/78855> for more information | ||
= help: add `#![feature(pub_macro_rules)]` to the crate attributes to enable | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(decl_macro)] | ||
#![feature(pub_macro_rules)] | ||
|
||
#[macro_export] | ||
macro m1() {} //~ ERROR `#[macro_export]` cannot be used on `macro` items | ||
|
||
#[macro_export] | ||
pub macro_rules! m2 { () => {} } | ||
//~^ ERROR `#[macro_export]` cannot be used on `macro_rules` with `pub` | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/macros/macro-export-on-modularized-macros.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: `#[macro_export]` cannot be used on `macro` items | ||
--> $DIR/macro-export-on-modularized-macros.rs:5:1 | ||
| | ||
LL | macro m1() {} | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: `#[macro_export]` cannot be used on `macro_rules` with `pub` | ||
--> $DIR/macro-export-on-modularized-macros.rs:8:1 | ||
| | ||
LL | pub macro_rules! m2 { () => {} } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![feature(pub_macro_rules)] | ||
|
||
#[macro_use] | ||
mod m { | ||
pub macro_rules! mac { () => {} } | ||
|
||
// `pub` `macro_rules` cannot be redefined in the same module. | ||
pub macro_rules! mac { () => {} } //~ ERROR the name `mac` is defined multiple times | ||
|
||
pub(self) macro_rules! private_mac { () => {} } | ||
} | ||
|
||
const _: () = { | ||
pub macro_rules! block_mac { () => {} } | ||
}; | ||
|
||
mod n { | ||
// Scope of `pub` `macro_rules` is not extended by `#[macro_use]`. | ||
mac!(); //~ ERROR cannot find macro `mac` in this scope | ||
|
||
// `pub` `macro_rules` doesn't put the macro into the root module, unlike `#[macro_export]`. | ||
crate::mac!(); //~ ERROR failed to resolve: maybe a missing crate `mac` | ||
crate::block_mac!(); //~ ERROR failed to resolve: maybe a missing crate `block_mac` | ||
|
||
crate::m::private_mac!(); //~ ERROR macro `private_mac` is private | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
error[E0428]: the name `mac` is defined multiple times | ||
--> $DIR/pub-macro-rules-fail.rs:8:5 | ||
| | ||
LL | pub macro_rules! mac { () => {} } | ||
| -------------------- previous definition of the macro `mac` here | ||
... | ||
LL | pub macro_rules! mac { () => {} } | ||
| ^^^^^^^^^^^^^^^^^^^^ `mac` redefined here | ||
| | ||
= note: `mac` must be defined only once in the macro namespace of this module | ||
|
||
error[E0433]: failed to resolve: maybe a missing crate `mac`? | ||
--> $DIR/pub-macro-rules-fail.rs:22:12 | ||
| | ||
LL | crate::mac!(); | ||
| ^^^ maybe a missing crate `mac`? | ||
|
||
error[E0433]: failed to resolve: maybe a missing crate `block_mac`? | ||
--> $DIR/pub-macro-rules-fail.rs:23:12 | ||
| | ||
LL | crate::block_mac!(); | ||
| ^^^^^^^^^ maybe a missing crate `block_mac`? | ||
|
||
error: cannot find macro `mac` in this scope | ||
--> $DIR/pub-macro-rules-fail.rs:19:5 | ||
| | ||
LL | mac!(); | ||
| ^^^ | ||
| | ||
= note: consider importing this macro: | ||
m::mac | ||
|
||
error[E0603]: macro `private_mac` is private | ||
--> $DIR/pub-macro-rules-fail.rs:25:15 | ||
| | ||
LL | crate::m::private_mac!(); | ||
| ^^^^^^^^^^^ private macro | ||
| | ||
note: the macro `private_mac` is defined here | ||
--> $DIR/pub-macro-rules-fail.rs:10:5 | ||
| | ||
LL | pub(self) macro_rules! private_mac { () => {} } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0428, E0433, E0603. | ||
For more information about an error, try `rustc --explain E0428`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// check-pass | ||
|
||
#![feature(pub_macro_rules)] | ||
|
||
mod m { | ||
// `pub` `macro_rules` can be used earlier in item order than they are defined. | ||
foo!(); | ||
|
||
pub macro_rules! foo { () => {} } | ||
|
||
// `pub(...)` works too. | ||
pub(super) macro_rules! bar { () => {} } | ||
} | ||
|
||
// `pub` `macro_rules` are available by module path. | ||
m::foo!(); | ||
|
||
m::bar!(); | ||
|
||
fn main() {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.