Skip to content

Reborrow expressionAdjustmentHints are rarely useful #20516

@9999years

Description

@9999years

These inlay hints seem to be unnecessary to me:

Image

This is in an otherwise-unchanged project created with cargo init.

fn a(s: &String) {}

fn main() {
    let s = "".to_owned();
    a(&s)
}

First, "".to_owned() gets adjusted to (&*"").to_owned(). std::borrow::ToOwned::to_owned takes a &self reciever, and "" is of type &'static str, so no reborrow or deref coercion should be needed here.

Then, a(&s) gets annotated as a(&*&s), which is again very strange: s: String and fn a takes a &String parameter, so the exact type requested is being supplied.

Apparently these are reborrow hints. I'd actually like to see when Rust automatically does deref coercion or similar, but reborrows appear to happen on basically every usage of basically every variable, so I don't get much value out of them.

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