Skip to content

RA generates inappropriate type information. #21398

@Magicloud

Description

@Magicloud

rust-analyzer version: 0.3.2735-standalone

rustc version: rustc 1.92.0 (ded5c06cf 2025-12-08)

editor or extension: VSCode + 0.3.2735

relevant settings:

repository link (if public, optional):

code snippet to reproduce:

let y = Some("".to_string());
let closure = || {
  if let Some(ref x) = y
    && x.is_empty()
  {
    false
  } else {
    true
  }
}

With above code, RA would hint that closure is impl FnOnce() -> bool = move(y).

If change the if let line to if let Some(x) = y.as_ref(), then hint is impl Fn() -> bool = move(&y).

Seems like RA thought the two closures move different things hence giving them different types. But actually both are impl Fn() -> bool. It should not be FnOnce.

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