Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
V0ldek opened this issue Dec 21, 2024 · 3 comments · Fixed by #404
Closed

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

V0ldek opened this issue Dec 21, 2024 · 3 comments · Fixed by #404

Comments

@V0ldek
Copy link

V0ldek commented Dec 21, 2024

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.

@dtolnay
Copy link
Owner

dtolnay commented Dec 21, 2024

Please try 2.0.9. It should behave equivalently to 1.x in regard to missing_inline_in_public_items.

@V0ldek
Copy link
Author

V0ldek commented Dec 22, 2024

should behave equivalently to 1.x in regard to missing_inline_in_public_items.

Indeed it does, thank you.

What about the ability to mark the generated functions as #[inline] somehow?

@dtolnay
Copy link
Owner

dtolnay commented Dec 22, 2024

I think that is almost certainly misguided. Those functions are only called on the error codepath and not on the usually performance sensitive happy path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants