Skip to content

Initializing wrapper struct private field blows up system memory. #119631

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

Closed
meowjesty opened this issue Jan 5, 2024 · 1 comment
Closed

Initializing wrapper struct private field blows up system memory. #119631

meowjesty opened this issue Jan 5, 2024 · 1 comment
Labels
C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@meowjesty
Copy link

I tried initializing a private field from a wrapper struct pub struct Foo(/*private fields*/) that is defined in another crate, and Rust started to eat all my system memory, until I was forced to restart the computer.

Unfortunately the code that caused this from my side is closed source, but I was trying to initialize the Extensions struct like this:

let extensions = Extensions(
        license
            .certificate
            .iter_extensions()
            .cloned()
            .collect::<Vec<_>>(),
    );

I expected to see this happen:

Either a compiler crash or just the compiler giving me an error saying that you can't do that!

Instead, this happened:

System memory usage kept going up and up, until it crashed my pc. Limiting cargo check memory usage just meant that the process was killed, so no error messages either.

Meta

rustc --version --verbose:

rustc 1.76.0-nightly (1fdfe1234 2023-12-06)
binary: rustc
commit-hash: 1fdfe1234795a289af1088aefa92ef80191cb611
commit-date: 2023-12-06
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

I've also tried (and got the same results) nightly-2024-01-05.

We got this issue in 3 different systems, 2 being linux x64 and one being macos (with the m1/2 arch, whatever that is called).

Backtrace

No backtrace, rust didn't produce any error output, it just got stuck in checking {crate-name} forever.

<backtrace>

@meowjesty meowjesty added the C-bug Category: This is a bug. label Jan 5, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 5, 2024
@lukas-code
Copy link
Member

Probably duplicate of #119625.

I tried this code:

// x509-certificate = "=0.23.1"

use x509_certificate::rfc5280::{Certificate, Extensions};

pub fn foo(cert: Certificate) {
    let _e = Extensions(cert.iter_extensions().cloned().collect::<Vec<_>>());
}

and it appears to be fixed by #119638 as well:

error[E0423]: cannot initialize a tuple struct which contains private fields
   --> src/lib.rs:4:14
    |
4   |     let _e = Extensions(cert.iter_extensions().cloned().collect::<Vec<_>>());
    |              ^^^^^^^^^^
    |
note: constructor is not visible here due to private fields
   --> /home/lukas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x509-certificate-0.23.1/src/rfc5280.rs:483:23
    |
483 | pub struct Extensions(Vec<Extension>);
    |                       ^^^^^^^^^^^^^^ private field

For more information about this error, try `rustc --explain E0423`.

@saethlin saethlin added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 7, 2024
@saethlin saethlin closed this as completed Jan 7, 2024
@saethlin saethlin added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 7, 2024
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-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. 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

4 participants