Skip to content

Commit e5c3aac

Browse files
committed
Make column macro output 1 based and document it
1 parent 1699293 commit e5c3aac

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/libstd/macros.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,12 @@ pub mod builtin {
460460
/// With [`column!`] and [`file!`], these macros provide debugging information for
461461
/// developers about the location within the source.
462462
///
463-
/// The expanded expression has type `u32`, and the returned line is not
464-
/// the invocation of the `line!()` macro itself, but rather the first macro
465-
/// invocation leading up to the invocation of the `line!()` macro.
463+
/// The expanded expression has type `u32` and is 1-based, so the first line
464+
/// in each file evaluates to 1, the second to 2, etc. This is consistent
465+
/// with error messages by common compilers or popular editors.
466+
/// The returned column is not the invocation of the `line!` macro itself,
467+
/// but rather the first macro invocation leading up to the invocation
468+
/// of the `line!` macro.
466469
///
467470
/// [`column!`]: macro.column.html
468471
/// [`file!`]: macro.file.html
@@ -482,9 +485,12 @@ pub mod builtin {
482485
/// With [`line!`] and [`file!`], these macros provide debugging information for
483486
/// developers about the location within the source.
484487
///
485-
/// The expanded expression has type `u32`, and the returned column is not
486-
/// the invocation of the `column!` macro itself, but rather the first macro
487-
/// invocation leading up to the invocation of the `column!` macro.
488+
/// The expanded expression has type `u32` and is 1-based, so the first column
489+
/// in each line evaluates to 1, the second to 2, etc. This is consistent
490+
/// with error messages by common compilers or popular editors.
491+
/// The returned column is not the invocation of the `column!` macro itself,
492+
/// but rather the first macro invocation leading up to the invocation
493+
/// of the `column!` macro.
488494
///
489495
/// [`line!`]: macro.line.html
490496
/// [`file!`]: macro.file.html

src/libsyntax/ext/source_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
4949
let topmost = cx.expansion_cause().unwrap_or(sp);
5050
let loc = cx.codemap().lookup_char_pos(topmost.lo());
5151

52-
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32))
52+
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32 + 1))
5353
}
5454

5555
/* __rust_unstable_column!(): expands to the current column number */

0 commit comments

Comments
 (0)