Skip to content

Allow use macro imports to shadow global macros - #40501

Merged
bors merged 2 commits into
rust-lang:masterfrom
jseyfried:shadow_builtin_macros
Mar 26, 2017
Merged

Allow use macro imports to shadow global macros#40501
bors merged 2 commits into
rust-lang:masterfrom
jseyfried:shadow_builtin_macros

Conversation

@jseyfried

@jseyfriedjseyfried commented Mar 14, 2017

Copy link
Copy Markdown
Contributor

Terminology:

  • global scope: builtin macros, macros from the prelude, #[macro_use], or #![plugin(..)].
  • legacy scope: crate-local macro_rules!.
  • modern scope: use macro imports, macro (once implemented).

Today, the legacy scope can shadow the global scope (modulo RFC 1560 expanded shadowing restrictions). However, the modern scope cannot shadow or be shadowed by either the global or legacy scopes, leading to ambiguity errors.

This PR allows the modern scope to shadow the global scope (subject to some restrictions).
More specifically, a name in the global scope is as shadowable as a glob import in the module self. In other words, we imagine a special, implicit glob import in each module item:

mod foo {#[lexical_only]// Not accessible via `foo::<name>`, like pre-RFC 1560 `use` imports.#[shadowable_by_legacy_scope]// for back-compatuse <global_macros>::*;}

r? @nrc

@jseyfried

jseyfried commented Mar 14, 2017

Copy link
Copy Markdown
ContributorAuthor

@jseyfriedjseyfried changed the title Allow use macro imports to shadow built macorsAllow use macro imports to shadow builtin macorsMar 14, 2017
@jseyfriedjseyfried changed the title Allow use macro imports to shadow builtin macorsAllow use macro imports to shadow builtin macrosMar 14, 2017
@jseyfried
jseyfriedforce-pushed the shadow_builtin_macros branch from 82ce9da to a19fde7CompareMarch 14, 2017 05:06
@nrc

nrc commented Mar 15, 2017

Copy link
Copy Markdown
Member

I think the terminology could be improved - built-in suggests that it is part of the compiler, but only a small subset of macros are and they are (iirc) in the prelude too. If I understand correctly, the distinction is more between legacy-imported and legacy-local?

@nrc

nrc commented Mar 15, 2017

Copy link
Copy Markdown
Member

LGTM, I'd like to fix (or better understand) the naming issue, but r+ with that.

@jseyfriedjseyfried changed the title Allow use macro imports to shadow builtin macrosAllow use macro imports to shadow global macrosMar 16, 2017
@jseyfried

Copy link
Copy Markdown
ContributorAuthor

Agreed -- I renamed "builtin scope" to "global scope".
@bors r=nrc

@bors

bors commented Mar 16, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit a0707df has been approved by nrc

@arielb1arielb1 mentioned this pull request Mar 18, 2017
bors added a commit that referenced this pull request Mar 18, 2017
@bors

bors commented Mar 19, 2017

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #40346) made this pull request unmergeable. Please resolve the merge conflicts.

@jseyfried
jseyfriedforce-pushed the shadow_builtin_macros branch from a0707df to d123e76CompareMarch 20, 2017 00:16
@jseyfried

Copy link
Copy Markdown
ContributorAuthor

@bors r=nrc

@bors

bors commented Mar 24, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit d123e76 has been approved by nrc

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 24, 2017
Allow `use` macro imports to shadow global macros
Terminology:
- global scope: builtin macros, macros from the prelude, `#[macro_use]`, or `#![plugin(..)]`.
- legacy scope: crate-local `macro_rules!`.
- modern scope: `use` macro imports, `macro` (once implemented).
Today, the legacy scope can shadow the global scope (modulo RFC 1560 expanded shadowing restrictions). However, the modern scope cannot shadow or be shadowed by either the global or legacy scopes, leading to ambiguity errors.
This PR allows the modern scope to shadow the global scope (subject to some restrictions).
More specifically, a name in the global scope is as shadowable as a glob import in the module `self`. In other words, we imagine a special, implicit glob import in each module item:
```rust
mod foo {
#[lexical_only] // Not accessible via `foo::<name>`, like pre-RFC 1560 `use` imports.
#[shadowable_by_legacy_scope] // for back-compat
use <global_macros>::*;
}
```
r? @nrc
@frewsxcvfrewsxcv mentioned this pull request Mar 24, 2017
bors added a commit that referenced this pull request Mar 24, 2017
Rollup of 5 pull requests
- Successful merges: #40501, #40524, #40636, #40739, #40756
- Failed merges:
@bors

bors commented Mar 24, 2017

Copy link
Copy Markdown
Collaborator

🔒 Merge conflict

@jseyfried
jseyfriedforce-pushed the shadow_builtin_macros branch from d123e76 to d64d381CompareMarch 24, 2017 21:06
@jseyfried

Copy link
Copy Markdown
ContributorAuthor

@bors r=nrc

@bors

bors commented Mar 24, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit d64d381 has been approved by nrc

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 25, 2017
Allow `use` macro imports to shadow global macros
Terminology:
- global scope: builtin macros, macros from the prelude, `#[macro_use]`, or `#![plugin(..)]`.
- legacy scope: crate-local `macro_rules!`.
- modern scope: `use` macro imports, `macro` (once implemented).
Today, the legacy scope can shadow the global scope (modulo RFC 1560 expanded shadowing restrictions). However, the modern scope cannot shadow or be shadowed by either the global or legacy scopes, leading to ambiguity errors.
This PR allows the modern scope to shadow the global scope (subject to some restrictions).
More specifically, a name in the global scope is as shadowable as a glob import in the module `self`. In other words, we imagine a special, implicit glob import in each module item:
```rust
mod foo {
#[lexical_only] // Not accessible via `foo::<name>`, like pre-RFC 1560 `use` imports.
#[shadowable_by_legacy_scope] // for back-compat
use <global_macros>::*;
}
```
r? @nrc
bors added a commit that referenced this pull request Mar 25, 2017
bors added a commit that referenced this pull request Mar 25, 2017
@bors

bors commented Mar 25, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit d64d381 with merge 7022e44...

@bors

bors commented Mar 25, 2017

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-travis

@arielb1

Copy link
Copy Markdown
Contributor

@bors

bors commented Mar 25, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit d64d381 with merge 1a95c82...

@bors

bors commented Mar 25, 2017

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-travis

@arielb1

Copy link
Copy Markdown
Contributor

@bors

bors commented Mar 25, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit d64d381 with merge 20ae752...

@bors

bors commented Mar 25, 2017

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-travis

@arielb1

Copy link
Copy Markdown
Contributor

@bors

bors commented Mar 26, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit d64d381 with merge ae3186d...

@arielb1

Copy link
Copy Markdown
Contributor

@bors

bors commented Mar 26, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit d64d381 with merge bcfd5c4...

bors added a commit that referenced this pull request Mar 26, 2017
Allow `use` macro imports to shadow global macros
Terminology:
- global scope: builtin macros, macros from the prelude, `#[macro_use]`, or `#![plugin(..)]`.
- legacy scope: crate-local `macro_rules!`.
- modern scope: `use` macro imports, `macro` (once implemented).
Today, the legacy scope can shadow the global scope (modulo RFC 1560 expanded shadowing restrictions). However, the modern scope cannot shadow or be shadowed by either the global or legacy scopes, leading to ambiguity errors.
This PR allows the modern scope to shadow the global scope (subject to some restrictions).
More specifically, a name in the global scope is as shadowable as a glob import in the module `self`. In other words, we imagine a special, implicit glob import in each module item:
```rust
mod foo {
#[lexical_only] // Not accessible via `foo::<name>`, like pre-RFC 1560 `use` imports.
#[shadowable_by_legacy_scope] // for back-compat
use <global_macros>::*;
}
```
r? @nrc
@bors

bors commented Mar 26, 2017

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: nrc
Pushing bcfd5c4 to master...

@bors
bors merged commit d64d381 into rust-lang:masterMar 26, 2017
@jseyfried
jseyfried deleted the shadow_builtin_macros branch March 26, 2017 21:00
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jseyfried@nrc@bors@arielb1