Skip to content

Commit 19b7a7d

Browse files
authored
Fix regression on concrete playback inplace (rust-lang#2454)
This fixes a regression from rust-lang#2439. The compiler should store the location of the function body instead of the declaration. Storing the correct location fixes how concrete playback stores the generated unit test.
1 parent 3d05d3f commit 19b7a7d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

kani-compiler/src/kani_middle/metadata.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::path::Path;
88
use crate::kani_middle::attributes::test_harness_name;
99
use kani_metadata::{ArtifactType, HarnessAttributes, HarnessMetadata};
1010
use rustc_hir::def_id::DefId;
11-
use rustc_middle::ty::{Instance, TyCtxt};
11+
use rustc_middle::ty::{Instance, InstanceDef, TyCtxt, WithOptConstParam};
1212

1313
use super::{attributes::extract_harness_attributes, SourceLocation};
1414

@@ -24,7 +24,8 @@ pub fn gen_proof_metadata(tcx: TyCtxt, def_id: DefId, base_name: &Path) -> Harne
2424
tcx.symbol_name(Instance::mono(tcx, def_id)).to_string()
2525
};
2626

27-
let loc = SourceLocation::def_id_loc(tcx, def_id);
27+
let body = tcx.instance_mir(InstanceDef::Item(WithOptConstParam::unknown(def_id)));
28+
let loc = SourceLocation::new(tcx, &body.span);
2829
let file_stem = format!("{}_{mangled_name}", base_name.file_stem().unwrap().to_str().unwrap());
2930
let model_file = base_name.with_file_name(file_stem).with_extension(ArtifactType::SymTabGoto);
3031

@@ -51,7 +52,8 @@ pub fn gen_test_metadata<'tcx>(
5152
) -> HarnessMetadata {
5253
let pretty_name = test_harness_name(tcx, test_desc);
5354
let mangled_name = tcx.symbol_name(test_fn).to_string();
54-
let loc = SourceLocation::def_id_loc(tcx, test_desc);
55+
let body = tcx.instance_mir(InstanceDef::Item(WithOptConstParam::unknown(test_desc)));
56+
let loc = SourceLocation::new(tcx, &body.span);
5557
let file_stem = format!("{}_{mangled_name}", base_name.file_stem().unwrap().to_str().unwrap());
5658
let model_file = base_name.with_file_name(file_stem).with_extension(ArtifactType::SymTabGoto);
5759

kani-compiler/src/kani_middle/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
use std::collections::HashSet;
77

88
use kani_queries::{QueryDb, UserInput};
9-
use rustc_hir::{
10-
def::DefKind,
11-
def_id::{DefId, LOCAL_CRATE},
12-
};
9+
use rustc_hir::{def::DefKind, def_id::LOCAL_CRATE};
1310
use rustc_middle::mir::mono::MonoItem;
1411
use rustc_middle::span_bug;
1512
use rustc_middle::ty::layout::{
@@ -103,11 +100,6 @@ impl SourceLocation {
103100
};
104101
SourceLocation { filename, start_line, start_col, end_line, end_col }
105102
}
106-
107-
pub fn def_id_loc(tcx: TyCtxt, def_id: DefId) -> Self {
108-
let span = tcx.def_span(def_id);
109-
Self::new(tcx, &span)
110-
}
111103
}
112104

113105
/// Get the FnAbi of a given instance with no extra variadic arguments.

0 commit comments

Comments
 (0)