Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler ICEs in a diagnositc "expected a type, found a trait" when Clone and Copy is derived. #138264

Open
FractalFir opened this issue Mar 9, 2025 · 1 comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@FractalFir
Copy link
Contributor

Code

This is a reduced example.
The nightly compiler panics when attempting to generate a diagnostic for this code:

trait Float{}
#[derive(Clone,Copy)]
struct Sphere{
	rad:Float,
}

The ICE occurs if a trait is used in place of the type of the field, and the struct containing the incorrect field definition is marked with #[derive(Copy,Clone)]. This ICE does not occur in stable or beta.

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (f5a1ef712 2025-03-07)
binary: rustc
commit-hash: f5a1ef7121ad661b5a21a1d02941c8064d54ee0b
commit-date: 2025-03-07
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Error output

    Checking swiatowid v0.1.0 (/home/michal/swiatowid)
error[E0782]: expected a type, found a trait
 --> src/sphere.rs:4:6
  |
4 |     rad:Float,
  |         ^^^^^
  |
help: you can add the `dyn` keyword if you want a trait object
  |
4 |     rad:dyn Float,
  |         +++


thread 'rustc' panicked at compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs:210:61:
$ident: found ImplItem(ImplItem { ident: clone#4, owner_id: DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone), generics: Generics { params: [GenericParam { hir_id: HirId(DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone).19), def_id: DefId(0:11 ~ swiatowid[28cd]::sphere::{impl#0}::clone::'_), name: Fresh, span: src/sphere.rs:2:10: 2:11 (#4), pure_wrt_drop: false, kind: Lifetime { kind: Elided(Ampersand) }, colon_span: None, source: Generics }], predicates: [], has_where_clause_predicates: false, where_clause_span: src/sphere.rs:2:10: 2:15 (#4), span: src/sphere.rs:2:10: 2:15 (#4) }, kind: Fn(FnSig { header: FnHeader { safety: Normal(Safe), constness: NotConst, asyncness: NotAsync, abi: Rust }, decl: FnDecl { inputs: [Ty { hir_id: HirId(DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone).23), span: src/sphere.rs:2:10: 2:15 (#4), kind: Ref(Lifetime { hir_id: HirId(DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone).20), ident: '_#4, res: Param(DefId(0:11 ~ swiatowid[28cd]::sphere::{impl#0}::clone::'_)) }, MutTy { ty: Ty { hir_id: HirId(DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone).22), span: src/sphere.rs:2:10: 2:15 (#0), kind: Path(Resolved(None, Path { span: src/sphere.rs:2:10: 2:15 (#0), res: SelfTyAlias { alias_to: DefId(0:8 ~ swiatowid[28cd]::sphere::{impl#0}), forbid_generic: false, is_trait_impl: true }, segments: [PathSegment { ident: Self#0, hir_id: HirId(DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone).21), res: SelfTyAlias { alias_to: DefId(0:8 ~ swiatowid[28cd]::sphere::{impl#0}), forbid_generic: false, is_trait_impl: true }, args: None, infer_args: true }] })) }, mutbl: Not }) }], output: Return(Ty { hir_id: HirId(DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone).24), span: src/sphere.rs:2:10: 2:15 (#4), kind: Path(Resolved(None, Path { span: src/sphere.rs:2:10: 2:10 (#4), res: Def(Struct, DefId(0:6 ~ swiatowid[28cd]::sphere::Sphere)), segments: [PathSegment { ident: Sphere#0, hir_id: HirId(DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone).25), res: Def(Struct, DefId(0:6 ~ swiatowid[28cd]::sphere::Sphere)), args: None, infer_args: false }] })) }), c_variadic: false, implicit_self: RefImm, lifetime_elision_allowed: true }, span: src/sphere.rs:2:10: 2:15 (#4) }, BodyId { hir_id: HirId(DefId(0:9 ~ swiatowid[28cd]::sphere::{impl#0}::clone).18) }), defaultness: Final, span: src/sphere.rs:2:10: 2:15 (#4), vis_span: src/sphere.rs:2:10: 2:10 (#4) })
Backtrace

stack backtrace:
   0:     0x7fd4ad3cb634 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc366073dd4ba6a4f
   1:     0x7fd4adc05aa2 - core::fmt::write::hb9256d1d79ff6859
   2:     0x7fd4aef9ddd1 - std::io::Write::write_fmt::hd9a4a51e43d6ab68
   3:     0x7fd4ad3cb492 - std::sys::backtrace::BacktraceLock::print::h81b51ca9905b58b8
   4:     0x7fd4ad3cdd72 - std::panicking::default_hook::{{closure}}::h800cff087746fb32
   5:     0x7fd4ad3cd964 - std::panicking::default_hook::h8e77302320466097
   6:     0x7fd4ac524177 - std[7d1496126c658a52]::panicking::update_hook::<alloc[b94a15b63fd00bf8]::boxed::Box<rustc_driver_impl[95ea3323f115095d]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7fd4ad3ce5e3 - std::panicking::rust_panic_with_hook::hf2880f219899d673
   8:     0x7fd4ad3ce2da - std::panicking::begin_panic_handler::{{closure}}::h42bf1fdcf963f876
   9:     0x7fd4ad3cbb09 - std::sys::backtrace::__rust_end_short_backtrace::hc4c003c597b25946
  10:     0x7fd4ad3cdf9d - rust_begin_unwind
  11:     0x7fd4aa05f240 - core::panicking::panic_fmt::h7ae6caa9a51b5d7e
  12:     0x7fd4ac5f1551 - rustc_hir[6a02ee2565274b65]::hir::expect_failed::<&rustc_hir[6a02ee2565274b65]::hir::Node>
  13:     0x7fd4aee5cd98 - <dyn rustc_hir_analysis[44a464fc9530b13d]::hir_ty_lowering::HirTyLowerer>::prohibit_or_lint_bare_trait_object_ty
  14:     0x7fd4ae3525b6 - <dyn rustc_hir_analysis[44a464fc9530b13d]::hir_ty_lowering::HirTyLowerer>::lower_ty
  15:     0x7fd4ae355628 - <dyn rustc_hir_analysis[44a464fc9530b13d]::hir_ty_lowering::HirTyLowerer>::lower_path
  16:     0x7fd4ae351c5a - <dyn rustc_hir_analysis[44a464fc9530b13d]::hir_ty_lowering::HirTyLowerer>::lower_ty
  17:     0x7fd4aeab6b9d - <rustc_hir_typeck[ad7c24fc563faa0d]::gather_locals::GatherLocalsVisitor>::declare
  18:     0x7fd4ae326b67 - <rustc_hir_typeck[ad7c24fc563faa0d]::gather_locals::GatherLocalsVisitor as rustc_hir[6a02ee2565274b65]::intravisit::Visitor>::visit_expr
  19:     0x7fd4ae327d0d - rustc_hir_typeck[ad7c24fc563faa0d]::check::check_fn
  20:     0x7fd4ae31bc78 - rustc_hir_typeck[ad7c24fc563faa0d]::typeck_with_inspect::{closure#0}
  21:     0x7fd4ae31b270 - rustc_query_impl[ffcc3d1c9e8154f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ffcc3d1c9e8154f]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[56e4ff076cda644b]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7fd4adf60d05 - rustc_query_system[973ddc25b5c3187c]::query::plumbing::try_execute_query::<rustc_query_impl[ffcc3d1c9e8154f]::DynamicConfig<rustc_data_structures[16871ea2f26fa4bd]::vec_cache::VecCache<rustc_span[515292683a253d38]::def_id::LocalDefId, rustc_middle[56e4ff076cda644b]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[973ddc25b5c3187c]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ffcc3d1c9e8154f]::plumbing::QueryCtxt, true>
  23:     0x7fd4adf5d307 - rustc_query_impl[ffcc3d1c9e8154f]::query_impl::typeck::get_query_incr::__rust_end_short_backtrace
  24:     0x7fd4adf5ce7f - <rustc_middle[56e4ff076cda644b]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[44a464fc9530b13d]::check_crate::{closure#3}>::{closure#0}
  25:     0x7fd4adf5c4fb - rustc_hir_analysis[44a464fc9530b13d]::check_crate
  26:     0x7fd4ae0754b2 - rustc_interface[307c5e6bd736cecc]::passes::run_required_analyses
  27:     0x7fd4aeb8637a - rustc_interface[307c5e6bd736cecc]::passes::analysis
  28:     0x7fd4aeb86359 - rustc_query_impl[ffcc3d1c9e8154f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ffcc3d1c9e8154f]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[56e4ff076cda644b]::query::erase::Erased<[u8; 0usize]>>
  29:     0x7fd4aeb8172a - rustc_query_system[973ddc25b5c3187c]::query::plumbing::try_execute_query::<rustc_query_impl[ffcc3d1c9e8154f]::DynamicConfig<rustc_query_system[973ddc25b5c3187c]::query::caches::SingleCache<rustc_middle[56e4ff076cda644b]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[ffcc3d1c9e8154f]::plumbing::QueryCtxt, true>
  30:     0x7fd4aeb81236 - rustc_query_impl[ffcc3d1c9e8154f]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  31:     0x7fd4aed1623d - rustc_interface[307c5e6bd736cecc]::passes::create_and_enter_global_ctxt::<core[2ed51ce221d9613e]::option::Option<rustc_interface[307c5e6bd736cecc]::queries::Linker>, rustc_driver_impl[95ea3323f115095d]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  32:     0x7fd4aed06160 - rustc_interface[307c5e6bd736cecc]::interface::run_compiler::<(), rustc_driver_impl[95ea3323f115095d]::run_compiler::{closure#0}>::{closure#1}
  33:     0x7fd4aeb94588 - std[7d1496126c658a52]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[307c5e6bd736cecc]::util::run_in_thread_with_globals<rustc_interface[307c5e6bd736cecc]::util::run_in_thread_pool_with_globals<rustc_interface[307c5e6bd736cecc]::interface::run_compiler<(), rustc_driver_impl[95ea3323f115095d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  34:     0x7fd4aeb94e74 - <<std[7d1496126c658a52]::thread::Builder>::spawn_unchecked_<rustc_interface[307c5e6bd736cecc]::util::run_in_thread_with_globals<rustc_interface[307c5e6bd736cecc]::util::run_in_thread_pool_with_globals<rustc_interface[307c5e6bd736cecc]::interface::run_compiler<(), rustc_driver_impl[95ea3323f115095d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[2ed51ce221d9613e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7fd4aeb96277 - std::sys::pal::unix::thread::Thread::new::thread_start::h39d9c8bec2c62e1a
  36:     0x7fd4a8c7e168 - start_thread
  37:     0x7fd4a8d0214c - __clone3
  38:                0x0 - <unknown>

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 `/home/michal/swiatowid/rustc-ice-2025-03-09T08_12_30-22110.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `sphere::<impl at src/sphere.rs:2:10: 2:15>::clone`
#1 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0782`.
error: could not compile `swiatowid` (bin "swiatowid") due to 1 previous error

@FractalFir FractalFir added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 9, 2025
@matthiaskrgr
Copy link
Member

duplicate of #138211 I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants