Repository: intellij-rust/intellij-rust
Issue: `pub(in self)` module is incorrectly marked as inaccessible when used within self/child modules

<!--
Hello and thank you for the issue!
If you would like to report a bug, we have added some points below that you can fill out.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **Intellij-Rust plugin version:** v0.2.94.2118-183
* **Rust toolchain version:** rustc 1.33.0 (2aa4c46cf 2019-02-28)
* **IDE name and version:** CLion 2018.3.4
* **Operating system:** Arch Linux 5.0.2

## Problem description
In the following code, the `use` statements for the `prelude` module are marked as errors, although the code compiles without issue via cargo. This also occurs when `pub(self)` is used in place of `pub(in self)`. The `use` statements for `CONST_VAL` are not marked as errors. This only started happening with the most recent update; I believe it's caused by the changes to `pub(in path)` resolution as described in [the changelog](https://intellij-rust.github.io/2019/03/18/changelog-94.html).
```rust
pub(in self) mod prelude {}
pub(in self) const CONST_VAL: u32 = 1;


mod inner {
    use super::prelude as inner_prelude; // marked as error
    use super::CONST_VAL as INNER_CONST; // not marked as error
}

use self::prelude as adjacent_prelude; // marked as error
use self::CONST_VAL as ADJACENT_CONST; // not marked as error
```

## Steps to reproduce
Create a new rust binary project and add `mod test;` to the beginning of the `src/main.rs` file, then create a new file `src/test.rs` and paste the code from above into it.

Changed files:
src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt, src/main/kotlin/org/rust/lang/core/psi/ext/RsPath.kt, src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt

diff --git a/src/main/kotlin/org/rust/lang/core/psi/ext/RsPath.kt b/src/main/kotlin/org/rust/lang/core/psi/ext/RsPath.kt
index d83463380..2e488c822 100644
--- a/src/main/kotlin/org/rust/lang/core/psi/ext/RsPath.kt
+++ b/src/main/kotlin/org/rust/lang/core/psi/ext/RsPath.kt
@@ -12,6 +12,7 @@ import com.intellij.psi.stubs.IStubElementType
 import org.rust.lang.core.macros.RsExpandedElement
 import org.rust.lang.core.psi.RsElementTypes.*
 import org.rust.lang.core.psi.RsPath
+import org.rust.lang.core.psi.RsVis
 import org.rust.lang.core.psi.tokenSetOf
 import org.rust.lang.core.resolve.ref.RsPathReference
 import org.rust.lang.core.resolve.ref.RsPathReferenceImpl
@@ -68,4 +69,16 @@ abstract class RsPathImplMixin : RsStubbedElementImpl<RsPathStub>,
     override val referenceName: String get() = stub?.referenceName ?: super.referenceName
 
     override fun getContext(): PsiElement? = RsExpandedElement.getContextImpl(this)
+
+    override val containingMod: RsMod
+        get() {
+            // In the case of path inside vis restriction for mod item, containingMod must be the parent module:
+            // ```
+            // mod foo {
+            //     pub(in self) mod bar {}
+            //          //^ containingMod == `foo`
+            // ```
+            val visParent = contextStrict<RsVis>()?.context
+            return if (visParent is RsMod) visParent.containingMod else super.containingMod
+        }
 }
diff --git a/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt b/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
index a384cbc2e..53448aa0c 100644
--- a/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
+++ b/src/test/kotlin/org/rust/ide/annotator/RsErrorAnnotatorTest.kt
@@ -1161,6 +1161,12 @@ class RsErrorAnnotatorTest : RsAnnotatorTestBase(RsErrorAnnotator::class.java) {
         use <error descr="Function `foo::bar::eggs` is private [E0603]">foo::bar::eggs</error>;
     """)
 
+    // Issue https://github.com/intellij-rust/intellij-rust/issues/3558
+    fun `test no E0603 for 'pub(in self)' restricted module`() = checkErrors("""
+        pub(self) mod foo {}
+        use self::foo as bar;
+    """)
+
     fun `test function args should implement Sized trait E0277`() = checkErrors("""
         fn foo1(bar: <error descr="the trait bound `[u8]: std::marker::Sized` is not satisfied [E0277]">[u8]</error>) {}
         fn foo2(bar: i32) {}
diff --git a/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt b/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt
index 2e789cf28..1e411a4ec 100644
--- a/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt
+++ b/src/test/kotlin/org/rust/lang/core/resolve/RsResolveTest.kt
@@ -1194,6 +1194,13 @@ class RsResolveTest : RsResolveTestBase() {
         }
     """)
 
+    fun `test 'pub (self)' mod`() = checkByCode("""
+        mod foo {
+          //X
+            pub(self) mod bar {}
+        }     //^
+    """)
+
     fun `test extern crate self`() = checkByCode("""
         extern crate self as foo;