Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts#145620
Merged
bors merged 2 commits intorust-lang:masterfrom Aug 25, 2025
Merged
Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts#145620bors merged 2 commits intorust-lang:masterfrom
bors merged 2 commits intorust-lang:masterfrom
Conversation
compiler-errors
commented
Aug 19, 2025
3131f84 to
0ee588a
Compare
Collaborator
|
This PR was rebased onto a different master 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. |
0ee588a to
e0fb6eb
Compare
Contributor
Author
|
@bors r=lcnr |
Collaborator
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 24, 2025
…=lcnr Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts Fixes rust-lang#141806 When we have an impossible where clause like `dyn Trait<u8>: Sized`, this may make a dyn-to-dyn cast like `dyn Trait<()> -> dyn trait<u8>` to successfully type check as if it were a wide-to-thin ptr cast (discarding metadata): https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_hir_typeck/src/cast.rs#L862-L865 In borrowck, we are expecting that the only meaningful dyn-to-dyn cast to be a metadata-preserving wide-to-wide ptr cast, which requires that the principals of the dyn pointers are equal. Borrowck additionally assumes that these principals have already been proven equal *modulo regions*, and we thus ICE since `Trait<u8>` and `Trait<()>` do not unify: https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_borrowck/src/type_check/mod.rs#L1481-L1524 This PR fixes this ICE by checking whether the RHS of the cast is considered to be Sized in the environment of the MIR typeck, and if so then skipping over this dyn->dyn principal compatibility check. r? `@lcnr` perhaps?
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 24, 2025
…=lcnr Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts Fixes rust-lang#141806 When we have an impossible where clause like `dyn Trait<u8>: Sized`, this may make a dyn-to-dyn cast like `dyn Trait<()> -> dyn trait<u8>` to successfully type check as if it were a wide-to-thin ptr cast (discarding metadata): https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_hir_typeck/src/cast.rs#L862-L865 In borrowck, we are expecting that the only meaningful dyn-to-dyn cast to be a metadata-preserving wide-to-wide ptr cast, which requires that the principals of the dyn pointers are equal. Borrowck additionally assumes that these principals have already been proven equal *modulo regions*, and we thus ICE since `Trait<u8>` and `Trait<()>` do not unify: https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_borrowck/src/type_check/mod.rs#L1481-L1524 This PR fixes this ICE by checking whether the RHS of the cast is considered to be Sized in the environment of the MIR typeck, and if so then skipping over this dyn->dyn principal compatibility check. r? ``@lcnr`` perhaps?
bors
added a commit
that referenced
this pull request
Aug 24, 2025
Rollup of 6 pull requests Successful merges: - #135761 (Dial down detail of B-tree description) - #144373 (remove deprecated Error::description in impls) - #145620 (Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts) - #145783 (add span to struct pattern rest (..)) - #145817 (cg_llvm: Replace the `llvm::Bool` typedef with a proper newtype) - #145820 (raw-dylib-elf: set correct `DT_VERDEFNUM`) r? `@ghost` `@rustbot` modify labels: rollup
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 24, 2025
…=lcnr Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts Fixes rust-lang#141806 When we have an impossible where clause like `dyn Trait<u8>: Sized`, this may make a dyn-to-dyn cast like `dyn Trait<()> -> dyn trait<u8>` to successfully type check as if it were a wide-to-thin ptr cast (discarding metadata): https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_hir_typeck/src/cast.rs#L862-L865 In borrowck, we are expecting that the only meaningful dyn-to-dyn cast to be a metadata-preserving wide-to-wide ptr cast, which requires that the principals of the dyn pointers are equal. Borrowck additionally assumes that these principals have already been proven equal *modulo regions*, and we thus ICE since `Trait<u8>` and `Trait<()>` do not unify: https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_borrowck/src/type_check/mod.rs#L1481-L1524 This PR fixes this ICE by checking whether the RHS of the cast is considered to be Sized in the environment of the MIR typeck, and if so then skipping over this dyn->dyn principal compatibility check. r? ```@lcnr``` perhaps?
bors
added a commit
that referenced
this pull request
Aug 25, 2025
Rollup of 5 pull requests Successful merges: - #135761 (Dial down detail of B-tree description) - #144373 (remove deprecated Error::description in impls) - #145620 (Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts) - #145817 (cg_llvm: Replace the `llvm::Bool` typedef with a proper newtype) - #145820 (raw-dylib-elf: set correct `DT_VERDEFNUM`) r? `@ghost` `@rustbot` modify labels: rollup
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Aug 25, 2025
…=lcnr Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts Fixes rust-lang#141806 When we have an impossible where clause like `dyn Trait<u8>: Sized`, this may make a dyn-to-dyn cast like `dyn Trait<()> -> dyn trait<u8>` to successfully type check as if it were a wide-to-thin ptr cast (discarding metadata): https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_hir_typeck/src/cast.rs#L862-L865 In borrowck, we are expecting that the only meaningful dyn-to-dyn cast to be a metadata-preserving wide-to-wide ptr cast, which requires that the principals of the dyn pointers are equal. Borrowck additionally assumes that these principals have already been proven equal *modulo regions*, and we thus ICE since `Trait<u8>` and `Trait<()>` do not unify: https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_borrowck/src/type_check/mod.rs#L1481-L1524 This PR fixes this ICE by checking whether the RHS of the cast is considered to be Sized in the environment of the MIR typeck, and if so then skipping over this dyn->dyn principal compatibility check. r? ````@lcnr```` perhaps?
Member
Contributor
rust-bors bot
added a commit
that referenced
this pull request
Aug 25, 2025
Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts try-job: dist-various-2
Contributor
Author
|
@bors try cancel due to that other pr |
Contributor
|
Try build cancelled. Cancelled workflows: |
bors
added a commit
that referenced
this pull request
Aug 25, 2025
Rollup of 10 pull requests Successful merges: - #135761 (Dial down detail of B-tree description) - #145620 (Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts) - #145788 (Fix attribute target checking for macro calls) - #145794 (bootstrap.py: Improve CPU detection on NetBSD) - #145817 (cg_llvm: Replace the `llvm::Bool` typedef with a proper newtype) - #145820 (raw-dylib-elf: set correct `DT_VERDEFNUM`) - #145828 (Update `bitflags` to 2.9.3.) - #145830 (Remove the lifetime from `ExpTokenPair`/`SeqSep`.) - #145836 (Remove outdated bug comments) - #145842 (rustc-dev-guide subtree update) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Aug 25, 2025
Rollup merge of #145620 - compiler-errors:fake-dyn-to-dyn, r=lcnr Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts Fixes #141806 When we have an impossible where clause like `dyn Trait<u8>: Sized`, this may make a dyn-to-dyn cast like `dyn Trait<()> -> dyn trait<u8>` to successfully type check as if it were a wide-to-thin ptr cast (discarding metadata): https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_hir_typeck/src/cast.rs#L862-L865 In borrowck, we are expecting that the only meaningful dyn-to-dyn cast to be a metadata-preserving wide-to-wide ptr cast, which requires that the principals of the dyn pointers are equal. Borrowck additionally assumes that these principals have already been proven equal *modulo regions*, and we thus ICE since `Trait<u8>` and `Trait<()>` do not unify: https://github.com/rust-lang/rust/blob/16ad385579cebb6f7d53367c552661b6b51a4a02/compiler/rustc_borrowck/src/type_check/mod.rs#L1481-L1524 This PR fixes this ICE by checking whether the RHS of the cast is considered to be Sized in the environment of the MIR typeck, and if so then skipping over this dyn->dyn principal compatibility check. r? `@lcnr` perhaps?
github-actions bot
pushed a commit
to rust-lang/rustc-dev-guide
that referenced
this pull request
Sep 8, 2025
Rollup of 10 pull requests Successful merges: - rust-lang/rust#135761 (Dial down detail of B-tree description) - rust-lang/rust#145620 (Account for impossible bounds making seemingly unsatisfyable dyn-to-dyn casts) - rust-lang/rust#145788 (Fix attribute target checking for macro calls) - rust-lang/rust#145794 (bootstrap.py: Improve CPU detection on NetBSD) - rust-lang/rust#145817 (cg_llvm: Replace the `llvm::Bool` typedef with a proper newtype) - rust-lang/rust#145820 (raw-dylib-elf: set correct `DT_VERDEFNUM`) - rust-lang/rust#145828 (Update `bitflags` to 2.9.3.) - rust-lang/rust#145830 (Remove the lifetime from `ExpTokenPair`/`SeqSep`.) - rust-lang/rust#145836 (Remove outdated bug comments) - rust-lang/rust#145842 (rustc-dev-guide subtree update) r? `@ghost` `@rustbot` modify labels: rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #141806
When we have an impossible where clause like
dyn Trait<u8>: Sized, this may make a dyn-to-dyn cast likedyn Trait<()> -> dyn trait<u8>to successfully type check as if it were a wide-to-thin ptr cast (discarding metadata):rust/compiler/rustc_hir_typeck/src/cast.rs
Lines 862 to 865 in 16ad385
In borrowck, we are expecting that the only meaningful dyn-to-dyn cast to be a metadata-preserving wide-to-wide ptr cast, which requires that the principals of the dyn pointers are equal. Borrowck additionally assumes that these principals have already been proven equal modulo regions, and we thus ICE since
Trait<u8>andTrait<()>do not unify:rust/compiler/rustc_borrowck/src/type_check/mod.rs
Lines 1481 to 1524 in 16ad385
This PR fixes this ICE by checking whether the RHS of the cast is considered to be Sized in the environment of the MIR typeck, and if so then skipping over this dyn->dyn principal compatibility check.
r? @lcnr perhaps?