Skip to content

False diagnostic with dyn Traits #13031

@Wardenfar

Description

@Wardenfar

This snippet of code trigger an error diagnostic from rust-analyzer.
But rustc compiles it fine.
When adding the dyn keyword : the diagnostic disappears.

rustc 1.63.0 (4b91a6ea7 2022-08-08)
rust-analyzer version: 0.3.1170-standalone (b6d59f2 2022-08-14)
edition: 2018

[Ln 3, Col 9] expected &dyn Fn(usize), found &|{unknown}| -> ()

fn main() {
    foo(
        &(|number| {
            // just use the parameter
            let _ = number.min(0);
        })
    );
}

fn foo(_bar: &Fn(usize)) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions