Skip to content

Panic during 'hir_expand' #11319

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

Closed
Tracked by #11387 ...
xldenis opened this issue Jan 19, 2022 · 7 comments
Closed
Tracked by #11387 ...

Panic during 'hir_expand' #11319

xldenis opened this issue Jan 19, 2022 · 7 comments
Labels
A-macro macro expansion A-ty type system / type inference / traits / method resolution C-bug Category: bug I-panic S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@xldenis
Copy link
Contributor

xldenis commented Jan 19, 2022

When trying to view RA diagnostics I found this message instead:

rust-analyzer: [ERROR hir_expand] Failed mapping up more for 20..27
rust-analyzer: thread '<unnamed>' panicked at 'internal error: entered unreachable code: pattern has unexpected type: pat: Pat { ty: FnDefId(44)<[?0 := {error}]>, kind: Variant { substs: [?0 := {error}], enum_variant: EnumVariantId { parent: EnumId(21), local_id: Idx::<EnumVariantData>(1) }, subpatterns: [] } }, ty: FnDefId(44)<[?0 := {error}]>', crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs:947:25
rust-analyzer: stack backtrace:
rust-analyzer:    0: rust_begin_unwind
rust-analyzer:              at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
rust-analyzer:    1: core::panicking::panic_fmt
rust-analyzer:              at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
rust-analyzer:    2: hir_ty::diagnostics::match_check::deconstruct_pat::DeconstructedPat::from_pat
rust-analyzer:    3: hir_ty::diagnostics::expr::BodyValidationDiagnostic::collect
rust-analyzer:    4: hir::DefWithBody::diagnostics
rust-analyzer:    5: hir::ModuleDef::diagnostics
rust-analyzer:    6: hir::Module::diagnostics
rust-analyzer:    7: ide_diagnostics::diagnostics
rust-analyzer:    8: std::panicking::try
rust-analyzer:    9: ide::Analysis::diagnostics
rust-analyzer:   10: rust_analyzer::handlers::publish_diagnostics
rust-analyzer:   11: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
rust-analyzer:   12: alloc::vec::source_iter_marker::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
rust-analyzer:   13: <F as threadpool::FnBox>::call_box
rust-analyzer: note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
rust-analyzer: [ERROR hir_expand] Failed mapping up more for 20..27
rust-analyzer: Panic context:
rust-analyzer: >
rust-analyzer: version: c574cf351 2022-01-06 dev
rust-analyzer: request: textDocument/documentHighlight DocumentHighlightParams {
rust-analyzer:     text_document_position_params: TextDocumentPositionParams {
rust-analyzer:         text_document: TextDocumentIdentifier {
rust-analyzer:             uri: Url {
rust-analyzer:                 scheme: "file",
rust-analyzer:                 cannot_be_a_base: false,
rust-analyzer:                 username: "",
rust-analyzer:                 password: None,
rust-analyzer:                 host: None,
rust-analyzer:                 port: None,
rust-analyzer:                 path: "/Users/xavier/Code/creusot/creusot/tests/should_succeed/syntax/07_extern_spec.rs",
rust-analyzer:                 query: None,
rust-analyzer:                 fragment: None,
rust-analyzer:             },
rust-analyzer:         },
rust-analyzer:         position: Position {
rust-analyzer:             line: 13,
rust-analyzer:             character: 21,
rust-analyzer:         },
rust-analyzer:     },
rust-analyzer:     work_done_progress_params: WorkDoneProgressParams {
rust-analyzer:         work_done_token: None,
rust-analyzer:     },
rust-analyzer:     partial_result_params: PartialResultParams {
rust-analyzer:         partial_result_token: None,
rust-analyzer:     },
rust-analyzer: }
rust-analyzer: 
rust-analyzer: thread '<unnamed>' panicked at 'Bad offset: range 0..220 offset 221', /Users/xavier/.cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/rowan-0.15.2/src/cursor.rs:751:9
rust-analyzer: stack backtrace:
rust-analyzer:    0: rust_begin_unwind
rust-analyzer:              at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
rust-analyzer:    1: core::panicking::panic_fmt
rust-analyzer:              at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
rust-analyzer:    2: rowan::cursor::SyntaxNode::token_at_offset
rust-analyzer:    3: ide::highlight_related::highlight_related
rust-analyzer:    4: std::panicking::try
rust-analyzer:    5: ide::Analysis::highlight_related
rust-analyzer:    6: rust_analyzer::handlers::handle_document_highlight
rust-analyzer:    7: std::panicking::try
rust-analyzer:    8: <F as threadpool::FnBox>::call_box
rust-analyzer: note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I'm using rust-analyzer c574cf351 2022-01-06 dev, with rustc 1.60.0-nightly (ad46af247 2022-01-14) inside ST4.

In all fairness the project I'm working on is not the most typical Rust project, it's a rustc driver which also makes heavy use of proc macros.

@Veykril Veykril added A-macro macro expansion Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug labels Jan 19, 2022
@iDawer
Copy link
Contributor

iDawer commented Jan 24, 2022

Do are both panics come when opening creusot/creusot/tests/should_succeed/syntax/07_extern_spec.rs file?

Regarding the first panic could you provide please an expansion of the extern_spec! macro call there? I'd like to look into generated match expressions.

@xldenis
Copy link
Contributor Author

xldenis commented Jan 24, 2022

Yes of course, I should add this crash is not deterministic, ie: while getting the expanded form for you I didn't encounter the issue, however here is the expansion of that file:


#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
extern crate creusot_contracts;
use creusot_contracts::*;

#[creusot::spec::requires =
  "extern_spec_b7977fad_f137_461f_bd4c_aaedc58f42a2_3dec2d31_da27_4359_a823_012d79f94ede"]
#[creusot::no_translate]
#[creusot::extern_spec]
fn extern_spec_b7977fad_f137_461f_bd4c_aaedc58f42a2<T>() -> Vec<T> {
    #[allow(unused_must_use)]
    let _ =
        #[creusot::no_translate] #[creusot::item =
                                   "extern_spec_b7977fad_f137_461f_bd4c_aaedc58f42a2_3dec2d31_da27_4359_a823_012d79f94ede"] #[creusot::decl::spec] ||
                                                                                                                                                       {
                                                                                                                                                           creusot_contracts::stubs::equal(true,
                                                                                                                                                                                           true)
                                                                                                                                                       };
    std::vec::Vec::new()
}

fn main() { let v: Vec<bool> = Vec::new(); }

Created using rustc --extern creusot_contracts=./target/debug/libcreusot_contracts.rlib -Ldependency=./target/debug/deps/ -Zunpretty=expanded creusot/tests/should_succeed/syntax/07_extern_spec.rs

@lnicola lnicola mentioned this issue Jan 31, 2022
15 tasks
@jonas-schievink jonas-schievink added the A-ty type system / type inference / traits / method resolution label Mar 15, 2022
@flodiebold
Copy link
Member

flodiebold commented Mar 30, 2022

@xldenis were you using a build of rust-analyzer with debug_assertions enabled? That error shouldn't be a panic in release builds 😕
Your expanded code doesn't contain any matches, so it's probably not the problematic code.

Actually, there are two seemingly unrelated panics here, the Bad offset: range 0..220 offset 221 and the pattern has unexpected type one.

@xldenis
Copy link
Contributor Author

xldenis commented Mar 30, 2022

I installed from source using the steps in the readme, that is: cargo xtask install --server

@iDawer
Copy link
Contributor

iDawer commented Apr 4, 2022

The first error comes from match check diagnostic on creusot/src/translation/function/statement.rs. It has been resolved in #11899.

@xldenis I see {error}'s in the log. I've got the same when "rust-analyzer.rustcSource": "discover", was not set. Is it set for you? Does rust-analyzer resolve rustc sources?

bors bot added a commit that referenced this issue Apr 4, 2022
11899: fix: Skip match check on patterns of unexpected TyKind::FnDef r=Veykril a=iDawer

Match checking does not expect patterns of `TyKind::FnDef` type.
It seems that in _rustc_ match checking is ruled out due to such type errors at the typecheck stage.

Spotted in #11319

Co-authored-by: iDawer <[email protected]>
@xldenis
Copy link
Contributor Author

xldenis commented Apr 4, 2022

Is it set for you?

Yes

Does rust-analyzer resolve rustc sources?

Yes quite well in fact :)

@Veykril Veykril added S-unactionable Issue requires feedback, design decisions or is blocked on other work I-panic and removed Broken Window Bugs / technical debt to be addressed immediately labels Feb 8, 2023
@Veykril
Copy link
Member

Veykril commented May 26, 2023

Closing as there is not much to do here from our side

@Veykril Veykril closed this as completed May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion A-ty type system / type inference / traits / method resolution C-bug Category: bug I-panic S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

5 participants