Skip to content

Regressions in 1.93.0 crater run: rustdoc errors on invalid #[test] attribute #150665

@theemathas

Description

@theemathas

This issue tracks the regressions found in the 1.93.0 beta crater run which involve rustdoc producing an error due to a #[test] attribute being applied to the wrong thing.

The regressions are categorized based on what the #[test] attribute is applied to.

#[test] on an associated function

Error output
[INFO] [stdout] error: the `#[test]` attribute may only be used on a free function
[INFO] [stdout]   --> src/plot.rs:60:5
[INFO] [stdout]    |
[INFO] [stdout] 60 |     #[test]
[INFO] [stdout]    |     ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
[INFO] [stdout]    |
[INFO] [stdout] help: replace with conditional compilation to make the item only exist when tests are being run
[INFO] [stdout]    |
[INFO] [stdout] 60 -     #[test]
[INFO] [stdout] 60 +     #[cfg(test)]
[INFO] [stdout]    |

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/gh/Nixes.rust_plot/log.txt

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/gh/abomb4.rust-five/log.txt

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/gh/laikas123.rusql/log.txt

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/reg/graphify-0.1.0/log.txt

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/reg/namespace-0.1.0/log.txt

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/gh/pgberlureau.kernel_shell/log.txt

#[test] on a use statement

Error output
[INFO] [stdout] error: the `#[test]` attribute may only be used on a free function
[INFO] [stdout]   --> src/task5.rs:1:1
[INFO] [stdout]    |
[INFO] [stdout]  1 | #[test]
[INFO] [stdout]    | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
[INFO] [stdout] ...
[INFO] [stdout] 24 | use std::collections::HashMap;
[INFO] [stdout]    | ------------------------------ expected a non-associated function, found a `use` import
[INFO] [stdout]    |
[INFO] [stdout] help: replace with conditional compilation to make the item only exist when tests are being run
[INFO] [stdout]    |
[INFO] [stdout]  1 - #[test]
[INFO] [stdout]  1 + #[cfg(test)]
[INFO] [stdout]    |

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/gh/OrlovBohdan._11_Collection_Types_11_3_HashMap/log.txt

#[test] on a macro invocation (which is a warning, but then this results in a seemingly unrelated error?)

Error output
[INFO] [stdout] warning: the `#[test]` attribute may only be used on a free function
[INFO] [stdout]    --> src/backend/geometry.rs:490:1
[INFO] [stdout]     |
[INFO] [stdout] 490 |   #[test]
[INFO] [stdout]     |   ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
[INFO] [stdout] 491 | / quickcheck! {
[INFO] [stdout] 492 | |     fn check_intersect_two_circles(
[INFO] [stdout] 493 | |         x1: f64,
[INFO] [stdout] 494 | |         y1: f64,
[INFO] [stdout] ...   |
[INFO] [stdout] 586 | | }
[INFO] [stdout]     | |_- expected a non-associated function, found an item macro invocation
[INFO] [stdout]     |
[INFO] [stdout] help: replace with conditional compilation to make the item only exist when tests are being run
[INFO] [stdout]     |
[INFO] [stdout] 490 - #[test]
[INFO] [stdout] 490 + #[cfg(test)]
[INFO] [stdout]     |
[INFO] [stdout] 
[INFO] [stdout] 
[INFO] [stdout] error: cannot find macro `quickcheck` in this scope
[INFO] [stdout]    --> src/backend/geometry.rs:491:1
[INFO] [stdout]     |
[INFO] [stdout] 491 | quickcheck! {
[INFO] [stdout]     | ^^^^^^^^^^
[INFO] [stdout]     |
[INFO] [stdout]     = note: `quickcheck` is in scope, but it is a crate, not a macro

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/gh/loovjo.drawmetry/log.txt

#[test] on an impl block

Error output
[INFO] [stdout] error: the `#[test]` attribute may only be used on a free function
[INFO] [stdout]    --> src/shell/fs.rs:309:1
[INFO] [stdout]     |
[INFO] [stdout] 309 |   #[test] // TODO : remove it
[INFO] [stdout]     |   ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
[INFO] [stdout] 310 | / impl std::fmt::Display for Fdesc {
[INFO] [stdout] 311 | |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> core::fmt::Result {
[INFO] [stdout] 312 | |         let name: std::string::String = self.name.iter().collect();
[INFO] [stdout] 313 | |         write!(f, "
[INFO] [stdout] ...   |
[INFO] [stdout] 320 | | }
[INFO] [stdout]     | |_- expected a non-associated function, found an implementation
[INFO] [stdout]     |
[INFO] [stdout] help: replace with conditional compilation to make the item only exist when tests are being run
[INFO] [stdout]     |
[INFO] [stdout] 309 - #[test] // TODO : remove it
[INFO] [stdout] 309 + #[cfg(test)] // TODO : remove it
[INFO] [stdout]     |

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/gh/pgberlureau.kernel_shell/log.txt

#[test] on a mod declaration

Error output
[INFO] [stdout] error: the `#[test]` attribute may only be used on a free function
[INFO] [stdout]    --> src/common/git.rs:152:1
[INFO] [stdout]     |
[INFO] [stdout] 152 |   #[test]
[INFO] [stdout]     |   ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
[INFO] [stdout] 153 | / mod tests {
[INFO] [stdout] 154 | |     use super::*;
[INFO] [stdout] 155 | |     use std::str::FromStr;
[INFO] [stdout] ...   |
[INFO] [stdout] 210 | | }
[INFO] [stdout]     | |_- expected a non-associated function, found a module
[INFO] [stdout]     |
[INFO] [stdout] help: replace with conditional compilation to make the item only exist when tests are being run
[INFO] [stdout]     |
[INFO] [stdout] 152 - #[test]
[INFO] [stdout] 152 + #[cfg(test)]
[INFO] [stdout]     |

https://crater-reports.s3.amazonaws.com/beta-rustdoc-1.93-3/beta-2025-12-22/reg/openfare-0.6.2/log.txt

#[test] on a statement in a doctest

Error output
[INFO] [stdout] ---- src/check.rs - check::check (line 8) stdout ----
[INFO] [stdout] error: the `#[test]` attribute may only be used on a free function
[INFO] [stdout]  --> src/check.rs:12:1
[INFO] [stdout]   |
[INFO] [stdout] 7 | #[test]
[INFO] [stdout]   | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
[INFO] [stdout]   |
[INFO] [stdout] help: replace with conditional compilation to make the item only exist when tests are being run
[INFO] [stdout]   |
[INFO] [stdout] 7 - #[test]
[INFO] [stdout] 7 + #[cfg(test)]
[INFO] [stdout]   |
[INFO] [stdout] 
[INFO] [stdout] error: the `#[test]` attribute may only be used on a free function
[INFO] [stdout]   --> src/check.rs:15:1
[INFO] [stdout]    |
[INFO] [stdout] 10 | #[test]
[INFO] [stdout]    | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
[INFO] [stdout]    |
[INFO] [stdout] help: replace with conditional compilation to make the item only exist when tests are being run
[INFO] [stdout]    |
[INFO] [stdout] 10 - #[test]
[INFO] [stdout] 10 + #[cfg(test)]
[INFO] [stdout]    |

https://crater-reports.s3.amazonaws.com/beta-1.93-4/beta-2025-12-22/reg/antelope-0.2.0/log.txt

#[test] on a macro invocation in a doctest

Error output
[INFO] [stdout] ---- src/../README.md - (line 82) stdout ----
[INFO] [stdout] error: the `#[test]` attribute may only be used on a free function
[INFO] [stdout]   --> src/../README.md:95:1
[INFO] [stdout]    |
[INFO] [stdout] 16 | #[test]
[INFO] [stdout]    | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions
[INFO] [stdout]    |
[INFO] [stdout] help: replace with conditional compilation to make the item only exist when tests are being run
[INFO] [stdout]    |
[INFO] [stdout] 16 - #[test]
[INFO] [stdout] 16 + #[cfg(test)]
[INFO] [stdout]    |

https://crater-reports.s3.amazonaws.com/beta-1.93-4/beta-2025-12-22/reg/should_error-0.1.1/log.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.I-lang-nominatedNominated for discussion during a lang team meeting.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.P-lang-drag-0Lang team prioritization drag level 0.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.S-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions