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

thread 'rustc' panicked at 'called Option::unwrap() on a None value' #66286

Closed
DDR0 opened this issue Nov 11, 2019 · 3 comments · Fixed by #66390
Closed

thread 'rustc' panicked at 'called Option::unwrap() on a None value' #66286

DDR0 opened this issue Nov 11, 2019 · 3 comments · Fixed by #66390
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-frontend Area: Compiler frontend (errors, parsing and HIR) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DDR0
Copy link

DDR0 commented Nov 11, 2019

The following rust code crashes rustc 1.39.0 (4560ea788 2019-11-04) running on x86_64-unknown-linux-gnu.

extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub extern fn third(a: Vec(u32)) -> u32 {
    return a[3]
}

(Note, changing Vec(u32) to Vec<u32> fixes the crash.)

Meta

Running with RUST_BACKTRACE, I get the following error message.

   Compiling wasm_sample v0.1.0 (/home/david/Documents/rust/wasm_sample_2)
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:76
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:60
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:64
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:196
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:210
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:477
  12: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:380
  13: rust_begin_unwind
             at src/libstd/panicking.rs:307
  14: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  15: core::panicking::panic
             at src/libcore/panicking.rs:49
  16: rustc::hir::lowering::LoweringContext::lower_path_segment
  17: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  18: <rustc::hir::ptr::P<[T]> as core::iter::traits::collect::FromIterator<T>>::from_iter
  19: rustc::hir::lowering::LoweringContext::lower_qpath
  20: rustc::hir::lowering::LoweringContext::lower_path_ty
  21: rustc::hir::lowering::LoweringContext::lower_ty_direct
  22: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  23: <rustc::hir::ptr::P<[T]> as core::iter::traits::collect::FromIterator<T>>::from_iter
  24: rustc::hir::lowering::LoweringContext::lower_fn_decl
  25: rustc::hir::lowering::item::<impl rustc::hir::lowering::LoweringContext>::lower_item
  26: rustc::hir::lowering::LoweringContext::with_hir_id_owner
  27: <rustc::hir::lowering::item::ItemLowerer as syntax::visit::Visitor>::visit_mod
  28: rustc::hir::lowering::lower_crate
  29: rustc::util::common::time
  30: rustc_interface::passes::BoxedResolver::access::{{closure}}
  31: rustc_interface::passes::configure_and_expand::{{closure}}
  32: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::access
  33: rustc_interface::queries::Query<T>::compute
  34: rustc_interface::queries::Query<T>::compute
  35: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::prepare_outputs
  36: rustc_interface::interface::run_compiler_in_existing_thread_pool
  37: std::thread::local::LocalKey<T>::with
  38: scoped_tls::ScopedKey<T>::set
  39: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.39.0 (4560ea788 2019-11-04) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type cdylib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `wasm_sample`.

To learn more, run the command again with --verbose.

rustc --version --verbose yields

rustc 1.39.0 (4560ea788 2019-11-04)
binary: rustc
commit-hash: 4560ea788cb760f0a34127156c78e2552949f734
commit-date: 2019-11-04
host: x86_64-unknown-linux-gnu
release: 1.39.0
LLVM version: 9.0

Thank you.

@hellow554
Copy link
Contributor

I reduced the proc macro to the following:

use wasm_bindgen_macro::wasm_bindgen;

#[wasm_bindgen]
pub extern fn third(_: Vec(u32)) -> u32 {
    0   
}
extern crate proc_macro;

use proc_macro::TokenStream;
use quote::ToTokens;

#[proc_macro_attribute]
pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
    let mut tokens = proc_macro2::TokenStream::new();
    let item = syn::parse::<syn::Item>(input).expect("parse");

    if let syn::Item::Fn(f) = item {
        f.to_tokens(&mut tokens);
    }

    tokens.into()
}

with tokens being:

[wmacro/src/lib.rs:15] &tokens = TokenStream [
    Ident {
        ident: "pub",
        span: #0 bytes(0..0),
    },
    Ident {
        ident: "extern",
        span: #0 bytes(0..0),
    },
    Literal { lit: Lit { kind: Str, symbol: C, suffix: None }, span: Span { lo: BytePos(0), hi: BytePos(0), ctxt: #0 } },
    Ident {
        ident: "fn",
        span: #0 bytes(0..0),
    },
    Ident {
        ident: "third",
        span: #0 bytes(0..0),
    },
    Group {
        delimiter: Parenthesis,
        stream: TokenStream [
            Ident {
                ident: "_",
                span: #0 bytes(0..0),
            },
            Punct {
                ch: ':',
                spacing: Alone,
                span: #0 bytes(0..0),
            },
            Ident {
                ident: "Vec",
                span: #0 bytes(0..0),
            },
            Group {
                delimiter: Parenthesis,
                stream: TokenStream [
                    Ident {
                        ident: "u32",
                        span: #0 bytes(0..0),
                    },
                ],
                span: #0 bytes(0..0),
            },
        ],
        span: #0 bytes(0..0),
    },
    Punct {
        ch: '-',
        spacing: Joint,
        span: #0 bytes(0..0),
    },
    Punct {
        ch: '>',
        spacing: Alone,
        span: #0 bytes(0..0),
    },
    Ident {
        ident: "u32",
        span: #0 bytes(0..0),
    },
    Group {
        delimiter: Brace,
        stream: TokenStream [
            Literal { lit: Lit { kind: Integer, symbol: 0, suffix: None }, span: Span { lo: BytePos(0), hi: BytePos(0), ctxt: #0 } },
        ],
        span: #0 bytes(0..0),
    },
]

@Centril Centril added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-frontend Area: Compiler frontend (errors, parsing and HIR) I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Nov 11, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Nov 11, 2019
@csmoe csmoe added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 13, 2019
@csmoe
Copy link
Member

csmoe commented Nov 13, 2019

let split = snippet.find('(').unwrap();

panic due to not found ( inside snippet while trying to suggest Vec(T) to Vec<T>.
cc @estebank

@pnkfelix
Copy link
Member

triage: P-high. Removing I-nominated.

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Nov 14, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 15, 2019
Fix ICE when trying to suggest `Type<>` instead of `Type()`

Fixes rust-lang#66286, but the output has no span:

```
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait

error: aborting due to previous error

For more information about this error, try `rustc --explain E0214`.
```
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 15, 2019
Fix ICE when trying to suggest `Type<>` instead of `Type()`

Fixes rust-lang#66286, but the output has no span:

```
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait

error: aborting due to previous error

For more information about this error, try `rustc --explain E0214`.
```
@bors bors closed this as completed in 1baa772 Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-frontend Area: Compiler frontend (errors, parsing and HIR) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants