Skip to content

Commit 7d20789

Browse files
committed
Make the UTF-8 statement more explicit and explicitly test for it
1 parent 5d7b659 commit 7d20789

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

library/proc_macro/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ pub struct LineColumn {
432432
/// The 1-indexed line in the source file on which the span starts or ends (inclusive).
433433
#[unstable(feature = "proc_macro_span", issue = "54725")]
434434
pub line: usize,
435-
/// The 1-indexed column (in UTF-8 characters) in the source file on which
436-
/// the span starts or ends (inclusive).
435+
/// The 1-indexed column (number of bytes in UTF-8 encoding) in the source
436+
/// file on which the span starts or ends (inclusive).
437437
#[unstable(feature = "proc_macro_span", issue = "54725")]
438438
pub column: usize,
439439
}

src/test/ui/proc-macro/span-absolute-posititions.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ assert_span_pos::assert_span_pos!(5, 35);
99
// Test tab indentation
1010
assert_span_pos::assert_span_pos!(10, 36);
1111

12+
// Two tests to ensure the promise of the docs that the column is the number
13+
// of UTF-8 bytes instead of some other number like number of code points.
14+
15+
// Test that multi byte UTF-8 characters indeed count as multiple bytes
16+
/*🌈*/assert_span_pos::assert_span_pos!(16, 40);
17+
// Test with a complete grapheme cluster
18+
/*🏳️‍🌈*/assert_span_pos::assert_span_pos!(18, 43);
19+
1220
// Test that the macro actually emits an error on a mismatch:
13-
assert_span_pos::assert_span_pos!(0, 35); //~ ERROR line/column mismatch: (0, 35) != (13, 35)
14-
assert_span_pos::assert_span_pos!(14, 0); //~ ERROR line/column mismatch: (14, 0) != (14, 35)
21+
assert_span_pos::assert_span_pos!(0, 35); //~ ERROR line/column mismatch: (0, 35) != (21, 35)
22+
assert_span_pos::assert_span_pos!(22, 0); //~ ERROR line/column mismatch: (22, 0) != (22, 35)
1523

1624
fn main() {}

src/test/ui/proc-macro/span-absolute-posititions.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error: line/column mismatch: (0, 35) != (13, 35)
2-
--> $DIR/span-absolute-posititions.rs:13:35
1+
error: line/column mismatch: (0, 35) != (21, 35)
2+
--> $DIR/span-absolute-posititions.rs:21:35
33
|
44
LL | assert_span_pos::assert_span_pos!(0, 35);
55
| ^
66

7-
error: line/column mismatch: (14, 0) != (14, 35)
8-
--> $DIR/span-absolute-posititions.rs:14:35
7+
error: line/column mismatch: (22, 0) != (22, 35)
8+
--> $DIR/span-absolute-posititions.rs:22:35
99
|
10-
LL | assert_span_pos::assert_span_pos!(14, 0);
10+
LL | assert_span_pos::assert_span_pos!(22, 0);
1111
| ^^
1212

1313
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)