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

[rustdoc-json] Make header a vec of modifiers, and FunctionPointer consistent #81891

Merged
merged 5 commits into from
Feb 15, 2021

Conversation

CraftSpider
Copy link
Contributor

@CraftSpider CraftSpider commented Feb 8, 2021

Bumps version number and adds tests, this is a breaking change. I can split this into two (is_unsafe -> header and header: Vec<Modifiers>) if desired.

Rationale: Modifiers are individual notes on a function, it makes more sense for them to be a list of an independent enum over a String which is inconsistently exposing the HIR representation (prefix_str vs custom literals).
Function pointers currently only support unsafe, but there has been talk on and off about allowing them to also support const, and this makes handling their modifiers consistent with handling those of a function, allowing better shared code.

@rustbot modify labels: +A-rustdoc-json +T-rustdoc
CC: @HeroicKatora
r? @jyn514

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 8, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2021
@@ -108,7 +108,7 @@ def check_type(ty):
elif ty["kind"] == "function_pointer":
for param in ty["inner"]["generic_params"]:
check_generic_param(param)
check_decl(ty["inner"]["inner"])
check_decl(ty["inner"]["decl"])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previous implementation looks wrong, other call(s) of check_decl are ["inner"]["decl"], and it doesn't look like there should ever be an ["inner"]["inner"] in the output.

@@ -281,19 +281,28 @@ pub enum StructType {
Unit,
}

#[non_exhaustive]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other things may be added as modifiers in the language, or default on methods could be interpreted as a modifier. This way things can be added without it being breaking

Copy link
Contributor

@HeroicKatora HeroicKatora Feb 9, 2021

Choose a reason for hiding this comment

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

One detail with the addition of new variants would be that the order is not quite arbitrary. The grammar apppears to be currently:

AsyncConstQualifiers? unsafe? (extern Abi?)?

So while technically permitting the forward compatible addition of new qualifiers, a pretty-printer might still be confused by their order and not produce syntactically valid method/type declarations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. Joshua said that we should use sets over vecs specifically so order is not guaranteed as part of the contract. I think that plus non_exhaustive means it's at least fairly obvious that we're not guaranteeing anything (all matches will require a _ part), the only issue is if people think we're implying something about the syntax.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a 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 to have @HeroicKatora to take a look if they have time.

src/rustdoc-json-types/lib.rs Outdated Show resolved Hide resolved
src/test/rustdoc-json/fns/header.rs Show resolved Hide resolved
src/rustdoc-json-types/lib.rs Show resolved Hide resolved
@jyn514 jyn514 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 Feb 8, 2021
@CraftSpider
Copy link
Contributor Author

Note: I considered and personally rejected instead using a struct with boolean flags. There were two main reasons:

  • More objectively: We lose the benefits of non_exhaustive, people can easily think they handle all possibilities
  • More subjectively: It feels like it implies every modifier can happen on every target, is_async: false on an fn pointer for example. Vec feels structurally more accurate.

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@HeroicKatora HeroicKatora left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for explaining the connection between using a set and ordering.

@jyn514
Copy link
Member

jyn514 commented Feb 13, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Feb 13, 2021

📌 Commit be4ea06 has been approved by jyn514

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 13, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#80523 (#[doc(inline)] sym_generated)
 - rust-lang#80920 (Visit more targets when validating attributes)
 - rust-lang#81720 (Updated smallvec version due to RUSTSEC-2021-0003)
 - rust-lang#81891 ([rustdoc-json] Make `header` a vec of modifiers, and FunctionPointer consistent)
 - rust-lang#81912 (Implement the precise analysis pass for lint `disjoint_capture_drop_reorder`)
 - rust-lang#81914 (Fixing bad suggestion for `_` in `const` type when a function rust-lang#81885)
 - rust-lang#81919 (BTreeMap: fix internal comments)
 - rust-lang#81927 (Add a regression test for rust-lang#32498)
 - rust-lang#81965 (Fix MIR pretty printer for non-local DefIds)
 - rust-lang#82029 (Use debug log level for developer oriented logs)
 - rust-lang#82056 (fix ice (rust-lang#82032))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 641c378 into rust-lang:master Feb 15, 2021
@rustbot rustbot added this to the 1.52.0 milestone Feb 15, 2021
@CraftSpider CraftSpider deleted the fn-header branch February 23, 2022 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend 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.

7 participants