Incorrect trace for Item-level syntax errors in modules included by macro-generated code #66071
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Using Rust nightly 2019-11-04.
Consider a macro that generates a
mod
statement:Call this in the src/main.rs in another crate:
In src/foo.rs, we have the following code:
Note the intentional syntax error
#{inline}
instead of#[inline]
in src/foo.rs.Compiling this setup (reproducible example in
upload.tar.gz)
with
cargo check
,we have the following error message:
The second error is an indirect consequence of the first error.
But where did the "found
{
" error message come from?Obviously, there is nothing wrong with the
codegen::generate!()
macro(we can verify this by fixing the intentional syntax error in src/foo.rs).
So let's try manually expanding the macro call, i.e. we now replace src/main.rs:1 with
And we have the following correct error message:
So this error is caused by incorrect error span detection.
I am unable to locate the exact set of syntax errors affected,
because this does not happen with every syntax error.
For example, if I replace src/foo.rs with
The resultant error message is correct:
The text was updated successfully, but these errors were encountered: