Skip to content

Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler #80845

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 6, 2021

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jan 9, 2021

It was surprisingly difficult to make this change, mostly because of two issues:

  • We now store the ExternCrate name in the parent struct (clean::Item), which forced me to modify the json conversion code a bit more than expected.
  • The second problem was that, since we now have a Some(name), it was trying to render it, ending up in a panic because we ended up in a unreachable statement. The solution was simply to add !item.is_extern_crate() in formats::renderer before calling cx.item(item, &cache)?;.

I'll continue to replace all the clean::ItemKind variants one by one until it looks exactly like hir::ItemKind. Then we'll simply discard the rustdoc type. Once this done, we'll be able to discard clean::Item too to use hir::Item.

r? @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 9, 2021
@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 9, 2021
@bors
Copy link
Collaborator

bors commented Jan 14, 2021

☔ The latest upstream changes (presumably #80802) made this pull request unmergeable. Please resolve the merge conflicts.

@camelid camelid added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 1, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2021
…ields, r=ollie27

Remove some function fields

Same kind as rust-lang#80845.

This PR removes the `all_types` and `ret_types` from the `clean::Function` type.

Another change that I had to do was implementing the `From` trait to be able to convert `hir::def::DefKind` into `clean::TypeKind` without requiring `DocContext` (and so I updated the `clean` method so that it's taken into account).

The last two commits improve a bit the `get_real_types` function and the `Type::generics` method.

r? `@jyn514`
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.

I like the idea but the implementation needs some work.

@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 15, 2021
@GuillaumeGomez GuillaumeGomez force-pushed the item-kind-transition branch 2 times, most recently from 0164171 to d5515ad Compare February 15, 2021 09:06
@GuillaumeGomez
Copy link
Member Author

Updated.

@GuillaumeGomez
Copy link
Member Author

Ping @jyn514

@GuillaumeGomez GuillaumeGomez force-pushed the item-kind-transition branch 2 times, most recently from c547676 to 4c70372 Compare February 23, 2021 18:56
@GuillaumeGomez
Copy link
Member Author

I'll go forward with this then! If you want the test back, don't hesitate to ask (either before after it's merged).

@bors: r=jyn514

@bors
Copy link
Collaborator

bors commented Feb 26, 2021

📌 Commit 4c70372 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 26, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 26, 2021
…, r=jyn514

Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler

It was surprisingly difficult to make this change, mostly because of two issues:

* We now store the `ExternCrate` name in the parent struct (`clean::Item`), which forced me to modify the json conversion code a bit more than expected.
* The second problem was that, since we now have a `Some(name)`, it was trying to render it, ending up in a panic because we ended up in a `unreachable` statement. The solution was simply to add `!item.is_extern_crate()` in `formats::renderer` before calling `cx.item(item, &cache)?;`.

I'll continue to replace all the `clean::ItemKind` variants one by one until it looks exactly like `hir::ItemKind`. Then we'll simply discard the rustdoc type. Once this done, we'll be able to discard `clean::Item` too to use `hir::Item`.

r? `@jyn514`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 26, 2021
…, r=jyn514

Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler

It was surprisingly difficult to make this change, mostly because of two issues:

* We now store the `ExternCrate` name in the parent struct (`clean::Item`), which forced me to modify the json conversion code a bit more than expected.
* The second problem was that, since we now have a `Some(name)`, it was trying to render it, ending up in a panic because we ended up in a `unreachable` statement. The solution was simply to add `!item.is_extern_crate()` in `formats::renderer` before calling `cx.item(item, &cache)?;`.

I'll continue to replace all the `clean::ItemKind` variants one by one until it looks exactly like `hir::ItemKind`. Then we'll simply discard the rustdoc type. Once this done, we'll be able to discard `clean::Item` too to use `hir::Item`.

r? ``@jyn514``
@jyn514
Copy link
Member

jyn514 commented Feb 26, 2021

@bors r-

You didn't fix the panic:

This will panic if you pass a StrippedItem(ExternCrateItem).

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 26, 2021
@GuillaumeGomez
Copy link
Member Author

Good catch, thanks!

@GuillaumeGomez
Copy link
Member Author

@jyn514: I went for what you suggested: I now pass the name argument to the function so we can now handle ExternCrateItem into it directly.

@bors
Copy link
Collaborator

bors commented Mar 5, 2021

☔ The latest upstream changes (presumably #82777) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez
Copy link
Member Author

Fixed the issue, so let's go!

@bors: r=jyn514

@bors
Copy link
Collaborator

bors commented Mar 5, 2021

📌 Commit 286a357 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 Mar 5, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Mar 5, 2021
…, r=jyn514

Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler

It was surprisingly difficult to make this change, mostly because of two issues:

* We now store the `ExternCrate` name in the parent struct (`clean::Item`), which forced me to modify the json conversion code a bit more than expected.
* The second problem was that, since we now have a `Some(name)`, it was trying to render it, ending up in a panic because we ended up in a `unreachable` statement. The solution was simply to add `!item.is_extern_crate()` in `formats::renderer` before calling `cx.item(item, &cache)?;`.

I'll continue to replace all the `clean::ItemKind` variants one by one until it looks exactly like `hir::ItemKind`. Then we'll simply discard the rustdoc type. Once this done, we'll be able to discard `clean::Item` too to use `hir::Item`.

r? `@jyn514`
Comment on lines +188 to +191
ExternCrateItem { ref src } => ItemEnum::ExternCrateItem {
name: name.as_ref().unwrap().to_string(),
rename: src.map(|x| x.to_string()),
},
Copy link
Member

@jyn514 jyn514 Mar 5, 2021

Choose a reason for hiding this comment

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

Yup, this is what I was expecting, thanks :)

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2021
…laumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#80845 (Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler)
 - rust-lang#82708 (Warn on `#![doc(test(...))]` on items other than the crate root and use future incompatible lint)
 - rust-lang#82714 (Detect match arm body without braces)
 - rust-lang#82736 (Bump optimization from mir_opt_level 2 to 3 and 3 to 4 and make "release" be level 2 by default)
 - rust-lang#82782 (Make rustc shim's verbose output include crate_name being compiled.)
 - rust-lang#82797 (Update tests names to start with `issue-`)
 - rust-lang#82809 (rustdoc: Use substrings instead of split to grab enum variant paths)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 92861c7 into rust-lang:master Mar 6, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 6, 2021
@GuillaumeGomez GuillaumeGomez deleted the item-kind-transition branch March 6, 2021 14:01
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. 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