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

RA panic: unexpected lifetime vars in fn ptr: NoSolution #17167

Closed
miraclx opened this issue May 1, 2024 · 2 comments
Closed

RA panic: unexpected lifetime vars in fn ptr: NoSolution #17167

miraclx opened this issue May 1, 2024 · 2 comments
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug I-panic

Comments

@miraclx
Copy link

miraclx commented May 1, 2024

rust-analyzer version: 0.3.1940-standalone (f216be4 2024-04-27)

rustc version: rustc 1.77.2 (25ef9e3d8 2024-04-09)

editor or extension: VSCode + RA v0.3.1940

relevant settings: normal

repository link (if public, optional): -

code snippet to reproduce:

trait MyTrait {}

type MyFunc<'a> = fn() -> Box<dyn MyTrait + 'a>;

thread_local! {
    static MY_TYPE: MyFunc<'static> = handler;
}

fn handler() -> Box<dyn MyTrait + 'static> {
    todo!()
}

This immediately produces #17124 in the form of:

Stack Trace
thread 'Worker' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/chalk-ir-0.97.0/src/lib.rs:2730:10:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <chalk_ir::SubstFolder<I,A> as chalk_ir::fold::TypeFolder<I>>::fold_free_var_lifetime
   4: chalk_ir::fold::TypeSuperFoldable::super_fold_with
   5: chalk_ir::_::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::DynTy<I>>::try_fold_with
   6: chalk_ir::fold::TypeSuperFoldable::super_fold_with
   7: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::GenericArg<I>>::try_fold_with
   8: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::next
   9: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  10: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::try_fold_with
  11: chalk_ir::fold::TypeSuperFoldable::super_fold_with
  12: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::GenericArg<I>>::try_fold_with
  13: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::next
  14: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  15: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::TypeFoldable<I> for chalk_ir::Substitution<I>>::try_fold_with
  16: chalk_solve::infer::instantiate::<impl chalk_solve::infer::InferenceTable<I>>::instantiate_binders_existentially
  17: chalk_solve::infer::unify::Unifier<I>::relate_ty_ty
  18: <chalk_solve::infer::unify::Unifier<I> as chalk_ir::zip::Zipper<I>>::zip_tys
  19: chalk_solve::infer::unify::Unifier<I>::relate
  20: chalk_solve::infer::unify::<impl chalk_solve::infer::InferenceTable<I>>::relate
  21: hir_ty::infer::coerce::<impl hir_ty::infer::unify::InferenceTable>::unify_and
  22: hir_ty::infer::coerce::<impl hir_ty::infer::unify::InferenceTable>::coerce_inner
  23: hir_ty::infer::coerce::<impl hir_ty::infer::unify::InferenceTable>::coerce
  24: hir_ty::infer::coerce::<impl hir_ty::infer::InferenceContext>::coerce
  25: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  26: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  27: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  28: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_return
  29: hir_ty::infer::infer_query
  30: salsa::Cycle::catch
  31: salsa::derived::slot::Slot<Q,MP>::execute
  32: salsa::derived::slot::Slot<Q,MP>::read
  33: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::fetch
  34: <DB as hir_ty::db::HirDatabase>::infer
  35: hir::DefWithBody::diagnostics
  36: hir::ModuleDef::diagnostics
  37: hir::Module::diagnostics
  38: hir::DefWithBody::diagnostics
  39: hir::ModuleDef::diagnostics
  40: hir::Module::diagnostics
  41: ide_diagnostics::diagnostics
  42: std::panicking::try
  43: ide::Analysis::assists_with_fixes
  44: rust_analyzer::handlers::request::handle_code_action
  45: std::panicking::try
  46: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

And when I hover over the MY_TYPE ident, I get the following:

thread 'Worker' panicked at crates/hir-ty/src/lib.rs:550:22:
unexpected lifetime vars in fn ptr: NoSolution
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: hir_ty::CallableSig::from_fn_ptr
   4: <chalk_ir::Ty<hir_ty::interner::Interner> as hir_ty::chalk_ext::TyExt>::callable_sig
   5: hir_ty::infer::unify::InferenceTable::callable_sig
   6: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
   7: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
   8: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
   9: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce_never
  10: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  11: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_coerce
  12: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  13: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  14: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_return
  15: hir_ty::infer::infer_query
  16: salsa::Cycle::catch
  17: salsa::derived::slot::Slot<Q,MP>::execute
  18: salsa::derived::slot::Slot<Q,MP>::read
  19: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::fetch
  20: <DB as hir_ty::db::HirDatabase>::infer
  21: hir::source_analyzer::SourceAnalyzer::new_for_body
  22: hir::semantics::SemanticsImpl::analyze_impl
  23: ide_db::defs::NameRefClass::classify
  24: ide_db::search::FindUsages::found_name_ref
  25: ide_db::search::FindUsages::search
  26: hashbrown::raw::RawIterRange<T>::fold_impl
  27: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  28: ide::highlight_related::highlight_related
  29: std::panicking::try
  30: ide::Analysis::highlight_related
  31: rust_analyzer::handlers::request::handle_document_highlight
  32: std::panicking::try
  33: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

When I inline the type alias in this form:

trait MyTrait {}

thread_local! {
    static MY_TYPE: fn() -> Box<dyn MyTrait + 'static> = handler;
}

fn handler() -> Box<dyn MyTrait + 'static> {
    todo!()
}

Both errors go away.

@miraclx miraclx added the C-bug Category: bug label May 1, 2024
@lnicola lnicola added A-ty type system / type inference / traits / method resolution I-panic labels May 1, 2024
@dfireBird
Copy link
Contributor

Hello,
A fix was pushed with PR #17190 and it was released as part of today's release (version number: 0.4.1949). Can you please test it and report whether the issue is fixed for you or not? Thanks.

@miraclx
Copy link
Author

miraclx commented May 15, 2024

Sorry for the delay, yeah I just checked and I can confirm this is indeed fixed on:

rust-analyzer version: 0.3.1958-standalone (5bf2f85c8 2024-05-09)

Thank you so much!

@miraclx miraclx closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug I-panic
Projects
None yet
Development

No branches or pull requests

3 participants