Skip to content

"trait bound not satisfied" error with HRTBs when just mentioning a fn. #94207

@Dirbaio

Description

@Dirbaio

rustc stable 1.58.1

The following code gives a strange error when just mentioning foo, without even calling it. As far as I can tell the bounds are well-formed, and the error can't be about passing the wrong type to foo because it isn't even getting called. Playground

trait Bar{}
trait Baz<T> {
    type Output;
}

fn foo<F>(f: F)
where
    for<'a> F: Baz<&'a u32>,
    for<'a> <F as Baz<&'a u32>>::Output: Bar,
{
}

fn main() {
    foo; // error[E0277]: the trait bound `for<'a> <_ as Baz<&'a u32>>::Output: Bar` is not satisfied
}

Full error:

error[E0277]: the trait bound `for<'a> <_ as Baz<&'a u32>>::Output: Bar` is not satisfied
  --> src/main.rs:14:5
   |
14 |     foo; // error[E0277]: the trait bound `for<'a> <_ as Baz<&'a u32>>::Output: Bar` is not satisfied
   |     ^^^ the trait `for<'a> Bar` is not implemented for `<_ as Baz<&'a u32>>::Output`
   |
note: required by a bound in `foo`
  --> src/main.rs:9:42
   |
6  | fn foo<F>(f: F)
   |    --- required by a bound in this
...
9  |     for<'a> <F as Baz<&'a u32>>::Output: Bar,
   |                                          ^^^ required by this bound in `foo`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-lifetimesArea: Lifetimes / regionsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions