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

"type annotations needed" in signature with HRTB #70290

Open
comex opened this issue Mar 23, 2020 · 1 comment
Open

"type annotations needed" in signature with HRTB #70290

comex opened this issue Mar 23, 2020 · 1 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-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@comex
Copy link
Contributor

comex commented Mar 23, 2020

Playground link

fn foo<F>(f: F) where
    F: for<'a> FnOnce(&'a i32) -> &'a i32,
    F: FnOnce(&'static i32) -> &'static i32
    {}

produces:

error[E0282]: type annotations needed
 --> src/main.rs:4:8
  |
4 |     F: FnOnce(&'static i32) -> &'static i32
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type

error: aborting due to previous error

Note that this error occurs when defining the function, not calling it. There is nowhere to add type annotations, so the error makes no sense. This code should presumably be accepted, since both of the bounds are accepted individually.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 23, 2020
@Dylan-DPC
Copy link
Member

Current output:

error[[E0283]](https://doc.rust-lang.org/nightly/error_codes/E0283.html): type annotations needed: cannot satisfy `F: FnOnce<(&'static i32,)>`
 --> src/main.rs:4:8
  |
4 |     F: FnOnce(&'static i32) -> &'static i32
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: multiple `impl`s or `where` clauses satisfying `F: FnOnce<(&'static i32,)>` found
 --> src/main.rs:3:8
  |
3 |     F: for<'a> FnOnce(&'a i32) -> &'a i32,
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 |     F: FnOnce(&'static i32) -> &'static i32
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

@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-traits Area: Trait system C-bug Category: This is a bug. 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

4 participants