Repository: intellij-rust/intellij-rust
Issue: 'Self' in generic arguments is wrongly accused of being a trait object

## Environment

* **IntelliJ Rust plugin version:** 0.2.102.2130-191
* **Rust toolchain version:** rustc 1.36.0 (a53f9df32 2019-07-03)
* **IDE name and version:** IntelliJ IDEA 2019.1.3 (Community Edition)
* **Operating system:** Arch Linux

## Problem
In the following snippet
```rust
// 2018 edition
trait X {
    type A;
}
trait Y<T> {}
trait Z: X + Y<<Self as X>::A> {}
```
`Self` is highlighted with orange background and shows the following hint: `Trait objects without an explicit 'dyn' are deprecated`. Of course, on every commit an "are you sure" dialog pops up, because this is counted as a warning, even though it doesn't come from the compiler.

Changed files:
src/test/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspectionTest.kt, src/main/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspection.kt

diff --git a/src/main/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspection.kt b/src/main/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspection.kt
index 7054d6168..1531e5c7e 100644
--- a/src/main/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspection.kt
+++ b/src/main/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspection.kt
@@ -19,12 +19,18 @@ import org.rust.lang.core.psi.ext.isEdition2018
 import org.rust.lang.core.resolve.ref.deepResolve
 
 class RsImplicitTraitObjectInspection : RsLocalInspectionTool() {
-    override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor = object : RsVisitor() {
-        override fun visitTypeReference(typeReference: RsTypeReference) {
-            if (!typeReference.isEdition2018) return
+    override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor =
+        object : RsVisitor() {
+            override fun visitTypeReference(typeReference: RsTypeReference) {
+                if (!typeReference.isEdition2018) return
 
-            if (typeReference.traitType?.run { dyn == null && impl == null } == true ||
-                typeReference.baseType?.path?.reference?.deepResolve() is RsTraitItem) {
+                val traitType = typeReference.traitType
+                val baseTypePath = typeReference.baseType?.path
+                val isTraitType = traitType != null || baseTypePath?.reference?.deepResolve() is RsTraitItem
+                val isSelf = baseTypePath?.cself != null
+                val hasDyn = traitType?.dyn != null
+                val hasImpl = traitType?.impl != null
+                if (!isTraitType || isSelf || hasDyn || hasImpl) return
 
                 holder.registerProblem(
                     typeReference,
@@ -38,8 +44,8 @@ class RsImplicitTraitObjectInspection : RsLocalInspectionTool() {
                             val new = RsPsiFactory(project).createDynTraitType(traitText)
                             target.firstChild.replace(new)
                         }
-                    })
+                    }
+                )
             }
         }
-    }
 }
diff --git a/src/test/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspectionTest.kt b/src/test/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspectionTest.kt
index 1d56c5fa4..82c5c0f42 100644
--- a/src/test/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspectionTest.kt
+++ b/src/test/kotlin/org/rust/ide/inspections/RsImplicitTraitObjectInspectionTest.kt
@@ -45,6 +45,10 @@ class RsImplicitTraitObjectInspectionTest : RsInspectionsTestBase(RsImplicitTrai
         fn test<X>(a: X) where X : Trait {}
     """)
 
+    fun `test no warning on Self`() = checkByText("""
+        trait Y where Self: Foo {}
+    """)
+
     @MockEdition(CargoWorkspace.Edition.EDITION_2015)
     fun `test simple trait object in edition 2015`() = checkByText("""
         trait Trait {}