fix: path display error when start with crate

This commit is contained in:
Dezhi Wu 2021-09-07 14:44:30 +08:00
parent 86ebc36fa3
commit 82ae228d98
2 changed files with 20 additions and 1 deletions

View file

@ -1154,7 +1154,7 @@ impl HirDisplay for Path {
}
for (seg_idx, segment) in self.segments().iter().enumerate() {
if seg_idx != 0 {
if seg_idx != 0 || matches!(self.kind(), PathKind::Crate) {
write!(f, "::")?;
}
write!(f, "{}", segment.name)?;

View file

@ -962,6 +962,25 @@ fn main() { let foo_test = fo$0o(); }
```
"#]],
);
// use literal `crate` in path
check(r#"
pub struct X;
fn foo() -> crate::X { X }
fn main() { f$0oo(); }
"#, expect![[r#"
*foo*
```rust
test
```
```rust
fn foo() -> crate::X
```
"#]]);
}
#[test]