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

Add field@ and variant@ doc-link disambiguators #130587

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

coolreader18
Copy link
Contributor

@coolreader18 coolreader18 commented Sep 19, 2024

I'm not sure if this is big enough to need an fcp or not, but this is something I found missing when trying to refer to a field in macro-generated docs, not knowing if a method might be defined as well. Obviously, there are definitely other uses.

In the case where it's not disambiguated, methods (and I suppose other associated items in the value namespace) still take priority, which @jyn514 said was an oversight but I think is probably the desired behavior 99% of the time anyway - shadowing a field with an accessor method is a very common pattern. If fields and methods with the same name started conflicting, it would be a breaking change. Though, to quote them:

jyn: maybe you can break this only if both [the method and the field] are public
jyn: rustc has some future-incompat warning level
jyn: that gets through -A warnings and --cap-lints from cargo

That'd be out of scope of this PR, though.

Fixes #80283

@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2024

r? @notriddle

rustbot has assigned @notriddle.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 19, 2024
@jyn514
Copy link
Member

jyn514 commented Sep 19, 2024

cc #80283

Comment on lines +1588 to +1589
// for purposes of link resolution, fields are in the value namespace.
Self::Kind(DefKind::Field) => ValueNS,
Copy link
Member

Choose a reason for hiding this comment

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

i'm confused, i thought you were going to remove this? is the problem that DefKind::ns is defined in rustc so you can't modify it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was, but it turns out it didn't make sense to move the disambiguator == Field so far up and out - that would mean putting it in resolve_disambiguator(), while it makes much more sense (and is easier to keep existing field-last resolution behavior) if it just gets considered to be in the value ns and fails to resolve to anything before getting picked up in the special-case in resolve_associated_item().

@jyn514
Copy link
Member

jyn514 commented Sep 19, 2024

jyn: maybe you can break this only if both [the method and the field] are public

this would also need to consider the story around --document-private-items; in general that flag is kinda broken for intra-doc links because rustc_resolve won't let you see private items outside the module you're resolving from under any circumstance, but maybe there's some compromise that will work 80% of the time.

@notriddle
Copy link
Contributor

In general, this PR's feature design seems fine. If it passes a crater run, I wouldn't mind making it insta-stable.

In the case where it's not disambiguated, methods (and I suppose other associated items in the value namespace) still take priority

Thanks to this choice, I don't think this should break anything, and I don't think it makes the --document-private-items situation any worse than it already is.

@jyn514
Copy link
Member

jyn514 commented Sep 19, 2024

oh tbc this pr doesn't break anything, i would be shocked if crater turned up anything, @ isn't valid outside disambiguators. i was just talking about if you want to error when methods and fields need to be disambiguated

@rust-log-analyzer

This comment has been minimized.

@coolreader18
Copy link
Contributor Author

Ah, oops, blessed the ui tests before finishing the implementation lol

@coolreader18
Copy link
Contributor Author

coolreader18 commented Sep 20, 2024

ah wait nevermind. i just broke it forgot to bless other ui tests

@notriddle
Copy link
Contributor

i was just talking about if you want to error when methods and fields need to be disambiguated

Rustdoc already has field-last resolution behavior. This PR doesn't make that one any worse than it already is, either.

If we want to make the disambiguator required later, this PR doesn't seem to prevent that.

@coolreader18
Copy link
Contributor Author

Bump on this review?

@notriddle
Copy link
Contributor

Good catch. I wanted to know if anyone else objected, and it doesn't seem they do.

@bors r=notriddle,jyn514

@bors
Copy link
Contributor

bors commented Oct 1, 2024

📌 Commit e91e015 has been approved by notriddle,jyn514

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 Oct 1, 2024
@bors
Copy link
Contributor

bors commented Oct 1, 2024

⌛ Testing commit e91e015 with merge f79ef02...

@bors
Copy link
Contributor

bors commented Oct 1, 2024

☀️ Test successful - checks-actions
Approved by: notriddle,jyn514
Pushing f79ef02 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 1, 2024
@bors bors merged commit f79ef02 into rust-lang:master Oct 1, 2024
7 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Oct 1, 2024
@coolreader18 coolreader18 deleted the field-variant-doclink-disambig branch October 1, 2024 04:33
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f79ef02): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

Results (primary -1.5%, secondary -3.1%)

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.5% [-1.5%, -1.5%] 1
Improvements ✅
(secondary)
-3.1% [-3.4%, -2.8%] 2
All ❌✅ (primary) -1.5% [-1.5%, -1.5%] 1

Cycles

Results (secondary 3.8%)

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)
- - 0
Regressions ❌
(secondary)
3.8% [3.8%, 3.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 770.872s -> 771.378s (0.07%)
Artifact size: 341.44 MiB -> 341.41 MiB (-0.01%)

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-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an intra-doc link disambiguator for fields
7 participants