rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.86k stars 12.66k forks source link

Compiler panic (rustc 1.58.1 (db9d1b20b 2022-01-20) running on x86_64-apple-darwin) #93998

Closed fschuetz closed 1 year ago

fschuetz commented 2 years ago

Code

Unfortunately I cannot provide a minimal example as my code base is quite large and I do not know what triggers the bug exactly. I did a commit in the git repo, so I can provide access to the full code. Bug triggers if I remove some code and try to compile (a Vec that I don't need in the struct).

Original part that compiles:

/// Structure that descibes a node
#[derive(Debug)]
pub struct Node {
    uid: AssetID,
    name: String,
    properties: Option<Vec<Property>>,
    description: String,
    ports: Vec<Port>,
    sub_assets: Vec<Box<dyn GameAsset>>,
}

impl Node {
    /// Create a new empty node
    pub fn new(uid: AssetID) -> Node {
        let name = String::from("");
        let properties = None;
        let description = String::from("");
        let ports = Vec::new();
        let sub_assets = Vec::new();
        Node { uid, name, properties, description, ports, sub_assets }
    }
....

If changed to this triggers panic:

/// Structure that descibes a node
#[derive(Debug)]
pub struct Node {
    uid: AssetID,
    name: String,
    properties: Option<Vec<Property>>,
    description: String,
    sub_assets: Vec<Box<dyn GameAsset>>,
}

impl Node {
    /// Create a new empty node
    pub fn new(uid: AssetID) -> Node {
        let name = String::from("");
        let properties = None;
        let description = String::from("");
        let sub_assets = Vec::new();
        Node { uid, name, properties, description, sub_assets }
    }
...

The trait on the query stack is:

pub trait GameAsset : std::fmt::Debug + Send + Sync {
    /// UID
    /// 
    /// Get the unique id of the asset
    fn uid(&self) -> AssetID;

    /// Name
    /// 
    /// Get the name of the asset
    fn name(&self) -> String;

    /// Properties
    /// 
    /// Return the properties of the asset
    fn properties(&self) -> Option<&Vec<Property>>;

    /// Describe
    /// 
    /// Describes the game asset. Depending on the asset type 
    /// contained assets may be added to the description to make
    /// it complete.
    /// 
    /// TODO - maybe remove as redundant due to interact
    fn describe(&self) -> String;

    /// React to
    /// 
    /// React to an interaction with the game asset. Interaction are based on
    /// verbs. The object responses to the verb by returning an Option, NONE
    /// if the object canot reatct to this and Some() if it does.
    /// 
    /// TODO - maybe add the subject that does the interaction to the signature
    /// TOTO - return a more generic result than String
    fn react_to(&self, a: &Action) -> String;
}

Meta

rustc --version --verbose:

rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-apple-darwin
release: 1.58.1
LLVM version: 13.0.0

Error output

Compiler panic.

Backtrace

``` fschuetz@MacBook-Pro mud-server % RUST_LOG="debug" RUST_BACKTRACE=full cargo run Compiling mud-server v0.1.0 (/Users/fschuetz/Development/balccon_badge/mud-server) thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/compiler/rustc_hir/src/definitions.rs:452:14 stack backtrace: 0: 0x1043e1921 - ::fmt::h90c059b532d34bdd 1: 0x10443323b - core::fmt::write::hefb311138778afb5 2: 0x1043d24da - std::io::Write::write_fmt::h0e0ed87b18ae870c 3: 0x1043e4ae5 - std::panicking::default_hook::{{closure}}::h43f0e51e5825bd5b 4: 0x1043e46cf - std::panicking::default_hook::ha1c3473cbcf391f7 5: 0x111059ad8 - rustc_driver[bc0c73f7d603340f]::DEFAULT_HOOK::{closure#0}::{closure#0} 6: 0x1043e5326 - std::panicking::rust_panic_with_hook::h0db3c4ba5fb4dc12 7: 0x1043e4d74 - std::panicking::begin_panic_handler::{{closure}}::hc6d8c92efeef5a19 8: 0x1043e1d97 - std::sys_common::backtrace::__rust_end_short_backtrace::h7ffb59e898e02a83 9: 0x1043e4d0a - _rust_begin_unwind 10: 0x10445deaf - core::panicking::panic_fmt::h7d73f67464d78916 11: 0x10445de07 - core::panicking::panic::h9721d5a8c5d33ad7 12: 0x1153c9e7b - ::def_path_hash_to_def_id 13: 0x1154b5cfb - as rustc_middle[9174e8a82de199b2]::dep_graph::dep_node::DepNodeExt>::extract_def_id 14: 0x1147ce0aa - rustc_query_impl[1ac6624115046e1]::query_callbacks::type_of::force_from_dep_node 15: 0x1153af87c - ::try_force_from_dep_node 16: 0x11481c72d - >::try_mark_previous_green:: 17: 0x11481c6f7 - >::try_mark_previous_green:: 18: 0x1147dcc9b - >::try_mark_green:: 19: 0x11463c21b - rustc_query_system[75d0032269cc35fc]::query::plumbing::try_load_from_disk_and_cache_in_memory::>, core[1f1de4c38f2722e7]::result::Result> 20: 0x11466fb54 - rustc_query_system[75d0032269cc35fc]::query::plumbing::get_query:: 21: 0x114730c14 - ::evaluate_obligation 22: 0x1150e3ba6 - ::evaluate_obligation 23: 0x1150e3e33 - ::evaluate_obligation_no_overflow 24: 0x1151100b9 - ::process_trait_obligation 25: 0x115106333 - ::progress_changed_obligations 26: 0x11516fcd6 - >::process_obligations::> 27: 0x1151048fa - ::select 28: 0x11510508f - ::select_with_constness_where_possible 29: 0x115104d02 - ::select_all_with_constness_or_error 30: 0x113a54138 - ::select_all_obligations_or_error 31: 0x113b3c896 - ::enter::<(), ::enter<::with_fcx::{closure#0}, ()>::{closure#0}> 32: 0x113bc34b5 - rustc_typeck[4a61b1f133ef930b]::check::wfcheck::check_item_well_formed 33: 0x1148376b8 - >::with_task:: 34: 0x11471331a - rustc_data_structures[2081bee2c561c475]::stack::ensure_sufficient_stack::<((), rustc_query_system[75d0032269cc35fc]::dep_graph::graph::DepNodeIndex), rustc_query_system[75d0032269cc35fc]::query::plumbing::execute_job::{closure#3}> 35: 0x1145b9b6c - rustc_query_system[75d0032269cc35fc]::query::plumbing::try_execute_query::> 36: 0x114678c8b - rustc_query_system[75d0032269cc35fc]::query::plumbing::get_query:: 37: 0x113bf87e9 - >, ::par_visit_all_item_likes::{closure#0}>::{closure#0}::{closure#0}> as core[1f1de4c38f2722e7]::ops::function::FnOnce<()>>::call_once 38: 0x113b4fe4b - rustc_data_structures[2081bee2c561c475]::sync::par_for_each_in::<&alloc[48780002bcfe71e6]::vec::Vec>, ::par_visit_all_item_likes::{closure#0}> 39: 0x113ac5f27 - ::track_errors:: 40: 0x113ac38f9 - rustc_typeck[4a61b1f133ef930b]::check_crate 41: 0x111182e8c - rustc_interface[d6065a329fdb5e3a]::passes::analysis 42: 0x11486377c - >::with_task::> 43: 0x114704575 - rustc_data_structures[2081bee2c561c475]::stack::ensure_sufficient_stack::<(core[1f1de4c38f2722e7]::result::Result<(), rustc_errors[f2b9fb98ecab94a8]::ErrorReported>, rustc_query_system[75d0032269cc35fc]::dep_graph::graph::DepNodeIndex), rustc_query_system[75d0032269cc35fc]::query::plumbing::execute_job>::{closure#3}> 44: 0x114614340 - rustc_query_system[75d0032269cc35fc]::query::plumbing::try_execute_query::>> 45: 0x11472cbc5 - ::analysis 46: 0x1110b7aab - ::enter::> 47: 0x1110732b5 - ::enter::, rustc_errors[f2b9fb98ecab94a8]::ErrorReported>> 48: 0x111064d7b - rustc_span[427cd302a9d93fff]::with_source_map::, rustc_interface[d6065a329fdb5e3a]::interface::create_compiler_and_run, rustc_driver[bc0c73f7d603340f]::run_compiler::{closure#1}>::{closure#1}> 49: 0x11107400f - >::set::, rustc_driver[bc0c73f7d603340f]::run_compiler::{closure#1}>::{closure#0}, core[1f1de4c38f2722e7]::result::Result<(), rustc_errors[f2b9fb98ecab94a8]::ErrorReported>>::{closure#0}::{closure#0}, core[1f1de4c38f2722e7]::result::Result<(), rustc_errors[f2b9fb98ecab94a8]::ErrorReported>> 50: 0x111070be2 - std[4fa01f090b31929d]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver[bc0c73f7d603340f]::run_compiler::{closure#1}>::{closure#0}, core[1f1de4c38f2722e7]::result::Result<(), rustc_errors[f2b9fb98ecab94a8]::ErrorReported>>::{closure#0}, core[1f1de4c38f2722e7]::result::Result<(), rustc_errors[f2b9fb98ecab94a8]::ErrorReported>> 51: 0x1110bd1a5 - <::spawn_unchecked, rustc_driver[bc0c73f7d603340f]::run_compiler::{closure#1}>::{closure#0}, core[1f1de4c38f2722e7]::result::Result<(), rustc_errors[f2b9fb98ecab94a8]::ErrorReported>>::{closure#0}, core[1f1de4c38f2722e7]::result::Result<(), rustc_errors[f2b9fb98ecab94a8]::ErrorReported>>::{closure#1} as core[1f1de4c38f2722e7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 52: 0x1043efa17 - std::sys::unix::thread::Thread::new::thread_start::h13359fe05abc98e9 53: 0x7ff809bf04f4 - __pthread_start 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md note: rustc 1.58.1 (db9d1b20b 2022-01-20) running on x86_64-apple-darwin note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [evaluate_obligation] evaluating trait selection obligation `world::assets::Port: core::marker::Sync` #1 [check_item_well_formed] checking that `world::assets::` is well-formed #2 [analysis] running analysis passes on this crate end of query stack error: could not compile `mud-server` ```

fschuetz commented 2 years ago

Note: Changing edition from 2018 to 2021 in Cargo.toml leads to a successful compilation that does not trigger the crash.

edition = "2021"
Aaron1011 commented 2 years ago

@fschuetz Can you link to your full repository?

fschuetz commented 2 years ago

@fschuetz Can you link to your full repository?

I can. However, its on gitlab. The repo is not public, so a user would be needed, or I can temporarily switch it to public. I can also checkin the code here in github. However, I just noticed one thing: When I checkout the code to a new directory, the compiler does NOT crash. Also, when I copy the directory (cp -r) containing all source and compile, it does not crash. It seems it only crashes in the current directory I have. Now, I could try to move this one out of the way and see if a) it still crashes at another location and b) if I checkout new in the same path as the one that crashes is it still crashes. However, I fear then the crash might become completely unreproducible. Please advise what helps you best?

Link to github repo I crated for this (including all local files, not checked in original gitlab repo): mud-server

Jc2k commented 2 years ago

I had the same panic (same file, same line), also on x86_64-apple-darwin.

I rm -rf my target folder and it fixed the problem, unfortunately I can't recreate the issue now.

One data point I guess is that i'm using VSCode with rust-analyzer. (to be clear, the failure is from cargo build). I know they fight over a lock and thought it was worth mentioning.

fschuetz commented 2 years ago

I had the same panic (same file, same line), also on x86_64-apple-darwin.

I rm -rf my target folder and it fixed the problem, unfortunately I can't recreate the issue now.

One data point I guess is that i'm using VSCode with rust-analyzer. (to be clear, the failure is from cargo build). I know they fight over a lock and thought it was worth mentioning.

I edit in VSCode with rust-analyzer running, but I do compile in the shell. Also, the panic occurs when VSCode is not running.

Jc2k commented 2 years ago

Same here, it's probably a co-incidence. But just making sure to capture anything I've done or use that could have contributed to something getting corrupted in my target folder.

It has been fine since I did cleaned out target, so your broken directory is key to repro atm.

workingjubilee commented 1 year ago

Closing as a probable duplicate of https://github.com/rust-lang/rust/issues/92163