Skip to content

Implement or fix a bunch of unsafe binders things - #163515

Draft
jackh726 wants to merge 27 commits into
rust-lang:mainfrom
jackh726:unsafe-binders-impl
Draft

jackh726 wants to merge 27 commits into
rust-lang:mainfrom
jackh726:unsafe-binders-impl

Conversation

@jackh726

@jackh726 jackh726 commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

View all comments

Supersedes #153458, #156373, #154524, #158856

First test adds many tests covering (expected) implementation behavior of unsafe binders. Many of these need further design discussion, but the point here is to figure out some behavior that we can pin an implementation to for testing.

Remaining commits fix broken tests one by one (mostly), and should be fairly independent.

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 29, 2026
@rust-log-analyzer

This comment has been minimized.

@adwinwhite adwinwhite left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skimming through pointee test, it seems we have quite some redundancy there?
The only exception is dyn objects which use bound vars in unsafe binders?

View changes since this review

Comment thread tests/ui/unsafe-binders/coherence.rs Resolved
Comment on lines +15 to +26
const _: () = assert!(size_of::<unsafe<'a> &'a u8>() == size_of::<&u8>());
const _: () = assert!(size_of::<Option<unsafe<'a> &'a u8>>() == size_of::<&u8>());
const _: () = assert!(size_of::<Option<unsafe<> NonZero<u32>>>() == 4);
const _: () = assert!(align_of::<unsafe<'a> (&'a u8, u16)>() == align_of::<(&u8, u16)>());

// The vtable niche survives a binder in the metadata type and in the pointee.
type BoundMeta = DynMetadata<unsafe<'a> MD<dyn Debug + 'a>>;
const _: () = assert!(size_of::<Option<BoundMeta>>() == size_of::<BoundMeta>());
const _: () = assert!(
size_of::<Option<*const unsafe<'a> MD<dyn Debug + 'a>>>()
== size_of::<*const unsafe<'a> MD<dyn Debug + 'a>>()
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can assert the layouts of unsafe binders versions are the same as inner types? This currently tests both layout equality and niche optimization.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These are above?

Comment on lines +18 to +19
assert_eq!(type_name::<unsafe<'a> &'a ()>(), "unsafe<> &'_ ()");
assert_eq!(type_name::<unsafe<'a> (&'a u8, u8)>(), "unsafe<> (&'_ u8, u8)");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should include bound vars as well?

Comment on lines +15 to +18
fn launder_free<'x>(r: &'x String) -> &'static String {
let b: unsafe<'a> (&'a u8, &'x String) = unsafe { wrap_binder!((&0, r)) };
unsafe { unwrap_binder!(b).1 }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is testing the same early param lifetime as the test case above rather than an temporary body region?

Comment thread tests/ui/unsafe-binders/wrap-assign.rs Resolved
Comment thread tests/ui/unsafe-binders/async.rs Resolved
@rust-bors

This comment has been minimized.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the unsafe-binders-impl branch from 3deb9c1 to 6f7011c Compare November 19, 2026 15:33
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the unsafe-binders-impl branch from 6f7011c to 0f4a9a8 Compare November 21, 2026 00:00

This branch has not been deployed

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

Labels

PG-exploit-mitigations Project group: Exploit mitigations 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants