Skip to content

ICE: panicked at compiler/rustc_errors/src/diagnostic.rs:1006:9 #133915

Closed as duplicate of#133834
@wxie7

Description

@wxie7

I tried this code:

#![allow(dead_code)]
#[derive(Debug)]
struct S {
    s: String,
    t: String,
}
struct T(*const S);
fn unsafe_imm() {
    let s = "".into();
    let t = {
        foo!(-2);
        bar!(-2);
    };
    let my_speed: Box<S> = Box::new(S { s, t });
}

It mutates from the following code, but the following code will not cause a ICE.

#![allow(dead_code)]
#[derive(Debug)]
struct S {
    s: String,
    t: String,
}
struct T(*const S);
fn unsafe_imm() {
    let s = "".into();
    let t = "".into();
    let my_speed: Box<S> = Box::new(S { s, t });
    let p: *const S = Box::into_raw(my_speed);
    let t = T(p);
    let c = || unsafe {
        println!("{:?}", (*t.0).s);
    };
    c();
}
fn unsafe_mut() {
    let s = "".into();
    let t = "".into();
    let mut my_speed: Box<S> = Box::new(S { s, t });
    let p: *mut S = &mut *my_speed;
    let c = || {
        let x = unsafe { &mut (*p).s };
        *x = "s".into();
    };
    c();
}
fn main() {
    unsafe_mut();
    unsafe_imm();
}

Meta

commit id: acabb52

require debug assertions

Backtrace

error: cannot find macro `foo` in this scope
  --> mutant.rs:11:9
   |
11 |         foo!(-2);
   |         ^^^

error: cannot find macro `bar` in this scope
  --> mutant.rs:12:9
   |
12 |         bar!(-2);
   |         ^^^

error[E0601]: `main` function not found in crate `mutant`
  --> mutant.rs:15:2
   |
15 | }
   |  ^ consider adding a `main` function to `mutant.rs`

thread 'rustc' panicked at /home/xieym/exp/rustc/test_data/rust-latest-src/compiler/rustc_errors/src/diagnostic.rs:1006:9:
Span must not be empty and have no suggestion
stack backtrace:
   0:     0x73f1d0b27ced - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h51e5276f25f67
   1:     0x73f1d0ba68a3 - core::fmt::write::h0a73bee6158cdbf1
   2:     0x73f1d0b5a8c9 - std::io::Write::write_fmt::h206d582822858877
   3:     0x73f1d0b27b93 - std::sys::backtrace::BacktraceLock::print::h84a9a4c750ade733
   4:     0x73f1d0af661c - std::panicking::default_hook::{{closure}}::h216e29259e3d5cff
   5:     0x73f1d0af63e5 - std::panicking::default_hook::h03ce982d60640bc4
   6:     0x73f1cc377342 - <alloc[7c2d8435141f8e1e]::boxed::Box<rustc_driver_impl[d7b86d9e63f9aaed]::install_ice_hook::{closure#0}>
   7:     0x73f1d0af6d88 - std::panicking::rust_panic_with_hook::h88b680004200a63a
   8:     0x73f1d0b2827a - std::panicking::begin_panic_handler::{{closure}}::ha56090df9488ab86
   9:     0x73f1d0b27fa9 - std::sys::backtrace::__rust_end_short_backtrace::h8833a10924a5c2d2
  10:     0x73f1d0af670d - rust_begin_unwind
  11:     0x73f1d0baea90 - core::panicking::panic_fmt::h57d6d212ea0ce749
  12:     0x73f1ccbf40cc - <rustc_errors[20cbecb65c2fd5d8]::diagnostic::Diag>::span_suggestion_with_style::<&str, &str>
  13:     0x73f1cca57ed6 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::emit_coerce_suggestions
  14:     0x73f1ccaec0f8 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::demand_coerce_diag
  15:     0x73f1cca5ffec - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_struct_fields
  16:     0x73f1ccaef775 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_kind
  17:     0x73f1cca5b0ef - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  18:     0x73f1ccaec625 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  19:     0x73f1cca81933 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_argument_types
  20:     0x73f1cca3bb4d - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::confirm_builtin_call
  21:     0x73f1ccaf2d4b - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_kind
  22:     0x73f1cca5b0ef - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x73f1ccaec625 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  24:     0x73f1cca8cd03 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_decl
  25:     0x73f1cca8d3f7 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_block
  26:     0x73f1ccaee1e2 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_kind
  27:     0x73f1cca5b0ef - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x73f1ccaec625 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  29:     0x73f1cca5c6cf - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_return_or_body_tail
  30:     0x73f1cce16854 - rustc_hir_typeck[c5136c63f534b988]::check::check_fn
  31:     0x73f1cce0f3ef - rustc_hir_typeck[c5136c63f534b988]::typeck
  32:     0x73f1cebb8e95 - rustc_query_impl[bec2af351405b693]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bec2af3514
  33:     0x73f1ceb283c5 - <rustc_query_impl[bec2af351405b693]::query_impl::typeck::dynamic_query::{closure#2} as core[dcda4f281d99
  34:     0x73f1cea86324 - rustc_query_system[1b6cbf762e62559d]::query::plumbing::try_execute_query::<rustc_query_impl[bec2af351405
  35:     0x73f1cedd836b - rustc_query_impl[bec2af351405b693]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  36:     0x73f1cd0b1074 - <rustc_middle[e6c5fc1c8185df83]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[beef3382d6061d7f]:
  37:     0x73f1cd0c459c - rustc_hir_analysis[beef3382d6061d7f]::check_crate
  38:     0x73f1cc60f1f1 - rustc_interface[3a875bb8a3a01a82]::passes::analysis
  39:     0x73f1cebb94b3 - rustc_query_impl[bec2af351405b693]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bec2af3514
  40:     0x73f1ceb28ef1 - <rustc_query_impl[bec2af351405b693]::query_impl::analysis::dynamic_query::{closure#2} as core[dcda4f281d
  41:     0x73f1ce9d3eec - rustc_query_system[1b6cbf762e62559d]::query::plumbing::try_execute_query::<rustc_query_impl[bec2af351405
  42:     0x73f1ceed8c08 - rustc_query_impl[bec2af351405b693]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  43:     0x73f1cc3505eb - <rustc_middle[e6c5fc1c8185df83]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[d7b86d9e63f9aaed]::
  44:     0x73f1cc3888ad - <rustc_interface[3a875bb8a3a01a82]::queries::QueryResult<&rustc_middle[e6c5fc1c8185df83]::ty::context::G
  45:     0x73f1cc388e85 - <rustc_interface[3a875bb8a3a01a82]::interface::Compiler>::enter::<rustc_driver_impl[d7b86d9e63f9aaed]::r
  46:     0x73f1cc3340f2 - <scoped_tls[46415f2badf08390]::ScopedKey<rustc_span[37f46e797e36bb53]::SessionGlobals>>::set::<rustc_int
  47:     0x73f1cc30495c - rustc_span[37f46e797e36bb53]::create_session_globals_then::<core[dcda4f281d996093]::result::Result<(), re[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
  48:     0x73f1cc33dc72 - std[31742bae037c253]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_with_globals<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_pool_with_globals<rustc_interface[3a875bb8a3a01a82]::interface::run_compiler<core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>, rustc_driver_impl[d7b86d9e63f9aaed]::run_compiler::{closure#0}>::{closure#1}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>
  49:     0x73f1cc3116d4 - <<std[31742bae037c253]::thread::Builder>::spawn_unchecked_<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_with_globals<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_pool_with_globals<rustc_interface[3a875bb8a3a01a82]::interface::run_compiler<core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>, rustc_driver_impl[d7b86d9e63f9aaed]::run_compiler::{closure#0}>::{closure#1}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#1} as core[dcda4f281d996093]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x73f1d0aff91d - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc538cfe9cf5a97c8
  51:     0x73f1d0b2c32b - std::sys::pal::unix::thread::Thread::new::thread_start::h7a196e16c036c2e2
  52:     0x73f1ca094ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  53:     0x73f1ca126850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  54:                0x0 - <unknown>

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.requires-debug-assertionsThis issue requires a build of rustc or tooling with debug-assertions in some way

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions