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: clean up a bunch of ts-expected-error declarations in main #136263

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

notriddle
Copy link
Contributor

This mostly consists of handling potentially-null input and adding more global functions to the list of globals.

Follow-up for #136161

@rustbot
Copy link
Collaborator

rustbot commented Jan 29, 2025

r? @fmease

rustbot has assigned @fmease.
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 Jan 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 29, 2025

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha

@rust-log-analyzer

This comment has been minimized.

@notriddle notriddle force-pushed the notriddle/typescript2 branch 2 times, most recently from 1a99bc5 to cf3ce0a Compare January 29, 2025 22:30
@rust-log-analyzer

This comment has been minimized.

@notriddle notriddle force-pushed the notriddle/typescript2 branch from cf3ce0a to db13f16 Compare January 30, 2025 00:16
@rust-log-analyzer

This comment has been minimized.

@fmease fmease 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 Jan 30, 2025
@notriddle notriddle force-pushed the notriddle/typescript2 branch from db13f16 to 85f7423 Compare January 30, 2025 20:23
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Nice, thanks! Two questions, r=me when resolved in one way or another

const sidebar = document.querySelector(".sidebar");
if (!resizer || !sidebar) {
// If this page has no sidebar at all, bail out.
if (!(resizer instanceof HTMLElement) || !(sidebar instanceof HTMLElement)) {
return;
Copy link
Member

@fmease fmease Feb 1, 2025

Choose a reason for hiding this comment

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

Why not /** @type {Element | null} */ for both resizer and sidebar and adding the check !resizer || !sidebar to the guarded return? This would eliminate the two new //@ts-expect-errors, wouldn't it?

(And it would eliminate the seeming tautology @type HTMLElement and !(resizer instanceof HTMLElement). I'm slightly surprised that querySelector doesn't unconditionally return Element if the param is string but I guess that's convenience over safety (ofc in practice none of this matters lol)?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this code uses offsetTop, which is defined on HTMLElement, not Element.

And querySelector returns Element.

Copy link
Member

@fmease fmease Feb 1, 2025

Choose a reason for hiding this comment

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

And querySelector returns Element.

As far as I can tell, (the relevant overload of) querySelector returns any caller-provided E that extends Element which allows you to instantiate it with HTMLElement -- if it was Element you wouldn't've been able to cast it to HTMLElement which is more specific than Element.

Unfortunately, this code uses offsetTop, which is defined on HTMLElement, not Element.

Yes, resizer and sidebar would start out as Elements but due to the guarded returns of the form if (!(… instanceof HTMLElement)) { return; } the type is automatically narrowed to HTMLElement following the if statement as part of flow-sensitive typing / control-flow based type analysis which should permit you to access offsetTop on them.

Copy link
Member

Choose a reason for hiding this comment

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

// lib.dom.d.ts
querySelector<E extends Element = Element>(selectors: string): E | null;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I was misunderstanding it. I admit, I'm not actually that familiar with TypeScript, beyond intro-level docs.

Copy link
Member

Choose a reason for hiding this comment

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

No worries

// @ts-expect-error
getSettingsButton().onclick = event => {
const settingsButton = getSettingsButton();
if (settingsButton) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In the unlikely event that the settings button cannot be located, I think it would be better to fail-fast, rather than silently ignore it, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if we went ahead and let it crash, it would still just drop an error in the browser console, probably never to be noticed by anyone.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair, I suppose.

@@ -1813,7 +1811,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
// from settings.js, which uses a separate function. It's done here because
// the minimum sidebar size is rather uncomfortable, and it must pass
// through that size when using the shrink-to-nothing gesture.
function hideSidebar() {
const hideSidebar = function hideSidebar() {
Copy link
Member

@fmease fmease Feb 2, 2025

Choose a reason for hiding this comment

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

Suggested change
const hideSidebar = function hideSidebar() {
const hideSidebar = function() {

Similarly for all other occurrences of this kind of change.

I guess this is just drive-by cleanup?

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 guess this is just drive-by cleanup?

No, it prevents the function definitions from being hoisted above the null check.

Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

r=me with new nitpick addressed and with the three last commits squashed

This mostly consists of handling potentially-null input and adding
more global functions to the list of globals.
@notriddle notriddle force-pushed the notriddle/typescript2 branch from 85aca23 to 2ea95f8 Compare February 3, 2025 17:06
@notriddle
Copy link
Contributor Author

@bors r=fmease rollup

@bors
Copy link
Contributor

bors commented Feb 3, 2025

📌 Commit 2ea95f8 has been approved by fmease

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 3, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Feb 4, 2025
…=fmease

rustdoc: clean up a bunch of ts-expected-error declarations in main

This mostly consists of handling potentially-null input and adding more global functions to the list of globals.

Follow-up for rust-lang#136161
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 4, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang#128045 (#[contracts::requires(...)]  + #[contracts::ensures(...)])
 - rust-lang#136263 (rustdoc: clean up a bunch of ts-expected-error declarations in main)
 - rust-lang#136375 (cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 1))
 - rust-lang#136392 (bootstrap: add wrapper macros for `feature = "tracing"`-gated `tracing` macros)
 - rust-lang#136405 (rustdoc-book: Clean up section on `--output-format`)
 - rust-lang#136497 (Report generic mismatches when calling bodyless trait functions)
 - rust-lang#136502 (Mark `std::fmt::from_fn` as `#[must_use]`)
 - rust-lang#136509 (Add tests for nested macro_rules edition behavior)
 - rust-lang#136526 (mir_build: Rename `thir::cx::Cx` to `ThirBuildCx` and remove `UserAnnotatedTyHelpers`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2025
Rollup of 8 pull requests

Successful merges:

 - rust-lang#128045 (#[contracts::requires(...)]  + #[contracts::ensures(...)])
 - rust-lang#136263 (rustdoc: clean up a bunch of ts-expected-error declarations in main)
 - rust-lang#136375 (cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 1))
 - rust-lang#136392 (bootstrap: add wrapper macros for `feature = "tracing"`-gated `tracing` macros)
 - rust-lang#136396 (rustdoc-json-types: Document that crate name isn't package name.)
 - rust-lang#136405 (rustdoc-book: Clean up section on `--output-format`)
 - rust-lang#136502 (Mark `std::fmt::from_fn` as `#[must_use]`)
 - rust-lang#136509 (Add tests for nested macro_rules edition behavior)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 207777b into rust-lang:master Feb 5, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 5, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2025
Rollup merge of rust-lang#136263 - notriddle:notriddle/typescript2, r=fmease

rustdoc: clean up a bunch of ts-expected-error declarations in main

This mostly consists of handling potentially-null input and adding more global functions to the list of globals.

Follow-up for rust-lang#136161
@notriddle notriddle deleted the notriddle/typescript2 branch February 5, 2025 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants