Skip to content

Commit f24bb99

Browse files
Clarify comment in about columns for zero-width spans
1 parent 4f38f11 commit f24bb99

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/librustc_codegen_llvm/debuginfo/source_loc.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,19 @@ impl InternalDebugLocation<'ll> {
5656
pub fn from_span(cx: &CodegenCx<'ll, '_>, scope: &'ll DIScope, span: Span) -> Self {
5757
let pos = cx.sess().source_map().lookup_char_pos(span.lo());
5858

59-
// FIXME: Rust likes to emit zero-width spans just after the end of a function. For now,
60-
// zero-width spans to the preceding column to avoid emitting a column that points past the
61-
// end of a line. E.g.,
62-
// |xyz = None
63-
// x|yz = 1
64-
// xy|z = 2
59+
// Rust likes to emit zero-width spans that point just after a closing brace to denote e.g.
60+
// implicit return from a function. Instead of mapping zero-width spans to the column at
61+
// `span.lo` like we do normally, map them to the column immediately before the span. This
62+
// ensures that we point to a closing brace in the common case, and that debuginfo doesn't
63+
// point past the end of a line. A zero-width span at the very start of the line gets
64+
// mapped to `0`, which is used to represent "no column information" in DWARF. For example,
6565
//
66-
// See discussion in https://github.com/rust-lang/rust/issues/65437
66+
// Span len = 0 Span len = 1
67+
//
68+
// |xyz => 0 (None) |x|yz => 1
69+
// x|yz => 1 x|y|z => 2
70+
//
71+
// See discussion in https://github.com/rust-lang/rust/issues/65437 for more info.
6772
let col0 = pos.col.to_usize();
6873
let col1 = if span.is_empty() {
6974
NonZeroUsize::new(col0)

0 commit comments

Comments
 (0)