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

panic: Option::unwrap() on a None value #5738

Open
langston-barrett opened this issue Apr 6, 2023 · 6 comments · May be fixed by #6396
Open

panic: Option::unwrap() on a None value #5738

langston-barrett opened this issue Apr 6, 2023 · 6 comments · May be fixed by #6396
Assignees
Labels
bug Panic, non-idempotency, invalid code, etc. p-low

Comments

@langston-barrett
Copy link

langston-barrett commented Apr 6, 2023

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.
@langston-barrett
Copy link
Author

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,
}

@ytmimi
Copy link
Contributor

ytmimi commented Apr 9, 2023

@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)

@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. p-low labels Apr 9, 2023
@calebcartwright
Copy link
Member

@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 #5738 (comment)

@HarrisonHemstreet
Copy link

@rustbot claim

@Tanjaint21
Copy link
Contributor

@rustbot claim

@ding-young
Copy link
Contributor

@rustbot claim

@rustbot rustbot assigned ding-young and unassigned Tanjaint21 Nov 17, 2024
@ding-young ding-young linked a pull request Nov 17, 2024 that will close this issue
2 tasks
ding-young added a commit to ding-young/rustfmt that referenced this issue Nov 29, 2024
- related issues: rust-lang#5738, rust-lang#6137, rust-lang#6318, rust-lang#6378
- instead of calling unwrap(), restore original snippet when we fail to format generics in enum
- we need to propagate this rewrite failure later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. p-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants