Skip to content

ICE with const_trait_impl and const_mut_refs and explicit lifetimes #94675

Closed
@leonardo-m

Description

@leonardo-m
#![feature(const_trait_impl, const_mut_refs)]
struct Foo<'a> { bar: &'a mut Vec<usize> }
impl<'a> Foo<'a> {
    const fn spam(&mut self, baz: &mut Vec<u32>) {
        self.bar[0] = baz.len();
    }
}
fn main() {}

Using:

rustc 1.61.0-nightly (c274e4969 2022-03-05)
binary: rustc
commit-hash: c274e4969f058b1c644243181ece9f829efa7594
commit-date: 2022-03-05
host: x86_64-pc-windows-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0
error[E0015]: cannot call non-const fn `Vec::<u32>::len` in constant functions
 --> ...\test.rs:5:27
  |
5 |         self.bar[0] = baz.len();
  |                           ^^^^^
  |
  = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

thread 'rustc' panicked at 'index out of bounds: the len is 2 but the index is 2', compiler\rustc_trait_selection\src\traits\error_reporting\on_unimplemented.rs:179:25
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c274e4969f058b1c644243181ece9f829efa7594\/library\std\src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/c274e4969f058b1c644243181ece9f829efa7594\/library\core\src/panicking.rs:143:14
   2: core::panicking::panic_bounds_check
             at /rustc/c274e4969f058b1c644243181ece9f829efa7594\/library\core\src/panicking.rs:84:5
   3: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::on_unimplemented::InferCtxtExt>::on_unimplemented_note
   4: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_selection_error
   5: <rustc_infer::infer::InferCtxtBuilder>::enter::<(), <rustc_const_eval::transform::check_consts::check::Checker as rustc_middle::mir::visit::Visitor>::visit_terminator::{closure#2}>
   6: <rustc_const_eval::transform::check_consts::check::Checker as rustc_middle::mir::visit::Visitor>::visit_terminator
   7: <rustc_const_eval::transform::check_consts::check::Checker>::check_body
   8: rustc_mir_transform::mir_const_qualif
   9: <rustc_mir_transform::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId)>>::call_once
  10: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::mir::query::ConstQualifs>>
  11: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::mir_const_qualif, rustc_query_impl::plumbing::QueryCtxt>
  12: rustc_mir_transform::mir_promoted
  13: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::mir_promoted, rustc_query_impl::plumbing::QueryCtxt>
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_promoted
  15: rustc_borrowck::mir_borrowck
  16: <rustc_borrowck::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
  17: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::mir::query::BorrowCheckResult>>
  18: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
  19: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::analysis::{closure#2}::{closure#0}>
  20: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
  21: rustc_interface::passes::analysis
  22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  23: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  24: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  25: <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>>
  26: 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}>
  27: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  28: <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.61.0-nightly (c274e4969 2022-03-05) running on x86_64-pc-windows-gnu

note: compiler flags: -Z unstable-options

query stack during panic:
#0 [mir_const_qualif] const checking `<impl at ...\test.rs:3:1: 7:2>::spam`
#1 [mir_promoted] processing `<impl at ...\test.rs:3:1: 7:2>::spam`
#2 [mir_borrowck] borrow-checking `<impl at ...\test.rs:3:1: 7:2>::spam`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0015`.

Tool completed with exit code 101
```rust

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"compiler-errors"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->

Metadata

Metadata

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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions