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

Rust compiler hangs when compiling code with complex struct #117443

Open
iamanonymouscs opened this issue Oct 31, 2023 · 3 comments
Open

Rust compiler hangs when compiling code with complex struct #117443

iamanonymouscs opened this issue Oct 31, 2023 · 3 comments
Labels
C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@iamanonymouscs
Copy link

I tried this code with rustc -C opt-level=1 code.rs

#![recursion_limit = "1024"]
#![allow(dead_code)]
use std::mem;
pub struct S0<T>(T, T);
pub struct S1<T>(Option<Box<S0<S0<T>>>>, Option<Box<S0<S0<T>>>>);
pub struct S2<T>(Option<Box<S1<S1<T>>>>, Option<Box<S1<S1<T>>>>);
pub struct S3<T>(Option<Box<S2<S2<T>>>>, Option<Box<S2<S2<T>>>>);
pub struct S4<T>(Option<Box<S3<S3<T>>>>, Option<Box<S3<S3<T>>>>);
pub struct S5<T>(Option<Box<S4<S4<T>>>>, Option<Box<S4<S4<T>>>>, Option<T>);
trait Foo {
    fn xxx(&self) {}
}
impl<T> Foo for T
where
    T: Foo,
    T: Sync,
{
    fn xxx(&self) {}
}
impl Foo for S5<u8> {
    fn xxx(&self) {}
}
trait Bar {}
impl<T> Foo for T
where
    T: Bar,
    T: Sync,
{
    fn xxx(&self) {}
}
impl Foo for S5<u8> {
    fn xxx(&self) {}
}

I expected to see this happen: The compiler compiles successfully or outputs an error message.

Instead, this happened: The Rust compiler hangs indefinitely.

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

The same problem is reproduced on the nightly version(1.75.0-nightly 31bc7e2c4 2023-10-30)

what's more, to get more information,I also tried '-Z time-passes' (using nighly version):

Output

time:   0.001; rss:   29MB ->   31MB (   +2MB)	parse_crate
time:   0.006; rss:   34MB ->   48MB (  +13MB)	expand_crate
time:   0.006; rss:   34MB ->   48MB (  +13MB)	macro_expand_crate
warning: unused import: `std::mem`
 --> code.rs:3:5
  |
3 | use std::mem;
  |     ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0601]: `main` function not found in crate `code`
  --> code.rs:33:2
   |
33 | }
   |  ^ consider adding a `main` function to `code.rs`

time:   0.014; rss:   51MB ->   56MB (   +6MB)	looking_for_entry_point
time:   0.014; rss:   51MB ->   57MB (   +6MB)	misc_checking_1
time:   0.001; rss:   57MB ->   60MB (   +3MB)	type_collecting

@iamanonymouscs iamanonymouscs added the C-bug Category: This is a bug. label Oct 31, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 31, 2023
@Jules-Bertholet
Copy link
Contributor

@rustbot label T-compiler I-hang

@rustbot rustbot added I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 31, 2023
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 31, 2023
@csmoe

This comment was marked as off-topic.

@jruderman
Copy link
Contributor

It abruptly starts hanging with #![recursion_limit = "159"]. Any lower and it quickly exits reporting an error of the form "overflow evaluating the requirement...". This seems unusual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants