]> git.lizzy.rs Git - rust.git/commitdiff
Make column macro output 1 based and document it
authorest31 <MTest31@outlook.com>
Sun, 24 Dec 2017 01:20:06 +0000 (02:20 +0100)
committerest31 <MTest31@outlook.com>
Sun, 24 Dec 2017 01:20:06 +0000 (02:20 +0100)
src/libstd/macros.rs
src/libsyntax/ext/source_util.rs

index de46fedaebb76e4e8c328c09d2304955dcf931a9..1fed918f246d8ae1e21cab9f60ba94ad8f9f8cca 100644 (file)
@@ -460,9 +460,12 @@ macro_rules! concat {
     /// 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 @@ macro_rules! line { () => ({ /* compiler built-in */ }) }
     /// 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
index 4da485fc9a42ccf0b9981cab7631c0516b1d63bf..6b08448107a9fbc54354bd3d2e904ae0f9109aff 100644 (file)
@@ -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 */