rust-lang / rust-lang/rust-analyzer

panic: `can't project out of`

Open
#22,828 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-mir C-bug I-panic
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

#[derive(Debug, PartialEq, Eq)]
pub enum Color {
    RGB(u8, u8, u8),
}

fn main() {
    let mut color = Color::RGB(0, 0, 0);
    let mut red = |v| {
        let Color::RGB(ref mut r, _, _) = color;
        *r = v;
    };
    assert_eq!(Color::RGB(1, 2, 3), color);
}

code compiles with rustc

rust-analyzer analysis-stats . --run-all-ide-things

Database loaded:     593.06ms, 224minstr, 48mb (metadata 307.62ms, 1011kinstr, 152kb; build 35.21ms, 179kinstr, 1744b)
  item trees: 1
  dependency lines of code: 1_462_633, item trees: 2_900
  dependency item stats: traits: 851, impl: 9_701, mods: 3_012, macro calls: 5_501, macro rules: 1_053
Item Tree Collection: 4.05s, 22ginstr, 425mb
  Total Statistics:
    crates: 1, mods: 1, decls: 2, bodies: 2, adts: 1, consts: 0, signatures: 2, variants: 1
  Workspace:
    traits: 0, macro_rules macros: 0, proc_macros: 0
    lines of code: 11, item trees: 1
    usages: traits: 0, impl: 0, mods: 0, macro calls: 0, macro rules: 0
  Dependencies:
    lines of code: 1_462_633, item trees: 2_900
    declarations: traits: 851, impl: 9_701, mods: 3_012, macro calls: 5_501, macro rules: 1_053
Item Collection:     2.41s, 11ginstr, 177mb
Crate lang items:    449.02ms, 2471minstr, 31mb
Expression Store Lowering: 271.44µs, 348kinstr, 8kb
  exprs: 14, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  pats: 8, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  panics: 0
Inference:           2.21ms, 973kinstr, 2622kb
MIR lowering:        330.91ms, 1243minstr, 33mb
Mir failed bodies: 0 (0%)
Data layouts:        44.63µs, 38kinstr, 96kb
Failed data layouts: 0 (0%)
Const evaluation:    29.68µs, 47kinstr, 208b
Failed const evals: 0 (100%)
0/1 0% diagnostics: /tmp/sn/dummy/src/main.rs
thread 'main' (2352877) panicked at src/tools/rust-analyzer/crates/hir-ty/src/mir.rs:1277:22:
can't project out of Color
stack backtrace:
   0:     0x7f1cb6e43416 - <<std[5264d755c47072bd]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[435d43ddfce3abfa]::fmt::Display>::fmt
   1:     0x7f1cb740ec88 - core[435d43ddfce3abfa]::fmt::write
   2:     0x7f1cb6e5867c - <std[5264d755c47072bd]::sys::stdio::unix::Stderr as core[435d43ddfce3abfa]::io::write::Write>::write_fmt
   3:     0x7f1cb6e1558a - std[5264d755c47072bd]::panicking::default_hook::{closure#0}
   4:     0x7f1cb6e35b33 - std[5264d755c47072bd]::panicking::default_hook
   5:     0x7f1cb6e35f9b - std[5264d755c47072bd]::panicking::panic_with_hook
   6:     0x7f1cb6e15642 - std[5264d755c47072bd]::panicking::panic_handler::{closure#0}
   7:     0x7f1cb6e0dfc9 - std[5264d755c47072bd]::sys::backtrace::__rust_end_short_backtrace::<std[5264d755c47072bd]::panicking::panic_handler::{closure#0}, !>
   8:     0x7f1cb6e16f9d - __rustc[efc60ea9c7e5e02b]::rust_begin_unwind
   9:     0x7f1cb3b3c8ec - core[435d43ddfce3abfa]::panicking::panic_fmt
  10:     0x55e2e2354c45 - <hir_ty[a11d2f9205227a88]::mir::PlaceTy>::field_ty
  11:     0x55e2e20b4f15 - <hir_ty[a11d2f9205227a88]::mir::PlaceTy>::projection_ty::<la_arena[3980ab47ed97dde9]::Idx<hir_ty[a11d2f9205227a88]::mir::Local>>
  12:     0x55e2e21ea808 - <hir_ty[a11d2f9205227a88]::mir::borrowck::_::borrowck_query_Configuration_ as salsa[bfa5eed162dfe307]::function::Configuration>::execute::inner_::{closure#0}
  13:     0x55e2e241267d - <hir_ty[a11d2f9205227a88]::mir::borrowck::_::borrowck_query_Configuration_ as salsa[bfa5eed162dfe307]::function::Configuration>::execute
  14:     0x55e2e225522e - <salsa[bfa5eed162dfe307]::function::IngredientImpl<hir_ty[a11d2f9205227a88]::mir::borrowck::_::borrowck_query_Configuration_>>::execute
  15:     0x55e2e2398246 - hir_ty[a11d2f9205227a88]::mir::borrowck::borrowck_query
  16:     0x55e2e2b90557 - <ide_db[9214579b98daef8b]::RootDatabase as hir_ty[a11d2f9205227a88]::db::HirDatabase>::borrowck
  17:     0x55e2e1cc098e - <hir[dc7c3d5fb10c5bc]::DefWithBody>::diagnostics
  18:     0x55e2e1c734be - <hir[dc7c3d5fb10c5bc]::ModuleDef>::diagnostics
  19:     0x55e2e1c7da5c - <hir[dc7c3d5fb10c5bc]::Module>::diagnostics
  20:     0x55e2e2b4c0ee - ide_diagnostics[3f577ca5efe14601]::semantic_diagnostics
  21:     0x55e2e2b46722 - ide_diagnostics[3f577ca5efe14601]::full_diagnostics
  22:     0x55e2e258fc79 - <ide[9e8b99a0b3725d5c]::Analysis>::full_diagnostics
  23:     0x55e2e2fd729f - <rust_analyzer[54a442221c605e5]::cli::flags::AnalysisStats>::run
  24:     0x55e2e3280272 - rust_analyzer[25166d87b799c29f]::main
  25:     0x55e2e3216aa3 - std[5264d755c47072bd]::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core[435d43ddfce3abfa]::result::Result<std[5264d755c47072bd]::process::ExitCode, anyhow[f9c252109e1c84fa]::Error>, core[435d43ddfce3abfa]::result::Result<std[5264d755c47072bd]::process::ExitCode, anyhow[f9c252109e1c84fa]::Error>>
  26:     0x55e2e3279412 - std[5264d755c47072bd]::rt::lang_start::<core[435d43ddfce3abfa]::result::Result<std[5264d755c47072bd]::process::ExitCode, anyhow[f9c252109e1c84fa]::Error>>::{closure#0}
  27:     0x7f1cb8614e99 - std[5264d755c47072bd]::rt::lang_start_internal
  28:     0x55e2e32994f8 - main
  29:     0x7f1cb1e27741 - <unknown>
  30:     0x7f1cb1e27879 - __libc_start_main
  31:     0x55e2e1b8b369 - <unknown>
  32:                0x0 - <unknown>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the panic with rust-analyzer analysis-stats . --run-all-ide-things using the Rust example in the report. Start at crates/hir-ty/src/mir.rs:1277 and inspect PlaceTy::field_ty and projection_ty; done means the analysis completes without the can't project out of Color panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.