Skip to content

Commit

Permalink
Use correct crate for trait env in render_const_scalar()
Browse files Browse the repository at this point in the history
  • Loading branch information
ChayimFriedman2 committed Feb 27, 2025
1 parent b1be533 commit ae6b3d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ impl HirFormatter<'_> {
}
}
}

pub fn krate(&self) -> CrateId {
match self.display_target {
DisplayTarget::Diagnostics { krate } | DisplayTarget::Test { krate } => krate,
DisplayTarget::SourceCode { module_id, .. } => module_id.krate(),
}
}
}

pub trait HirDisplay {
Expand Down Expand Up @@ -655,10 +662,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 {
Expand Down
7 changes: 6 additions & 1 deletion crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down

0 comments on commit ae6b3d0

Please sign in to comment.