[rustdoc] Do not emit redundant_explicit_links lint if the doc comment comes from expansion
Fixes https://github.com/rust-lang/rust/issues/141553.
The problem was that we change the context for the attributes in some cases to get better error output, preventing us to detect if the attribute comes from expansion. Most of the changes are about keeping track of the "does this span comes from expansion" information.
r? @Manishearth
The job mingw-check-tidy failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
info: removing rustup binaries
info: rustup is uninstalled
##[group]Image checksum input
mingw-check-tidy
# We use the ghcr base image because ghcr doesn't have a rate limit
# and the mingw-check-tidy job doesn't cache docker images in CI.
FROM ghcr.io/rust-lang/ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
---
COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/
# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
--stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#12 3.357 Building wheels for collected packages: reuse
#12 3.358 Building wheel for reuse (pyproject.toml): started
#12 3.568 Building wheel for reuse (pyproject.toml): finished with status 'done'
#12 3.569 Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132719 sha256=d2a2565e7037ad3883fb9337653f2e25bbb588534fbef3697286cbc26d1bf634
#12 3.569 Stored in directory: /tmp/pip-ephem-wheel-cache-bx5esjb8/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#12 3.572 Successfully built reuse
#12 3.572 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#12 3.962 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#12 3.962 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#12 4.526 Collecting virtualenv
#12 4.607 Downloading virtualenv-20.31.2-py3-none-any.whl (6.1 MB)
#12 4.728 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.1/6.1 MB 51.4 MB/s eta 0:00:00
#12 4.797 Collecting platformdirs<5,>=3.9.1
#12 4.811 Downloading platformdirs-4.3.8-py3-none-any.whl (18 kB)
#12 4.847 Collecting distlib<1,>=0.3.7
#12 4.861 Downloading distlib-0.3.9-py2.py3-none-any.whl (468 kB)
#12 4.868 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 91.8 MB/s eta 0:00:00
#12 4.914 Collecting filelock<4,>=3.12.2
#12 4.929 Downloading filelock-3.18.0-py3-none-any.whl (16 kB)
#12 5.010 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#12 5.201 Successfully installed distlib-0.3.9 filelock-3.18.0 platformdirs-4.3.8 virtualenv-20.31.2
#12 5.201 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#12 DONE 5.3s
#13 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#13 DONE 0.0s
---
DirectMap4k: 149440 kB
DirectMap2M: 7190528 kB
DirectMap1G: 11534336 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
##[group]Building bootstrap
Finished `dev` profile [unoptimized] target(s) in 0.05s
##[endgroup]
WARN: currently no CI rustc builds have rustc debug assertions enabled. Please either set `rust.debug-assertions` to `false` if you want to use download CI rustc or set `rust.download-rustc` to `false`.
downloading https://static.rust-lang.org/dist/2025-05-12/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
---
fmt check
fmt: checked 6029 files
tidy check
tidy: Skipping binary file check, read-only filesystem
##[error]tidy error: /checkout/tests/rustdoc-ui/lints/redundant_explicit_links-expansion.rs:15: tab character
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (25.1.1)
linting python files
All checks passed!
checking python file formatting
26 files already formatted
checking C++ file formatting
some tidy checks failed
Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:01:55
local time: Tue May 27 13:29:32 UTC 2025
network time: Tue, 27 May 2025 13:29:32 GMT
##[error]Process completed with exit code 1.
Post job cleanup.
The job mingw-check failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
Checking rustfix v0.8.1
error[E0308]: mismatched types
--> src/tools/clippy/clippy_lints/src/doc/mod.rs:734:9
|
733 | fn span(self, cx: &LateContext<'_>, range: Range<usize>) -> Option<Span> {
| ------------ expected `std::option::Option<rustc_span::Span>` because of return type
734 | source_span_for_markdown_range(cx.tcx, self.doc, &range, self.fragments)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<Span>`, found `Option<(Span, bool)>`
|
= note: expected enum `std::option::Option<rustc_span::Span>`
found enum `std::option::Option<(rustc_span::Span, bool)>`
[RUSTC-TIMING] annotate_snippets test:false 0.240
Some changes occurred in src/tools/clippy
cc @rust-lang/clippy
A job failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
#2 transferring dockerfile: 2.62kB done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/ubuntu:22.04
#3 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
------
> [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
1 | >>> FROM ubuntu:22.04
2 |
3 | ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
Command failed. Attempt 2/5:
#0 building with "blissful_hellman" instance using docker-container driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2.62kB done
#1 DONE 0.0s
#2 [internal] load metadata for docker.io/library/ubuntu:22.04
#2 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
------
> [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
1 | >>> FROM ubuntu:22.04
2 |
3 | ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
Command failed. Attempt 3/5:
#0 building with "blissful_hellman" instance using docker-container driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2.62kB done
#1 DONE 0.0s
#2 [internal] load metadata for docker.io/library/ubuntu:22.04
#2 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
------
> [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
1 | >>> FROM ubuntu:22.04
2 |
3 | ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
Command failed. Attempt 4/5:
#0 building with "blissful_hellman" instance using docker-container driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2.62kB done
#1 DONE 0.0s
#2 [internal] load metadata for docker.io/library/ubuntu:22.04
#2 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
------
> [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
1 | >>> FROM ubuntu:22.04
2 |
3 | ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
Command failed. Attempt 5/5:
#0 building with "blissful_hellman" instance using docker-container driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2.62kB done
#1 DONE 0.0s
#2 [internal] load metadata for docker.io/library/ubuntu:22.04
#2 ERROR: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
------
> [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
1 | >>> FROM ubuntu:22.04
2 |
3 | ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to resolve source metadata for docker.io/library/ubuntu:22.04: failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/library/ubuntu/manifests/sha256:899ec23064539c814a4dbbf98d4baf0e384e4394ebc8638bea7bbe4cb8ef4e12: 429 Too Many Requests - Server message: toomanyrequests: You have reached your unauthenticated pull rate limit. https://www.docker.com/increase-rate-limit
The command has failed after 5 attempts.
##[error]Process completed with exit code 1.
Post job cleanup.
:umbrella: The latest upstream changes (presumably #141869) made this pull request unmergeable. Please resolve the merge conflicts.
(I've been rather busy catching up with stuff after vacation; I probably won't be able to review this myself soon ,sorry!)
The job mingw-check-2 failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] rustc_mir_transform test:true 4.410
error[E0063]: missing field `from_expansion` in initializer of `DocFragment`
--> compiler/rustc_resolve/src/rustdoc/tests.rs:17:11
|
17 | &[DocFragment {
| ^^^^^^^^^^^ missing `from_expansion`
[RUSTC-TIMING] rustc_hir_typeck test:true 6.170
error[E0599]: no method named `lo` found for tuple `(rustc_span::Span, bool)` in the current scope
--> compiler/rustc_resolve/src/rustdoc/tests.rs:26:21
|
26 | assert_eq!(span.lo(), BytePos(9));
| ^^
|
help: there is a method `le` with a similar name, but with different arguments
--> /checkout/library/core/src/cmp.rs:1400:5
|
1400 | fn le(&self, other: &Rhs) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0599]: no method named `hi` found for tuple `(rustc_span::Span, bool)` in the current scope
--> compiler/rustc_resolve/src/rustdoc/tests.rs:27:21
|
27 | assert_eq!(span.hi(), BytePos(10));
| ^^ method not found in `(Span, bool)`
error[E0063]: missing field `from_expansion` in initializer of `DocFragment`
--> compiler/rustc_resolve/src/rustdoc/tests.rs:39:11
|
39 | &[DocFragment {
| ^^^^^^^^^^^ missing `from_expansion`
error[E0599]: no method named `lo` found for tuple `(rustc_span::Span, bool)` in the current scope
--> compiler/rustc_resolve/src/rustdoc/tests.rs:48:21
|
48 | assert_eq!(span.lo(), BytePos(9));
| ^^
|
help: there is a method `le` with a similar name, but with different arguments
--> /checkout/library/core/src/cmp.rs:1400:5
|
1400 | fn le(&self, other: &Rhs) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0599]: no method named `hi` found for tuple `(rustc_span::Span, bool)` in the current scope
--> compiler/rustc_resolve/src/rustdoc/tests.rs:49:21
|
49 | assert_eq!(span.hi(), BytePos(12));
| ^^ method not found in `(Span, bool)`
[RUSTC-TIMING] rustc_privacy test:true 0.282
[RUSTC-TIMING] rustc_borrowck test:true 4.925
[RUSTC-TIMING] rustc_mir_build test:true 2.840
[RUSTC-TIMING] rustc_traits test:true 0.188
No worries, take your time. We can pick another reviewer in the meantime.
r? notriddle
Applied suggestions and added more tests.
I understand that this bail-out is needed because, in the event of a false positive, disabling the lint in the macro is impossible. There's nowhere to attach the attribute.
In that case, would it be simpler and make more sense to disable all of the markdown lints, and not just this one?
Applied suggestions.
Thanks for the review! Let's approve so this bug can finally be removed. :)
@bors r=lolbinarycat rollup
:pushpin: Commit 3b5525bc420551c9c32ad3b5b6c8d673dd25da0d has been approved by lolbinarycat
It is now in the queue for this repository.