Skip to content

Conversation

@theemathas
Copy link
Contributor

@theemathas theemathas commented Nov 22, 2025

Also, delete impls on non-Deref types.

Pin doesn't do anything useful for non-Deref types, so PinCoerceUnsized on such types makes no sense.

This is a breaking change, since stable code can observe the deleted PinCoerceUnsized impls by uselessly coercing between such types inside a Pin.

There is still some strange behavior, such as Pin<&mut i32> being able to coerce to Pin<&dyn Send>, but not being able to coerce to Pin<&i32>. However, I don't think it's possible to fix this.

Fixes #145081

@theemathas theemathas added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-coercions Area: implicit and explicit `expr as Type` coercions needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. A-pin Area: Pin T-types Relevant to the types team, which will review and decide on the PR/issue. needs-crater This change needs a crater run to check for possible breakage in the ecosystem. labels Nov 22, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 22, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 22, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@theemathas theemathas force-pushed the pin-coerce-unsized branch 2 times, most recently from f921d32 to f4fa919 Compare November 23, 2025 03:35
@jdonszelmann
Copy link
Contributor

@bors try

rust-bors bot added a commit that referenced this pull request Nov 23, 2025
@rust-bors

This comment has been minimized.

@rust-bors
Copy link
Contributor

rust-bors bot commented Nov 23, 2025

☀️ Try build successful (CI)
Build commit: 94e8487 (94e848735e78b58442e0b82e9c60f8f430840389, parent: e0e204f3e97ad5f79524b9c259dc38df606ed82c)

@saethlin
Copy link
Member

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-149218 created and queued.
🤖 Automatically detected try build 94e8487
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-149218 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@Darksonn
Copy link
Contributor

Darksonn commented Dec 1, 2025

I added these impls because otherwise the introduction of PinCoerceUnsized would have been a breaking change. I'm in favor of removing them.

@craterbot
Copy link
Collaborator

🎉 Experiment pr-149218 is completed!
📊 6 regressed and 5 fixed (743358 total)
📊 1966 spurious results on the retry-regessed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-149218/retry-regressed-list.txt

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Dec 2, 2025
@workingjubilee
Copy link
Member

@craterbot
Copy link
Collaborator

👌 Experiment pr-149218-1 created and queued.
🤖 Automatically detected try build 94e8487
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 3, 2025
@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Dec 9, 2025
@theemathas
Copy link
Contributor Author

Crater results are clean.

Which team does this need an FCP with?

@theemathas theemathas removed the needs-crater This change needs a crater run to check for possible breakage in the ecosystem. label Dec 10, 2025
@bors
Copy link
Collaborator

bors commented Dec 18, 2025

☔ The latest upstream changes (presumably #150115) made this pull request unmergeable. Please resolve the merge conflicts.

@Darksonn
Copy link
Contributor

Probably T-lang?

@Darksonn Darksonn added the I-lang-nominated Nominated for discussion during a lang team meeting. label Dec 18, 2025
Also, delete impls on non-Deref types.

Pin doesn't do anything useful for non-Deref types, so PinCoerceUnsized
on such types makes no sense.

This is a breaking change, since stable code can observe the deleted
`PinCoerceUnsized` impls by uselessly coercing between such types
inside a `Pin`.

There is still some strange behavior, such as `Pin<&mut i32>` being
able to coerce to `Pin<&dyn Send>`, but not being able to coerce to
`Pin<&i32>`. However, I don't think it's possible to fix this.

Fixes rust-lang#145081
@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2025

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@tgross35
Copy link
Contributor

tgross35 commented Jan 3, 2026

I don't have any concerns with the library changes here, but this design change is indeed owned by @rust-lang/lang.

r? lang

(Sorry, I should have rerolled a long time ago)

@rustbot rustbot added the T-lang Relevant to the language team label Jan 3, 2026
@rustbot rustbot assigned tmandry and unassigned tgross35 Jan 3, 2026
@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Jan 5, 2026
@tmandry
Copy link
Member

tmandry commented Jan 7, 2026

The lang team discussed this today. Everyone present was in agreement that we should remove the impls.

Adding the Deref supertrait was more controversial. @traviscross commented that Pin<*const u32> could be a useful type for communicating invariants – in a world where Pin::new_unchecked() did not have a Deref bound on the impl. In that case we might want the coercion in this example to work:

fn bar(x: Pin<&i32>) -> Pin<*const dyn Send> {
    x
}

Note: This trait is unstable, so we could leave the Deref supertrait as an open question for when it stabilizes. We could also use a sealed supertrait with a blanket impl to require for now that implementers of PinCoerceUnsized also implement Deref, without allowing users to rely on that supertrait relationship.

@traviscross
Copy link
Contributor

traviscross commented Jan 8, 2026

Proposal: Let's merge this PR, but in accepting this let's leave open the question of whether Deref should be a supertrait of PinCoerceUnsized or whether we'd be better served doing something else.

@rfcbot fcp merge lang,libs-api

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Jan 8, 2026

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jan 8, 2026
@Darksonn
Copy link
Contributor

Darksonn commented Jan 10, 2026

Let's merge this PR, but in accepting this let's leave open the question of whether Deref should be a supertrait of PinCoerceUnsized or whether we'd be better served doing something else.

Yes, absolutely. This FCP should be about whether we are ok with the breaking change of removing all unsizing coercions where the source or target type is any of the following:

  • Pin<NonNull<T>>
  • Pin<*const T>
  • Pin<*mut T>
  • Pin<rc::Weak<T>>
  • Pin<sync::Weak<T>>
  • Pin<UnsafeCell<P>>
  • Pin<Cell<P>>
  • Pin<RefCell<P>>
  • (and a few more unstable types)

with the justification that you can't construct any of these types because all Pin<P> constructors require P: Deref. Edit: Apparently you can construct Pin<*mut T> in some edge cases, see below.

How to express unsizing coercions in the trait system should be kept as a separate topic. It happens to involve PinCoerceUnsized right now, but all of the involved traits are unstable.

@theemathas
Copy link
Contributor Author

with the justification that you can't construct any of these types because all Pin<P> constructors require P: Deref.

You can construct a Pin<*const dyn Trait> or a Pin<*mut dyn Trait> by unsize-coercing from a Pin<&mut T>

@Darksonn
Copy link
Contributor

I see, I did not realize that. However I believe this PR would remove that coercion too, since impl CoerceUnsized for Pin requires PinCoerceUnsized for both the source and target pointer type.

@Darksonn
Copy link
Contributor

I guess my list is also missing some Pin<Pin<_>> cases, since Pin<Pin<P>> can be unsizing coerced iff Pin<P> can.

@tmandry
Copy link
Member

tmandry commented Jan 14, 2026

Agreed with the plan to revisit the PinCoerceUnsized/Deref relationship when we go to stabilize that. The removed coercion from Pin<&mut T> to Pin<*{const,mut} dyn Trait> can be added back later.

@rfcbot reviewed

@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

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

Labels

A-coercions Area: implicit and explicit `expr as Type` coercions A-pin Area: Pin disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PinCoerceUnsized has strange impls