Implicit trait bounds from parameter's type bounds?

Hi there, I recently stumbled upon a scenario similar to this one in my code:

struct A<T>(T)
where T: PartialEq;

impl<T> A<T>
where T: PartialEq{
    fn do_something(&self){
        //do something here
    }
}

fn do_something_else<T>(data: A<T>)
where T: std::fmt::Debug{
    A.do_something();
}

And then the compiler got mad at me:

error[E0277]: can't compare `T` with `T`
  --> src\main.rs:11:1
   |
11 | / fn do_something_else<T>(data: A<T>)
12 | | where T: std::fmt::Debug{
13 | |     A.do_something();
14 | | }
   | |_^ no implementation for `T == T`
   |
   = help: the trait `std::cmp::PartialEq` is not implemented for `T`
   = help: consider adding a `where T: std::cmp::PartialEq` bound
Note truncated for size

Which I get in this example, but I get a less kind error on my actual code:

error[E0599]: no method named `size` found for type `algorithms::data_structures::binary_tree::Node<T>` in 
the current scope
  --> src\main.rs:22:14
   |
22 |         (*r).size() as f64
   |              ^^^^
   |
   = note: the method `size` exists but the following trait bounds were not satisfied:
           `T : std::cmp::PartialOrd`

And, I was wondering why, if A<T> depends on T being bound to std::cmp::PartialEq then why doesn’t the compiler automatically infer that the <T> in do_something_else is bound by std::cmp::PartialEq and require the caller to make sure that T implements std::cmp::PartialEq rather than us having to specify it manually.

This is known as implied bounds, which is a feature missing today (apart from trait bounds on associated types). But, the RFC to implement that was accepted - https://github.com/rust-lang/rust/issues/44491 - so perhaps we’ll see this in the not too distant future.

Thanks for the heads up! I will look forward to this in the near future hopefully!