Skip to content

Unable to return an impl Fn/FnMut/FnOnce that takes a concrete associated type #61903

Closed
@carado

Description

@carado

A blank project with the following main.rs:

trait Trait {
	type Associated;
}

struct Struct;

impl Trait for Struct {
	type Associated = u8;
}

fn f() -> impl Fn(<Struct as Trait>::Associated) {
	// All of the following produce more or less the same error:
	//loop {}
	//unimplemented!()
	//panic!()
	//|_: <Struct as Trait>::Associated| {}
	//|_: u8| {}
	|_| {}
}

fn main() {}

Produces the following error:

    Checking rust9 v0.1.0 (/home/carado/tmp/rust9)
error[E0631]: type mismatch in closure arguments
  --> src/main.rs:11:11
   |
11 | fn f() -> impl Fn(<Struct as Trait>::Associated) {
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected signature of `fn(<Struct as Trait>::Associated) -> _`
...
18 |     |_| {}
   |     --- found signature of `fn(u8) -> _`
   |
   = note: the return type of a function must have a statically known size

error: aborting due to previous error

error: Could not compile `rust9`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.T-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