Skip to content

Commit 7984e94

Browse files
committed
Add resource drop source-map markers
1 parent 90af7a3 commit 7984e94

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/rust_lower.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ impl<'a> RustLowerer<'a> {
526526
));
527527
out.push_str(&format!("{pad}{{\n"));
528528
self.lower_block(&stmt.body, out, indent + 1);
529+
self.record_source_marker(out, indent + 1, "resource_drop", &stmt.span);
529530
out.push_str(&format!("{pad}}}\n"));
530531
}
531532
Stmt::If(stmt) => {

tests/checker.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,33 @@ pub fn make_session(id: Int) -> Session {
960960
}));
961961
}
962962

963+
#[test]
964+
fn rust_lowering_maps_with_resource_drop_points() {
965+
let source = r#"
966+
fn copy(path: read Path) -> Result<Unit, FileError> {
967+
with File.open_read(path: read path) as file {
968+
File.read_all(file: mut file)?
969+
}
970+
971+
return Ok(Unit)
972+
}
973+
"#;
974+
let lowered =
975+
lower_source_to_rust_with_map("resource.rss", source).expect("source should lower");
976+
977+
assert!(
978+
lowered
979+
.rust_source
980+
.contains("// rss:span kind=resource_drop file=resource.rss")
981+
);
982+
assert!(
983+
lowered
984+
.source_map
985+
.iter()
986+
.any(|entry| entry.kind == "resource_drop" && entry.source.file == "resource.rss")
987+
);
988+
}
989+
963990
#[test]
964991
fn rustc_diagnostics_map_back_to_rsscript_source_spans() {
965992
let source = r#"

0 commit comments

Comments
 (0)