panic: `Option::unwrap()` on a `None` value
This is a fuzzer-generated bug, please feel free to close and/or let me know if it's not helpful!
rustfmt 1.5.2-nightly (2eaeb1e 2023-04-05)
enum En4<'x1, 'x2, T: Tr1<As1: >> {
V0,
V1,
}
enum _En5<'x1, 'x2, T: Tr1<As1: >> {
_V0,
_V1,
}
enum En6
where
T: Tr1<En2<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S>>>>>>>>>>>>>>>>>>>>>>>>,
{
V0,
V1,
V2,
V3,
}
enum _En7
where
T: ,
{
V0,
V1,
}
fn _make_en7()
where
T: ,
{
}
enum EnSelf<T> where Self: Tr1<As1: > {
V0(T),
V1,
V2,
}
impl EnSelf { }
fn main() {
if ::Outest("") = wrap_en1_1::<_> { };
;
;
}
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/tools/rustfmt/src/items.rs:439:10
stack backtrace:
0: rust_begin_unwind
at /rustc/2eaeb1eee1b21772de8b935236d16ff8e03fdcf5/library/std/src/panicking.rs:577:5
1: core::panicking::panic_fmt
at /rustc/2eaeb1eee1b21772de8b935236d16ff8e03fdcf5/library/core/src/panicking.rs:67:14
2: core::panicking::panic
at /rustc/2eaeb1eee1b21772de8b935236d16ff8e03fdcf5/library/core/src/panicking.rs:117:5
3: <rustfmt_nightly::visitor::FmtVisitor>::visit_item
4: <rustfmt_nightly::visitor::FmtVisitor>::visit_items_with_reordering
5: <rustfmt_nightly::visitor::FmtVisitor>::walk_mod_items
6: <rustfmt_nightly::visitor::FmtVisitor>::format_separate_mod
7: rustfmt_nightly::formatting::format_project::<rustfmt_nightly::Session<std::io::stdio::Stdout>>
8: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::with::<<rustfmt_nightly::Session<std::io::stdio::Stdout>>::format_input_inner::{closure#0}, core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>>
9: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_span::create_session_if_not_set_then<core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>, <rustfmt_nightly::Session<std::io::stdio::Stdout>>::format_input_inner::{closure#0}>::{closure#0}, core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>>
10: <rustfmt_nightly::Session<std::io::stdio::Stdout>>::format
11: rustfmt::format_and_emit_report::<std::io::stdio::Stdout>
12: <rustfmt_nightly::Session<std::io::stdio::Stdout>>::override_config::<rustfmt::format::{closure#0}, ()>
13: rustfmt::execute
14: rustfmt::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Smaller:
enum Node where P::<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S>>>>>>>>>>>>>>>>>>>>>>>>: {
Cons,
}
@langston-barrett thanks for the report and for condensing the reproducible example. Confirming I can reproduce the panic with rustfmt 1.5.2-nightly (a3b2bfc2 2023-04-01)
@HarrisonHemstreet - this is another one that could be interesting for you to look at. At the end of the day, we've got a bad invariant where we've got an assumption that we can safely unwrap() because the option will always be a Some variant (which clearly isn't always the case).
As such there's two aspects to this panic-triggering bug, (1) get rid of the panic by addressing that invariant (note that this could involve having to update various function signatures and respective call sites, and (2) whatever is producing the None in the first place, I'd guess probably some generic-formatting related failure based on the contents in the minimal snippet in https://github.com/rust-lang/rustfmt/issues/5738#issuecomment-1499645341
@rustbot claim
@rustbot claim