rust-lang / rust-lang/rust-clippy

`missing_inline_in_public_items` triggers for `impl From<Private> for Public`

Open
#12,911 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

AFAIK, it's not possible to call <Public as From<Private>>::from(_) from an outer crate since Private is not accesible.
So there is no need to mark the method #[inline].

Lint Name

missing_inline_in_public_items

Reproducer

I tried this code:

#![warn(clippy::missing_inline_in_public_items)]

pub struct Public;
struct Private;

impl From<Private> for Public {
    fn from(_value: Private) -> Self {
        todo!();
    }
}

I saw this happen:

warning: missing `#[inline]` for a method
  --> src/lib.rs:8:5
   |
8  | /     fn from(_value: Private) -> Self {
9  | |         todo!();
10 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_inline_in_public_items
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![warn(clippy::missing_inline_in_public_items)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see this happen:

The lint should not trigger.

Version
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-pc-windows-msvc
release: 1.78.0
LLVM version: 18.1.2
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the missing_inline_in_public_items lint and reproduce the report with the example in src/lib.rs. Check the lint's handling of impl From<Private> for Public; done means this private-argument method no longer produces a warning while the lint continues to cover applicable public items.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.