Skip to content

Commit 6a80620

Browse files
bors[bot]dzvon
andauthored
Merge #10174
10174: fix: path display error when start with `crate` r=flodiebold a=dzvon Fixes #10172 Co-authored-by: Dezhi Wu <[email protected]>
2 parents 108b080 + 87436a0 commit 6a80620

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

crates/hir_ty/src/display.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,20 +1141,22 @@ impl HirDisplay for Path {
11411141
write!(f, ">")?;
11421142
}
11431143
(_, PathKind::Plain) => {}
1144-
(_, PathKind::Abs) => write!(f, "::")?,
1144+
(_, PathKind::Abs) => {}
11451145
(_, PathKind::Crate) => write!(f, "crate")?,
11461146
(_, PathKind::Super(0)) => write!(f, "self")?,
11471147
(_, PathKind::Super(n)) => {
1148-
write!(f, "super")?;
1149-
for _ in 0..*n {
1150-
write!(f, "::super")?;
1148+
for i in 0..*n {
1149+
if i > 0 {
1150+
write!(f, "::")?;
1151+
}
1152+
write!(f, "super")?;
11511153
}
11521154
}
11531155
(_, PathKind::DollarCrate(_)) => write!(f, "{{extern_crate}}")?,
11541156
}
11551157

11561158
for (seg_idx, segment) in self.segments().iter().enumerate() {
1157-
if seg_idx != 0 {
1159+
if !matches!(self.kind(), PathKind::Plain) || seg_idx > 0 {
11581160
write!(f, "::")?;
11591161
}
11601162
write!(f, "{}", segment.name)?;

crates/ide/src/hover.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,50 @@ fn main() { let foo_test = fo$0o(); }
962962
```
963963
"#]],
964964
);
965+
966+
// Use literal `crate` in path
967+
check(
968+
r#"
969+
pub struct X;
970+
971+
fn foo() -> crate::X { X }
972+
973+
fn main() { f$0oo(); }
974+
"#,
975+
expect![[r#"
976+
*foo*
977+
978+
```rust
979+
test
980+
```
981+
982+
```rust
983+
fn foo() -> crate::X
984+
```
985+
"#]],
986+
);
987+
988+
// Check `super` in path
989+
check(
990+
r#"
991+
pub struct X;
992+
993+
mod m { pub fn foo() -> super::X { super::X } }
994+
995+
fn main() { m::f$0oo(); }
996+
"#,
997+
expect![[r#"
998+
*foo*
999+
1000+
```rust
1001+
test::m
1002+
```
1003+
1004+
```rust
1005+
pub fn foo() -> super::X
1006+
```
1007+
"#]],
1008+
);
9651009
}
9661010

9671011
#[test]

0 commit comments

Comments
 (0)