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

Update E0072 bonus to new error format #36466

Closed
wants to merge 6 commits into from
Closed

Update E0072 bonus to new error format #36466

wants to merge 6 commits into from

Conversation

phungleson
Copy link
Contributor

WIP

Fixes #35965
Part of #35233

r? @jonathandturner

@rust-highfive
Copy link
Collaborator

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.

@phungleson phungleson changed the title E0072 bonus Update E0072 bonus to new error format Sep 14, 2016
@@ -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>,
Copy link
Member

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.

Copy link
Contributor Author

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

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?

Copy link
Member

@KiChjang KiChjang Sep 14, 2016

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@KiChjang
Copy link
Member

This is a parser [breaking change], btw.

@bors
Copy link
Contributor

bors commented Sep 22, 2016

☔ The latest upstream changes (presumably #36551) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to resubmit with a rebase!

@phungleson phungleson deleted the e0072-bonus branch November 8, 2016 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants