-
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
Display better error messages for E0282 #38057
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
867d426
to
1fbbe93
Compare
FYI, Travis found some issues. |
1fbbe93
to
94697b1
Compare
☔ The latest upstream changes (presumably #37954) made this pull request unmergeable. Please resolve the merge conflicts. |
94697b1
to
f4bbfd2
Compare
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.
Looks good! I just left one minor suggestion. The other thing that I'm missing is some kind of dedicated test where we show off a nice error. Maybe a UI test for this case?
fn foo<X>() { }
fn bar() {
foo();
}
@@ -64,14 +65,14 @@ pub fn super_lattice_tys<'a, 'gcx, 'tcx, L>(this: &mut L, | |||
match (&a.sty, &b.sty) { | |||
(&ty::TyInfer(TyVar(..)), &ty::TyInfer(TyVar(..))) | |||
if infcx.type_var_diverges(a) && infcx.type_var_diverges(b) => { | |||
let v = infcx.next_diverging_ty_var(); | |||
let v = infcx.next_diverging_ty_var(TypeVariableOrigin::LatticeVariable); |
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.
We can give more information about lattice variables -- at minimum, we can give a span. The this
variable is always of a type (either Lub
or Glb
) that has access to a CombineFields
(self.fields
, in each case). CombineFields
has a field trace
of type TypeTrace
, and hiding in there is a field cause
of type ObligationCause
. This is basically "why we are computing the common-supertype or common-subtype of these types". At minimum though it'd be nice to add a method fn cause(&self) -> &OlbligationCause<'tcx>
to LatticeDir
that returns &self.fields.cause
. Then we can create give a span here like LatticeVariable(this.cause().span)
.
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.
Ack, the complication here is that self.fields.cause
is an Option<ty::relate::Cause>
, and is not an ObligationCause
at all! Let me check whether there are other fields that I can use...
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.
Found it, self.fields.trace.cause
may work.
AdjustmentType(Span), | ||
DivergingStmt(Span), | ||
DivergingBlockExpr(Span), | ||
LatticeVariable, |
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.
...if we give LatticeVariable
a span, then every variant will have one.
f4bbfd2
to
da1a1ae
Compare
@nikomatsakis There is actually a UI test that demonstrates this and it's at |
2828f41
to
f344f62
Compare
f344f62
to
87e76e6
Compare
I think it's better to have a targeted test. For one thing, when doing refactorings, it is often hard to tell if a change to the test's output is acceptable or not; but if there is a focused test that is aimed at this particular feature, it will be more obvious. Another thing that happens from time to time is that when we are doing refactorings some test is hard to port to the new system and winds up getting deleted, thereby inadvertendly removing the only test for this feature. So I think it's best to have simple tests that specifically target your change (in addition to the ones which accidentally do so). Plus, the scenario in that UI test was not quite the one I suggested, right?
|
(Sorry for the delay.) |
UI test added. |
tidy error: |
77e288a
to
d24028b
Compare
Dumb vim. Fixed license now. |
Huh... I'm not sure what the error in Travis CI is about this time. |
@bors r=nikomatsakis |
📌 Commit d24028b has been approved by |
…akis Display better error messages for E0282 Fixes #36554.
Fixes #36554.