-
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
Point out the known type when field doesn't satisfy bound #38150
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,13 +487,29 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |
} else { | ||
let trait_ref = trait_predicate.to_poly_trait_ref(); | ||
|
||
let mut err = struct_span_err!(self.tcx.sess, span, E0277, | ||
"the trait bound `{}` is not satisfied", | ||
trait_ref.to_predicate()); | ||
err.span_label(span, &format!("the trait `{}` is not implemented \ | ||
for `{}`", | ||
trait_ref, | ||
trait_ref.self_ty())); | ||
let (post_message, pre_message) = | ||
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) | ||
= obligation.cause.code { | ||
let parent_trait_ref = self.resolve_type_vars_if_possible( | ||
&data.parent_trait_ref); | ||
(format!(" in `{}`", parent_trait_ref.0.self_ty()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One concern I have is that this only goes up one level, but there are similar cases where multiple levels are needed. For example, it'd be nice if this patch addressed this example: https://is.gd/BZjfP6 The current output is
and I think your suggested approach would be a big improvement:
But I believe your patch as is will print "within should be easy enough though -- just have to iterate on the cause chain rather than just going up one level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added test for new case and a recursive search up the cause chain. |
||
format!("within `{}`, ", parent_trait_ref.0.self_ty())) | ||
} else { | ||
(String::new(), String::new()) | ||
}; | ||
let mut err = struct_span_err!( | ||
self.tcx.sess, | ||
span, | ||
E0277, | ||
"the trait bound `{}` is not satisfied{}", | ||
trait_ref.to_predicate(), | ||
post_message); | ||
err.span_label(span, | ||
&format!("{}the trait `{}` is not \ | ||
implemented for `{}`", | ||
pre_message, | ||
trait_ref, | ||
trait_ref.self_ty())); | ||
|
||
// Try to report a help message | ||
|
||
|
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.
Missing an indent level here.
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.
Is it? the
if let
is part of the previous line, the only reason is below is because I couldn't get to fit nicely in under 100 chars. In this were to fit in one line it would be:I don't see why then line 493 would have to have double indentation. :)
I agree that it is slightly confusing as it is now, but haven't come up with a better way of presenting this.
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.
Oh indeed, you're absolutely right, my bad!
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.
one better way might be using
match
:)