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 in Rust Analyzer with impl Trait and PartialOrd + Display #17236

Open
megaproes opened this issue May 15, 2024 · 0 comments
Open
Labels
C-bug Category: bug

Comments

@megaproes
Copy link

rust-analyzer version: v0.3.1958 and others before (and also prelease)

rustc version: rustc 1.78.0 (9b00956e5 2024-04-29) and any other versions.

code snippet to reproduce:

use std::fmt::Display;

fn prints_it_impl_trait(input: impl Display) {
    println!("You can print many things, including {input}");
}

fn prints_it_regular_generic<T: Display>(input: T) {
    println!("You can print many things, including {input}");
}

fn main() {
    prints_it_regular_generic::<u8>(100);
    prints_it_impl_trait(100);
    prints_it_impl_trait(100u8);
    // prints_it_impl_trait::<u8>(100);

    gives_higher(8, 10);
}

fn gives_higher(one: impl PartialOrd + Display, two: impl PartialOrd + Display) {
    let higher = if one > two { one } else { two };
    println!("{higher} is higher.");
}

When the above code is included in my project, Rust Analyzer crashes with a stack overflow error. Removing the gives_higher function resolves the issue.

Also commenting out the gives_higher function prevents the crash, suggesting the issue lies within the handling of impl Trait with PartialOrd + Display in this context. Within the 3 minutes it consistently restarts the server for all dependencies.

Logs:
thread 'Worker' has overflowed its stack

thread 'Worker' has overflowed its stack

thread 'Worker' has overflowed its stack
[Info - 11:12:05 AM] Connection to server got closed. Server will restart.
true

thread 'Worker' has overflowed its stack
[Info - 11:12:30 AM] Connection to server got closed. Server will restart.
true

.... and so on and then:
thread 'Worker' has overflowed its stack
[Error - 11:15:30 AM] The Rust Analyzer Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

@megaproes megaproes added the C-bug Category: bug label May 15, 2024
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

1 participant