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

Stack overflow when using type_alias_impl_trait with async functions #17403

Closed
alexkirsz opened this issue Jun 12, 2024 · 7 comments · Fixed by #17505
Closed

Stack overflow when using type_alias_impl_trait with async functions #17403

alexkirsz opened this issue Jun 12, 2024 · 7 comments · Fixed by #17505
Assignees
Labels
A-ty type system / type inference / traits / method resolution B-unstable unstable feature C-bug Category: bug I-crash

Comments

@alexkirsz
Copy link
Contributor

alexkirsz commented Jun 12, 2024

rust-analyzer version: rust-analyzer 0.0.0 (72dfbe9 2024-06-10)

rustc version: rustc 1.80.0-nightly (1871252fc 2024-05-15)

editor or extension: Zed

code snippet to reproduce:

#![feature(type_alias_impl_trait)]

type TypeAlias = impl Clone;

async fn alias() -> TypeAlias {
    todo!()
}

This causes an infinite recursion in insert_inference_vars_for_impl_trait, eventually resulting in a stack overflow which crashes RA.

My very naive fix for this issue was to add a set of already seen types to avoid fold_tys recursing, but this causes other issues down the road:

stderr: 2024-06-12T08:06:33.796309Z ERROR hir_ty::infer: Missed RPIT in `insert_inference_vars_for_rpit`
stderr: Panic context:
stderr: > fetch_native_diagnostics
stderr:
stderr: thread 'Worker' panicked at crates/hir/src/semantics.rs:1516:13:
stderr:
stderr:
stderr: Failed to lookup [email protected] in this Semantics.
stderr: Make sure to use only query nodes, derived from this instance of Semantics.
stderr: root node:   [email protected]
stderr: known nodes: [email protected]
stderr:
stderr:
stderr: stack backtrace:
stderr: 0: _rust_begin_unwind
stderr: 1: core::panicking::panic_fmt
stderr: 2: hir::semantics::SemanticsImpl::find_file
stderr: 3: hir::semantics::SemanticsImpl::analyze_impl
stderr: 4: hir::semantics::SemanticsImpl::scope
stderr: 5: ide_diagnostics::handlers::type_mismatch::type_mismatch
stderr: 6: ide_diagnostics::diagnostics
stderr: 7: salsa::Cancelled::catch
stderr: 8: ide::Analysis::diagnostics
stderr: 9: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
stderr: 10: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
stderr: 11: rust_analyzer::diagnostics::fetch_native_diagnostics
stderr: 12: core::ops::function::FnOnce::call_once{{vtable.shim}}
stderr: note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@alexkirsz alexkirsz added the C-bug Category: bug label Jun 12, 2024
@lnicola lnicola added the A-ty type system / type inference / traits / method resolution label Jun 12, 2024
@Veykril Veykril added B-unstable unstable feature I-crash labels Jun 12, 2024
@alexkirsz
Copy link
Contributor Author

Bisected and this started crashing with #16852

@alexkirsz
Copy link
Contributor Author

Here's my naive workaround if anyone else is blocked on this issue:
7299e6a

@kmicklas
Copy link

Here's my naive workaround if anyone else is blocked on this issue: 7299e6a

Thank you! I'm hitting a variation of this issue (no async) and this has restored my productivity.

@kmicklas
Copy link

Looks like this is a duplicate of #17199.

@ShoyuVanilla
Copy link
Member

😱 @rustbot claim

@ShoyuVanilla
Copy link
Member

I found the root cause and solution. I'll make a PR when I get back home in few hours.
Sorry for the inconvenience to those who suffered from this issue 😢

@alexkirsz
Copy link
Contributor Author

All good @ShoyuVanilla, thank you for your work on RA!

@bors bors closed this as completed in 9463d9e Jun 28, 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 B-unstable unstable feature C-bug Category: bug I-crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants