Skip to content
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

Allow use macro imports to shadow global macros #40501

Merged
merged 2 commits into from
Mar 26, 2017

Conversation

jseyfried
Copy link
Contributor

@jseyfried jseyfried commented Mar 14, 2017

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-compat
    use <global_macros>::*;
}

r? @nrc

@jseyfried
Copy link
Contributor Author

jseyfried commented Mar 14, 2017

cc #35896
cc @keeperofdakeys @abonander

@jseyfried jseyfried changed the title Allow use macro imports to shadow built macors Allow use macro imports to shadow builtin macors Mar 14, 2017
@jseyfried jseyfried changed the title Allow use macro imports to shadow builtin macors Allow use macro imports to shadow builtin macros Mar 14, 2017
@nrc
Copy link
Member

nrc commented Mar 15, 2017

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
Copy link
Member

nrc commented Mar 15, 2017

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

@jseyfried jseyfried changed the title Allow use macro imports to shadow builtin macros Allow use macro imports to shadow global macros Mar 16, 2017
@jseyfried
Copy link
Contributor Author

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

@bors
Copy link
Contributor

bors commented Mar 16, 2017

📌 Commit a0707df has been approved by nrc

bors added a commit that referenced this pull request Mar 18, 2017
@bors
Copy link
Contributor

bors commented Mar 19, 2017

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

@jseyfried
Copy link
Contributor Author

@bors r=nrc

@bors
Copy link
Contributor

bors commented Mar 24, 2017

📌 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
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
Copy link
Contributor

bors commented Mar 24, 2017

🔒 Merge conflict

@jseyfried
Copy link
Contributor Author

@bors r=nrc

@bors
Copy link
Contributor

bors commented Mar 24, 2017

📌 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
Rollup of 11 pull requests

- Successful merges: #40347, #40501, #40516, #40524, #40540, #40642, #40683, #40764, #40778, #40807, #40809
- Failed merges: #40771
bors added a commit that referenced this pull request Mar 25, 2017
Rollup of 11 pull requests

- Successful merges: #40347, #40501, #40516, #40524, #40540, #40642, #40683, #40764, #40778, #40807, #40809
- Failed merges: #40771
@bors
Copy link
Contributor

bors commented Mar 25, 2017

⌛ Testing commit d64d381 with merge 7022e44...

@bors
Copy link
Contributor

bors commented Mar 25, 2017

💔 Test failed - status-travis

@arielb1
Copy link
Contributor

arielb1 commented Mar 25, 2017

@bors
Copy link
Contributor

bors commented Mar 25, 2017

⌛ Testing commit d64d381 with merge 1a95c82...

@bors
Copy link
Contributor

bors commented Mar 25, 2017

💔 Test failed - status-travis

@arielb1
Copy link
Contributor

arielb1 commented Mar 25, 2017

@bors
Copy link
Contributor

bors commented Mar 25, 2017

⌛ Testing commit d64d381 with merge 20ae752...

@bors
Copy link
Contributor

bors commented Mar 25, 2017

💔 Test failed - status-travis

@arielb1
Copy link
Contributor

arielb1 commented Mar 25, 2017

@bors
Copy link
Contributor

bors commented Mar 26, 2017

⌛ Testing commit d64d381 with merge ae3186d...

@arielb1
Copy link
Contributor

arielb1 commented Mar 26, 2017

@bors
Copy link
Contributor

bors commented Mar 26, 2017

⌛ 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
Copy link
Contributor

bors commented Mar 26, 2017

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

@bors bors merged commit d64d381 into rust-lang:master Mar 26, 2017
@jseyfried jseyfried deleted the shadow_builtin_macros branch March 26, 2017 21:00
Sign up for free to 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