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

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

Open
Dirbaio opened this issue Feb 21, 2022 · 3 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented Feb 21, 2022

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`
@jackh726
Copy link
Member

Pretty sure this is #90950. Specifying a type for F for foo should work: foo::<X>

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-associated_type_bounds `#![feature(associated_type_bounds)]` labels Mar 1, 2022
@nikomatsakis
Copy link
Contributor

I'm not sure this is a bug at all, or rather, it may be a diagnostics issue-- the value of F is not given, so we are not going to be able to prove that the where clauses on foo hold, but I would expect it to say 'please provide a type annotation'. Am I missing something?

(Also, this is not GATs, right?)

@nikomatsakis nikomatsakis added the GATs-triaged Issues using the `generic_associated_types` feature that have been triaged label Mar 9, 2022
@jackh726
Copy link
Member

jackh726 commented Mar 9, 2022

Yeah, this isn't GATs.

@jackh726 jackh726 removed F-associated_type_bounds `#![feature(associated_type_bounds)]` F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs GATs-triaged Issues using the `generic_associated_types` feature that have been triaged labels Mar 9, 2022
@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-diagnostics Area: Messages for errors, warnings, and lints A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants