rust-lang / rust-lang/rust

incompletely relating alias args may cause borrowck ICE

Open
#140,211 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

fixed-by-next-solver
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

trait Id {
    type This<'a>;
}

#[derive(Copy, Clone)]
struct W<T>(T);
impl Id for W<u32> {
    type This<'a> = W<u32>;
}
impl Id for W<i32> {
    type This<'a> = W<i32>;
}

trait Trait<T> {}
// when using this impl we only normalize after instantiating
// with infer vars, at this point `<?t as Id>::This<'a>` is still
// ambig, so we keep the alias around and require it to structurally
// relate.
impl<T: Id> Trait<for<'a> fn(T::This<'a>)> for T {}
fn is_trait<T: Trait<U>, U>(_x: T) {}

fn main() {
    let x = W(1);
    // We prove `W<_>: Trait<for<'a> fn(<W<_>>::This<'a>)>` during
    // typeck, and `W<i32>: Trait<for<'a> fn(<W<i32>)>` during borrowck.
    // This then fails.
    is_trait(x);
    let _: W<i32> = x;
}

ICEs with

error: internal compiler error: error performing operation: fully_perform
  --> src/main.rs:20:5
   |
20 |     is_trait::<_, _>(x);
   |     ^^^^^^^^^^^^^^^^^^^
   |
note: delayed at /rustc/05f9846f893b09a1be1fc8560e33fc3c815cfecb/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:87:25 - disabled backtrace
  --> src/main.rs:20:5
   |
20 |     is_trait::<_, _>(x);
   |     ^^^^^^^^^^^^^^^^^^^

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 reproducer in src/main.rs and the delayed diagnostic location in compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:87. Run the example to reproduce the borrowck ICE, then trace the incompletely related alias arguments through the type-operation path. Done means the example no longer ICEs 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
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.