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
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
Contributor Author

dingxiangfei2009 commented Feb 17, 2026

cc @BennoLossin @nxsaken FYI.

@rust-log-analyzer

This comment has been minimized.

Copy link
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

@BennoLossin
Copy link
Contributor

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

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
@dingxiangfei2009
Copy link
Contributor Author

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

@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
fmt: checked 6742 files
tidy check
tidy [rustdoc_json (src)]: `rustdoc-json-types` modified, checking format version
tidy: Skipping binary file check, read-only filesystem
tidy [features]: /checkout/compiler/rustc_feature/src/unstable.rs:625: no tracking issue for feature partial_init_locals
tidy [features]: FAIL
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (26.0.1)
linting python files
---
info: ES-Check: there were no ES version matching errors!  🎉
typechecking javascript files
tidy: The following check failed: features
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy --root-path=/checkout --cargo-path=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo --output-dir=/checkout/obj/build --concurrency=4 --npm-path=/node/bin/yarn --ci=true --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1612:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1388:29

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:02:51
  local time: Tue Mar 10 20:44:33 UTC 2026
  network time: Tue, 10 Mar 2026 20:44:33 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

@theemathas
Copy link
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
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);
}

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