Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
typeck: always expose repeat count
AnonConst
s' parent ingenerics_of
. #70452typeck: always expose repeat count
AnonConst
s' parent ingenerics_of
. #70452Changes from all commits
2bbc33a
38d3834
5ebd300
ad1617b
8989029
8bb7b7b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 think we should improve the wording of the error. In my eyes I would prefer something along the lines of
preferably with a link to documentation, tracking issue or its own error code so that we explain why we don't support it yet and when it might be done.
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 error is indeed misleading, because what you're suggesting isn't what the error means.
The error is trying to say that evaluating the constant expression may only succeed for some "values" of the generic parameter.
The missing piece of the puzzle is a way to put that expression in a
where
clause to force the caller to evaluate it, ruling out post-monomorphization errors (#68436).Note that expressions using generics can still evaluate just fine while remaining polymorphic.
cc @varkor
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 agree that this diagnostic could be improved, especially as it was misinterpreted. How about something like:
This is a bit long, though this sort of thing hopefully gets the intention across better.
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.
"constant expression may not depend on a generic parameter"? (emphasis mine)
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.
(Let's not make promises. ^^)
I think we tend to prefer cannot over may not. The former is more definitive.
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.
Maybe
is not allowed to depend
, which makes clear whether the constant expression is supposed to or not.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.
But it can depend on generic parameters, the only problem is we have no guarantor for it evaluating successfully.
So perhaps a better phrasing for the error itself might be "cannot prove/determine/guarantee/etc. that constant expression will evaluate successfully" and then we can search its
Substs
for type/const parameters and list them out to give the more helpful information.We should also link
https://github.com/rust-lang/rust/issues/68436
, in some sort of help messaging along the lines of "there is no way to currently write the necessarywhere
clause, watch this space".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.
Well, I suppose I meant that it could not depend on an "unrestricted" generic parameter (or "guaranteed well-formed"). Yes, it's quite difficult to use language that's both intuitive, and doesn't take up a lot of space. Linking to the issue would be good.
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.
+1 on linking to that issue. I would say I've come around to the position that reducing verbosity is a goal, but much lower than correct understandable wording.
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.
Opened #71142 for this subthread.