Skip to content

Turbofish triggers loss of spans #68489

Closed
@dtolnay

Description

@dtolnay

This is a subissue of #43081 but likely fixable without fixing #43081 in full generality.

src/lib.rs

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn repro(_args: TokenStream, input: TokenStream) -> TokenStream {
    println!("{:#?}", input);
    input.into_iter().collect()
}

src/main.rs

#[repro::repro]
fn repro() {
    f :: < Vec < _ > > ( ) ;
}
fn main() {}

When running cargo check, notice that all the spans in the output are #0 bytes(0..0) (classic #43081) and therefore all error reporting within the function body is broken; there is no line number on the "cannot find function `f` in this scope" error.

The following script reproduces the issue as of rustc 1.42.0-nightly (d1e594f 2020-01-22):

#!/bin/bash

cargo new repro

echo >>repro/Cargo.toml '
[lib]
proc-macro = true
'

echo >repro/src/lib.rs '
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn repro(_args: TokenStream, input: TokenStream) -> TokenStream {
    println!("{:#?}", input);
    TokenStream::new()
}
'

echo >repro/src/main.rs '
#[repro::repro]
fn repro() {
    f :: < Vec < _ > > ( ) ;
}
fn main() {}
'

cargo +nightly check --manifest-path repro/Cargo.toml

cc @petrochenkov who fixed a previous special case of #43081.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosC-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