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

Resolve visibility paths as modules not as types. #109348

Merged
merged 2 commits into from
Aug 5, 2023

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Mar 19, 2023

Asking for a resolution with opt_ns = Some(TypeNS) allows path resolution to look for type-relative paths, leaving unresolved segments behind. However, for visibility paths we really need to look for a module, so we need to pass opt_ns = None.

Fixes #109146

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 19, 2023
@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

CI is failing.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 19, 2023
@est31
Copy link
Member

est31 commented Mar 19, 2023

is there a test for what happens if the path is valid? newy is an invalid path but theoretically there could be a bug where if the path is valid but points to a struct or a function it accepts that.

@cjgillot
Copy link
Contributor Author

cjgillot commented Aug 4, 2023

@est31 there are additional tests in tests/ui/resolve/resolve-bad-visibility.rs

One surprising consequence of this PR is a different diagnostic between structs and enums. Enums are modules for resolve, so trigger E0577, while structs and unions are not, triggering E0433.

@rustbot ready

@rustbot rustbot 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 Aug 4, 2023
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 5, 2023

📌 Commit 69ea85d has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors 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 Aug 5, 2023
@petrochenkov
Copy link
Contributor

It fixes the ICE, but generally I don't think this is a right thing to do.

Paths in trait contexts for example, also do not support unresolved segments, but do not result in ICEs because they are only resolved during late resolution and late resolution uses enum PathSource and its methods like defer_to_typeck and is_expected instead of bare Namespace.

Right now None in resolve_path means an import prefix specifically, i.e. TypeNs + DefKind::{Mod,Enum,Trait} + defer_ty_typeck -> false restrictions.
You can see the consequences of that in tests/ui/use/use-self-type.stderr where the error message talks about imports now.

Ideally resolve_path should use something like PathSource too.
And resolve_visibility should use it as well, but with slightly different restrictions (TypeNs + DefKind::Mod + defer_ty_typeck -> false).

@bors
Copy link
Contributor

bors commented Aug 5, 2023

⌛ Testing commit 69ea85d with merge 28b6607...

@bors
Copy link
Contributor

bors commented Aug 5, 2023

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 28b6607 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 5, 2023
@bors bors merged commit 28b6607 into rust-lang:master Aug 5, 2023
12 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Aug 5, 2023
@cjgillot cjgillot deleted the issue-109146 branch August 5, 2023 14:41
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (28b6607): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-0.3%, -0.3%] 1

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.7% [2.7%, 2.7%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.2% [-1.2%, -1.2%] 1
All ❌✅ (primary) 2.7% [2.7%, 2.7%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 648.817s -> 649.629s (0.13%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: unexpected unresolved segments
7 participants