Skip to content

Commit f50e4ee

Browse files
committed
auto merge of #15719 : michaelwoerister/rust/global_var_null_span_fix, r=alexcrichton
This should fix issue #15541. It would be good to have an test case for this would also be nice but I haven't had the time to write one. The change is very small though and it doesn't break anything in the existing test suite, so I guess we can add it without test for now.
2 parents e288fc6 + 731f44d commit f50e4ee

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/librustc/middle/trans/debuginfo.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -799,15 +799,16 @@ pub fn create_global_var_metadata(cx: &CrateContext,
799799
var_item).as_slice())
800800
};
801801

802-
let filename = span_start(cx, span).file.name.clone();
803-
let file_metadata = file_metadata(cx, filename.as_slice());
802+
let (file_metadata, line_number) = if span != codemap::DUMMY_SP {
803+
let loc = span_start(cx, span);
804+
(file_metadata(cx, loc.file.name.as_slice()), loc.line as c_uint)
805+
} else {
806+
(UNKNOWN_FILE_METADATA, UNKNOWN_LINE_NUMBER)
807+
};
804808

805809
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
806-
let loc = span_start(cx, span);
807-
808810
let variable_type = ty::node_id_to_type(cx.tcx(), node_id);
809811
let type_metadata = type_metadata(cx, variable_type, span);
810-
811812
let namespace_node = namespace_for_item(cx, ast_util::local_def(node_id));
812813
let var_name = token::get_ident(ident).get().to_string();
813814
let linkage_name =
@@ -822,7 +823,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
822823
var_name,
823824
linkage_name,
824825
file_metadata,
825-
loc.line as c_uint,
826+
line_number,
826827
type_metadata,
827828
is_local_to_unit,
828829
global,

0 commit comments

Comments
 (0)