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

Display better error messages for E0282 #38057

Merged
merged 4 commits into from
Dec 12, 2016

Conversation

KiChjang
Copy link
Member

Fixes #36554.

@rust-highfive
Copy link
Collaborator

r? @nrc

(rust_highfive has picked a reviewer for you, use r? to override)

@KiChjang KiChjang force-pushed the display-formal-type-param branch 2 times, most recently from 867d426 to 1fbbe93 Compare November 28, 2016 22:53
@frewsxcv
Copy link
Member

FYI, Travis found some issues.

@KiChjang KiChjang force-pushed the display-formal-type-param branch from 1fbbe93 to 94697b1 Compare November 29, 2016 20:01
@KiChjang
Copy link
Member Author

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned nrc Nov 29, 2016
@bors
Copy link
Contributor

bors commented Nov 30, 2016

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

@KiChjang KiChjang force-pushed the display-formal-type-param branch from 94697b1 to f4bbfd2 Compare November 30, 2016 18:20
Copy link
Contributor

@nikomatsakis nikomatsakis left a 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);
Copy link
Contributor

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).

Copy link
Member Author

@KiChjang KiChjang Nov 30, 2016

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...

Copy link
Member Author

@KiChjang KiChjang Dec 1, 2016

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,
Copy link
Contributor

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.

@KiChjang KiChjang force-pushed the display-formal-type-param branch from f4bbfd2 to da1a1ae Compare November 30, 2016 19:53
@KiChjang
Copy link
Member Author

@nikomatsakis There is actually a UI test that demonstrates this and it's at src/test/ui/codemap_tests/repair_span_std_macros.rs. Would that suffice or do you think it's still better to create a new one specifically for this?

@KiChjang KiChjang force-pushed the display-formal-type-param branch 6 times, most recently from 2828f41 to f344f62 Compare December 3, 2016 22:07
@KiChjang KiChjang force-pushed the display-formal-type-param branch from f344f62 to 87e76e6 Compare December 4, 2016 01:12
@nikomatsakis
Copy link
Contributor

@KiChjang

There is actually a UI test that demonstrates this and it's at src/test/ui/codemap_tests/repair_span_std_macros.rs. Would that suffice or do you think it's still better to create a new one specifically for this?

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?

fn foo<X>() { }
fn bar() {
    foo();
}

@nikomatsakis
Copy link
Contributor

(Sorry for the delay.)

@KiChjang
Copy link
Member Author

KiChjang commented Dec 9, 2016

UI test added.

@nikomatsakis
Copy link
Contributor

@KiChjang

tidy error: /checkout/src/test/ui/missing-items/missing-type-parameter.rs: incorrect license

@KiChjang KiChjang force-pushed the display-formal-type-param branch from 77e288a to d24028b Compare December 10, 2016 02:23
@KiChjang
Copy link
Member Author

Dumb vim. Fixed license now.

@KiChjang
Copy link
Member Author

Huh... I'm not sure what the error in Travis CI is about this time.

@eddyb
Copy link
Member

eddyb commented Dec 11, 2016

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Dec 11, 2016

📌 Commit d24028b has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Dec 12, 2016

⌛ Testing commit d24028b with merge 5e2f37f...

bors added a commit that referenced this pull request Dec 12, 2016
…akis

Display better error messages for E0282

Fixes #36554.
@bors bors merged commit d24028b into rust-lang:master Dec 12, 2016
@KiChjang KiChjang deleted the display-formal-type-param branch December 12, 2016 05:11
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.

7 participants