]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #36767 - jseyfried:enforce_rfc_1560_shadowing, r=nrc
authorbors <bors@rust-lang.org>
Mon, 3 Oct 2016 08:30:32 +0000 (01:30 -0700)
committerGitHub <noreply@github.com>
Mon, 3 Oct 2016 08:30:32 +0000 (01:30 -0700)
Enforce the shadowing restrictions from RFC 1560 for today's macros

This PR enforces a weakened version of the shadowing restrictions from RFC 1560. More specifically,
 - If a macro expansion contains a `macro_rules!` macro definition that is used outside of the expansion, the defined macro may not shadow an existing macro.
 - If a macro expansion contains a `#[macro_use] extern crate` macro import that is used outside of the expansion, the imported macro may not shadow an existing macro.

This is a [breaking-change]. For example,
```rust
macro_rules! m { () => {} }
macro_rules! n { () => {
    macro_rules! m { () => {} } //< This shadows an existing macro.
    m!(); //< This is inside the expansion that generated `m`'s definition, so it is OK.
} }
n!();
m!(); //< This use of `m` is outside the expansion, so it causes the shadowing to be an error.
```

r? @nrc

1  2 
src/librustc/hir/map/def_collector.rs
src/librustc_resolve/lib.rs
src/librustc_resolve/macros.rs

Simple merge
Simple merge
Simple merge