Skip to content

ICE: Type may implement copy, but there is no other error. #144165

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

struct S<T: 'static>( Option<&'static T>);




impl<T: 'static> Copy for S<T> where S<T>: Copy + Clone {}
impl<T: 'static> Clone for S<T>  {
    fn clone(&self) -> Self { *self }
}
fn main() {
    
}

original:

//@ run-pass
struct S<T: 'static>(#[allow(dead_code)] Option<&'static T>);

trait Tr { type Out; }
impl<T> Tr for T { type Out = T; }

impl<T: 'static> Copy for S<T> where S<T>: Copy + Clone {}
impl<T: 'static> Clone for S<T> where S<T>: Tr<Out=T> {
    fn clone(&self) -> Self { *self }
}
fn main() {
    S::<()>(None);
}

Version information

rustc 1.90.0-nightly (82310651b 2025-07-18)
binary: rustc
commit-hash: 82310651b93a594a3fd69015e1562186a080d94c
commit-date: 2025-07-18
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

warning: struct `S` is never constructed
 --> /tmp/icemaker_global_tempdir.M5kg6WQXJqfU/rustc_testrunner_tmpdir_reporting.PyxBZ6ga2OTn/mvce.rs:2:8
  |
2 | struct S<T: 'static>( Option<&'static T>);
  |        ^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: Type may implement copy, but there is no other error.
 --> /tmp/icemaker_global_tempdir.M5kg6WQXJqfU/rustc_testrunner_tmpdir_reporting.PyxBZ6ga2OTn/mvce.rs:9:31
  |
9 |     fn clone(&self) -> Self { *self }
  |                               ^^^^^
  |
note: delayed at compiler/rustc_borrowck/src/diagnostics/move_errors.rs:275:28
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: <rustc_borrowck::MirBorrowckCtxt>::report
         5: rustc_borrowck::do_mir_borrowck
         6: rustc_borrowck::mir_borrowck
         7: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<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>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
         9: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
        10: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
        11: rustc_interface::passes::analysis
        12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        14: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        15: 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}
        16: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        17: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        18: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        19: std::sys::pal::unix::thread::Thread::new::thread_start
        20: <unknown>
        21: <unknown>
 --> /tmp/icemaker_global_tempdir.M5kg6WQXJqfU/rustc_testrunner_tmpdir_reporting.PyxBZ6ga2OTn/mvce.rs:9:31
  |
9 |     fn clone(&self) -> Self { *self }
  |                               ^^^^^

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: rustc 1.90.0-nightly (82310651b 2025-07-18) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions