Skip to content

Feature request: allow adding inline to the generated from impls #403

@V0ldek

Description

@V0ldek

I have the missing_inline_in_public_items lint enabled in my crate and I'm currently upping thiserror to 2.0. For some reason, the From impls from thiserror start tripping up this lint after the upgrade (see e.g. this action). I don't know why the upgrade causes it, since as far as I can see the From impls were never inline in 1.0 either, but that's a secondary issue.

It'd be nice if it was possible to add an inline attribute to the #[from] specifier. I could see two ways for this:

  1. Just allow #[from(inline)] which slaps #[inline] onto the generated impl.
  2. Allow a more generic mechanism where this:
#[derive(Error)]
enum MyError {
  IO(#[from] #[inline] #[deprecated("Reason")] #[any_other_attr("with", "args")] std::io::Error)
}

results in this impl:

impl From<std::io::Error> for MyError {
    #[inline]
    #[deprecated("Reason")]
    #[any_other_attr("with", "args")]
    fn from(value: std::io::Error) -> Self {
        Self::IO(value)
    }
}

I'm not familiar enough with macros to figure out how hard the second approach would be, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions