Skip to content

Derive for items defined inside a function receive incorrect span information #47983

Closed
@sgrif

Description

@sgrif

Steps to reproduce (rustc 1.25.0-nightly (56733bc9f 2018-02-01))

src/main.rs

#![feature(proc_macro)]

extern crate repro;
use repro::AsChangeset;

fn main() {
    #[derive(AsChangeset)]
    #[table_name = "users"]
    struct UserForm {
        id: i32,
        name: String,
    }
}

src/lib.rs

#![feature(proc_macro)]

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_derive(AsChangeset, attributes(table_name))]
pub fn derive(input: TokenStream) -> TokenStream {
    for tt in input {
        println!("{:#?}", tt);
    }
    TokenStream::empty()
}

The struct token will have an incorrect span which points at the correct source code, but shows <macro expansion>:1:1 instead of a file/line number when used. Every other token will have a useless span Span { lo: BytePos(0), hi: BytePos(0), ctxt: #0 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-decl-macros-1-2Area: Declarative macros 1.2A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)C-bugCategory: This is a bug.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