about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorNathan Nguyen <nathan.tm.nguyen@gmail.com>2021-02-18 23:18:20 -0600
committerNathan Nguyen <nathan.tm.nguyen@gmail.com>2021-02-20 11:46:50 -0600
commitf5aa1bceb92ce2207a2f3db07c3fe892fa196086 (patch)
treee2743f5d666df1f4c7de105c7315eac4108c1bce /compiler/rustc_codegen_llvm/src
parent0148b971c921a0831fbf3357e5936eec724e3566 (diff)
downloadrust-f5aa1bceb92ce2207a2f3db07c3fe892fa196086.tar.gz
rust-f5aa1bceb92ce2207a2f3db07c3fe892fa196086.zip
nhwn: use Option<NonZeroU32> in DebugLoc
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs4
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs4
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/mod.rs17
3 files changed, 13 insertions, 12 deletions
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<SourceFile>,
     /// The (1-based) line number.
-    pub line: Option<u32>,
+    pub line: Option<NonZeroU32>,
     /// The (1-based) column number.
-    pub col: Option<u32>,
+    pub col: Option<NonZeroU32>,
 }
 
 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,