Skip to content

Allow phased initializing structs#152774

Draft
dingxiangfei2009 wants to merge 1 commit intorust-lang:mainfrom
dingxiangfei2009:partial-init
Draft

Allow phased initializing structs#152774
dingxiangfei2009 wants to merge 1 commit intorust-lang:mainfrom
dingxiangfei2009:partial-init

Conversation

@dingxiangfei2009
Copy link
Copy Markdown
Contributor

@dingxiangfei2009 dingxiangfei2009 commented Feb 17, 2026

Partially undoing #54986

This PR introduces an unstable feature partial_init_nodrop_types. This work corresponds to the new action item in rust-lang/rust-project-goals#548.

Action Items

  • What should we do with non_exhaustive?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 17, 2026
@dingxiangfei2009
Copy link
Copy Markdown
Contributor Author

dingxiangfei2009 commented Feb 17, 2026

cc @BennoLossin @nxsaken FYI.

@rust-log-analyzer

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@BennoLossin BennoLossin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool to see that it's less than 200 lines changed!

Just two small things that I noticed. I can't speak on any of the actual modifications :)

View changes since this review

Comment thread tests/ui/borrowck/partial-init-locals.stderr
Comment thread compiler/rustc_feature/src/unstable.rs Outdated
@BennoLossin
Copy link
Copy Markdown
Contributor

Regarding non-exhaustive: I think it's pretty simple, the reference already covers all of this:

@dingxiangfei2009
Copy link
Copy Markdown
Contributor Author

This PR is ready for previewing. It is pending a formal RFC and a tracking issue.

@rust-log-analyzer

This comment has been minimized.

@theemathas
Copy link
Copy Markdown
Contributor

theemathas commented Mar 11, 2026

These two code snippets compile with this PR and causes a crash seemingly inside free.

#![feature(partial_init_locals)]

fn main() {
    let x: (String, String);
    x.0 = String::new();
}
#![feature(partial_init_locals)]

struct Thing(String, String);

fn main() {
    let x: Thing;
    x.0 = String::new();
}

@theemathas
Copy link
Copy Markdown
Contributor

This code compiles with this PR and prints garbage data:

#![feature(partial_init_locals)]

fn main() {
    let x: (i32, i32);
    x.0 = 123;
    let weird = x.1;
    println!("{}", weird);
}

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants