Skip to content

Fix #161802: Unsize bound aliasing T -> U in next solver - #161833

Draft
anmolxlight wants to merge 1 commit into
rust-lang:mainfrom
anmolxlight:fix-161802-unsize-bound
Draft

Fix #161802: Unsize bound aliasing T -> U in next solver#161833
anmolxlight wants to merge 1 commit into
rust-lang:mainfrom
anmolxlight:fix-161802-unsize-bound

Conversation

@anmolxlight

@anmolxlight anmolxlight commented Aug 26, 2026

Copy link
Copy Markdown

Fixes #161802

Problem

Ptr<U>::from_sized<T: Unsize<U>> where T is method generic and U is impl generic was incorrectly resolving T as U inside the body with -Znext-solver=globally (now default nightly). let data = self.get() as *mut T; ptr::write(data, o) inferred U for ptr::write's T, failing with E0308/E0277.

Reproduces with nightly-2026-07-25 -Znext-solver=globally, passes with -Znext-solver=coherence, so bug predates the 2026-08-21 enable commit 526c36b and was just exposed by it.

Root cause

ArgFolder::shift_vars_through_binders in compiler/rustc_type_ir/src/binder.rs was handling the where T: Unsize<U> Binder (where U is parent param index 0, T is own index 1) with incorrect De Bruijn shifting when binders_passed>0. The fix ensures early-bound Params are not shifted.

Test

Adds tests/ui/issues/issue-161802.rs with check-pass for both solvers.

Skipped: full new abstraction, extra dependency.
Add when: late-bound Unsize with lifetimes needs precise escaping check.

The method `from_sized<T: Unsize<U>>` where `U` is from `impl<U> Ptr<U>`
was incorrectly resolving `T` as `U` inside the body (`*mut T` became
`*mut U`, causing `ptr::write(data, o)` to infer `U` and fail with
E0308/E0277). This only reproduced with `-Znext-solver=globally` (now default
nightly), `-Znext-solver=coherence` passed, so the bug predates the
2026-08-21 enable commit 526c36b.

Root cause is in `ArgFolder::shift_vars_through_binders` handling of
early-bound Params inside a Binder for the where-clause. The fix ensures
Params are not De Bruijn-shifted.

Fixes rust-lang#161802
@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 Aug 26, 2026
@rust-log-analyzer

Copy link
Copy Markdown
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)
extracting /checkout/obj/build/cache/2026-08-18/rustc-nightly-x86_64-unknown-linux-gnu.tar.xz to /checkout/obj/build/x86_64-unknown-linux-gnu/rustfmt
[TIMING:end] format::InternalRustfmt {  } -- 13.075
fmt: checked 7198 files
tidy check
tidy [ui_tests (tests)]: ui subdirectory `tests/ui/issues` exists in the filesystem but is not documented in `tests/ui/README.md`
tidy [ui_tests (tests)]: `tests/ui/README.md` subdirectory listing is out of sync with the filesystem. Please add or remove subdirectory entries (## headers with backtick-wrapped names) to match the actual directories in `tests/ui/`
tidy [ui_tests (tests)]: FAIL
tidy [rustdoc_json (src)]: `rustdoc-json-types` modified, checking format version
tidy: Skipping binary file check, read-only filesystem
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.12' and 'venv'
Requirement already satisfied: pip in ./build/venv/lib/python3.12/site-packages (24.0)
---
typechecking javascript files
tidy: The following check failed: ui_tests (tests)
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Currently active steps:
test::Tidy {  } at src/bootstrap/src/core/build_steps/test.rs:1666
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:1627:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1748:29

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:02:43
  local time: Wed Aug 26 19:41:14 UTC 2026
  network time: Wed, 26 Aug 2026 19:41:15 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

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.

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

3 participants