-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #52234 - petrochenkov:macuse2, r=Mark-Simulacrum
resolve: Modularize crate-local `#[macro_export] macro_rules` Based on #50911, cc #50911 (comment) `#[macro_export] macro_rules` items are collected from the whole crate and are planted into the root module as items, so the external view of the crate is symmetric with its internal view and something like `$crate::my_macro` where `my_macro` is `#[macro_export] macro_rules` works both locally and from other crates. Closes #52726
- Loading branch information
Showing
14 changed files
with
415 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,18 @@ | ||
// Copyright 2016 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(use_extern_macros)] | ||
#![allow(duplicate_macro_exports)] | ||
|
||
#[macro_export] | ||
macro_rules! foo_modern { ($i:ident) => {} } | ||
|
||
#[macro_export] | ||
macro_rules! foo_modern { () => {} } |
This file contains 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 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 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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
error: a macro named `panic` has already been exported | ||
error[E0255]: the name `panic` is defined multiple times | ||
--> $DIR/duplicate-check-macro-exports.rs:16:1 | ||
| | ||
LL | macro_rules! panic { () => {} } //~ ERROR a macro named `panic` has already been exported | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `panic` already exported | ||
LL | pub use std::panic; | ||
| ---------- previous import of the macro `panic` here | ||
... | ||
LL | macro_rules! panic { () => {} } //~ ERROR the name `panic` is defined multiple times | ||
| ^^^^^^^^^^^^^^^^^^ `panic` redefined here | ||
| | ||
note: previous macro export here | ||
--> $DIR/duplicate-check-macro-exports.rs:13:9 | ||
= note: `panic` must be defined only once in the macro namespace of this module | ||
help: You can use `as` to change the binding name of the import | ||
| | ||
LL | pub use std::panic; | ||
| ^^^^^^^^^^ | ||
LL | pub use std::panic as other_panic; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0255`. |
This file contains 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,57 @@ | ||
// 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)] | ||
|
||
macro_rules! define_exported { () => { | ||
#[macro_export] | ||
macro_rules! exported { | ||
() => () | ||
} | ||
}} | ||
macro_rules! define_panic { () => { | ||
#[macro_export] | ||
macro_rules! panic { | ||
() => () | ||
} | ||
}} | ||
macro_rules! define_include { () => { | ||
#[macro_export] | ||
macro_rules! include { | ||
() => () | ||
} | ||
}} | ||
|
||
use inner1::*; | ||
|
||
mod inner1 { | ||
pub macro exported() {} | ||
} | ||
|
||
exported!(); //~ ERROR `exported` is ambiguous | ||
|
||
mod inner2 { | ||
define_exported!(); | ||
} | ||
|
||
fn main() { | ||
panic!(); //~ ERROR `panic` is ambiguous | ||
//~^ ERROR `panic` is ambiguous | ||
} | ||
|
||
mod inner3 { | ||
define_panic!(); | ||
} | ||
|
||
mod inner4 { | ||
define_include!(); | ||
} | ||
|
||
include!(); //~ ERROR `include` is ambiguous |
Oops, something went wrong.