Description
While I was investigating a fix for #63064, I noticed one problematic error case, where, as it turns out, the compiler emits a broken span.
fn main() {}
trait Foo<X = Box<dyn Foo>> {}
This is the error I'm getting with the nightly:
error[E0391]: cycle detected when processing `Foo::X`
--> ./src/test/ui/cycle-trait/cycle-trait-default-type-trait-oneliner.rs:3:23
|
3 | trait Foo<X = Box<dyn Foo>> {}
| ^^^
|
= note: ...which again requires processing `Foo::X`, completing the cycle
note: cycle used when collecting item types in top-level module
--> ./src/test/ui/cycle-trait/cycle-trait-default-type-trait-oneliner.rs:1:1
|
1 | fn main() {}
| ^^^^^^^^^
The second span should extend to the whole top-level module but instead terminates at the first {
. This is due to how SourceMap::def_span()
is defined:
rust/src/libsyntax/source_map.rs
Lines 689 to 691 in 023525d
This works kind of okay for all item definitions, except for top-level modules. I did try to come up with a way to fix it up in libsyntax
, but there's no clean way of doing it as it only deals with Spans
. I figured the place to look at would be:
rust/src/librustc/ty/query/plumbing.rs
Lines 313 to 315 in 023525d
but I am not at all familiar with the new query system, so decided to file this issue.
Activity
jakubadamw commentedon Jul 28, 2019
@eddyb, there's a relevant-looking
FIXME
with your name in that file:rust/src/librustc/ty/query/plumbing.rs
Lines 900 to 909 in 023525d
Would you have an idea on a good fix for this? Seemed like an easy one for me at first but then I noticed that it would involve meddling with this plumbing.
[-]Invalid span when emitting a diagnostic notice on the top-level module[/-][+]Invalid span when emitting a diagnostic note on the top-level module[/+]eddyb commentedon Aug 9, 2019
That
def_span
is pretty weird, cc @petrochenkovestebank commentedon Jun 29, 2023
Current output: