Skip to content

ICE in codemap::CodeMap::span_to_lines when error occurs in macro #25793

Closed
@nwin

Description

@nwin

The following code produces an ICE (using the latest nightly)

macro_rules! width(
    ($this:expr) => {
        $this.width.unwrap()
    }
);

struct HasInfo {
    width: Option<usize>
}

impl HasInfo {
    fn get_size(&mut self, n: usize) -> usize {
        n
    }

    fn get_other(&mut self) -> usize {
        self.get_size(width!(self))
    }
}

fn main() {
    println!("hello?");
}

Backtrace:

$ RUST_BACKTRACE=1 rustc test.rs
test.rs:17:30: 3:20 error: cannot use `self.width` because it was mutably borrowed
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'capacity overflow', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libcore/option.rs:330

stack backtrace:
   1:        0x10834491f - sys::backtrace::write::hbd92b2f3b9d1f59bh7r
   2:        0x10834cf80 - panicking::on_panic::hdc2c5977e67a233aUlw
   3:        0x108308105 - rt::unwind::begin_unwind_inner::h01673f860cb84cd8D3v
   4:        0x108308f3c - rt::unwind::begin_unwind_fmt::h9151fe47c4b99bcdJ2v
   5:        0x10834cadc - rust_begin_unwind
   6:        0x10839c7f5 - panicking::panic_fmt::he085f3b18c15d040hJy
   7:        0x107ab1183 - codemap::CodeMap::span_to_lines::hb2f0d1a92c447e1btLA
   8:        0x107af89eb - diagnostic::emit::h0cb83e197668e62aspC
   9:        0x107af631c - diagnostic::EmitterWriter.Emitter::emit::h514d00ff1c0c52feamC
  10:        0x107aa7969 - diagnostic::SpanHandler::span_err::h2e7e4e702a3c83e0gSB
  11:        0x1054c5c43 - session::Session::span_err::hb309dbdc83438db3WGq
  12:        0x104f015f4 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>::consume_common::h37627587e5d63ecfQWa
  13:        0x104f00fd1 - borrowck::check_loans::CheckLoanCtxt<'a, 'tcx>.euv..Delegate<'tcx>::consume::h70f8cd9f17ba9508Bea
  14:        0x104f1530a - middle::expr_use_visitor::ExprUseVisitor<'d, 't, 'tcx, TYPER>::consume_expr::h15185387293697103588
  15:        0x104f11f2e - middle::expr_use_visitor::ExprUseVisitor<'d, 't, 'tcx, TYPER>::walk_expr::h15228336715392409603
  16:        0x104f1531e - middle::expr_use_visitor::ExprUseVisitor<'d, 't, 'tcx, TYPER>::consume_expr::h15185387293697103588
  17:        0x104f11f2e - middle::expr_use_visitor::ExprUseVisitor<'d, 't, 'tcx, TYPER>::walk_expr::h15228336715392409603
  18:        0x104f1531e - middle::expr_use_visitor::ExprUseVisitor<'d, 't, 'tcx, TYPER>::consume_expr::h15185387293697103588
  19:        0x104f30aef - borrowck::borrowck_fn::h4c8fd678dfdeee49NOe
  20:        0x104f300dc - borrowck::BorrowckCtxt<'a, 'tcx>.Visitor<'v>::visit_fn::h55da20bf55e34495bGe
  21:        0x104f32ab4 - visit::walk_impl_item::h12505514548441264404
  22:        0x104f3378a - visit::walk_item::h2754692921043539544
  23:        0x104f32c08 - borrowck::check_crate::h3db16b6efa27d8adQIe
  24:        0x104a9b880 - driver::phase_3_run_analysis_passes::hba2077d3401024fbtGa
  25:        0x104a7bd5c - driver::compile_input::hddc4eab8e7fc8420Qba
  26:        0x104b3ac83 - run_compiler::hf4a5110b6d35543565b
  27:        0x104b383ea - boxed::F.FnBox<A>::call_box::h8166354692369242215
  28:        0x104b37947 - rt::unwind::try::try_fn::h645230996156021718
  29:        0x1083cf488 - rust_try_inner
  30:        0x1083cf475 - rust_try
  31:        0x104b37c1d - boxed::F.FnBox<A>::call_box::h7235942386744103169
  32:        0x10834b97d - sys::thread::Thread::new::thread_start::h7bede09625198736Cov
  33:     0x7fff8b475267 - _pthread_body
  34:     0x7fff8b4751e4 - _pthread_start

Probably an duplicate of #25353 or #24761. I opened a new bug since I was able to reduce it to a minimal example. This is not related to the borrow checker as it also crashes if I change $this.width to $this.undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions