Skip to content

Commit 3ca5fff

Browse files
committed
rustc: Use spans for #env errors
Issue #444
1 parent ac83e34 commit 3ca5fff

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

src/comp/front/extenv.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ fn expand_syntax_ext(&ext_ctxt cx,
2323
option::t[str] body) -> @ast::expr {
2424

2525
if (vec::len[@ast::expr](args) != 1u) {
26-
p.err("malformed #env call");
26+
cx.span_err(sp, "malformed #env call");
2727
}
2828

2929
// FIXME: if this was more thorough it would manufacture an
3030
// option::t[str] rather than just an maybe-empty string.
3131

32-
auto var = expr_to_str(p, args.(0));
32+
auto var = expr_to_str(cx, p, args.(0));
3333
alt (generic_os::getenv(var)) {
3434
case (option::none) {
3535
ret make_new_str(p, sp, "");
@@ -42,19 +42,23 @@ fn expand_syntax_ext(&ext_ctxt cx,
4242

4343
// FIXME: duplicate code copied from extfmt:
4444

45-
fn expr_to_str(parser::parser p,
45+
fn expr_to_str(&ext_ctxt cx, parser::parser p,
4646
@ast::expr expr) -> str {
4747
alt (expr.node) {
4848
case (ast::expr_lit(?l, _)) {
4949
alt (l.node) {
5050
case (ast::lit_str(?s)) {
5151
ret s;
5252
}
53+
case (_) {
54+
cx.span_err(l.span, "malformed #env call");
55+
}
5356
}
5457
}
58+
case (_) {
59+
cx.span_err(expr.span, "malformed #env call");
60+
}
5561
}
56-
p.err("malformed #env call");
57-
fail;
5862
}
5963

6064
fn make_new_lit(parser::parser p, common::span sp, ast::lit_ lit)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// error-pattern:malformed #env call
2+
3+
fn main() {
4+
#env();
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// error-pattern:malformed #env call
2+
3+
fn main() {
4+
#env(10);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// error-pattern:malformed #env call
2+
3+
fn main() {
4+
#env("one", "two");
5+
}

0 commit comments

Comments
 (0)