# Implicit trait bounds from parameter's type bounds?

**URL:** <https://users.rust-lang.org/t/implicit-trait-bounds-from-parameters-type-bounds/21061>\
**Category:** help\
**Created:** [October 7, 2018, 3:08am UTC](https://users.rust-lang.org/t/implicit-trait-bounds-from-parameters-type-bounds/21061 "2018-10-07T03:08:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OptimisticPeach](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/optimisticpeach/32/19544_2.png) [@OptimisticPeach](https://users.rust-lang.org/u/OptimisticPeach)\
**Post date:** [October 7, 2018, 3:08am UTC](https://users.rust-lang.org/t/implicit-trait-bounds-from-parameters-type-bounds/21061/1 "2018-10-07T03:08:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vitalyd](https://avatars.discourse-cdn.com/v4/letter/v/edb3f5/32.png) [@vitalyd](https://users.rust-lang.org/u/vitalyd)\
**Post date:** [October 7, 2018, 3:19am UTC](https://users.rust-lang.org/t/implicit-trait-bounds-from-parameters-type-bounds/21061/2 "2018-10-07T03:19:54Z")

</div>

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](https://github.com/rust-lang/rust/issues/44491) - so perhaps we’ll see this in the not too distant future.

---

<div class="post-metadata">

**Author:** ![OptimisticPeach](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/optimisticpeach/32/19544_2.png) [@OptimisticPeach](https://users.rust-lang.org/u/OptimisticPeach)\
**Post date:** [October 7, 2018, 3:48am UTC](https://users.rust-lang.org/t/implicit-trait-bounds-from-parameters-type-bounds/21061/3 "2018-10-07T03:48:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 8:50am UTC](https://users.rust-lang.org/t/implicit-trait-bounds-from-parameters-type-bounds/21061/4 "2023-01-12T08:50:03Z")

</div>


