Skip to content

Commit b0647fe

Browse files
committed
Limit spans in bytes!() error messages to the argument in question
This constrains the span to the appropriate argument, so you know which one caused the problem. Instead of foo.rs:2:4: 2:21 error: Too large integer literal in bytes! foo.rs:2 bytes!(1, 256, 2) ^~~~~~~~~~~~~~~~~ it will say foo.rs:2:14 2:17 error: Too large integer literal in bytes! foo.rs:2 bytes!(1, 256, 2) ^~~
1 parent 0ec4d34 commit b0647fe

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/libsyntax/ext/bytes.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,43 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> bas
3030
// string literal, push each byte to vector expression
3131
ast::lit_str(s) => {
3232
for byte in s.byte_iter() {
33-
bytes.push(cx.expr_u8(sp, byte));
33+
bytes.push(cx.expr_u8(expr.span, byte));
3434
}
3535
}
3636

3737
// u8 literal, push to vector expression
3838
ast::lit_uint(v, ast::ty_u8) => {
3939
if v > 0xFF {
40-
cx.span_err(sp, "Too large u8 literal in bytes!")
40+
cx.span_err(expr.span, "Too large u8 literal in bytes!")
4141
} else {
42-
bytes.push(cx.expr_u8(sp, v as u8));
42+
bytes.push(cx.expr_u8(expr.span, v as u8));
4343
}
4444
}
4545

4646
// integer literal, push to vector expression
4747
ast::lit_int_unsuffixed(v) => {
4848
if v > 0xFF {
49-
cx.span_err(sp, "Too large integer literal in bytes!")
49+
cx.span_err(expr.span, "Too large integer literal in bytes!")
5050
} else if v < 0 {
51-
cx.span_err(sp, "Negative integer literal in bytes!")
51+
cx.span_err(expr.span, "Negative integer literal in bytes!")
5252
} else {
53-
bytes.push(cx.expr_u8(sp, v as u8));
53+
bytes.push(cx.expr_u8(expr.span, v as u8));
5454
}
5555
}
5656

5757
// char literal, push to vector expression
5858
ast::lit_char(v) => {
5959
if char::from_u32(v).unwrap().is_ascii() {
60-
bytes.push(cx.expr_u8(sp, v as u8));
60+
bytes.push(cx.expr_u8(expr.span, v as u8));
6161
} else {
62-
cx.span_err(sp, "Non-ascii char literal in bytes!")
62+
cx.span_err(expr.span, "Non-ascii char literal in bytes!")
6363
}
6464
}
6565

66-
_ => cx.span_err(sp, "Unsupported literal in bytes!")
66+
_ => cx.span_err(expr.span, "Unsupported literal in bytes!")
6767
},
6868

69-
_ => cx.span_err(sp, "Non-literal in bytes!")
69+
_ => cx.span_err(expr.span, "Non-literal in bytes!")
7070
}
7171
}
7272

0 commit comments

Comments
 (0)