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

Make std available to proc macro root in phase 1 #47314

Closed
dtolnay opened this issue Jan 10, 2018 · 2 comments
Closed

Make std available to proc macro root in phase 1 #47314

dtolnay opened this issue Jan 10, 2018 · 2 comments
Assignees
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Jan 10, 2018

Following up on #38356 (comment).

Right now, the prelude is in scope at the definition site (unless the proc-macro crate is #![no_implicit_prelude]) and this is an accident (in some sense) due to the phase 0 vs phase 1 distinction as you point out.

However, I think that phase 1 should implicitly contain std at the proc-macro root (so that you can always quote!(use std::...);) and the prelude for convenience/ergonomics and since these are already implicit in phase 0. There will be a PR to add std at the root in phase 1 soon.

The following procedural macro invocation should compile and print None.

#![feature(proc_macro)]

extern crate proc_macro;
use proc_macro::{quote, TokenStream};

#[proc_macro]
pub fn none(input: TokenStream) -> TokenStream {
    quote! {
        // Works currently, because `None` is in the prelude.
        //None::<$input>

        // Does not work, but should.
        std::option::Option::None::<$input>
    }
}
#![feature(proc_macro)]

extern crate mac;

fn main() {
    println!("{:?}", mac::none!(u8));
}

@jseyfried

@dtolnay dtolnay changed the title Make std available to proc macro def site in phase 0 Make std available to proc macro root in phase 1 Jan 10, 2018
@petrochenkov
Copy link
Contributor

Another alternative (was decided somewhere in rust-lang/rfcs#2126, but never put into the RFC text) is to add the name std into the libstd prelude.

This can be done either through old $crate (pub use $crate as std;), or new crate (pub use crate as std;), but not right now because there are some bugs.

@jseyfried jseyfried self-assigned this Jan 10, 2018
@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-macros-2.0 Area: Declarative macros 2.0 (#39412) labels Feb 6, 2018
@petrochenkov
Copy link
Contributor

This is

  • fixed on 2018 edition, ::std::foo will certainly resolve to an extern crate named std
  • mostly fixed on 2015 edition, std::foo will resolve to an extern crate named std unless it's shadowed by something also named std.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants