about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2025-02-27 14:30:10 +0200
committerChayim Refael Friedman <chayimfr@gmail.com>2025-03-06 21:00:08 +0200
commit92de0ffd5cf7a9cf35618a0f66c20b55918c69d6 (patch)
treede043360ce6f1527cf3a04696b39d926b6e9b123
parentfcb34b17e22268636a7b227ce78237b158737d39 (diff)
downloadrust-92de0ffd5cf7a9cf35618a0f66c20b55918c69d6.tar.gz
rust-92de0ffd5cf7a9cf35618a0f66c20b55918c69d6.zip
Use correct crate for trait env in `render_const_scalar()`
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/display.rs5
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/hover/tests.rs7
2 files changed, 7 insertions, 5 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
index 41152d90220..95ce36390d3 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
@@ -680,10 +680,7 @@ fn render_const_scalar(
     memory_map: &MemoryMap,
     ty: &Ty,
 ) -> Result<(), HirDisplayError> {
-    // FIXME: We need to get krate from the final callers of the hir display
-    // infrastructure and have it here as a field on `f`.
-    let trait_env =
-        TraitEnvironment::empty(*f.db.crate_graph().crates_in_topological_order().last().unwrap());
+    let trait_env = TraitEnvironment::empty(f.krate());
     let ty = normalize(f.db, trait_env.clone(), ty.clone());
     match ty.kind(Interner) {
         TyKind::Scalar(s) => match s {
diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
index 964b1d7eb7d..6b470d921f7 100644
--- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
@@ -10950,8 +10950,12 @@ pub struct ManuallyDrop$0<T: ?Sized> {
 
 #[test]
 fn projection_const() {
+    // This uses two crates, which have *no* relation between them, to test another thing:
+    // `render_const_scalar()` used to just use the last crate for the trait env, which will
+    // fail in this scenario.
     check(
         r#"
+//- /foo.rs crate:foo
 pub trait PublicFlags {
     type Internal;
 }
@@ -10967,12 +10971,13 @@ pub struct InternalBitFlags;
 impl PublicFlags for NoteDialects {
     type Internal = InternalBitFlags;
 }
+//- /bar.rs crate:bar
     "#,
         expect![[r#"
             *CLAP*
 
             ```rust
-            ra_test_fixture::NoteDialects
+            foo::NoteDialects
             ```
 
             ```rust