rust-lang / rust-lang/rust

help change add `FnMut` in where clause no return type

Open
#128,979 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
struct FOper<T, U, F>
where F: FnMut(T) -> U,
{
    _phantom: std::marker::PhantomData<fn(T) -> U>,
    pub f: F,
}
impl<T, U, F> FOper<T, U, F> {
    fn new(f: F) -> Self {
        Self {
            _phantom: std::marker::PhantomData,
            f,
        }
    }
}
Current output
Checking test_ v0.1.0 (/home/lrne/Project/Rust/test_)
error[E0277]: expected a `FnMut(T)` closure, found `F`
    --> src/main.rs:2591:15
     |
2591 | impl<T, U, F> FOper<T, U, F> {
     |               ^^^^^^^^^^^^^^ expected an `FnMut(T)` closure, found `F`
     |
note: required by a bound in `FOper`
    --> src/main.rs:2586:10
     |
2585 | struct FOper<T, U, F>
     |        ----- required by a bound in this struct
2586 | where F: FnMut(T) -> U,
     |          ^^^^^^^^^^^^^ required by this bound in `FOper`
help: consider restricting type parameter `F`
     |
2591 | impl<T, U, F: FnMut(T)> FOper<T, U, F> {
     |             ++++++++++

error[E0277]: expected a `FnMut(T)` closure, found `F`
    --> src/main.rs:2592:21
     |
2592 |     fn new(f: F) -> Self {
     |                     ^^^^ expected an `FnMut(T)` closure, found `F`
     |
note: required by a bound in `FOper`
    --> src/main.rs:2586:10
     |
2585 | struct FOper<T, U, F>
     |        ----- required by a bound in this struct
2586 | where F: FnMut(T) -> U,
     |          ^^^^^^^^^^^^^ required by this bound in `FOper`
help: consider restricting type parameter `F`
     |
2591 | impl<T, U, F: FnMut(T)> FOper<T, U, F> {
     |             ++++++++++

error[E0277]: expected a `FnMut(T)` closure, found `F`
    --> src/main.rs:2593:9
     |
2593 |         Self {
     |         ^^^^ expected an `FnMut(T)` closure, found `F`
     |
note: required by a bound in `FOper`
    --> src/main.rs:2586:10
     |
2585 | struct FOper<T, U, F>
     |        ----- required by a bound in this struct
2586 | where F: FnMut(T) -> U,
     |          ^^^^^^^^^^^^^ required by this bound in `FOper`
help: consider restricting type parameter `F`
     |
2591 | impl<T, U, F: FnMut(T)> FOper<T, U, F> {
     |             ++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_` (bin "test_") due to 3 previous errors
Desired output
Checking test_ v0.1.0 (/home/lrne/Project/Rust/test_)
error[E0277]: expected a `FnMut(T) -> U` closure, found `F`
    --> src/main.rs:2591:15
     |
2591 | impl<T, U, F> FOper<T, U, F> {
     |               ^^^^^^^^^^^^^^ expected an `FnMut(T) -> U` closure, found `F`
     |
note: required by a bound in `FOper`
    --> src/main.rs:2586:10
     |
2585 | struct FOper<T, U, F>
     |        ----- required by a bound in this struct
2586 | where F: FnMut(T) -> U,
     |          ^^^^^^^^^^^^^ required by this bound in `FOper`
help: consider restricting type parameter `F`
     |
2591 | impl<T, U, F: FnMut(T) -> U> FOper<T, U, F> {
     |             +++++++++++++++

error[E0277]: expected a `FnMut(T) -> U` closure, found `F`
    --> src/main.rs:2592:21
     |
2592 |     fn new(f: F) -> Self {
     |                     ^^^^ expected an `FnMut(T) -> U` closure, found `F`
     |
note: required by a bound in `FOper`
    --> src/main.rs:2586:10
     |
2585 | struct FOper<T, U, F>
     |        ----- required by a bound in this struct
2586 | where F: FnMut(T) -> U,
     |          ^^^^^^^^^^^^^ required by this bound in `FOper`
help: consider restricting type parameter `F`
     |
2591 | impl<T, U, F: FnMut(T) -> U> FOper<T, U, F> {
     |             +++++++++++++++

error[E0277]: expected a `FnMut(T) -> U` closure, found `F`
    --> src/main.rs:2593:9
     |
2593 |         Self {
     |         ^^^^ expected an `FnMut(T) -> U` closure, found `F`
     |
note: required by a bound in `FOper`
    --> src/main.rs:2586:10
     |
2585 | struct FOper<T, U, F>
     |        ----- required by a bound in this struct
2586 | where F: FnMut(T) -> U,
     |          ^^^^^^^^^^^^^ required by this bound in `FOper`
help: consider restricting type parameter `F`
     |
2591 | impl<T, U, F: FnMut(T) -> U> FOper<T, U, F> {
     |             +++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_` (bin "test_") due to 3 previous errors
Rationale and extra context

No response

Other cases

No response

Rust Version
rustc 1.82.0-nightly (7c2012d0e 2024-07-26)
binary: rustc
commit-hash: 7c2012d0ec3aae89fefc40e5d6b317a0949cda36
commit-date: 2024-07-26
host: aarch64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided FOper example with the stated rustc 1.82.0-nightly version and compare the current E0277 output with the desired wording. Trace the compiler's E0277 diagnostic handling and add a focused regression test for the closure bound; done means the diagnostic consistently includes FnMut(T) -> U in both the error and suggested restriction.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.