fix super path wrong display

This commit is contained in:
Dezhi Wu 2021-09-07 17:49:46 +08:00
parent 880af425d4
commit 87436a08fa
2 changed files with 29 additions and 5 deletions

View file

@ -1141,13 +1141,15 @@ impl HirDisplay for Path {
write!(f, ">")?;
}
(_, PathKind::Plain) => {}
(_, PathKind::Abs) => write!(f, "")?,
(_, PathKind::Abs) => {}
(_, PathKind::Crate) => write!(f, "crate")?,
(_, PathKind::Super(0)) => write!(f, "self")?,
(_, PathKind::Super(n)) => {
write!(f, "super")?;
for _ in 0..*n {
write!(f, "::super")?;
for i in 0..*n {
if i > 0 {
write!(f, "::")?;
}
write!(f, "super")?;
}
}
(_, PathKind::DollarCrate(_)) => write!(f, "{{extern_crate}}")?,

View file

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