From 82ae228d9864cfb47e349a702053ba189d776966 Mon Sep 17 00:00:00 2001 From: Dezhi Wu Date: Tue, 7 Sep 2021 14:44:30 +0800 Subject: [PATCH] fix: path display error when start with `crate` --- crates/hir_ty/src/display.rs | 2 +- crates/ide/src/hover.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index bce24b825c..6281e3c2a5 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -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)?; diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 2a505c621f..3fb1956d80 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -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]