Skip to content

Commit

Permalink
Make column macro output 1 based and document it
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Dec 24, 2017
1 parent 1699293 commit e5c3aac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/libstd/macros.rs
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/source_util.rs
Expand Up @@ -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 */
Expand Down

0 comments on commit e5c3aac

Please sign in to comment.