Skip to content

column!() should start at 1 not 0 #46868

Closed
@dtolnay

Description

@dtolnay

In #46762 we noticed that column numbering is handled inconsistently throughout Rust. As of 1.22, panic columns are reported starting with 0.

fn main() {
panic!("line 2 column 0");
}

Except panics that originate within the compiler which seem to start with 1, at least in the following case.

fn main() {
let mut array = [];
array[7] = "line 3 column 1";
}

For #46762 we decided to at least make all panics consistent and go with 1 based. Discussed with the libs team today and we would be interested in applying the same fix for the column!() macro as well. Currently the first line!() is 1 and the first column!() is 0. This seems like an oversight. We would like to make column!() return 1 in the first column. This matches how panics report the column as of #46762, and matches how most text editors number columns.

Obviously if this change turns out to cause major problems then we would revisit, but column!() is used infrequently enough and its uses tend to be such that off-by-one is not important (pretty much limited to error reporting) so we are not too worried.

Documentation for both line!() and column!() will need to be updated to be explicit about the numbering.

@est31 would you be interested in tackling this change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions