Skip to content

Commit 92de0ff

Browse files
Use correct crate for trait env in render_const_scalar()
1 parent fcb34b1 commit 92de0ff

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/display.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,7 @@ fn render_const_scalar(
680680
memory_map: &MemoryMap,
681681
ty: &Ty,
682682
) -> Result<(), HirDisplayError> {
683-
// FIXME: We need to get krate from the final callers of the hir display
684-
// infrastructure and have it here as a field on `f`.
685-
let trait_env =
686-
TraitEnvironment::empty(*f.db.crate_graph().crates_in_topological_order().last().unwrap());
683+
let trait_env = TraitEnvironment::empty(f.krate());
687684
let ty = normalize(f.db, trait_env.clone(), ty.clone());
688685
match ty.kind(Interner) {
689686
TyKind::Scalar(s) => match s {

Diff for: src/tools/rust-analyzer/crates/ide/src/hover/tests.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10950,8 +10950,12 @@ pub struct ManuallyDrop$0<T: ?Sized> {
1095010950

1095110951
#[test]
1095210952
fn projection_const() {
10953+
// This uses two crates, which have *no* relation between them, to test another thing:
10954+
// `render_const_scalar()` used to just use the last crate for the trait env, which will
10955+
// fail in this scenario.
1095310956
check(
1095410957
r#"
10958+
//- /foo.rs crate:foo
1095510959
pub trait PublicFlags {
1095610960
type Internal;
1095710961
}
@@ -10967,12 +10971,13 @@ pub struct InternalBitFlags;
1096710971
impl PublicFlags for NoteDialects {
1096810972
type Internal = InternalBitFlags;
1096910973
}
10974+
//- /bar.rs crate:bar
1097010975
"#,
1097110976
expect![[r#"
1097210977
*CLAP*
1097310978
1097410979
```rust
10975-
ra_test_fixture::NoteDialects
10980+
foo::NoteDialects
1097610981
```
1097710982
1097810983
```rust

0 commit comments

Comments
 (0)