Skip to content

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

@ultrabear

Description

@ultrabear

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions