Skip to content

Fix NoneType error in rustdoc - #4159

Merged
UebelAndre merged 2 commits into
bazelbuild:mainfrom
UebelAndre:docinfo
Jul 21, 2026
Merged

Fix NoneType error in rustdoc#4159
UebelAndre merged 2 commits into
bazelbuild:mainfrom
UebelAndre:docinfo

Conversation

@UebelAndre

@UebelAndre UebelAndre commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

There seemed to be a confusion around CrateInfo.output being optional within the rustdoc rules that leads to a NoneType error when using rustdoc on a generated crate root:

external/rules_rust+/rust/private/rustc.bzl:1090:38: Traceback (most recent call last):
File "external/rules_rust+/rust/private/rustc.bzl", line 2883, column 16, in _get_dirname
    return file.dirname
Error: 'NoneType' value has no field or method 'dirname'

This change adds a proper output to satisfy the the current CrateInfo interface.

@UebelAndre

Copy link
Copy Markdown
Collaborator Author

@krasimirgg @slackito do either of you know if this would break anything on Google's end?

@UebelAndre
UebelAndre requested a review from slackito July 21, 2026 01:16
@UebelAndre
UebelAndre marked this pull request as ready for review July 21, 2026 01:18
@UebelAndre
UebelAndre enabled auto-merge July 21, 2026 01:18
Comment thread rust/private/rustc.bzl Outdated
require_explicit_unstable_features (bool): Whether to require all unstable features to be explicitly opted in to using `-Zallow-features=...`.
error_format (str, optional): Error format to pass to the `--error-format` command line argument. If set to None, uses the "_error_format" entry in `attr`.
allowed_unstable_rust_features (list, optional): List of unstable Rust language features allowed for this target.
emit_out_dir_flag (bool): Whether to emit `--out-dir=<crate_info.output.dirname>`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if instead we could simulate this behavior by checking whether crate_info.output is a directory or a file? If I understand correctly, it's a directory if and only if we're in a rustdoc context, and it's exactly when we want to suppress emitting --out-dir?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done, now if output is a directory, we only emit --out-dir for that path but if it's a source we emit it for dirname.

Comment thread rust/private/rustc.bzl
@krasimirgg

krasimirgg commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

@krasimirgg @slackito do either of you know if this would break anything on Google's end?

we don't directly use the rustfmt aspect, but I'm not sure if we don't have other extensions that produce a CrateInfo with an empty output. Let me run a check about that...

EDIT: ran a sample test, that bit looks OK. Left a comment about potentially simplifying the logic by sniffing if crate_info.output is a directory or not.

@slackito slackito left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me. I'll report back if it breaks anything once we import it.

@UebelAndre
UebelAndre added this pull request to the merge queue Jul 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 21, 2026
@slackito

Copy link
Copy Markdown
Collaborator

Actually I just raced with Krasimir and it turns out he had comments. Please address them before merging.

@UebelAndre
UebelAndre enabled auto-merge July 21, 2026 15:54
@UebelAndre
UebelAndre added this pull request to the merge queue Jul 21, 2026
Merged via the queue into bazelbuild:main with commit 9c1dcbb Jul 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants