Skip to content

Commit 9287332

Browse files
committed
coverage: Pass a LocalFileId to CoverageSpan::from_source_region
1 parent 3c30fe3 commit 9287332

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_middle::mir::coverage::{CounterId, CovTerm, ExpressionId, SourceRegion};
2+
use crate::coverageinfo::mapgen::LocalFileId;
23

34
/// Must match the layout of `LLVMRustCounterKind`.
45
#[derive(Copy, Clone, Debug)]
@@ -137,7 +138,8 @@ pub(crate) struct CoverageSpan {
137138
}
138139

139140
impl CoverageSpan {
140-
pub(crate) fn from_source_region(file_id: u32, code_region: &SourceRegion) -> Self {
141+
pub(crate) fn from_source_region(local_file_id: LocalFileId, code_region: &SourceRegion) -> Self {
142+
let file_id = local_file_id.as_u32();
141143
let &SourceRegion { start_line, start_col, end_line, end_col } = code_region;
142144
// Internally, LLVM uses the high bit of `end_col` to distinguish between
143145
// code regions and gap regions, so it can't be used by the column number.

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ rustc_index::newtype_index! {
210210
/// An index into a function's list of global file IDs. That underlying list
211211
/// of local-to-global mappings will be embedded in the function's record in
212212
/// the `__llvm_covfun` linker section.
213-
struct LocalFileId {}
213+
pub(crate) struct LocalFileId {}
214214
}
215215

216216
/// Holds a mapping from "local" (per-function) file IDs to "global" (per-CGU)
@@ -280,7 +280,7 @@ fn encode_mappings_for_function(
280280
// form suitable for FFI.
281281
for (mapping_kind, region) in counter_regions {
282282
debug!("Adding counter {mapping_kind:?} to map for {region:?}");
283-
let span = ffi::CoverageSpan::from_source_region(local_file_id.as_u32(), region);
283+
let span = ffi::CoverageSpan::from_source_region(local_file_id, region);
284284
match mapping_kind {
285285
MappingKind::Code(term) => {
286286
code_regions.push(ffi::CodeRegion { span, counter: ffi::Counter::from_term(term) });

0 commit comments

Comments
 (0)