Skip to content

Better error message when trying to write default impls #49372

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.err_handler().span_err(item.span, "inherent impls cannot be negative");
}
if defaultness == Defaultness::Default {
self.err_handler().span_err(item.span, "inherent impls cannot be default");
self.err_handler()
.struct_span_err(item.span, "inherent impls cannot be default")
.help("maybe a missing `for` keyword?");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is creating a DiagnosticBuilder but never has .emit() called on it, which causes an Internal Compiler Error in test compile-fail/specialization/defaultimpl/validation.rs.

Assign the result of the struct_span_err to a mutable variable err and then err.help(...) and err.emit().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, okay. Sorry, I'm not very familiar with internals. And there's no rush for feedback, thanks for the warning.

}
}
ItemKind::ForeignMod(..) => {
Expand Down