Skip to content

Commit 3fd27b2

Browse files
committed
Auto merge of #46977 - est31:column_fix, r=dtolnay
Make the output of the column! macro 1 based Fixes #46868. I didn't add any regression tests as the change already had to change tests inside the codebase. r? @dtolnay
2 parents e8098c5 + 6081989 commit 3fd27b2

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/libstd/macros.rs

+12-6
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 line 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

+1-1
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 */

src/test/run-pass/issue-26322.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ fn main() {
2828
columnline!()
2929
} else { (0, 0) };
3030
let cl = columnline!();
31-
assert_eq!(closure(), (8, 25));
32-
assert_eq!(iflet, (8, 28));
33-
assert_eq!(cl, (13, 30));
31+
assert_eq!(closure(), (9, 25));
32+
assert_eq!(iflet, (9, 28));
33+
assert_eq!(cl, (14, 30));
3434
let indirect = indirectcolumnline!();
35-
assert_eq!(indirect, (19, 34));
35+
assert_eq!(indirect, (20, 34));
3636
}

src/test/run-pass/syntax-extension-source-utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro_rules! indirect_line { () => ( line!() ) }
2222

2323
pub fn main() {
2424
assert_eq!(line!(), 24);
25-
assert_eq!(column!(), 15);
25+
assert_eq!(column!(), 16);
2626
assert_eq!(indirect_line!(), 26);
2727
assert!((file!().ends_with("syntax-extension-source-utils.rs")));
2828
assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string());

0 commit comments

Comments
 (0)