Skip to content

Alias-eq weakens inference in HIR typeck #7

Closed
@compiler-errors

Description

@compiler-errors

originally reported this in lcnr/solver-woes#13 --

trait Mk {
    type Assoc;
}

fn mk<T: Mk>(t: T) -> T::Assoc {
    todo!()
}

fn foo<S: Mk + Default>() {
    let x = Default::default();
    let y = mk::<_ /* ?z */>(x);
    let x: S = x;
}
error[E0282]: type annotations needed for `<_ as Mk>::Assoc`
  --> <source>:11:9
   |
11 |     let y = mk::<_ /* ?z */>(x);
   |         ^
   |
help: consider giving `y` an explicit type, where the type for associated type `<_ as Mk>::Assoc` is specified
   |
11 |     let y: <_ as Mk>::Assoc = mk::<_ /* ?z */>(x);
   |          ++++++++++++++++++

Related, heavily reduced from an example in syn:

fn main() {
    let mut x: Vec<_> = vec![];
    x.extend(Some(1i32).into_iter().map(|x| x));
}

General direction of the fix would be to not prefer the subst-relate branch of alias-relate...

Something like compiler-errors/rust@d7001d2 + compiler-errors/rust@10064381389 (so we don't prefer alias-eq results that do no inference) will probably be needed ultimately, though fixed so it doesn't do this behavior during coherence, etc., maybe some other tweaking idk.

Activity

added
hacked-aroundA hack exists to work around this, but it may not be the optimal solution
needs-designA clear root cause exists, but needs medium/hard re-architecture work towards a solution
fundamental-issueSomething that'll need fundamental restructuring or a hack existing at the solver level
on Mar 29, 2023
compiler-errors

compiler-errors commented on Apr 13, 2023

@compiler-errors
OwnerAuthor
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

    fundamental-issueSomething that'll need fundamental restructuring or a hack existing at the solver levelhacked-aroundA hack exists to work around this, but it may not be the optimal solutionneeds-designA clear root cause exists, but needs medium/hard re-architecture work towards a solution

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @compiler-errors

        Issue actions

          Alias-eq weakens inference in HIR typeck · Issue #7 · compiler-errors/next-solver-hir-issues