mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
Merge #10174
10174: fix: path display error when start with `crate` r=flodiebold a=dzvon Fixes #10172 Co-authored-by: Dezhi Wu <wu543065657@163.com>
This commit is contained in:
commit
6a8062092b
2 changed files with 51 additions and 5 deletions
|
@ -1141,20 +1141,22 @@ 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}}")?,
|
||||
}
|
||||
|
||||
for (seg_idx, segment) in self.segments().iter().enumerate() {
|
||||
if seg_idx != 0 {
|
||||
if !matches!(self.kind(), PathKind::Plain) || seg_idx > 0 {
|
||||
write!(f, "::")?;
|
||||
}
|
||||
write!(f, "{}", segment.name)?;
|
||||
|
|
|
@ -962,6 +962,50 @@ 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
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
|
||||
// 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]
|
||||
|
|
Loading…
Reference in a new issue