From 731f44de454dff23d655f93705c3db002216fac4 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 10 Jul 2014 15:38:57 +0200 Subject: [PATCH] debuginfo: Don't crash when encountering global variable with unknown source span. --- src/librustc/middle/trans/debuginfo.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 6e81c10c4a0..d5520148cb4 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -798,15 +798,16 @@ pub fn create_global_var_metadata(cx: &CrateContext, var_item).as_slice()) }; - let filename = span_start(cx, span).file.name.clone(); - let file_metadata = file_metadata(cx, filename.as_slice()); + let (file_metadata, line_number) = if span != codemap::DUMMY_SP { + let loc = span_start(cx, span); + (file_metadata(cx, loc.file.name.as_slice()), loc.line as c_uint) + } else { + (UNKNOWN_FILE_METADATA, UNKNOWN_LINE_NUMBER) + }; let is_local_to_unit = is_node_local_to_unit(cx, node_id); - let loc = span_start(cx, span); - let variable_type = ty::node_id_to_type(cx.tcx(), node_id); let type_metadata = type_metadata(cx, variable_type, span); - let namespace_node = namespace_for_item(cx, ast_util::local_def(node_id)); let var_name = token::get_ident(ident).get().to_string(); let linkage_name = @@ -821,7 +822,7 @@ pub fn create_global_var_metadata(cx: &CrateContext, var_name, linkage_name, file_metadata, - loc.line as c_uint, + line_number, type_metadata, is_local_to_unit, global,