-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
E0072 needs better underline #35965
Comments
I think the best solution here is to have two spans, one underlining the struct |
So in other words, we're basically clarifying "some point" in the help error message and giving it a concrete location. I'm not sure why this isn't done before? |
@KiChjang - could just be that no one had fixed it, yet. |
Hey guys, have been looking into this for last few days and do some trials and errors to understand the structure here. rust/src/librustc/traits/error_reporting.rs Lines 575 to 584 in 147371f
I seem to get the basic ideas but it would be helpful if there is some documents or some similar examples to guide how to fix this? |
@phungleson - yeah, some of these bonuses can definitely be tricky, and some of them don't even have a clear solution given the representations available in the compiler. From what I, @KiChjang, and others have seen so far, types seem to be the ones with the least amount of span information, and so this bonus might not have a clear solution. Now, that doesn't mean we can't change things up a bit. I was chatting with @nikomatsakis this morning, and there may be a fix we can do. It's a pretty major fix, especially compared to the other bonuses. Basically, the Name struct of Item would become something like a Spanned, where the .name would have a span and an id associated with it. As you can imagine, this fix will cause a ripple across the compiler. If you want to give it a try, let me know. I'd also be happy to do this change, but it may take me a little while to get to it (preparing for RustConf for the next week) |
Check what the span contains here. It's being passed to Since you already have the AST node, it's just a matter of scanning the struct's fields/enum variants again to check which of the fields/variants have the exact same type of the struct/enum. You'll have to convert the field/variant into a |
@KiChjang the span represents the whole struct |
Hmm... in which case, the span provided is not so useful. I'd say remove it from the method signature altogether. Furthermore, I think this is a little bit more involved - you cannot assume that the struct/enum type is the one that is being recursive. You may need to change |
Sure thanks @KiChjang, understand what you mean. However let's discuss about the expected structure of the With this struct struct ListNode {
head: u8,
tail: Option<ListNode>,
} The current Node looks like this
I assume what @jonathandturner meant by A couple of questions: Firstly, about structure of new
Secondly, should we create a new |
fwiw -- and I might be mistaken in exactly where it's best to put this -- but I was thinking the work would be to update From: pub struct Item {
pub name: Name,
pub attrs: HirVec<Attribute>,
pub id: NodeId,
pub node: Item_,
pub vis: Visibility,
pub span: Span,
} To: pub struct Item {
pub name: Spanned<Name>,
pub attrs: HirVec<Attribute>,
pub id: NodeId,
pub node: Item_,
pub vis: Visibility,
pub span: Span,
} |
Thanks @jonathandturner yes that should work as well, in this case: |
pinging @nikomatsakis ... @phungleson: I'm not entirely sure I follow what you're saying... are you saying For #2 - I'm not sure. Maybe @nikomatsakis might know. |
@jonathandturner ah sorry, let me clarify. Yep I know Other than that I am happy to make changes based on what you suggested. |
@phungleson - yeah, I could see how what I said was a confusing way to say it. Sorry about that. What I meant was pub struct Name(pub u32); The |
Cool thanks @jonathandturner, I will make the changes. |
I re-make a new PR to change to It is still WIP and need some inputs from you and @KiChjang to move forward. |
@jonathandturner @KiChjang, sorry I was a bit busy last few months so this issue became rather old.. This is a very interesting issue so I want to pick this up again, is it ok? |
It looks like no-one else have worked on this issue while you were away, so go right ahead and pick this back up! |
@phungleson Oh whoops, looks like @estebank submitted a PR to solve this issue. |
@estebank Is this still being worked on? |
@KiChjang I've been offline for a couple of weeks and haven't been able to go back to this yet. Although it is still on my radar, it's unlikely I'll take another stab at this for at least a month. If you want to take it instead: What I did:
What I was planning on doing when working on it again:
By doing it that way the patch should be much smaller than my PR ended up being. Take a look at the thread on #38328 for the discussion. |
…nkov Add a way to get shorter spans until `char` for pointing at defs ```rust error[E0072]: recursive type `X` has infinite size --> file.rs:10:1 | 10 | struct X { | ^^^^^^^^ recursive type has infinite size | = help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `X` representable ``` vs ```rust error[E0072]: recursive type `X` has infinite size --> file.rs:10:1 | 10 | struct X { | _^ starting here... 11 | | x: X, 12 | | } | |_^ ...ending here: recursive type has infinite size | = help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `X` representable ``` Re: rust-lang#35965, rust-lang#38246. Follow up to rust-lang#38328. r? @jonathandturner
Closing as per #41214 (comment). |
Currently, E0072 falls back to a multi-line
Instead, can we underline a better span. It might take some experimentation to find the one that works with the ast, but perhaps something like:
The text was updated successfully, but these errors were encountered: