rust-lang / rust-lang/rust

Broken Unsize bound in generic function in nightly-2026-08-22.

Open
#161,802 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

The following code snippet compiled with nightly-2026-08-21 but does not since 2026-08-22.

In the std::ptr::write() line, the compiler pretends it gets a U while o is a T.
There is no error without the Unsize<> bound on from_sized.

#![feature(unsize)]

use std::marker::{PhantomData, Unsize};

pub struct Ptr<T: ?Sized> {
    _phantom: PhantomData<T>,
}

impl<U: ?Sized> Ptr<U> {
    unsafe fn get(&self) -> *mut () {
        unimplemented!()
    }

    pub fn from_sized<T: Unsize<U>>(self, o: T) -> Self {
        unsafe {
            let data = self.get() as *mut T;
            std::ptr::write(data, o);
            todo!()
        }
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided minimal reproducer, comparing nightly-2026-08-21 and nightly-2026-08-22, and inspect the handling of the Unsize bound around std::ptr::write(). Trace why the compiler treats the pointer as U while the value is T. Done means the reproducer has consistent, correct type checking and a regression test covers the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.