Skip to content

Diagnostic error due to wrong APIT inference #20021

@Threated

Description

@Threated

rust-analyzer version: 0.3.2500-standalone

rustc version: 1.86.0 (05f9846f8 2025-03-31)

editor or extension: Vscode 0.3.2500

relevant settings: nothing relevant I think

code snippet to reproduce:

pub fn gets_apit(s: impl Into<String>) {
    let a = s.into();
    takes_str(&a);
    takes_string(a);
}

fn takes_str(_: &str) {}
fn takes_string(_: String) {}

Seems like r-a ignores the APIT constraints and tries to infer it from the first usage leading it to think its a string.
This also reproduces on the pre-release vscode version. I vaguely remember this kind of inference in inlay hints being wrong at times but now it emits an error diagnostic although of course this works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions