Make std available to proc macro root in phase 1 (original) (raw)

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