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

ICE on trying to impl Add for i32 #110538

Closed
bugaevc opened this issue Apr 19, 2023 · 7 comments
Closed

ICE on trying to impl Add for i32 #110538

bugaevc opened this issue Apr 19, 2023 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lang-item Area: Language items C-bug Category: This is a bug. F-no_core `#![feature(no_core)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bugaevc
Copy link

bugaevc commented Apr 19, 2023

Code

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

#[lang = "sized"]
pub trait Sized {}

#[lang = "copy"]
pub trait Copy {}

#[lang = "add"]
pub trait Add<Rhs = Self> {
    type Output;
    fn add(self, rhs: Rhs) -> Self::Output;
}

impl Add for i32 {
    type Output = i32;
    fn add(self, rhs: i32) -> i32 {
        self + rhs
    }
}

Playground

Meta

rustc --version --verbose:

note: rustc 1.71.0-nightly (d0f204e4d 2023-04-16) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: broken MIR in DefId(0:9 ~ playground[7903]::{impl#0}::add) (NoSolution): could not prove Binder(TraitPredicate(<i32 as Copy>, polarity:Positive), [])
  |
  = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
             1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
             2: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_place
             3: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
             4: rustc_borrowck::nll::compute_regions
             5: rustc_borrowck::do_mir_borrowck
             6: rustc_borrowck::mir_borrowck
             7: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
             8: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
             9: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
            10: rustc_interface::passes::analysis
            11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
            12: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
            13: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            14: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
            15: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
            16: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            17: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/d0f204e4d750b62f9d6c2593405e828757126832/library/alloc/src/boxed.rs:1973:9
            19: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/d0f204e4d750b62f9d6c2593405e828757126832/library/alloc/src/boxed.rs:1973:9
            20: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/d0f204e4d750b62f9d6c2593405e828757126832/library/std/src/sys/unix/thread.rs:108:17
            21: start_thread
            22: clone

Tentatively adding some labels:
@rustbot modify labels: +A-diagnostics +requires-nightly

@bugaevc bugaevc 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 Apr 19, 2023
@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints requires-nightly This issue requires a nightly compiler in some way. labels Apr 19, 2023
@asquared31415
Copy link
Contributor

no_core and lang_items are not well supported and not intended to be used by consumers, so errors are often in the form of ICEs. Here the compiler expects the builtin type i32 to implement Copy but you don't have that impl.

@asquared31415
Copy link
Contributor

@rustbot label +A-lang-item +F-no_core

@rustbot rustbot added A-lang-item Area: Language items F-no_core `#![feature(no_core)]` labels Apr 19, 2023
@compiler-errors
Copy link
Member

Yeah, I don't think this necessarily deserves to fix given that no_core is a perma-unstable feature.

@bugaevc
Copy link
Author

bugaevc commented Apr 20, 2023

Perma-unstable doesn't necessarily have to mean the compiler has to ICE in the most cryptic way, no? Could it at least ICE with something like "expected the built-in i32 type to implement the Copy trait"?

@compiler-errors
Copy link
Member

Sure, My gut feeling is that it's not worth complicating the compiler in this case, sorry 😅

Writing a bug in a core implementation is akin to writing a bug in the compiler itself, as core can be viewed conceptually as an extension of the compiler, just outlining all of the "built-in type info" into a privileged crate.

And just like sometimes, but not always, a malformed function in the compiler itself causes an ICE, sometimes a malformed implementation of core will also cause an ICE.

@compiler-errors
Copy link
Member

As for improving the ICE message itself, not sure. I guess we could do that, but I think it's actually typically more useful for compiler developers to have that (somewhat cryptic, but also more descriptive) error message that it has right now, for when they write real bugs in the compiler

@Noratrieb
Copy link
Member

wontfix: rust-lang/compiler-team#620

@Noratrieb Noratrieb closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2024
@fmease fmease added the requires-internal-features This issue requires the use of internal features. label Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lang-item Area: Language items C-bug Category: This is a bug. F-no_core `#![feature(no_core)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. requires-nightly This issue requires a nightly compiler in some way. 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

6 participants