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

Custom Box::new throws error #101198

Closed
d-sonuga opened this issue Aug 30, 2022 · 3 comments
Closed

Custom Box::new throws error #101198

d-sonuga opened this issue Aug 30, 2022 · 3 comments
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

@d-sonuga
Copy link
Contributor

Code

#![no_std]
#![feature(lang_items, start)]

#[lang = "owned_box"]
struct Box<T>(*mut T);

#[lang = "exchange_malloc"]
unsafe fn alloc() -> *mut u8 {
    core::ptr::null_mut()
}

#[lang = "box_free"]
unsafe fn free<T: ?Sized>(ptr: *mut T) { }

impl<T> Box<T> {
    pub fn new(val: T) -> Box<T> {
        Box::new(val)
    }
}

#[start]
fn main(i: isize, args: *const *const u8) -> isize {
    let x = Box::new(3);
    0
}

#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
    loop {}
}

Meta

rustc --version --verbose:

rustc 1.63.0-nightly (b31f9cc22 2022-06-15)
binary: rustc
commit-hash: b31f9cc22bcd720b37ddf927afe378108a5b9a54
commit-date: 2022-06-15
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5

Error output

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /rustc/b31f9cc22bcd720b37ddf927afe378108a5b9a54/compiler/rustc_middle/src/ty/subst.rs:363:43
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/b31f9cc22bcd720b37ddf927afe378108a5b9a54/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/b31f9cc22bcd720b37ddf927afe378108a5b9a54/library/core/src/panicking.rs:142:14
   2: core::panicking::panic_bounds_check
             at /rustc/b31f9cc22bcd720b37ddf927afe378108a5b9a54/library/core/src/panicking.rs:84:5
   3: rustc_codegen_llvm::debuginfo::metadata::type_di_node
   4: <rustc_codegen_llvm::context::CodegenCx as rustc_codegen_ssa::traits::debuginfo::DebugInfoMethods>::create_dbg_var
   5: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
   6: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
   7: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::symbol::Symbol, rustc_codegen_ssa::ModuleCodegen<rustc_codegen_llvm::ModuleLlvm>>
   8: rustc_codegen_llvm::base::compile_codegen_unit
   9: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  10: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  11: <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::ErrorGuaranteed>>
  12: <rustc_interface::queries::Queries>::ongoing_codegen
  13: <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::ErrorGuaranteed>>
  14: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  15: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
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.63.0-nightly (b31f9cc22 2022-06-15) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
end of query stack

@d-sonuga d-sonuga 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 Aug 30, 2022
@5225225
Copy link
Contributor

5225225 commented Aug 30, 2022

I suspect it's failing because Box in the stdlib isn't defined like that, it has an Allocator generic parameter and allocator field.

@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented Aug 30, 2022

This is probably related to #9307.

@inquisitivecrystal inquisitivecrystal added the requires-nightly This issue requires a nightly compiler in some way. label Dec 11, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 20, 2022
@Noratrieb
Copy link
Member

Noratrieb commented Mar 14, 2023

The compiler expects lang items and intrinsics to be defined as correctly.

@Noratrieb Noratrieb closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2023
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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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