Stabilize proc_macro::Span::{start,end,line,column}. by m-ou-se · Pull Request #139865 · rust-lang/rust (original) (raw)
Has there been a discussion about whether to change the return values of
line()
andcolumn()
fromusize
toNonZero<usize>
?I believe that using
NonZero
would have the advantage of eliminating confusion about whether it is 0-based or 1-based.
The NonZero
types can sometimes be a bit annoying to work with. In places where it is important for optimization (e.g. Option<NonZeroUsize>
in perf-sensitive code) or correctness (e.g. avoid dividing by zero) it makes sense to pay the (small) ergonomics cost of using NonZero. But in this case, I don't think we're improving anyones lives by using NonZero for these methods.
I don't think there will be a lot of confusion: the line+column numbers are exactly what rustc would show for a diagnostic, and the line number matches you see in your editor. In text editors, code listings, compiler diagnostics, etc., line numbers always start at one.
Just documenting it seems more than enough.