Re: [PATCH] rust: doctest: fix line numbers after crate-level attributes
From: Miguel Ojeda
Date: Mon Nov 02 2026 - 11:36:02 EST
On Mon, Nov 2, 2026 at 1:56 PM Younes <git@xxxxxxxxx> wrote:
>
> It can only underflow if rustdoc stops emitting its own
> `#![allow(unused)]`, e.g. in a future version. A related case is a
> crate setting `#![doc(test(attr(...)))]`: rustdoc then emits those
> attributes instead, so the `- 1` can silently become wrong and
> doctests without any attributes get shifted. Either way we'd want to
> notice, so in v2 I'll check that the first line is `#![allow(unused)]`
> and panic otherwise, instead of clamping. What do you think?
If what we want is for people to simply notice, then I was thinking of
just `unwrap()`ping like others we have around there.
Having said that, it can be annoying and confusing if someone writes a
doctest and has to figure out what to change in these scripts (scripts
that they may not even know they exist...).
Ideally, I think we would have a "warning" somehow, i.e. something
that doesn't stop people from working but that will get noticed.
Cheers,
Miguel