Skip to content

ICE: called Result::unwrap() on an Err value: NoSolution in rustc_borrowck/src/type_check/mod.rs #137579

Closed
@cushionbadak

Description

@cushionbadak

Code

#![allow(incomplete_features)]
#![feature(dyn_star)]

trait Trait {}
impl Trait for () {}

struct Wrapper<T: ?Sized>(T);

const OBJECT: *const (dyn Trait + Send) = &();
const _: *const Wrapper<dyn* Drop> = OBJECT as _;

fn main() {}
Original Code (Mutant from Fuzzing)

//! Test that non-coercion casts aren't allowed to drop the principal,
//! because they cannot modify the pointer metadata.
//!
//! We test this in a const context to guard against UB if this is allowed
//! in the future.

trait Trait {}
impl Trait for () {}

struct Wrapper<T: ?Sized>(T);

const OBJECT: *const (dyn Trait + Send) = &();

// coercions are allowed
const _: *const dyn Send = OBJECT as _;

// casts are **not** allowed
const _: *const Wrapper<dyn* Drop> = OBJECT as _;
//~^ ERROR casting `*const (dyn Trait + Send + 'static)` as `*const Wrapper<dyn Send>` is invalid

fn main() {}


// /home/jb/workspace/seeds_250219/tests/ui/cast/ptr-to-trait-obj-drop-principal.rs

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (617aad8c2 2025-02-24)
binary: rustc
commit-hash: 617aad8c2e8783f6df8e5d1f8bb1e4bcdc70aa7b
commit-date: 2025-02-24
host: x86_64-apple-darwin
release: 1.87.0-nightly
LLVM version: 20.1.0

Error output

thread 'rustc' panicked at compiler/rustc_borrowck/src/type_check/mod.rs:2165:38:
called `Result::unwrap()` on an `Err` value: NoSolution
Backtrace

thread 'rustc' panicked at compiler/rustc_borrowck/src/type_check/mod.rs:2165:38:
called `Result::unwrap()` on an `Err` value: NoSolution
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: <rustc_borrowck::type_check::TypeChecker>::check_rvalue
   4: <rustc_borrowck::type_check::TypeChecker>::typeck_mir
   5: rustc_borrowck::type_check::type_check
   6: rustc_borrowck::nll::compute_regions
   7: rustc_borrowck::do_mir_borrowck
   8: rustc_borrowck::mir_borrowck
      [... omitted 1 frame ...]
   9: rustc_middle::query::plumbing::query_get_at::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>>
  10: rustc_mir_transform::mir_drops_elaborated_and_const_checked
      [... omitted 1 frame ...]
  11: rustc_middle::query::plumbing::query_get_at::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>>
  12: rustc_mir_transform::mir_for_ctfe
      [... omitted 1 frame ...]
  13: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  14: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 2 frames ...]
  15: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 24]>>>
  16: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
      [... omitted 2 frames ...]
  17: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}
  18: rustc_hir_analysis::check_crate
  19: rustc_interface::passes::run_required_analyses
  20: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  21: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  22: 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.

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/Volumes/T7/workspace/250225 scratch/codes/rustc-ice-2025-02-25T03_28_26-8433.txt` to your bug report

query stack during panic:
#0 [mir_borrowck] borrow-checking `_`
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `_`
#2 [mir_for_ctfe] caching mir of `_` for CTFE
#3 [eval_to_allocation_raw] const-evaluating + checking `_`
#4 [eval_to_const_value_raw] simplifying constant for the type system `_`
#5 [analysis] running analysis passes on this crate
end of query stack

Note

  • ICE location: compiler/rustc_borrowck/src/type_check/mod.rs Line-2165
    self.sub_types(
    src_obj,
    dst_obj,
    location.to_locations(),
    ConstraintCategory::Cast {
    is_implicit_coercion: false,
    unsize_to: None,
    },
    )
    .unwrap();

@rustbot label +F-dyn_star

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-dyn_star`#![feature(dyn_star)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-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