From f5aa1bceb92ce2207a2f3db07c3fe892fa196086 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Thu, 18 Feb 2021 23:18:20 -0600 Subject: nhwn: use Option in DebugLoc --- .../src/debuginfo/create_scope_map.rs | 4 ++-- compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 4 ++-- compiler/rustc_codegen_llvm/src/debuginfo/mod.rs | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 7673dfb744c..6febfc9abd6 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -102,8 +102,8 @@ fn make_mir_scope( DIB(cx), parent_scope.dbg_scope.unwrap(), file_metadata, - loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), - loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER), + loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), + loc.col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()), ) }, }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6e7c0b3e347..42a0db54d41 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1841,7 +1841,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> { let loc = cx.lookup_debug_loc(span.lo()); return Some(SourceInfo { file: file_metadata(cx, &loc.file), - line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), + line: loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), }); } } @@ -2504,7 +2504,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global linkage_name.as_ptr().cast(), linkage_name.len(), file_metadata, - line_number.unwrap_or(UNKNOWN_LINE_NUMBER), + line_number.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), type_metadata, is_local_to_unit, global, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 955e739b2c1..f10cc1f4f59 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -38,6 +38,7 @@ use rustc_target::abi::{LayoutOf, Primitive, Size}; use libc::c_uint; use smallvec::SmallVec; use std::cell::RefCell; +use std::num::NonZeroU32; use tracing::debug; mod create_scope_map; @@ -224,9 +225,9 @@ pub struct DebugLoc { /// Information about the original source file. pub file: Lrc, /// The (1-based) line number. - pub line: Option, + pub line: Option, /// The (1-based) column number. - pub col: Option, + pub col: Option, } impl CodegenCx<'ll, '_> { @@ -243,7 +244,7 @@ impl CodegenCx<'ll, '_> { let line = (line + 1) as u32; let col = (pos - line_pos).to_u32() + 1; - (file, Some(line), Some(col)) + (file, NonZeroU32::new(line), NonZeroU32::new(col)) } Err(file) => (file, None, None), }; @@ -358,9 +359,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { linkage_name.as_ptr().cast(), linkage_name.len(), file_metadata, - loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), + loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), function_type_metadata, - scope_line.unwrap_or(UNKNOWN_LINE_NUMBER), + scope_line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), flags, spflags, maybe_definition_llfn, @@ -552,8 +553,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { unsafe { llvm::LLVMRustDIBuilderCreateDebugLocation( - line.unwrap_or(UNKNOWN_LINE_NUMBER), - col.unwrap_or(UNKNOWN_COLUMN_NUMBER), + line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), + col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()), scope, inlined_at, ) @@ -606,7 +607,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { name.as_ptr().cast(), name.len(), file_metadata, - loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), + loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), type_metadata, true, DIFlags::FlagZero, -- cgit 1.4.1-3-g733a5