Skip to content

fn fudge_inference_if_ok can result in unnormalizeable aliases #252

@lcnr

Description

@lcnr
trait Trait {
    type Assoc;
}
impl<T: Trait> Trait for W<T> {
    type Assoc = T::Assoc;
}
impl Trait for i32 {
    type Assoc = i32;
}

struct W<T>(T);
fn foo<T: Trait>(_: <T as Trait>::Assoc) -> T {
    todo!()
}

fn main() {
    let x: W<_> = foo(1);
    let _: W<i32> = x;
}

fails in the new solver

error[E0282]: type annotations needed
  --> src/main.rs:18:23
   |
18 |     let x: W<_> = foo(1);
   |                       ^ cannot infer type

The reason is that we fudge inference to compute the expectation for the call to foo. After equating the output of foo with W<?x> its input is <W<?new_var> as Trait>::Assoc with ?new_var :> ?x. We then fudge ?new_var, dropping the way its relatedd to ?x, meaning that this inference variable will never get constrained.

Metadata

Metadata

Assignees

No one assigned

    Labels

    from-craterA regression found via a crater run, not part of our test suite

    Type

    No type

    Projects

    Status

    todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions