mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Fix lowering trailing self paths in UseTrees
This commit is contained in:
parent
aa38fa1c72
commit
ca7cd41a48
2 changed files with 40 additions and 2 deletions
|
@ -101,9 +101,13 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ast::PathSegmentKind::SelfKw => {
|
ast::PathSegmentKind::SelfKw => {
|
||||||
|
// don't break out if `self` is the last segment of a path, this mean we got an
|
||||||
|
// use tree like `foo::{self}` which we want to resolve as `foo`
|
||||||
|
if !segments.is_empty() {
|
||||||
kind = PathKind::Super(0);
|
kind = PathKind::Super(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ast::PathSegmentKind::SuperKw => {
|
ast::PathSegmentKind::SuperKw => {
|
||||||
let nested_super_count = if let PathKind::Super(n) = kind { n } else { 0 };
|
let nested_super_count = if let PathKind::Super(n) = kind { n } else { 0 };
|
||||||
kind = PathKind::Super(nested_super_count + 1);
|
kind = PathKind::Super(nested_super_count + 1);
|
||||||
|
@ -117,6 +121,11 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
|
||||||
segments.reverse();
|
segments.reverse();
|
||||||
generic_args.reverse();
|
generic_args.reverse();
|
||||||
|
|
||||||
|
if segments.is_empty() && kind == PathKind::Plain && type_anchor.is_none() {
|
||||||
|
// plain empty paths don't exist, this means we got a single `self` segment as our path
|
||||||
|
kind = PathKind::Super(0);
|
||||||
|
}
|
||||||
|
|
||||||
// handle local_inner_macros :
|
// handle local_inner_macros :
|
||||||
// Basically, even in rustc it is quite hacky:
|
// Basically, even in rustc it is quite hacky:
|
||||||
// https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456
|
// https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456
|
||||||
|
|
|
@ -3496,4 +3496,33 @@ mod foo$0;
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hover_self_in_use() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//! This should not appear
|
||||||
|
mod foo {
|
||||||
|
/// But this should appear
|
||||||
|
pub mod bar {}
|
||||||
|
}
|
||||||
|
use foo::bar::{self$0};
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*self*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
test::foo
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub mod bar
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
But this should appear
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue