Skip to content

Remove kw::Empty uses in rustdoc #139846

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

Merged
merged 5 commits into from
Apr 17, 2025
Merged

Conversation

nnethercote
Copy link
Contributor

Helps with #137978.

r? @GuillaumeGomez

Some `unwrap` uses here, but they are on paths involving item kinds that
are known to have an identifier.
Again by using `Option<Symbol>` to represent "no name".
`sym::dummy` also appears to work.
@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Apr 15, 2025
@nnethercote
Copy link
Contributor Author

Best reviewed one commit at a time.

@nnethercote
Copy link
Contributor Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 15, 2025
Remove `kw::Empty` uses in rustdoc

Helps with rust-lang#137978.

r? `@GuillaumeGomez`
@bors
Copy link
Collaborator

bors commented Apr 15, 2025

⌛ Trying commit 65942d1 with merge 54da544...

@bors
Copy link
Collaborator

bors commented Apr 15, 2025

☀️ Try build successful - checks-actions
Build commit: 54da544 (54da5441ec9c66bd9355d508aa708c45376d0bc0)

Comment on lines 2794 to 2798
let mut name = if renamed.is_some() {
renamed
} else {
cx.tcx.hir_opt_name(item.hir_id())
};
Copy link
Member

@GuillaumeGomez GuillaumeGomez Apr 15, 2025

Choose a reason for hiding this comment

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

No need to keep an Option around, right? If so:

Suggested change
let mut name = if renamed.is_some() {
renamed
} else {
cx.tcx.hir_opt_name(item.hir_id())
};
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir_opt_name(item.hir_id()).unwrap());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't work because he hir_opt_name can return None. So it must be an Option, and then lower down we only unwrap it for certain item kinds that always have an ident.

Copy link
Member

Choose a reason for hiding this comment

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

Right. I have some ideas on how to improve it but for now let's move on.

@GuillaumeGomez
Copy link
Member

Thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 16, 2025

📌 Commit 65942d1 has been approved by GuillaumeGomez

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 Apr 16, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 16, 2025
…illaumeGomez

Remove `kw::Empty` uses in rustdoc

Helps with rust-lang#137978.

r? `@GuillaumeGomez`
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#139084 (hygiene: Rename semi-transparent to semi-opaque)
 - rust-lang#139236 (Use a session counter to make anon dep nodes unique)
 - rust-lang#139650 (Fix `register_group_alias` for tools)
 - rust-lang#139770 (Rename `LifetimeName` as `LifetimeKind`.)
 - rust-lang#139846 (Remove `kw::Empty` uses in rustdoc)
 - rust-lang#139891 (Include optional dso_local marker for functions in `enum-match.rs`)
 - rust-lang#139908 (parser: Remove old diagnostic notes for type ascription syntax)
 - rust-lang#139917 (fix for multiple `#[repr(align(N))]` on functions)

Failed merges:

 - rust-lang#139615 (Remove `name_or_empty`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fb3338c into rust-lang:master Apr 17, 2025
7 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 17, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2025
Rollup merge of rust-lang#139846 - nnethercote:kw-Empty-rustdoc, r=GuillaumeGomez

Remove `kw::Empty` uses in rustdoc

Helps with rust-lang#137978.

r? ``@GuillaumeGomez``
@nnethercote nnethercote deleted the kw-Empty-rustdoc branch April 17, 2025 05:27
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 17, 2025
…ng, r=GuillaumeGomez

rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)

**(0)** PR rust-lang#136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional.

**(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two:

```rs
pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32);
unsafe extern "C" { pub fn foreign_fn(_: i32); }

// Since 1.86 the fns above gets mis-rendered as:
pub fn assoc_fn(: i32) // <-- BUTCHERED
pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED
```

**(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of rust-lang#44306 I once fixed in PR rust-lang#103885.

**(1)** Lastly, PR rust-lang#139035 introduced an ICE triggered by the following input file:

```rs
trait Trait { fn anon(()) {} } // internal error: entered unreachable code
```

---

This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible.

~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC rust-lang#137978.~~ Independently done in PR rust-lang#139846 a day prior.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 17, 2025
…ng, r=GuillaumeGomez

rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)

**(0)** PR rust-lang#136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional.

**(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two:

```rs
pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32);
unsafe extern "C" { pub fn foreign_fn(_: i32); }

// Since 1.86 the fns above gets mis-rendered as:
pub fn assoc_fn(: i32) // <-- BUTCHERED
pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED
```

**(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of rust-lang#44306 I once fixed in PR rust-lang#103885.

**(1)** Lastly, PR rust-lang#139035 introduced an ICE triggered by the following input file:

```rs
trait Trait { fn anon(()) {} } // internal error: entered unreachable code
```

---

This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible.

~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC rust-lang#137978.~~ Independently done in PR rust-lang#139846 a day prior.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 18, 2025
…ng, r=GuillaumeGomez

rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)

**(0)** PR rust-lang#136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional.

**(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two:

```rs
pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32);
unsafe extern "C" { pub fn foreign_fn(_: i32); }

// Since 1.86 the fns above gets mis-rendered as:
pub fn assoc_fn(: i32) // <-- BUTCHERED
pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED
```

**(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of rust-lang#44306 I once fixed in PR rust-lang#103885.

**(1)** Lastly, PR rust-lang#139035 introduced an ICE triggered by the following input file:

```rs
trait Trait { fn anon(()) {} } // internal error: entered unreachable code
```

---

This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible.

~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC rust-lang#137978.~~ Independently done in PR rust-lang#139846 a day prior.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2025
Rollup merge of rust-lang#139913 - fmease:rustdoc-fix-fn-param-handling, r=GuillaumeGomez

rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)

**(0)** PR rust-lang#136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional.

**(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two:

```rs
pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32);
unsafe extern "C" { pub fn foreign_fn(_: i32); }

// Since 1.86 the fns above gets mis-rendered as:
pub fn assoc_fn(: i32) // <-- BUTCHERED
pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED
```

**(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of rust-lang#44306 I once fixed in PR rust-lang#103885.

**(1)** Lastly, PR rust-lang#139035 introduced an ICE triggered by the following input file:

```rs
trait Trait { fn anon(()) {} } // internal error: entered unreachable code
```

---

This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible.

~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC rust-lang#137978.~~ Independently done in PR rust-lang#139846 a day prior.
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 19, 2025
…_renamed_item, r=nnethercote

Improve `clean_maybe_renamed_item` function code a bit

Follow-up of rust-lang#139846.

This is what I tried to say in there: the `name` variable can be unwrapped in most cases so better do it directly once and for all if possible and move the cases where it's not possible above.

r? `@nnethercote`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
Rollup merge of rust-lang#140008 - GuillaumeGomez:cleanup-clean_maybe_renamed_item, r=nnethercote

Improve `clean_maybe_renamed_item` function code a bit

Follow-up of rust-lang#139846.

This is what I tried to say in there: the `name` variable can be unwrapped in most cases so better do it directly once and for all if possible and move the cases where it's not possible above.

r? `@nnethercote`
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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants