Skip to content

called Option::unwrap() on a None value in compiler/rustc_hir_analysis/src/delegation.rs #128810

Closed
@Naserume

Description

@Naserume

Code

#![feature(fn_delegation)]

use std::marker::PhantomData;

pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>);

impl<'a> InvariantRef<'a, ()> {
    pub const NEW: Self = InvariantRef::new(&());
}

trait Trait {
    fn foo(&self) -> u8 { 0 }
}

struct Z(u8);

impl Trait for Z {
    reuse <u8 as Trait>::{foo} { &const { InvariantRef::<'a>::NEW } }
}

fn main() { }

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (60d146580 2024-08-06)
binary: rustc
commit-hash: 60d146580c10036ce89e019422c6bc2fd9729b65
commit-date: 2024-08-06
host: x86_64-apple-darwin
release: 1.82.0-nightly
LLVM version: 19.1.0

Error output

error[E0261]: use of undeclared lifetime name `'a`
  --> ./1E910.rs:18:58
   |
18 |     reuse <u8 as Trait>::{foo} { &const { InvariantRef::<'a>::NEW } }
   |                                                          ^^ undeclared lifetime
   |
help: consider introducing lifetime `'a` here
   |
18 |     reuse <u8 as Trait>::{foo'a, } { &const { InvariantRef::<'a>::NEW } }
   |                              +++
help: consider introducing lifetime `'a` here
   |
17 | impl<'a> Trait for Z {
   |     ++++

warning: the feature `fn_delegation` is incomplete and may not be safe to use and/or cause compiler crashes
 --> ./1E910.rs:1:12
  |
1 | #![feature(fn_delegation)]
  |            ^^^^^^^^^^^^^
  |
  = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
  = note: `#[warn(incomplete_features)]` on by default

error[E0599]: no function or associated item named `new` found for struct `InvariantRef` in the current scope
 --> ./1E910.rs:8:41
  |
5 | pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>);
  | -------------------------------------- function or associated item `new` not found for this struct
...
8 |     pub const NEW: Self = InvariantRef::new(&());
  |                                         ^^^ function or associated item not found in `InvariantRef<'_, _>`

Backtrace

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/delegation.rs:245:58:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:        0x104af3eb7 - std::backtrace::Backtrace::create::hab0b2157d02f6e92
   1:        0x104af3e05 - std::backtrace::Backtrace::force_capture::h20bc09614659a271
   2:        0x10e16f2b4 - std[513de39480af1bab]::panicking::update_hook::<alloc[88fbee91b568d05e]::boxed::Box<rustc_driver_impl[1a7a7dac5035a0ee]::install_ice_hook::{closure#0}>>::{closure#0}
   3:        0x104b0ded0 - std::panicking::rust_panic_with_hook::h68d7251319b974a6
   4:        0x104b0d722 - std::panicking::begin_panic_handler::{{closure}}::ha88851b9fb268d98
   5:        0x104b0acd9 - std::sys::backtrace::__rust_end_short_backtrace::h5540b8654da0543b
   6:        0x104b0d39c - _rust_begin_unwind
   7:        0x104b74aea - core::panicking::panic_fmt::h6a779485efe923d2
   8:        0x104b74b94 - core::panicking::panic::h222bc2761b0de3d1
   9:        0x104b74a38 - core::option::unwrap_failed::h5fc060f6c9bf92ba
  10:        0x10e5127d2 - rustc_hir_analysis[540b4a187aa4fa02]::delegation::inherit_sig_for_delegation_item
  11:        0x10f81956b - rustc_query_impl[db7d5818ebb544c0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db7d5818ebb544c0]::query_impl::inherit_sig_for_delegation_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef4ebef1f35b9a45]::query::erase::Erased<[u8; 16usize]>>
  12:        0x10f7e0b9e - <rustc_query_impl[db7d5818ebb544c0]::query_impl::inherit_sig_for_delegation_item::dynamic_query::{closure#2} as core[31c80208252ed77d]::ops::function::FnOnce<(rustc_middle[ef4ebef1f35b9a45]::ty::context::TyCtxt, rustc_span[af5dc13a57d4458]::def_id::LocalDefId)>>::call_once
  13:        0x10f6933e5 - rustc_query_system[9c8bd583e072577f]::query::plumbing::try_execute_query::<rustc_query_impl[db7d5818ebb544c0]::DynamicConfig<rustc_query_system[9c8bd583e072577f]::query::caches::VecCache<rustc_span[af5dc13a57d4458]::def_id::LocalDefId, rustc_middle[ef4ebef1f35b9a45]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[db7d5818ebb544c0]::plumbing::QueryCtxt, false>
  14:        0x10f867b57 - rustc_query_impl[db7d5818ebb544c0]::query_impl::inherit_sig_for_delegation_item::get_query_non_incr::__rust_end_short_backtrace
  15:        0x10e5a21f7 - <dyn rustc_hir_analysis[540b4a187aa4fa02]::hir_ty_lowering::HirTyLowerer>::lower_ty_common::{closure#0}
  16:        0x10e86bad0 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::suggest_missing_return_type
  17:        0x10e7585aa - <rustc_hir_typeck[d66b43df352b27be]::coercion::CoerceMany<rustc_hir[53162fccad4b280c]::hir::Expr>>::report_return_mismatched_types
  18:        0x10e7b5007 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_block_with_expected
  19:        0x10e76f684 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  20:        0x10e84e499 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_expr_kind
  21:        0x10e76f684 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22:        0x10e84bd10 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_expr_kind
  23:        0x10e76f684 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24:        0x10e7a47cb - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_argument_types
  25:        0x10e743e5d - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::confirm_builtin_call
  26:        0x10e8549ab - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_expr_kind
  27:        0x10e76f684 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:        0x10e7b3904 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_block_with_expected
  29:        0x10e76f684 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:        0x10e7718b3 - <rustc_hir_typeck[d66b43df352b27be]::fn_ctxt::FnCtxt>::check_return_expr
  31:        0x10e836ccc - rustc_hir_typeck[d66b43df352b27be]::check::check_fn
  32:        0x10e8317e8 - rustc_hir_typeck[d66b43df352b27be]::typeck
  33:        0x10f819e5c - rustc_query_impl[db7d5818ebb544c0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db7d5818ebb544c0]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef4ebef1f35b9a45]::query::erase::Erased<[u8; 8usize]>>
  34:        0x10f68ed4e - rustc_query_system[9c8bd583e072577f]::query::plumbing::try_execute_query::<rustc_query_impl[db7d5818ebb544c0]::DynamicConfig<rustc_query_system[9c8bd583e072577f]::query::caches::VecCache<rustc_hir[53162fccad4b280c]::hir_id::OwnerId, rustc_middle[ef4ebef1f35b9a45]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[db7d5818ebb544c0]::plumbing::QueryCtxt, false>
  35:        0x10f83dde1 - rustc_query_impl[db7d5818ebb544c0]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  36:        0x10e4081a6 - <rustc_middle[ef4ebef1f35b9a45]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[540b4a187aa4fa02]::check_crate::{closure#4}>::{closure#0}
  37:        0x10e570d1c - rustc_hir_analysis[540b4a187aa4fa02]::check_crate
  38:        0x10eab2f98 - rustc_interface[55f0bb586236ba3f]::passes::run_required_analyses
  39:        0x10eab5463 - rustc_interface[55f0bb586236ba3f]::passes::analysis
  40:        0x10f819f0c - rustc_query_impl[db7d5818ebb544c0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db7d5818ebb544c0]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef4ebef1f35b9a45]::query::erase::Erased<[u8; 1usize]>>
  41:        0x10f5f8d8e - rustc_query_system[9c8bd583e072577f]::query::plumbing::try_execute_query::<rustc_query_impl[db7d5818ebb544c0]::DynamicConfig<rustc_query_system[9c8bd583e072577f]::query::caches::SingleCache<rustc_middle[ef4ebef1f35b9a45]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[db7d5818ebb544c0]::plumbing::QueryCtxt, false>
  42:        0x10f82445d - rustc_query_impl[db7d5818ebb544c0]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  43:        0x10e119c67 - <rustc_interface[55f0bb586236ba3f]::queries::QueryResult<&rustc_middle[ef4ebef1f35b9a45]::ty::context::GlobalCtxt>>::enter::<core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>, rustc_driver_impl[1a7a7dac5035a0ee]::run_compiler::{closure#0}::{closure#1}::{closure#5}>
  44:        0x10e1765a9 - rustc_interface[55f0bb586236ba3f]::interface::run_compiler::<core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>, rustc_driver_impl[1a7a7dac5035a0ee]::run_compiler::{closure#0}>::{closure#1}
  45:        0x10e1619c1 - std[513de39480af1bab]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[55f0bb586236ba3f]::util::run_in_thread_with_globals<rustc_interface[55f0bb586236ba3f]::util::run_in_thread_pool_with_globals<rustc_interface[55f0bb586236ba3f]::interface::run_compiler<core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>, rustc_driver_impl[1a7a7dac5035a0ee]::run_compiler::{closure#0}>::{closure#1}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#0}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>
  46:        0x10e178a06 - <<std[513de39480af1bab]::thread::Builder>::spawn_unchecked_<rustc_interface[55f0bb586236ba3f]::util::run_in_thread_with_globals<rustc_interface[55f0bb586236ba3f]::util::run_in_thread_pool_with_globals<rustc_interface[55f0bb586236ba3f]::interface::run_compiler<core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>, rustc_driver_impl[1a7a7dac5035a0ee]::run_compiler::{closure#0}>::{closure#1}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#0}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#1} as core[31c80208252ed77d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:        0x104b16afb - std::sys::pal::unix::thread::Thread::new::thread_start::h38612934f7248e43
  48:     0x7ff801f5318b - __pthread_start


rustc version: 1.82.0-nightly (60d146580 2024-08-06)
platform: x86_64-apple-darwin

query stack during panic:
#0 [inherit_sig_for_delegation_item] inheriting delegation signature
#1 [typeck] type-checking `<impl at ./1E910.rs:17:1: 17:17>::foo`
#2 [analysis] running analysis passes on this crate
end of query stack

Note

ICE location

pub(crate) fn inherit_sig_for_delegation_item<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
) -> &'tcx [Ty<'tcx>] {
let sig_id = tcx.hir().opt_delegation_sig_id(def_id).unwrap();
let caller_sig = tcx.fn_sig(sig_id);
if let Err(err) = check_constraints(tcx, def_id, sig_id) {
let sig_len = caller_sig.instantiate_identity().skip_binder().inputs().len() + 1;
let err_type = Ty::new_error(tcx, err);
return tcx.arena.alloc_from_iter((0..sig_len).map(|_| err_type));
}

@rustbot label +F-fn_delegation

Metadata

Metadata

Assignees

Labels

A-HIRArea: The high-level intermediate representation (HIR)C-bugCategory: This is a bug.F-fn_delegation`#![feature(fn_delegation)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.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