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

Possible lifetime recursion causes unresponsive behaviour #17524

Open
cedtwo opened this issue Jul 1, 2024 · 1 comment
Open

Possible lifetime recursion causes unresponsive behaviour #17524

cedtwo opened this issue Jul 1, 2024 · 1 comment
Labels
C-bug Category: bug

Comments

@cedtwo
Copy link

cedtwo commented Jul 1, 2024

The following code will cause rust analyzer to become unresponsive, exhausting all (?) available CPU and memory resources:

use std::marker::PhantomData;

struct TypeWrapper<'a> {
    inner: InnerType,

    _ref: PhantomData<&'a mut BorrowWrapper<'a>>,
}

struct BorrowWrapper<'a> {
    inner: &'a mut InnerType,
}

struct InnerType;

pub trait GetBorrow {
    type TypeA;
    type TypeB;

    fn get_type_a(&mut self) -> Self::TypeA;
    fn get_type_b(&mut self) -> Self::TypeB;
}

impl<'a> GetBorrow for TypeWrapper<'a>
where
    Self::TypeA: 'a,
    Self::TypeB: 'a,
{
    type TypeA = BorrowWrapper<'a>;
    type TypeB = BorrowWrapper<'a>;

    fn get_type_a(&mut self) -> Self::TypeA {
        BorrowWrapper {
            inner: &mut self.inner,
        }
    }

    fn get_type_b(&mut self) -> Self::TypeB {
        BorrowWrapper {
            inner: &mut self.inner,
        }
    }
}

Updating, and switching between nightly and stable do not solve the issue.

rustc --version --verbose gives the following:

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

rust-analyzer --version gives the following:

rust-analyzer 1 (c4618fe14 2024-05-05)
@cedtwo cedtwo added the C-bug Category: bug label Jul 1, 2024
@Veykril
Copy link
Member

Veykril commented Jul 1, 2024

Hmm, this does not happen for me on the latest release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants