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

Turbofish triggers loss of spans #68489

Closed
dtolnay opened this issue Jan 23, 2020 · 0 comments · Fixed by #72306
Closed

Turbofish triggers loss of spans #68489

dtolnay opened this issue Jan 23, 2020 · 0 comments · Fixed by #72306
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Jan 23, 2020

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.

@dtolnay dtolnay added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jan 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 20, 2020
…petrochenkov

Break tokens before checking if they are 'probably equal'

Fixes rust-lang#68489
Fixes rust-lang#70987

When checking two `TokenStreams` to see if they are 'probably equal',
we ignore the `IsJoint` information associated with each `TokenTree`.
However, the `IsJoint` information determines whether adjacent tokens
will be 'glued' (if possible) when construction the `TokenStream` - e.g.
`[Gt Gt]` can be 'glued' to `BinOp(Shr)`.

Since we are ignoring the `IsJoint` information, 'glued' and 'unglued'
tokens are equivalent for determining if two `TokenStreams` are
'probably equal'. Therefore, we need to 'unglue' all tokens in the
stream to avoid false negatives (which cause us to throw out the cached
tokens, losing span information).
@Aaron1011 Aaron1011 added the A-proc-macros Area: Procedural macros label May 21, 2020
RalfJung added a commit to RalfJung/rust that referenced this issue May 22, 2020
…petrochenkov

Break tokens before checking if they are 'probably equal'

Fixes rust-lang#68489
Fixes rust-lang#70987

When checking two `TokenStreams` to see if they are 'probably equal',
we ignore the `IsJoint` information associated with each `TokenTree`.
However, the `IsJoint` information determines whether adjacent tokens
will be 'glued' (if possible) when construction the `TokenStream` - e.g.
`[Gt Gt]` can be 'glued' to `BinOp(Shr)`.

Since we are ignoring the `IsJoint` information, 'glued' and 'unglued'
tokens are equivalent for determining if two `TokenStreams` are
'probably equal'. Therefore, we need to 'unglue' all tokens in the
stream to avoid false negatives (which cause us to throw out the cached
tokens, losing span information).
@bors bors closed this as completed in 9b2b8a5 May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants