Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function type with HRTB and associated type argument unifies inconsistently #101794

Open
laurmaedje opened this issue Sep 14, 2022 · 1 comment
Open
Labels
A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@laurmaedje
Copy link
Contributor

laurmaedje commented Sep 14, 2022

This is a similar issue as #84937, #89436, and #90875. Those were fixed by #90887, but it seems like the issue still exists (on stable and nightly). It is pretty flakey: In this case, it can be fixed by adding a type annotation and even by changing the order of the exec function's arguments.

fn main() {
    // error: mismatched types
    //   expected fn pointer `for<'a> fn(<u32 as Input>::Projected<'a>) -> _`
    //         found fn item `fn(u32) -> u32 {double}`
    //
    // Two ways to fix the problem here:
    // - Add `::<u32, _>` below
    // - Switch the order of the parameters on `exec`
    exec(double, 10);
}

fn double(x: u32) -> u32 {
    2 * x
}

fn exec<In, Out>(f: for<'a> fn(<In as Input<'a>>::Projected) -> Out, input: In) -> Out
where
    In: for<'a> Input<'a>,
{
    todo!()
}

trait Input<'a> {
    type Projected;
}

impl<'a> Input<'a> for u32 {
    type Projected = u32;
}

Full Diagnostic

error[E0308]: mismatched types
  --> src/lib.rs:26:11
   |
26 |     query(double, 10);
   |     ----- ^^^^^^ expected associated type, found `u32`
   |     |
   |     arguments to this function are incorrect
   |
   = note: expected fn pointer `for<'a> fn(<u32 as Input<'a>>::Projected) -> _`
                 found fn item `fn(u32) -> u32 {double}`
   = help: consider constraining the associated type `<_ as Input<'a>>::Projected` to `u32` or calling a method that returns `<_ as Input<'a>>::Projected`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: function defined here
  --> src/lib.rs:33:4
   |
33 | fn query<In, Out>(f: for<'a> fn(<In as Input<'a>>::Projected) -> Out, input: In) -> Out
   |    ^^^^^          --------------------------------------------------

For more information about this error, try `rustc --explain E0308`.

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (17cbdfd07 2022-09-13)
binary: rustc
commit-hash: 17cbdfd07178349d0a3cecb8e7dde8f915666ced
commit-date: 2022-09-13
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 15.0.0

cc @jackh726

@laurmaedje laurmaedje added the C-bug Category: This is a bug. label Sep 14, 2022
@fmease fmease added A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) T-types Relevant to the types team, which will review and decide on the PR/issue. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. and removed needs-triage-legacy labels Jan 25, 2024
@fmease
Copy link
Member

fmease commented Jan 25, 2024

Fixed in the next-gen trait solver (-Znext-solver).

@fmease fmease added the A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants