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

Calling a function declared in the Sized trait from a pub function results in an ICE #90366

Closed
Aiden2207 opened this issue Oct 28, 2021 · 3 comments
Labels
A-lang-item Area: Language items C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aiden2207
Copy link

The following bare bones no_core program results in an ICE.

#![no_std]
#![no_core]
#![feature(lang_items)]
#![feature(no_core)]


#[lang = "sized"]
pub trait Sized {
  fn foo(){}
}

pub fn bar() {
    u16::foo();
}

Playground

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_monomorphize/src/collector.rs:894:93
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e269e6bf47f40c9046cd44ab787881d700099252/library/std/src/panicking.rs:495:5
   1: core::panicking::panic_fmt
             at /rustc/e269e6bf47f40c9046cd44ab787881d700099252/library/core/src/panicking.rs:107:14
   2: core::panicking::panic
             at /rustc/e269e6bf47f40c9046cd44ab787881d700099252/library/core/src/panicking.rs:50:5
   3: rustc_monomorphize::collector::collect_neighbours
   4: rustc_monomorphize::collector::collect_items_rec
   5: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
   6: rustc_monomorphize::collector::collect_crate_mono_items
   7: rustc_monomorphize::partitioning::collect_and_partition_mono_items
   8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>>
   9: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_and_partition_mono_items, rustc_query_impl::plumbing::QueryCtxt>
  10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  11: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
  12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::CrateNum, &[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)]>>
  13: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::exported_symbols, rustc_query_impl::plumbing::QueryCtxt>
  14: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  15: rustc_metadata::rmeta::encoder::encode_metadata_impl
  16: rustc_data_structures::sync::join::<rustc_metadata::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata::rmeta::encoder::encode_metadata::{closure#1}, rustc_metadata::rmeta::encoder::EncodedMetadata, ()>
  17: rustc_metadata::rmeta::encoder::encode_metadata
  18: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorReported>>
  19: <rustc_interface::queries::Queries>::ongoing_codegen
  20: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  21: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}>
  22: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.0-nightly (e269e6bf4 2021-10-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
#1 [exported_symbols] exported_symbols
end of query stack
error: could not compile `playground` 

Interestingly, if you remove the pub from bar it compiles fine. The most sensible thing to do is probably disallow adding methods to the Sized lang item.

@Aiden2207 Aiden2207 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 Oct 28, 2021
@asquared31415
Copy link
Contributor

would be covered by #9307, but this is an interesting and new example!

@asquared31415
Copy link
Contributor

@rustbot label +A-lang-item

@rustbot rustbot added the A-lang-item Area: Language items label Oct 29, 2021
@Noratrieb Noratrieb added the requires-internal-features This issue requires the use of internal features. label Apr 5, 2023
@Noratrieb
Copy link
Member

wontfix

@Noratrieb Noratrieb closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lang-item Area: Language items C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. 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

4 participants