-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Move generic arg/param validation to create_substs_for_generic_args
to resolve various const generics issues
#68434
Conversation
Some changes occurred in diagnostic error codes |
9b4b01e
to
d2a750c
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.
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)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1174b94
to
afad00d
Compare
src/librustc_typeck/astconv.rs
Outdated
arg.descr(), | ||
kind, | ||
) | ||
.emit(); |
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.
No reordering suggestion for this case?
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.
I'd rather leave this PR for the bug-fixes and follow up with the diagnostics improvements. That's a good follow up, though.
r? @nikomatsakis for a second opinion (#68434 (review)) |
src/librustc_typeck/astconv.rs
Outdated
explicit_lifetimes = Err(GenericArgCountMismatch(Some(ErrorReported))); | ||
let mut err = tcx.sess.struct_span_err(span, msg); | ||
err.span_note(span_late, note); | ||
err.emit(); |
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.
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, that'd be cute. :)
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.
Are we tracking this anywhere?
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.
Don't think so.
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.
Created #69426.
Is this PR waiting on anything specific? |
@yodaldevoid: a second reviewer's opinion on the PR. |
☔ The latest upstream changes (presumably #68893) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
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?
@@ -4,7 +4,6 @@ struct Bar<'a>(&'a ()); | |||
|
|||
fn main() { | |||
Foo::<'static, 'static, ()>(&0); //~ ERROR wrong number of lifetime arguments |
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.
why does this error go away?
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.
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.
(Some(generic_args), infer_args) | ||
} else { | ||
// The last component of this tuple is unimportant. | ||
(None, false) |
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.
(Annoying, it'd be nice to change this to a custom enum -- but obviously pre-existing for this PR.)
@@ -74,29 +74,30 @@ LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, ' | |||
| | this associated type binding should be moved after the generic parameters | |||
| this associated type binding should be moved after the generic parameters | |||
|
|||
error: lifetime arguments must be declared prior to type arguments | |||
--> $DIR/suggest-move-types.rs:34:46 | |||
error[E0747]: type provided when a lifetime was expected |
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.
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.
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.
I'm not quite sure what the "mental model" is that we are trying to convey to users.
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.
I'm convinced we should be suggesting the correct order in all of these cases.
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.
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.
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.
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.
src/librustc_typeck/astconv.rs
Outdated
explicit_lifetimes = Err(GenericArgCountMismatch(Some(ErrorReported))); | ||
let mut err = tcx.sess.struct_span_err(span, msg); | ||
err.span_note(span_late, note); | ||
err.emit(); |
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, that'd be cute. :)
src/test/ui/const-generics/const-param-after-const-literal-arg.rs
Outdated
Show resolved
Hide resolved
@@ -74,29 +74,30 @@ LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, ' | |||
| | this associated type binding should be moved after the generic parameters | |||
| this associated type binding should be moved after the generic parameters | |||
|
|||
error: lifetime arguments must be declared prior to type arguments | |||
--> $DIR/suggest-move-types.rs:34:46 | |||
error[E0747]: type provided when a lifetime was expected |
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.
I'm convinced we should be suggesting the correct order in all of these cases.
332b61f
to
b0b88e7
Compare
@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. |
This comment has been minimized.
This comment has been minimized.
b0b88e7
to
bead79e
Compare
📌 Commit bead79e has been approved by |
☀️ Test successful - checks-azure |
📣 Toolstate changed by #68434! Tested on commit 6d69cab. 🎉 book on windows: test-fail → test-pass (cc @carols10cents @steveklabnik). |
Tested on commit rust-lang/rust@6d69cab. Direct link to PR: <rust-lang/rust#68434> 🎉 book on windows: test-fail → test-pass (cc @carols10cents @steveklabnik).
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