-
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
Generic arg disambiguation #66104
Generic arg disambiguation #66104
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
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.
Mostly LGTM, I'm only worried about the "value namespace" check, maybe @petrochenkov has some ideas there?
This will probably have to wait until the weekend. |
@@ -86,7 +64,19 @@ LL | use foo2::Bar; | |||
LL | use foo3::Bar; | |||
| | |||
|
|||
error: aborting due to 4 previous errors | |||
error[E0107]: wrong number of const arguments: expected 0, found 1 |
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.
This is interesting fallout. I imagine we should be able to special-case this sort of error to get back the old ones, though I'm not sure how much work that would be.
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.
As far as I remember, the fix may be non-trivial and error-prone, so it's better to make an issue and fix it in a separate PR.
src/librustc/hir/lowering.rs
Outdated
DefPathData::AnonConst, | ||
ExpnId::root(), | ||
ty.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.
Hmm, this distinction between types and consts (consts requiring an extra def path node) is something I didn't expect.
@eddyb, is it possible that creating this node during lowering is too late?
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? But if you limit this to a really simple path with no generic args, there shouldn't be any children defs nested inside so making a leaf AnonConst
should be fine.
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.
@yodaldevoid
Could you bring back the "no generic args" restriction then?
(It should rarely be relevant in practice.)
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.
It is done.
It should be noted that this does mean that we cannot remove all of the braces from the const-generics tests, specifically in "fn-const-param-infer.rs" which uses type params all over the place. How hard/wise would it be to iterate through the children of the new def to create defs for them if needed?
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.
How hard/wise would it be to iterate through the children of the new def to create defs for them if needed?
I'm not sure.
First, we need to at least construct a test where things would break due to def paths not being constructed properly.
This is a material for another PR, IMO.
We get, like, 90% of benefits from disambiguating simple identifiers, so it would be nice to land this PR sooner.
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 already have such a test in "fn-const-param-infer.rs", but I agree that is something for a future PR.
@@ -86,7 +64,19 @@ LL | use foo2::Bar; | |||
LL | use foo3::Bar; | |||
| | |||
|
|||
error: aborting due to 4 previous errors | |||
error[E0107]: wrong number of const arguments: expected 0, found 1 |
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.
As far as I remember, the fix may be non-trivial and error-prone, so it's better to make an issue and fix it in a separate PR.
I believe I have addressed all comments given so far. There is one comment that I would like to have resolved before we move forward with these changes. |
We need to disambiguate in favor of types, but for multi-segment paths we cannot do that until type checking in general case (due to associated types). We can do some "figure disambiguation" for multi-segment paths to accept some cases, but that complicates the rules, and other alternatives like delaying the disambiguation until the generic argument substitution is really required (in type checking) may be preferable. |
b030eff
to
512f344
Compare
Braces were left in cases where generic args were in the generic const paths.
The error messages of the two tests effected degraded in quality. The errors no longer suggest types in other modules as they now assume that the arguments are const args, not type args.
ae90ff5
to
0207a15
Compare
@bors r+ |
📌 Commit 0207a15 has been approved by |
⌛ Testing commit 0207a15 with merge 0a431b8e96bfc211dd2247e3cd56105e589b13a2... |
Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
💔 Test failed - checks-azure |
@bors retry |
…ochenkov Generic arg disambiguation Using the tactic suggested by @petrochenkov in #60804 (comment) and on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/generic.20argument.20disambiguation), this change checks type arguments to see if they are really incorrectly-parsed const arguments. it should be noted that `segments.len() == 1 && segments[0].arg.is_none()` was reduced to `segments.len() == 1` as suggested by @petrochenkov in [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/generic.20argument.20disambiguation/near/177848002). This change allowed a few more existing tests to have their braces removed. There are a couple of "problems" with these changes that I should note. First, there was a regression in the error messages found in "src/test/ui/privacy-ns1.rs" and "src/test/ui/privacy-ns1.rs". Second, some braces were unable to be removed from "src/test/ui/const-generics/fn-const-param-infer.rs". Those on line 24 caused the statement to stop equating when removed, and those on line 20 cause a statement that should not equate to produce no error when removed. I have not looked further into any of these issues yet, though I would be willing to look into them before landing this. I simply wanted to get some other eyes on this before going further. Fixes #60804 cc @varkor @jplatte
☀️ Test successful - checks-azure |
📣 Toolstate changed by #66104! Tested on commit f50d6ea. 🎉 rustc-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra). |
Tested on commit rust-lang/rust@f50d6ea. Direct link to PR: <rust-lang/rust#66104> 🎉 rustc-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).
Using the tactic suggested by @petrochenkov in #60804 (comment) and on zulip, this change checks type arguments to see if they are really incorrectly-parsed const arguments.
it should be noted that
segments.len() == 1 && segments[0].arg.is_none()
was reduced tosegments.len() == 1
as suggested by @petrochenkov in zulip. This change allowed a few more existing tests to have their braces removed.There are a couple of "problems" with these changes that I should note. First, there was a regression in the error messages found in "src/test/ui/privacy-ns1.rs" and "src/test/ui/privacy-ns1.rs". Second, some braces were unable to be removed from "src/test/ui/const-generics/fn-const-param-infer.rs". Those on line 24 caused the statement to stop equating when removed, and those on line 20 cause a statement that should not equate to produce no error when removed.
I have not looked further into any of these issues yet, though I would be willing to look into them before landing this. I simply wanted to get some other eyes on this before going further.
Fixes #60804
cc @varkor @jplatte