Skip to content

Conversation

@enthropy7
Copy link
Contributor

@enthropy7 enthropy7 commented Jan 27, 2026

using -Znext-solver=globally with dyn A<Ty = i32, CT = 0> was able to trigger a couple of different ICEs: first when trait_object_dummy_self (FreshTy(0)) leaked into sizedness fast paths and object candidates, and then when fudge_inference_if_ok ran into Fresh* vars and hit an unreachable! (i saw second one while fixing the original issue). this patch makes those code paths either bail out early or just treat Fresh* as regular types (including forwarding them through InferenceFudger)

also, of course i added a test

about the issue: when we lower dyn A<Ty = i32, CT = 0> with the new trait solver, we use an internal dummy Self called trait_object_dummy_self, represented as FreshTy(0) (and FreshIntTy / FreshFloatTy for the other cases). that means the solver ends up with goals like FreshTy(0): MetaSized or FreshTy(0): A<…>, even though FreshTy(0) is just the Self of this dyn object, not a real user type. several fast paths and bits of diagnostics assumed they would never see Fresh* there (has_trivial_sizedness, sizedness assembly, for_each_relevant_impl, fudge_inference_if_ok) and buged or hit unreachable!, so once trait_object_dummy_self started going through those paths, we got ICEs instead of normal errors.

fixes #151709

FreshTy is used as trait_object_dummy_self for dyn types and should not
reach has_trivial_sizedness or assemble_object_bound_candidates. add
checks to skip the fast path and return early for FreshTy types to
prevent ICEs in the new trait solver.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jan 27, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 27, 2026

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
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

@lcnr lcnr self-assigned this Jan 27, 2026
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Thanks for trying to fix this but this is not the right fix. trait_object_dummy_self should never escape HIR ty lowering, it's lower_trait_object_ty's fault that it currently does. This issue has been known for around 2 years and there are other similar GH issues which are still open.

See e.g., this source code comment I've recently added:

// FIXME(mgca): We actually leak `trait_object_dummy_self` if the type of any assoc
// const mentions `Self` (in "Self projections" which we intentionally
// allow). That's because we query feed the instantiated type to `type_of`.
// That's really bad, dummy self should never escape lowering! It leads us
// to accept less code we'd like to support and can lead to ICEs later.

Or this one:

// FIXME(mgca): Ideally this would compile -- at least if the user annotated the instantiated type
// of the assoc const (but we don't have the syntax for this (yet)). In any case, we
// should not leak `trait_object_dummy_self` (defined as `FreshTy(0)` under the hood)
// to the rest of the compiler and by extension the user via diagnostics.
//@ known-bug: unknown

The proper fix will be different, I don't yet have a clear picture in my head though.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 27, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 27, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@fmease
Copy link
Member

fmease commented Jan 27, 2026

I don't think it makes sense to keep this PR open since the final approach will look completely different. Therefore I'm going to close this. Boxy, please correct me if I'm wrong.

CC https://github.com/rust-lang/rust/blob/main/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs and maybe also #123140.

These kinds of issues are intentionally kept unsolved right now (see e.g., PR description of #150843).

@fmease fmease closed this Jan 27, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 27, 2026
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [ui] tests/ui/asm/aarch64/type-check-2-2.rs ... ok
test [ui] tests/ui/asm/aarch64/type-check-3.rs ... ok
test [ui] tests/ui/asm/aarch64/ttbr0_el2.rs ... ok
test [ui] tests/ui/asm/aarch64/type-check-2.rs ... ok
test [ui] tests/ui/asm/aarch64v8r.rs#hf ... ok
test [ui] tests/ui/asm/aarch64/type-f16.rs ... ok
test [ui] tests/ui/asm/aarch64v8r.rs#sf ... ok
test [ui] tests/ui/asm/arm-low-dreg.rs ... ok
test [ui] tests/ui/asm/asm-with-nested-closure.rs ... ok
test [ui] tests/ui/asm/binary_asm_labels.rs ... ignored, only executed when the architecture is x86_64
test [ui] tests/ui/asm/bad-template.rs#x86_64 ... ok
test [ui] tests/ui/asm/cfg-parse-error.rs ... ok
---
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#fat2 ... ok
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#fat3 ... ok
test [ui] tests/ui/extern/issue-80074.rs ... ok
test [ui] tests/ui/extern/issue-95829.rs ... ok
test [ui] tests/ui/extern/lgamma-linkage.rs ... ok
test [ui] tests/ui/extern/no-mangle-associated-fn.rs ... ok
test [ui] tests/ui/extern/not-in-block.rs ... ok
test [ui] tests/ui/extern/unsized-extern-derefmove.rs ... ok
test [ui] tests/ui/extern/windows-tcb-trash-13259.rs ... ok
test [ui] tests/ui/feature-gates/allow-features-empty.rs ... ok
---
test [ui] tests/ui/imports/ambiguous-2.rs ... ok
test [ui] tests/ui/imports/ambiguous-4.rs ... ok
test [ui] tests/ui/imports/ambiguous-7.rs ... ok
test [ui] tests/ui/imports/ambiguous-9.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-glob-vs-multiouter.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-globvsglob.rs ... ok
test [ui] tests/ui/imports/ambiguous-8.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-no-implicit-prelude.rs ... ok
test [ui] tests/ui/imports/ambiguous-glob-vs-expanded-extern.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-non-prelude-core-glob.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-non-prelude-std-glob.rs ... ok
---
test [ui] tests/ui/zero-sized/zero-sized-btreemap-insert.rs ... ok

failures:

---- [ui] tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/traits/next-solver/fresh-ty-has-trivial-sizedness/fresh-ty-has-trivial-sizedness.stderr`
diff of stderr:

1 error[E0658]: associated const equality is incomplete
-   --> $DIR/fresh-ty-has-trivial-sizedness.rs:12:29
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:10:29
3    |
4 LL |     let _: &dyn A<Ty = i32, CT = 0> = &();
5    |                             ^^^^^^

9    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10 
11 error[E0038]: the trait `A` is not dyn compatible
-   --> $DIR/fresh-ty-has-trivial-sizedness.rs:12:17
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:10:17
13    |
14 LL |     let _: &dyn A<Ty = i32, CT = 0> = &();
15    |                 ^^^^^^^^^^^^^^^^^^^ `A` is not dyn compatible

16    |
17 note: for a trait to be dyn compatible it needs to allow building a vtable
18       for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
-   --> $DIR/fresh-ty-has-trivial-sizedness.rs:8:11
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:6:11
20    |
21 LL | trait A {
22    |       - this trait is not dyn compatible...

23 LL |     type Ty;
24 LL |     const CT: Self::Ty;
-    |           ^^ ...because it contains this associated `const`
+    |           ^^ ...because it contains associated const `CT`
26    = help: consider moving `CT` to another trait
27 
28 error[E0277]: the size for values of type `FreshTy(0)` cannot be known

-   --> $DIR/fresh-ty-has-trivial-sizedness.rs:12:34
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:10:34
30    |
31 LL |     let _: &dyn A<Ty = i32, CT = 0> = &();
32    |                                  ^ doesn't have a known size

33    |
34    = help: the nightly-only, unstable trait `MetaSized` is not implemented for `FreshTy(0)`
35 note: required by a bound in `A`
---
39 LL | |     type Ty;

42    | |_^ required by this bound in `A`
43 
44 error[E0277]: the trait bound `FreshTy(0): A` is not satisfied
-   --> $DIR/fresh-ty-has-trivial-sizedness.rs:12:34
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:10:34
46    |
47 LL |     let _: &dyn A<Ty = i32, CT = 0> = &();
48    |                                  ^ the trait `A` is not implemented for `FreshTy(0)`

49    |
50 help: this trait has no implementations, consider adding one
-   --> $DIR/fresh-ty-has-trivial-sizedness.rs:6:1
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:4:1
52    |
53 LL | trait A {
54    | ^^^^^^^

Note: some mismatched output was normalized before being compared
-   --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:10:29
-   --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:10:17
-   --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:6:11
-   --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:10:34
-   --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:4:1
-   --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:10:34
-   --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:4:1
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:10:29
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:10:17
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:6:11
+    |           ^^ ...because it contains associated const `CT`
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:10:34
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:4:1
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:10:34
+   --> $DIR/fresh-ty-has-trivial-sizedness.rs:4:1


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args traits/next-solver/fresh-ty-has-trivial-sizedness.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/traits/next-solver/fresh-ty-has-trivial-sizedness" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Znext-solver=globally"
stdout: none
--- stderr -------------------------------
error[E0658]: associated const equality is incomplete
##[error]  --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:10:29
   |
LL |     let _: &dyn A<Ty = i32, CT = 0> = &();
   |                             ^^^^^^
   |
   = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
   = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0038]: the trait `A` is not dyn compatible
##[error]  --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:10:17
   |
LL |     let _: &dyn A<Ty = i32, CT = 0> = &();
   |                 ^^^^^^^^^^^^^^^^^^^ `A` is not dyn compatible
   |
note: for a trait to be dyn compatible it needs to allow building a vtable
      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
  --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:6:11
   |
LL | trait A {
   |       - this trait is not dyn compatible...
LL |     type Ty;
LL |     const CT: Self::Ty;
   |           ^^ ...because it contains associated const `CT`
   = help: consider moving `CT` to another trait

error[E0277]: the size for values of type `FreshTy(0)` cannot be known
##[error]  --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:10:34
   |
LL |     let _: &dyn A<Ty = i32, CT = 0> = &();
   |                                  ^ doesn't have a known size
   |
   = help: the nightly-only, unstable trait `MetaSized` is not implemented for `FreshTy(0)`
note: required by a bound in `A`
  --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:4:1
   |
LL | / trait A {
LL | |     type Ty;
LL | |     const CT: Self::Ty;
LL | | }
   | |_^ required by this bound in `A`

error[E0277]: the trait bound `FreshTy(0): A` is not satisfied
##[error]  --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:10:34
   |
LL |     let _: &dyn A<Ty = i32, CT = 0> = &();
   |                                  ^ the trait `A` is not implemented for `FreshTy(0)`
   |
help: this trait has no implementations, consider adding one
  --> /checkout/tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs:4:1
   |
LL | trait A {
---
Some errors have detailed explanations: E0038, E0277, E0658.
For more information about an error, try `rustc --explain E0038`.
------------------------------------------

---- [ui] tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs stdout end ----

failures:
    [ui] tests/ui/traits/next-solver/fresh-ty-has-trivial-sizedness.rs

test result: FAILED. 20131 passed; 1 failed; 332 ignored; 0 measured; 21 filtered out; finished in 553.37s

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

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

[ICE]: has_trivial_sizedness applied to unexpected type: FreshTy(0)

6 participants