Skip to content

Hang on TAIT with diverging projection in its ParamEnv #132797

Open

Description

@ym-xie

I tried this code:

rustc file.rs
#![feature(type_alias_impl_trait)]
trait Id {
    type Assoc;
}
impl<T> *const u8 {
    type Assoc = T;
}
type Ty
where
    Ty: Id<Assoc = Ty>,
= impl Sized;
fn define() -> Ty {}
fn main() {}

This file causes rustc to hang and is derived from mutant #109387. #109387 can terminate successfully.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (b91a3a056 2024-11-07)
binary: rustc
commit-hash: b91a3a05609a46f73d23e0995ae7ebb4a4f429a5
commit-date: 2024-11-07
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3
Compiler Output (before the hang)
error[E0658]: inherent associated types are unstable
 --> file.rs:6:5
  |
6 |     type Assoc = T;
  |     ^^^^^^^^^^^^^^^
  |
  = note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
  = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable
  = note: this compiler was built on 2024-11-04; consider upgrading it if it is out of date

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
 --> file.rs:5:6
  |
5 | impl<T> *const u8 {
  |      ^ unconstrained type parameter

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:8:1
   |
8  | type Ty
   | ^^^^^^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
note: required by a bound on the type alias `Ty`
  --> file.rs:10:9
   |
10 |     Ty: Id<Assoc = Ty>,
   |         ^^^^^^^^^^^^^^ required by this bound

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:10:5
   |
10 |     Ty: Id<Assoc = Ty>,
   |     ^^^^^^^^^^^^^^^^^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
   = help: see issue #48214
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
   |
2  + #![feature(trivial_bounds)]
   |

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:11:3
   |
11 | = impl Sized;
   |   ^^^^^^^^^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
note: required by a bound on the type alias `Ty`
  --> file.rs:10:9
   |
10 |     Ty: Id<Assoc = Ty>,
   |         ^^^^^^^^^^^^^^ required by this bound

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:12:16
   |
12 | fn define() -> Ty {}
   |                ^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
note: required by a bound on the type alias `Ty`
  --> file.rs:10:9
   |
10 |     Ty: Id<Assoc = Ty>,
   |         ^^^^^^^^^^^^^^ required by this bound

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:12:19
   |
12 | fn define() -> Ty {}
   |                   ^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
note: required by a bound on the type alias `Ty`
  --> file.rs:10:9
   |
10 |     Ty: Id<Assoc = Ty>,
   |         ^^^^^^^^^^^^^^ required by this bound

error[E0390]: cannot define inherent `impl` for primitive types
 --> file.rs:5:1
  |
5 | impl<T> *const u8 {
  | ^^^^^^^^^^^^^^^^^
  |
  = help: consider using an extension trait instead

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 9, 2024
  2. kadenlnelson commented on Nov 9, 2024

    @kadenlnelson
    Contributor

    How long does it hang for? Are you able to provide a profile that shows where the time is being spent?

    If you may as well, provide the full output that is shown when you execute rustc.

  3. ym-xie commented on Nov 9, 2024

    @ym-xie
    Author

    How long does it hang for? Are you able to provide a profile that shows where the time is being spent?

    If you may as well, provide the full output that is shown when you execute rustc.

    I used the command timeout 60 rustc file.rs, and when it timed out, the partial output was as follows:

    1211900:     0x7f27970b56e9 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
    1211901:     0x7f2796f3d463 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_predicate_recursively
    1211902:     0x7f27970b56e9 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
    1211903:     0x7f2796f3d463 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_predicate_recursively
    1211904:     0x7f27970b56e9 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
    
  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.
    I-compilememIssue: Problems and improvements with respect to memory usage during compilation.
    on Nov 10, 2024
  5. fmease commented on Nov 10, 2024

    @fmease
    Member

    The IAT (inherent associated type) isn't needed; the hang also occurs without it:

    #![feature(type_alias_impl_trait)]
    trait Id {
        type Assoc;
    }
    type Ty
    where
        Ty: Id<Assoc = Ty>,
    = impl Sized;
    fn define() -> Ty {}
    fn main() {}

    I'd also like to note the extreme growth in memory use apart from the hang (e.g., I'm getting jumps from roughly 6GiB (baseline) to 9GiB to 12GiB RAM use).

  6. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 10, 2024
  7. changed the title [-]Hang: type_alias_impl_trait[/-] [+]Hang on TAIT with diverging projection in its ParamEnv[/+] on Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`I-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions