Skip to content

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

Closed
@dtolnay

Description

@dtolnay

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

Metadata

Metadata

Assignees

Labels

A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions