Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/view_memory_layout.rs')
-rw-r--r--crates/ide/src/view_memory_layout.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/ide/src/view_memory_layout.rs b/crates/ide/src/view_memory_layout.rs
index df3f2f18b4..830c39e21e 100644
--- a/crates/ide/src/view_memory_layout.rs
+++ b/crates/ide/src/view_memory_layout.rs
@@ -6,6 +6,7 @@ use ide_db::{
helpers::{get_definition, pick_best_token},
RootDatabase,
};
+use span::Edition;
use syntax::{AstNode, SyntaxKind};
use crate::FilePosition;
@@ -85,6 +86,10 @@ pub(crate) fn view_memory_layout(
) -> Option<RecursiveMemoryLayout> {
let sema = Semantics::new(db);
let file = sema.parse_guess_edition(position.file_id);
+ let edition = sema
+ .attach_first_edition(position.file_id)
+ .map(|it| it.edition())
+ .unwrap_or(Edition::CURRENT);
let token =
pick_best_token(file.syntax().token_at_offset(position.offset), |kind| match kind {
SyntaxKind::IDENT => 3,
@@ -111,6 +116,7 @@ pub(crate) fn view_memory_layout(
ty: &Type,
layout: &Layout,
parent_idx: usize,
+ edition: Edition,
) {
let mut fields = ty
.fields(db)
@@ -141,7 +147,7 @@ pub(crate) fn view_memory_layout(
if let Ok(child_layout) = child_ty.layout(db) {
nodes.push(MemoryLayoutNode {
item_name: field.name(db),
- typename: child_ty.display(db).to_string(),
+ typename: child_ty.display(db, edition).to_string(),
size: child_layout.size(),
alignment: child_layout.align(),
offset: match *field {
@@ -157,7 +163,7 @@ pub(crate) fn view_memory_layout(
item_name: field.name(db)
+ format!("(no layout data: {:?})", child_ty.layout(db).unwrap_err())
.as_ref(),
- typename: child_ty.display(db).to_string(),
+ typename: child_ty.display(db, edition).to_string(),
size: 0,
offset: 0,
alignment: 0,
@@ -170,7 +176,7 @@ pub(crate) fn view_memory_layout(
for (i, (_, child_ty)) in fields.iter().enumerate() {
if let Ok(child_layout) = child_ty.layout(db) {
- read_layout(nodes, db, child_ty, &child_layout, children_start + i);
+ read_layout(nodes, db, child_ty, &child_layout, children_start + i, edition);
}
}
}
@@ -188,7 +194,7 @@ pub(crate) fn view_memory_layout(
def => def.name(db).map(|n| n.as_str().to_owned()).unwrap_or("[ROOT]".to_owned()),
};
- let typename = ty.display(db).to_string();
+ let typename = ty.display(db, edition).to_string();
let mut nodes = vec![MemoryLayoutNode {
item_name,
@@ -200,7 +206,7 @@ pub(crate) fn view_memory_layout(
children_start: -1,
children_len: 0,
}];
- read_layout(&mut nodes, db, &ty, &layout, 0);
+ read_layout(&mut nodes, db, &ty, &layout, 0, edition);
RecursiveMemoryLayout { nodes }
})