Skip to content

Move generic arg/param validation to create_substs_for_generic_args to resolve various const generics issues - #68434

Merged
bors merged 12 commits into
rust-lang:masterfrom
varkor:astconv-mismatch-error
Feb 27, 2020
Merged

Move generic arg/param validation to create_substs_for_generic_args to resolve various const generics issues#68434
bors merged 12 commits into
rust-lang:masterfrom
varkor:astconv-mismatch-error

Conversation

@varkor

Copy link
Copy Markdown
Contributor

This changes some diagnostics, but I think they're around as helpful as the previous ones, and occur infrequently regardless.

Fixes#68257.
Fixes#68398.

r? @eddyb

@varkorvarkor added the F-const_generics `#![feature(const_generics)]` label Jan 21, 2020
@rust-highfive

Copy link
Copy Markdown
Contributor

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 21, 2020
@varkor
varkorforce-pushed the astconv-mismatch-error branch from 9b4b01e to d2a750cCompareJanuary 21, 2020 23:11

@eddybeddyb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but I'd like a second opinion from @rust-lang/compiler (and maybe we need a check-mode crater run? I doubt it though)

Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment threadsrc/librustc_typeck/astconv.rs Outdated
@rust-highfive

This comment has been minimized.

Comment threadsrc/librustc/ty/structural_impls.rs Outdated
Comment threadsrc/librustc_typeck/astconv.rs Outdated
@rust-highfive

This comment has been minimized.

@varkor
varkorforce-pushed the astconv-mismatch-error branch from 1174b94 to afad00dCompareJanuary 23, 2020 01:16
Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment threadsrc/librustc_typeck/astconv.rs Outdated
@petrochenkovpetrochenkov removed their assignment Jan 24, 2020
Comment threadsrc/librustc_typeck/astconv.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No reordering suggestion for this case?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather leave this PR for the bug-fixes and follow up with the diagnostics improvements. That's a good follow up, though.

@varkor

Copy link
Copy Markdown
ContributorAuthor

r? @nikomatsakis for a second opinion (#68434 (review))

Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment on lines 332 to 337

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Centril@estebank Can we make it so you have to emit an error to get an ErrorReported token, and maybe make it unconstructible except by the diagnostic reporting machinery?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, that'd be cute. :)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Are we tracking this anywhere?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't think so.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Created #69426.

@yodaldevoid

Copy link
Copy Markdown
Contributor

Is this PR waiting on anything specific?

@varkor

Copy link
Copy Markdown
ContributorAuthor

@yodaldevoid: a second reviewer's opinion on the PR.

@bors

bors commented Feb 6, 2020

Copy link
Copy Markdown
Collaborator

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

@nikomatsakisnikomatsakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't follow 100% of what's going on here, but it overall seems pretty reasonable -- except that I think the new errors are kind of confusingly worded. Am I missing something?

Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment threadsrc/librustc_typeck/astconv.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why does this error go away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Previously if we encountered an incorrect generic argument, we would just try to skip it and continue going: https://github.com/rust-lang/rust/pull/68434/files#diff-1b4d50b82a87f1031cd5f99b64123de7L578. Now we just stop checking the remaining arguments, because there's a high likelihood the remaining arguments are invalid and we'd just spit out lots of errors that aren't particularly helpful.

Comment threadsrc/librustc_typeck/astconv.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Annoying, it'd be nice to change this to a custom enum -- but obviously pre-existing for this PR.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I find this error quite a bit more confusing than the old one. It suggests to me that the fix is to change T into a lifetime -- but that won't help.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not quite sure what the "mental model" is that we are trying to convey to users.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm convinced we should be suggesting the correct order in all of these cases.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The reason I changed this is because there isn't really a restriction on the order of generic arguments: the restriction is on generic parameters, but generic arguments must match the order of generic parameters. The fact that lifetime arguments must precede type arguments is a side-effect of the parameter order. I'll try tweaking the wording to improve this. As @estebank says, ideally we'd suggest the correct order, but I'd like to get this merged sooner rather than later, as I don't know how much time I'll have for more elaborate changes now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, I see. I still find the message more confusing than the old one, but perhaps I now better understand what this PR is aiming for.

Comment threadsrc/librustc_typeck/astconv.rs Outdated
Comment on lines 332 to 337

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, that'd be cute. :)

Comment threadsrc/librustc_error_codes/error_codes/E0747.md Outdated
Comment threadsrc/test/ui/const-generics/const-param-after-const-literal-arg.rs Outdated
Comment threadsrc/test/ui/const-generics/const-param-before-other-params.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm convinced we should be suggesting the correct order in all of these cases.

@varkor
varkorforce-pushed the astconv-mismatch-error branch from 332b61f to b0b88e7CompareFebruary 22, 2020 02:35
@varkor

varkor commented Feb 22, 2020

Copy link
Copy Markdown
ContributorAuthor

@nikomatsakis: I've addressed the code comments, and also added a note to the error messages making them as descriptive as the previous ones. I'll open an issue for suggesting the correct order of all provided arguments: I'd rather split it out into a separate PR than conflate it with this one.

@varkorvarkor added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 22, 2020
@rust-highfive

This comment has been minimized.

@nikomatsakis

Copy link
Copy Markdown
Contributor

@bors r+

thanks, @varkor

@bors

bors commented Feb 25, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit bead79e has been approved by nikomatsakis

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2020
@bors

bors commented Feb 27, 2020

Copy link
Copy Markdown
Collaborator

⌛ Testing commit bead79e with merge 6d69cab...

@bors

bors commented Feb 27, 2020

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-azure
Approved by: nikomatsakis
Pushing 6d69cab to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Feb 27, 2020
@bors
bors merged commit 6d69cab into rust-lang:masterFeb 27, 2020
@rust-highfive

Copy link
Copy Markdown
Contributor

📣 Toolstate changed by #68434!

Tested on commit 6d69cab.
Direct link to PR: #68434

🎉 book on windows: test-fail → test-pass (cc @carols10cents@steveklabnik).

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-const_generics`#![feature(const_generics)]`merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Const generic parameters are allowed in the wrong position (causing ICEs). Cannot use generic const argument without {}, despite no conflict

10 participants

@varkor@rust-highfive@yodaldevoid@bors@nikomatsakis@eddyb@Centril@estebank@petrochenkov@JohnTitor