From e5c3aac0b482ea8b37787445cd4f73380c01e345 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 24 Dec 2017 02:20:06 +0100 Subject: [PATCH 1/3] Make column macro output 1 based and document it --- src/libstd/macros.rs | 18 ++++++++++++------ src/libsyntax/ext/source_util.rs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index de46fedaebb..1fed918f246 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -460,9 +460,12 @@ pub mod builtin { /// With [`column!`] and [`file!`], these macros provide debugging information for /// developers about the location within the source. /// - /// The expanded expression has type `u32`, and the returned line is not - /// the invocation of the `line!()` macro itself, but rather the first macro - /// invocation leading up to the invocation of the `line!()` macro. + /// The expanded expression has type `u32` and is 1-based, so the first line + /// in each file evaluates to 1, the second to 2, etc. This is consistent + /// with error messages by common compilers or popular editors. + /// The returned column is not the invocation of the `line!` macro itself, + /// but rather the first macro invocation leading up to the invocation + /// of the `line!` macro. /// /// [`column!`]: macro.column.html /// [`file!`]: macro.file.html @@ -482,9 +485,12 @@ pub mod builtin { /// With [`line!`] and [`file!`], these macros provide debugging information for /// developers about the location within the source. /// - /// The expanded expression has type `u32`, and the returned column is not - /// the invocation of the `column!` macro itself, but rather the first macro - /// invocation leading up to the invocation of the `column!` macro. + /// The expanded expression has type `u32` and is 1-based, so the first column + /// in each line evaluates to 1, the second to 2, etc. This is consistent + /// with error messages by common compilers or popular editors. + /// The returned column is not the invocation of the `column!` macro itself, + /// but rather the first macro invocation leading up to the invocation + /// of the `column!` macro. /// /// [`line!`]: macro.line.html /// [`file!`]: macro.file.html diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 4da485fc9a4..6b08448107a 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -49,7 +49,7 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) let topmost = cx.expansion_cause().unwrap_or(sp); let loc = cx.codemap().lookup_char_pos(topmost.lo()); - base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32)) + base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32 + 1)) } /* __rust_unstable_column!(): expands to the current column number */ From b03af365fa318dfa6e219bd17f09135069885022 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 24 Dec 2017 03:02:28 +0100 Subject: [PATCH 2/3] Fix tests --- src/test/run-pass/issue-26322.rs | 8 ++++---- src/test/run-pass/syntax-extension-source-utils.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/run-pass/issue-26322.rs b/src/test/run-pass/issue-26322.rs index 766d1ce25d1..7f8c7f5521f 100644 --- a/src/test/run-pass/issue-26322.rs +++ b/src/test/run-pass/issue-26322.rs @@ -28,9 +28,9 @@ fn main() { columnline!() } else { (0, 0) }; let cl = columnline!(); - assert_eq!(closure(), (8, 25)); - assert_eq!(iflet, (8, 28)); - assert_eq!(cl, (13, 30)); + assert_eq!(closure(), (9, 25)); + assert_eq!(iflet, (9, 28)); + assert_eq!(cl, (14, 30)); let indirect = indirectcolumnline!(); - assert_eq!(indirect, (19, 34)); + assert_eq!(indirect, (20, 34)); } diff --git a/src/test/run-pass/syntax-extension-source-utils.rs b/src/test/run-pass/syntax-extension-source-utils.rs index 25c7417f7eb..1b2741f14b6 100644 --- a/src/test/run-pass/syntax-extension-source-utils.rs +++ b/src/test/run-pass/syntax-extension-source-utils.rs @@ -22,7 +22,7 @@ macro_rules! indirect_line { () => ( line!() ) } pub fn main() { assert_eq!(line!(), 24); - assert_eq!(column!(), 15); + assert_eq!(column!(), 16); assert_eq!(indirect_line!(), 26); assert!((file!().ends_with("syntax-extension-source-utils.rs"))); assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string()); From 6081989adc7e06dcb6b88feb12908dbb08565c6c Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 25 Dec 2017 14:15:59 +0100 Subject: [PATCH 3/3] Fix docs mistake --- src/libstd/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 1fed918f246..9f3f0ea2742 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -463,7 +463,7 @@ pub mod builtin { /// The expanded expression has type `u32` and is 1-based, so the first line /// in each file evaluates to 1, the second to 2, etc. This is consistent /// with error messages by common compilers or popular editors. - /// The returned column is not the invocation of the `line!` macro itself, + /// The returned line is not the invocation of the `line!` macro itself, /// but rather the first macro invocation leading up to the invocation /// of the `line!` macro. ///