5664: Fix renamed self module. r=jonas-schievink a=Nashenas88

Fixes #5663 

Now `inner_mod` below is properly marked as a `module`.
```rust
use crate::inner::{self as inner_mod};
mod inner {}
```

Co-authored-by: Paul Daniel Faria <Nashenas88@users.noreply.github.com>
This commit is contained in:
bors[bot] 2020-08-05 16:56:39 +00:00 committed by GitHub
commit 32246b91c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 4 deletions

View file

@ -9,6 +9,9 @@ use crate::{mock_analysis::single_file, FileRange, TextRange};
fn test_highlighting() { fn test_highlighting() {
check_highlighting( check_highlighting(
r#" r#"
use inner::{self as inner_mod};
mod inner {}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct Foo { struct Foo {
pub x: i32, pub x: i32,

View file

@ -35,7 +35,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; } .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
</style> </style>
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">derive</span><span class="punctuation">(</span><span class="attribute">Clone</span><span class="punctuation">,</span><span class="attribute"> Debug</span><span class="punctuation">)</span><span class="attribute">]</span> <pre><code><span class="keyword">use</span> <span class="module">inner</span><span class="operator">::</span><span class="punctuation">{</span><span class="self_keyword">self</span> <span class="keyword">as</span> <span class="module declaration">inner_mod</span><span class="punctuation">}</span><span class="punctuation">;</span>
<span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="punctuation">{</span><span class="punctuation">}</span>
<span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">derive</span><span class="punctuation">(</span><span class="attribute">Clone</span><span class="punctuation">,</span><span class="attribute"> Debug</span><span class="punctuation">)</span><span class="attribute">]</span>
<span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span> <span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span>
<span class="keyword">pub</span> <span class="field declaration">x</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span> <span class="keyword">pub</span> <span class="field declaration">x</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span>
<span class="keyword">pub</span> <span class="field declaration">y</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span> <span class="keyword">pub</span> <span class="field declaration">y</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span>

View file

@ -12,7 +12,7 @@ use hir::{
use ra_prof::profile; use ra_prof::profile;
use ra_syntax::{ use ra_syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
match_ast, match_ast, SyntaxNode,
}; };
use crate::RootDatabase; use crate::RootDatabase;
@ -123,8 +123,27 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?; let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?;
let path = use_tree.path()?; let path = use_tree.path()?;
let path_segment = path.segment()?; let path_segment = path.segment()?;
let name_ref = path_segment.name_ref()?; let name_ref_class = path_segment
let name_ref_class = classify_name_ref(sema, &name_ref)?; .name_ref()
// The rename might be from a `self` token, so fallback to the name higher
// in the use tree.
.or_else(||{
if path_segment.self_token().is_none() {
return None;
}
let use_tree = use_tree
.syntax()
.parent()
.as_ref()
// Skip over UseTreeList
.and_then(SyntaxNode::parent)
.and_then(ast::UseTree::cast)?;
let path = use_tree.path()?;
let path_segment = path.segment()?;
path_segment.name_ref()
})
.and_then(|name_ref| classify_name_ref(sema, &name_ref))?;
Some(NameClass::Definition(name_ref_class.definition())) Some(NameClass::Definition(name_ref_class.definition()))
}, },