Skip to content

Signature suggested for missing trait item implementation is missing ?Sized bound #85643

Closed

Description

@adamreichold

Given the following code:

struct D;

impl rand::distributions::Distribution<()> for D {}

The current output is:

error[E0046]: not all trait items implemented, missing: `sample`
 --> src/lib.rs:3:1
  |
3 | impl rand::distributions::Distribution<()> for D {} 
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `sample` in implementation
  |
  = help: implement the missing item: `fn sample<R>(&self, _: &mut R) -> T where R: Rng { todo!() }`

Following the suggestion

use rand::Rng;

struct D;

impl rand::distributions::Distribution<()> for D {
    fn sample<R>(&self, _: &mut R) -> () where R: Rng { todo!() }
} 

however leads to an error about incorrectly adding a requirement

error[E0276]: impl has stricter requirements than trait
 --> src/lib.rs:6:5
  |
6 |     fn sample<R>(&self, _: &mut R) -> () where R: Rng { todo!() }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `R: Sized`

which might be difficult to understand as the Sized bound is implicit and hence it is not obvious that ?Sized needs to be added.

Ideally, this would be part of the initial suggestion to implement the missing item as the original signature is indeed

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> T;

Activity

  1. added
    A-diagnostics
    T-compiler
    on May 24, 2021
  2. estebank commented on Aug 13, 2026

    @estebank
    Contributor

    Current output:

    error[E0046]: not all trait items implemented, missing: `sample`
     --> src/lib.rs:3:1
      |
    3 | impl rand::distr::distribution::Distribution<()> for D {}
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `sample` in implementation
      |
      = help: implement the missing item: `fn sample<R>(&self, _: &mut R) where R: ?Sized, R: Rng { todo!() }`
    

    The test will need to have an auxiliary crate dep for the trait definition so that the suggestion will trigger (for the same crate, we just point at the signature).

  3. added
    E-easy
    E-needs-test
    on Aug 13, 2026
  4. KevinA-cpu commented on Aug 17, 2026

    @KevinA-cpu
    Contributor

    @rustbot claim

  5. added a commit that references this issue on Aug 18, 2026
    5a1c5ce
  6. added a commit that references this issue on Aug 18, 2026
    1e87c1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsE-easyE-needs-testT-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions