Skip to content

Code causes Compile Error without any Cause #146537

@EvilsSouls

Description

@EvilsSouls

Code

use std::collections::HashMap;

#[derive(PartialEq, Eq)]
pub enum Associativity {
    LeftAssociative,
    RightAssociative
}

fn get_higher_precedence_operators(operators: &HashMap<char, (u8, Associativity)>, operator_stack: &mut Vec<char>, new_operator_precedence: u8) -> Vec<String> {
    let mut higher_precedence_operators = Vec::new();

    loop {
        if operator_stack.len() <= 0 {return higher_precedence_operators;}

        let top_operator = operator_stack[operator_stack.len() - 1];
        let top_operator_properties = operators.get(&top_operator);
        let top_operator_precedence: u8;
        let top_operator_associativity: Associativity;

        if top_operator_properties.is_some() {
            (top_operator_precedence, top_operator_associativity) = *top_operator_properties.expect("There is no way in hell, that this is None");
        } else {
            return higher_precedence_operators;
        }

        if top_operator_precedence > new_operator_precedence || (top_operator_precedence == new_operator_precedence && top_operator_associativity == Associativity::LeftAssociative) {
            higher_precedence_operators.push(operator_stack.pop().expect("Once again... there is no way that this Option Enum has the value of None").to_string());
        } else {
            return higher_precedence_operators;
        }
    }
}

pub fn to_postfix(raw_infix_expression: &str, operators: &HashMap<char, (u8, Associativity)>) -> Vec<String> {
    let infix_expression = raw_infix_expression.replace('"', "");
    let mut postfix_expression: Vec<String> = Vec::new();
    let mut operator_stack: Vec<char> = Vec::new();
    let mut number_buffer = String::new();

    for current_char in infix_expression.chars() {
        if operators.contains_key(&current_char) {
            if number_buffer.len() > 0 {
                postfix_expression.push(number_buffer.clone());
                number_buffer.clear();
            } else if current_char == '-' {
                number_buffer.push(current_char);
                continue;
            } else {
                panic!("Syntax Error! Expected number before operator in math expression");
            }

            let (operator_precedence, _) = *(operators.get(&current_char)).expect("You won't see this error message");
            postfix_expression.append(&mut get_higher_precedence_operators(&operators, &mut operator_stack, operator_precedence));
            operator_stack.push(current_char);
        }

        else if current_char == '(' {
            if number_buffer.len() > 0 {
                postfix_expression.push(number_buffer.clone());
                number_buffer.clear();
            }

            operator_stack.push('(');
        }

        else if current_char == ')' {
            if number_buffer.len() > 0 {
                postfix_expression.push(number_buffer.clone());
                number_buffer.clear();
            }

            postfix_expression.append(&mut get_higher_precedence_operators(&operators, &mut operator_stack, 0));

            if operator_stack.len() > 0 && operator_stack[operator_stack.len() - 1] == '(' {
                operator_stack.pop();
            } else {panic!("Unmatched Paranthesis in Math Expression!");}
        }

        else {
            number_buffer.push(current_char);
        }
    }

    postfix_expression.append(&mut get_higher_precedence_operators(&operators, &mut operator_stack, 0));

    postfix_expression
}

Meta

rustc --version --verbose:

rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-unknown-linux-gnu
release: 1.89.0
LLVM version: 20.1.7

Error output

thread 'rustc' panicked at compiler/rustc_borrowck/src/diagnostics/move_errors.rs:828:76:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7ff8108d8203 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hf435e8e9347709a8
   1:     0x7ff811002bff - core::fmt::write::h0a51fad3804c5e7c
   2:     0x7ff8124d1591 - std::io::Write::write_fmt::h9759e4151bf4a45e
   3:     0x7ff8108d8062 - std::sys::backtrace::BacktraceLock::print::h1ec5ce5bb8ee285e
   4:     0x7ff8108dbb5a - std::panicking::default_hook::{{closure}}::h5ffefe997a3c75e4
   5:     0x7ff8108db6df - std::panicking::default_hook::h820c77ba0601d6bb
   6:     0x7ff80f9c9103 - std[da76efc55aba569b]::panicking::update_hook::<alloc[679dddab44c6194d]::boxed::Box<rustc_driver_impl[aa7064ecaea87566]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7ff8108dc3ab - std::panicking::rust_panic_with_hook::h8b29cbe181d50030
   8:     0x7ff8108dc076 - std::panicking::begin_panic_handler::{{closure}}::h9f5b6f6dc6fde83e
   9:     0x7ff8108d86d9 - std::sys::backtrace::__rust_end_short_backtrace::hd7b0c344383b0b61
  10:     0x7ff8108dbd8d - __rustc[5224e6b81cd82a8f]::rust_begin_unwind
  11:     0x7ff80d091480 - core::panicking::panic_fmt::hc49fc28484033487
  12:     0x7ff80d09943c - core::panicking::panic::h239804395728b21f
  13:     0x7ff80d092f89 - core::option::unwrap_failed::hec54eb4737b382ca
  14:     0x7ff80f766c28 - <rustc_borrowck[655779ff03f826b6]::MirBorrowckCtxt>::add_move_error_details
  15:     0x7ff80f763b01 - <rustc_borrowck[655779ff03f826b6]::MirBorrowckCtxt>::report
  16:     0x7ff812595d44 - rustc_borrowck[655779ff03f826b6]::do_mir_borrowck
  17:     0x7ff8112688a8 - rustc_borrowck[655779ff03f826b6]::mir_borrowck
  18:     0x7ff8112685d9 - rustc_query_impl[36e6800b9757404d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[36e6800b9757404d]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e0a019250b2560b5]::query::erase::Erased<[u8; 8usize]>>
  19:     0x7ff81126403e - rustc_query_system[4eadbad177027a71]::query::plumbing::try_execute_query::<rustc_query_impl[36e6800b9757404d]::DynamicConfig<rustc_data_structures[f798075dc9c9ee18]::vec_cache::VecCache<rustc_span[93f6ac7b0b889bbe]::def_id::LocalDefId, rustc_middle[e0a019250b2560b5]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[4eadbad177027a71]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[36e6800b9757404d]::plumbing::QueryCtxt, true>
  20:     0x7ff8111efbd4 - rustc_query_impl[36e6800b9757404d]::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
  21:     0x7ff811971955 - <rustc_middle[e0a019250b2560b5]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[5344109f4998426e]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  22:     0x7ff81196f3a8 - rustc_interface[5344109f4998426e]::passes::analysis
  23:     0x7ff81196e875 - rustc_query_impl[36e6800b9757404d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[36e6800b9757404d]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e0a019250b2560b5]::query::erase::Erased<[u8; 0usize]>>
  24:     0x7ff8121cca02 - rustc_query_system[4eadbad177027a71]::query::plumbing::try_execute_query::<rustc_query_impl[36e6800b9757404d]::DynamicConfig<rustc_query_system[4eadbad177027a71]::query::caches::SingleCache<rustc_middle[e0a019250b2560b5]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[36e6800b9757404d]::plumbing::QueryCtxt, true>
  25:     0x7ff8121cc323 - rustc_query_impl[36e6800b9757404d]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  26:     0x7ff812447f16 - rustc_interface[5344109f4998426e]::passes::create_and_enter_global_ctxt::<core[4727a1a5e2f8bf41]::option::Option<rustc_interface[5344109f4998426e]::queries::Linker>, rustc_driver_impl[aa7064ecaea87566]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  27:     0x7ff8122ea125 - rustc_interface[5344109f4998426e]::interface::run_compiler::<(), rustc_driver_impl[aa7064ecaea87566]::run_compiler::{closure#0}>::{closure#1}
  28:     0x7ff8122366b8 - std[da76efc55aba569b]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5344109f4998426e]::util::run_in_thread_with_globals<rustc_interface[5344109f4998426e]::util::run_in_thread_pool_with_globals<rustc_interface[5344109f4998426e]::interface::run_compiler<(), rustc_driver_impl[aa7064ecaea87566]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29:     0x7ff812236396 - <<std[da76efc55aba569b]::thread::Builder>::spawn_unchecked_<rustc_interface[5344109f4998426e]::util::run_in_thread_with_globals<rustc_interface[5344109f4998426e]::util::run_in_thread_pool_with_globals<rustc_interface[5344109f4998426e]::interface::run_compiler<(), rustc_driver_impl[aa7064ecaea87566]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[4727a1a5e2f8bf41]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7ff81223c385 - std::sys::pal::unix::thread::Thread::new::thread_start::h1ff51d6e85162efd
  31:     0x7ff80ba969cb - <unknown>
  32:     0x7ff80bb1aa0c - <unknown>
  33:                0x0 - <unknown>

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.89.0 (29483883e 2025-08-04) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `topostfix::get_higher_precedence_operators`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `slmcompiler` (bin "slmcompiler")

Caused by:
  process didn't exit successfully: `/home/evilssouls/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name slmcompiler --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=232 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=a455d1093776e0ce -C extra-filename=-71e51354082a1ebf --out-dir /home/evilssouls/repos/local/Rust/slmcompiler/target/debug/deps -C incremental=/home/evilssouls/repos/local/Rust/slmcompiler/target/debug/incremental -L dependency=/home/evilssouls/repos/local/Rust/slmcompiler/target/debug/deps` (exit status: 101)
Backtrace

thread 'rustc' panicked at compiler/rustc_borrowck/src/diagnostics/move_errors.rs:828:76:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: core::option::unwrap_failed
   4: <rustc_borrowck::MirBorrowckCtxt>::add_move_error_details
   5: <rustc_borrowck::MirBorrowckCtxt>::report
   6: rustc_borrowck::do_mir_borrowck
   7: rustc_borrowck::mir_borrowck
      [... omitted 1 frame ...]
   8: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
   9: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  10: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  11: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions