Skip to content

mismatched types, one type is more general than the other error shows types with the same name #77365

Closed
@micouy

Description

@micouy

Example code:

fn main() {
    let mut v: Vec<i32> = vec![];
    let f = |_| true;
    v.retain(f);
}

Error message:

error[E0308]: mismatched types
 --> src/main.rs:4:7
  |
4 |     v.retain(f);
  |       ^^^^^^ one type is more general than the other
  |
  = note: expected type `FnOnce<(&i32,)>`
             found type `FnOnce<(&i32,)>`

rustc version:

rustc 1.48.0-nightly (dbb73f8f7 2020-09-12)
binary: rustc
commit-hash: dbb73f8f79ab176a897d5a95e696adb71b957cbe
commit-date: 2020-09-12
host: x86_64-apple-darwin
release: 1.48.0-nightly
LLVM version: 11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsA-type-systemArea: Type systemC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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