rust-lang / rust-lang/rust

Pin diagnostic `might not be found because of this arbitrary self type` is not fired in some cases

Open
#144,598 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
use std::convert::Infallible;

// http-body = "1.0.1"
use http_body::Body;

struct FooImpl;

impl Body for FooImpl {
    type Data = &'static [u8];

    type Error = Infallible;

    fn poll_frame(
        self: std::pin::Pin<&mut Self>,
        _cx: &mut std::task::Context<'_>,
    ) -> std::task::Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>> {
        todo!()
    }
}

fn what() {
    let mut instance = FooImpl;

    instance.poll_frame();
}

fn main() {}
Current output
error[E0599]: no method named `poll_frame` found for struct `FooImpl` in the current scope
  --> src/main.rs:23:14
   |
5  | struct FooImpl;
   | -------------- method `poll_frame` not found for this struct
...
23 |     instance.poll_frame();
   |              ^^^^^^^^^^ method not found in `FooImpl`
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `poll_frame`, perhaps you need to implement it:
           candidate #1: `Body`
help: trait `Body` which provides `poll_frame` is implemented but not in scope; perhaps you want to import it
   |
1  + use http_body::Body;
   |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `horror_repro` (bin "horror_repro") due to 1 previous error
Desired output
error[E0599]: no method named `poll_frame` found for struct `FooImpl` in the current scope
  --> src/main.rs:35:14
   |
5  | struct FooImpl;
   | -------------- method `poll_frame` not found for this struct
...
13 |         self: std::pin::Pin<&mut Self>,
   |               ------------------------ the method might not be found because of this arbitrary self type
...
35 |     instance.poll_frame();
   |              ^^^^^^^^^^ method not found in `FooImpl`
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `poll_frame`, perhaps you need to implement it:
           candidate #1: `Body`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `horror_repro` (bin "horror_repro") due to 1 previous error
Rationale and extra context

It seems reasonable that this diagnostic hint should always fire in this case

Other cases

The desired output was generated via

use std::convert::Infallible;

// http-body = "1.0.1"
use http_body::Body;

struct FooImpl;

trait EasyBody {
    type Data;

    type Error;

    fn poll_frame(
        self: std::pin::Pin<&mut Self>,
        _cx: &mut std::task::Context<'_>,
    ) -> std::task::Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>>;
}

impl EasyBody for FooImpl {
    type Data = &'static [u8];

    type Error = Infallible;

    fn poll_frame(
        self: std::pin::Pin<&mut Self>,
        _cx: &mut std::task::Context<'_>,
    ) -> std::task::Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>> {
        todo!()
    }
}

fn what() {
    let mut instance = FooImpl;

    instance.poll_frame();
}

fn main() {}

Which indicates that the diagnostic not firing stems from the trait being from an external module/crate? I cannot reduce this repro further unfortunately
Rust Version
rustc 1.90.0-nightly (f8e355c23 2025-07-27)
binary: rustc
commit-hash: f8e355c230c6eb7b78ffce6a92fd81f78c890524
commit-date: 2025-07-27
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8
Anything else?

also reproduces on stable:

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

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 with the minimal Rust reproduction and compare the current and desired E0599 diagnostics, including the external http_body::Body trait case and the local EasyBody comparison. Trace the compiler's handling of arbitrary self types for trait methods and add a regression test that verifies the diagnostic includes the explanatory hint.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.