Skip to content

Commit f5aa1bc

Browse files
committed
nhwn: use Option<NonZeroU32> in DebugLoc
1 parent 0148b97 commit f5aa1bc

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ fn make_mir_scope(
102102
DIB(cx),
103103
parent_scope.dbg_scope.unwrap(),
104104
file_metadata,
105-
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
106-
loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
105+
loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
106+
loc.col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()),
107107
)
108108
},
109109
};

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
18411841
let loc = cx.lookup_debug_loc(span.lo());
18421842
return Some(SourceInfo {
18431843
file: file_metadata(cx, &loc.file),
1844-
line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
1844+
line: loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
18451845
});
18461846
}
18471847
}
@@ -2504,7 +2504,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
25042504
linkage_name.as_ptr().cast(),
25052505
linkage_name.len(),
25062506
file_metadata,
2507-
line_number.unwrap_or(UNKNOWN_LINE_NUMBER),
2507+
line_number.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
25082508
type_metadata,
25092509
is_local_to_unit,
25102510
global,

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use rustc_target::abi::{LayoutOf, Primitive, Size};
3838
use libc::c_uint;
3939
use smallvec::SmallVec;
4040
use std::cell::RefCell;
41+
use std::num::NonZeroU32;
4142
use tracing::debug;
4243

4344
mod create_scope_map;
@@ -224,9 +225,9 @@ pub struct DebugLoc {
224225
/// Information about the original source file.
225226
pub file: Lrc<SourceFile>,
226227
/// The (1-based) line number.
227-
pub line: Option<u32>,
228+
pub line: Option<NonZeroU32>,
228229
/// The (1-based) column number.
229-
pub col: Option<u32>,
230+
pub col: Option<NonZeroU32>,
230231
}
231232

232233
impl CodegenCx<'ll, '_> {
@@ -243,7 +244,7 @@ impl CodegenCx<'ll, '_> {
243244
let line = (line + 1) as u32;
244245
let col = (pos - line_pos).to_u32() + 1;
245246

246-
(file, Some(line), Some(col))
247+
(file, NonZeroU32::new(line), NonZeroU32::new(col))
247248
}
248249
Err(file) => (file, None, None),
249250
};
@@ -358,9 +359,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
358359
linkage_name.as_ptr().cast(),
359360
linkage_name.len(),
360361
file_metadata,
361-
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
362+
loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
362363
function_type_metadata,
363-
scope_line.unwrap_or(UNKNOWN_LINE_NUMBER),
364+
scope_line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
364365
flags,
365366
spflags,
366367
maybe_definition_llfn,
@@ -552,8 +553,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
552553

553554
unsafe {
554555
llvm::LLVMRustDIBuilderCreateDebugLocation(
555-
line.unwrap_or(UNKNOWN_LINE_NUMBER),
556-
col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
556+
line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
557+
col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()),
557558
scope,
558559
inlined_at,
559560
)
@@ -606,7 +607,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
606607
name.as_ptr().cast(),
607608
name.len(),
608609
file_metadata,
609-
loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
610+
loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()),
610611
type_metadata,
611612
true,
612613
DIFlags::FlagZero,

0 commit comments

Comments
 (0)