-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Update E0072 bonus to new error format #36466
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jonathandturner (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -1450,7 +1450,7 @@ pub struct ItemId { | |||
/// The name might be a dummy name in case of anonymous items | |||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] | |||
pub struct Item { | |||
pub name: Name, | |||
pub name: Spanned<Name>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you misunderstood what I said. HIR items are NOT supposed to contain spans.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no worries, I just kept last changes so that it is easier to continue the discussion.
Okay so continue, when we display the error, we only have hir::Item
. Specifically at this section
rust/src/librustc/traits/error_reporting.rs
Lines 571 to 585 in f1f40f8
pub fn recursive_type_with_infinite_size_error(self, | |
type_def_id: DefId) | |
-> DiagnosticBuilder<'tcx> | |
{ | |
assert!(type_def_id.is_local()); | |
let span = self.map.span_if_local(type_def_id).unwrap(); | |
let mut err = struct_span_err!(self.sess, span, E0072, | |
"recursive type `{}` has infinite size", | |
self.item_path_str(type_def_id)); | |
err.span_label(span, &format!("recursive type has infinite size")); | |
err.help(&format!("insert indirection (e.g., a `Box`, `Rc`, or `&`) \ | |
at some point to make `{}` representable", | |
self.item_path_str(type_def_id))); | |
err | |
} |
It seems that we can get the hir::Item
by doing something like this self.map.find(4)
, not sure if we can get ast::Item
at that place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't even need to go through all this. recursive_type_with_infinite_size_error
is only called in librustc_typeck/check/mod.rs
, and it already contains an item_id
that you can use.
So instead of passing in a DefId
to recursive_type_with_infinite_size_error
, pass in an ast::NodeId
, and then use self.map.expect_item(item_id)
, and you'll get the ast::Item
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice thanks, I will try to make the changes that way.
In that case do we need to change ast::Item#ident
or ast::Item#ident#name
to become Spanned
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to make a span field on ast::Ident
instead. Pinging @jonathandturner here to see what he thinks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KiChjang - that's an interesting approach. I don't work much in the front end, so pinging @nikomatsakis for comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While waiting for @nikomatsakis
@KiChjang if we add a span
to ast::Ident
then we likely to change the signature of this method.
pub const fn with_empty_ctxt(name: Name) -> Ident {
Ident { name: name, ctxt: SyntaxContext::empty() }
}
And this will require to change in many places where the method is called.
Should it be ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be a problem. When you change Name
to Spanned<Name>
, you're also making a breaking change that requires a lot of changes in the code where it originally expects Name
.
This is a parser [breaking change], btw. |
☔ The latest upstream changes (presumably #36551) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing due to inactivity, but feel free to resubmit with a rebase! |
WIP
Fixes #35965
Part of #35233
r? @jonathandturner