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

Adding a comment next to #![feature(ptr_metadata,)] silences failing doctests #134221

Open
raldone01 opened this issue Dec 12, 2024 · 10 comments · May be fixed by #134260
Open

Adding a comment next to #![feature(ptr_metadata,)] silences failing doctests #134221

raldone01 opened this issue Dec 12, 2024 · 10 comments · May be fixed by #134260
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@raldone01
Copy link
Contributor

raldone01 commented Dec 12, 2024

Reproduce

https://github.com/ink-feather-org/trait_cast_rs/tree/80a0a0994dfdbf5e8b6978879ce3205188401df1

1:

git clone https://github.com/ink-feather-org/trait_cast_rs.git
git checkout 80a0a0994dfdbf5e8b6978879ce3205188401df1
cargo test --all-features

All tests pass!

2:

Remove the comment in line 43 of the README.md:

#![feature(
  ptr_metadata, // <- Remove this comment
)]
use trait_cast_rs::{
  make_trait_castable, TraitcastableAny, TraitcastableAnyInfra, TraitcastableAnyInfraExt,
};
#[make_trait_castable(Print)]
struct Source(i32);
...

Next run the tests again:

cargo test --all-features

Oh no! The test fails with E0119.

What is going on?!? I did not expect the comment breaking anything.

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (21fe748be 2024-12-11)
binary: rustc
commit-hash: 21fe748be15271ea5804e0507cd699b675efe038
commit-date: 2024-12-11
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5
@raldone01 raldone01 added the C-bug Category: This is a bug. label Dec 12, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 12, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Dec 12, 2024

The bug appears to be not that your test fails, but rather that it suceeds when you add the comment.
Here is a reduced example:

/*!
```rust
#![feature(
  foo, //
)]
```
*/

This as a sole lib.rs should fail after cargo test because foo isn't a feature, but it silently suceeds with the comment. Removing it causes the test to fail as expected.

In 1.81, this code still errored correctly, but it was accepted in 1.82 and above.
@rustbot label: +regression-from-stable-to-stable

@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 12, 2024
@jieyouxu jieyouxu added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 12, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 12, 2024

Would be good to get a more precise bisection and a more self-contained MCVE, looks not ideal.

@jieyouxu jieyouxu added E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example A-attributes Area: Attributes (`#[…]`, `#![…]`) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 12, 2024
@jieyouxu
Copy link
Member

Wait on hold, @cyrgani to double-check, do you mean this as a doctest?

@jieyouxu
Copy link
Member

searched nightlies: from nightly-2024-07-20 to nightly-2024-08-30
regressed nightly: nightly-2024-08-15
searched commit range: 80eb5a8...13a5289
regressed commit: e5b3e68

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --script=./check.sh --start=1.81.0 --end=2024-08-30 --regress=success

@jieyouxu
Copy link
Member

jieyouxu commented Dec 12, 2024

cc @GuillaumeGomez as this bisects to #126245, do you know if this is intended behavior change?

@jieyouxu jieyouxu added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-doctests Area: Documentation tests, run by rustdoc and removed A-attributes Area: Attributes (`#[…]`, `#![…]`) E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Dec 12, 2024
@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue S-has-bisection Status: a bisection has been found for this issue and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 12, 2024
@raldone01
Copy link
Contributor Author

raldone01 commented Dec 12, 2024

Intended behavior change

Good one. 🫠

It's true my doctest was broken but the // in the feature expression silenced the failure.
If I had kept the comment I would have never noticed that the doctest was failing.


Can't get a doctest to pass?

Add a nonexistent #[feature()] with //.

raldone01 added a commit to ink-feather-org/trait-cast-rs that referenced this issue Dec 12, 2024
@raldone01 raldone01 changed the title Removing a comment next to #![feature(ptr_metadata,)] breaks doctests Removing a comment next to #![feature(ptr_metadata,)] silences failing doctests Dec 12, 2024
@raldone01 raldone01 changed the title Removing a comment next to #![feature(ptr_metadata,)] silences failing doctests Adding a comment next to #![feature(ptr_metadata,)] silences failing doctests Dec 12, 2024
@onestacked
Copy link
Contributor

Great now I know how to get all my doctests to pass!

@cyrgani
Copy link
Contributor

cyrgani commented Dec 12, 2024

Note that there seem to be 2 underlying problems:

  1. Any doctest starting with a malformed inner attribute is silently accepted, even just
//! ```rust
//! #![
//! ```
  1. I guess that line breaks inside the attribute are removed before comments are removed, so adding the comment creates a malformed attribute and 1. applies.

@GuillaumeGomez
Copy link
Member

No it's not an intended behaviour change. ^^'

Gonna check what's going on.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 13, 2024
@GuillaumeGomez
Copy link
Member

Opened #134260.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 13, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

6 participants