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

Stabilize extern_crate_self #57407

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
7 participants
@mehcode
Copy link
Contributor

mehcode commented Jan 7, 2019

Fixes #56409

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 8, 2019

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

@Centril
Copy link
Contributor

Centril left a comment

Looks good; the version needs to be adjusted tho.

Show resolved Hide resolved src/libsyntax/feature_gate.rs Outdated
@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Jan 9, 2019

Stabilization report

r? @Centril

I propose that we stabilize #[feature(extern_crate_self)] with 1.34 as the earliest stable version.

@rfcbot merge

History

Motivation

To resolve #54647 (and so that proc macro crates can migrate to 2018). Also see #56409 (comment).

As noted in #55275 (comment), this solution doesn't introduce any new syntax and has minimal maintenance cost.

What is stabilized

Suppose that we have the following item in the current crate:

fn the_answer() -> usize { 42 }

It now becomes semantically possible (test) (it already was syntactically possible) to write extern crate self as ALIAS; where ALIAS is an identifier. The semantics of extern crate self as ALIAS; is ALIAS is added to the extern prelude and will refer to the current crate. Since ALIAS is now in the extern prelude you may now write ::ALIAS::the_answer and ALIAS::the_answer under the rules due to #54658.

Since ALIAS is any identifier, you may now for example write: extern crate self as serde; and then refer to the_answer by serde::the_answer.

You may also write:

  • macro_rules! alias_self {
        ($alias:ident) => { extern crate self as $alias; }
    }
    
    alias_self!(the_alias);
    
    fn main() {
        assert_eq!(the_alias::the_answer(), 42);
    }
  • macro_rules! extern_something {
        ($alias:ident) => { extern crate $alias as the_alias; }
    }
    
    extern_something!(self);
    
    fn main() {
        assert_eq!(the_alias::the_answer(), 42);
    }

    (@mehcode: please extend the set of tests to include both as // run-pass tests..) Done.

What is not stabilized:

  • extern crate self; is semantically rejected (test) since it would add self to the extern prelude thus coming into conflict with self::.

    However, it is already syntactically valid and will remain so.
    For example:

    macro_rules! accept_item { ($x:item) => {} }
    
    accept_item! {
        extern crate self;
    }

    (@mehcode: please extend the set of tests to include this as a // compile-pass test..) Done.

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Jan 9, 2019

Team member @Centril has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@mehcode mehcode force-pushed the mehcode:stabilize-extern-crate-self branch from 0df044c to 8c946d9 Jan 15, 2019

@mehcode

This comment has been minimized.

Copy link
Contributor

mehcode commented Jan 15, 2019

Thanks for walking me through this @Centril.

@Centril
Copy link
Contributor

Centril left a comment

Some minor style nits; it looks great otherwise.

@mehcode mehcode force-pushed the mehcode:stabilize-extern-crate-self branch from 8c946d9 to 777e5c3 Jan 15, 2019

@mehcode mehcode force-pushed the mehcode:stabilize-extern-crate-self branch from 777e5c3 to 09d073a Jan 15, 2019

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Jan 16, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment