Repository: intellij-rust/intellij-rust
Issue: [Bug] False positive for [E0277] 

## Environment

Plugin Version: 0.3.133.3426-202
IDE:  CLion Commercial 2020.2.4 
Rust Toolchain: 1.47.0 stable-x86_64-unknown-linux-gnu
OS: Fedora 33 KDE

## Problem description / Steps to reproduce
False positive for [E0277] 
The code below, which can be compiled successfully, demonstrates the issue:
```rust
trait Foo {}

trait Bar: Foo {}

trait Baz: Foo {}

trait Bif: Baz + Bar {}

impl<T> Baz for T where T: Foo {}

impl<T> Bif for T where T: Bar {}
```
In this example `Bif` will be incorrectly highlighted by CLion to say [E0277] because the trait bound Baz is not satisfied.
This is incorrect. 
The reason being is as follows: 
- In `impl Bif` `T` is already bound by `Bar`, and any implementation of `Bar` must implement `Foo`
- `Baz` is is automatically implemented for any `T` where `T` implements `Foo`

Because of these two things it is guaranteed that when a type `T` is bound by the trait `Bar` it must have an implementation of `Baz`and thus the trait bound of `Baz` is satisfied.

The problem can be 'solved' by changing the last line to this:
```
impl<T> Bif for T where T: Bar + Baz {}
```
however this is not needed for rustc to compile the code.

Changed files:
src/test/kotlin/org/rust/lang/core/type/RsGenericExpressionTypeInferenceTest.kt, src/main/kotlin/org/rust/lang/core/resolve/ImplLookup.kt, src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt, src/test/kotlin/org/rust/lang/core/resolve/RsResolveTestBase.kt

diff --git a/src/main/kotlin/org/rust/lang/core/resolve/ImplLookup.kt b/src/main/kotlin/org/rust/lang/core/resolve/ImplLookup.kt
index 5d706ece4..5e6c6e0c2 100644
--- a/src/main/kotlin/org/rust/lang/core/resolve/ImplLookup.kt
+++ b/src/main/kotlin/org/rust/lang/core/resolve/ImplLookup.kt
@@ -655,7 +655,7 @@ class ImplLookup(
                     .filter { ctx.probe { ctx.combineBoundElements(it, ref.trait) } }
                     .map { SelectionCandidate.TypeParameter(it) }
                     .forEach(::add)
-                if (ref.selfTy is TyTypeParameter) return@buildList
+
                 if (ref.selfTy is TyProjection) {
                     val subst = ref.selfTy.trait.subst + mapOf(TyTypeParameter.self() to ref.selfTy.type).toTypeSubst()
                     for (bound in ref.selfTy.trait.element.bounds) {
diff --git a/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt b/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
index ab5a5d42c..a80f3044b 100644
--- a/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
+++ b/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
@@ -1565,6 +1565,14 @@ class RsErrorAnnotatorTest : RsAnnotatorTestBase(RsErrorAnnotator::class) {
         impl <T> Trait2 for X<T> where T: Trait<T> {}
     """)
 
+    fun `test supertrait is not implemented E0277 self substitution 4`() = checkErrors("""
+        trait Foo {}
+        trait Baz: Foo {}
+
+        impl<T> Foo for T {}
+        impl<T> Baz for T {}
+    """)
+
     @MockRustcVersion("1.27.1")
     fun `test crate visibility feature E0658`() = checkErrors("""
         <error descr="`crate` visibility modifier is experimental [E0658]">crate</error> struct Foo;
diff --git a/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTestBase.kt b/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTestBase.kt
index b1714b161..ae740a245 100644
--- a/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTestBase.kt
+++ b/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTestBase.kt
@@ -17,8 +17,11 @@ import org.rust.RsTestBase
 import org.rust.TestProject
 import org.rust.fileTreeFromText
 import org.rust.lang.core.macros.isExpandedFromMacro
+import org.rust.lang.core.psi.RsFunction
 import org.rust.lang.core.psi.ext.*
+import org.rust.lang.core.resolve.ref.RsMethodCallReferenceImpl
 import org.rust.lang.core.resolve.ref.RsReference
+import org.rust.lang.core.types.inference
 
 abstract class RsResolveTestBase : RsTestBase() {
     protected open fun checkByCode(@Language("Rust") code: String) =
diff --git a/src/test/kotlin/org/rust/lang/core/type/RsGenericExpressionTypeInferenceTest.kt b/src/test/kotlin/org/rust/lang/core/type/RsGenericExpressionTypeInferenceTest.kt
index 360f41259..94ea25975 100644
--- a/src/test/kotlin/org/rust/lang/core/type/RsGenericExpressionTypeInferenceTest.kt
+++ b/src/test/kotlin/org/rust/lang/core/type/RsGenericExpressionTypeInferenceTest.kt
@@ -1851,4 +1851,36 @@ class RsGenericExpressionTypeInferenceTest : RsTypificationTestBase() {
             a;
         } //^ i32
     """)
+
+    fun `test infer type parameter from blank impl 1`() = testExpr("""
+        struct S;
+        trait Foo<O> {}
+
+        impl<T> Foo<S> for T {}
+
+        fn foo<T: Foo<B>, B>(t: T) -> B {
+            todo!()
+        }
+
+        fn bar<T>(t: T) {
+            let a = foo(t);
+            a;
+        } //^ S
+    """)
+
+    fun `test infer type parameter from blank impl 2`() = testExpr("""
+        struct S;
+        trait Foo<O> {}
+
+        impl<T> Foo<S> for T {}
+
+        fn foo<T: Foo<B>, B>(t: T) -> B {
+            todo!()
+        }
+
+        fn bar<T: Foo<S>>(t: T) {
+            let a = foo(t);
+            a;
+        } //^ S
+    """)
 }