Skip to content

Commit

Permalink
rustc: Use spans for #env errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brson authored and paulstansifer committed Jun 9, 2011
1 parent 457b6ba commit dac75ff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/comp/front/extenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ fn expand_syntax_ext(&ext_ctxt cx,
option::t[str] body) -> @ast::expr {

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

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

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

// FIXME: duplicate code copied from extfmt:

fn expr_to_str(parser::parser p,
fn expr_to_str(&ext_ctxt cx, parser::parser p,
@ast::expr expr) -> str {
alt (expr.node) {
case (ast::expr_lit(?l, _)) {
alt (l.node) {
case (ast::lit_str(?s)) {
ret s;
}
case (_) {
cx.span_err(l.span, "malformed #env call");
}
}
}
case (_) {
cx.span_err(expr.span, "malformed #env call");
}
}
p.err("malformed #env call");
fail;
}

fn make_new_lit(parser::parser p, common::span sp, ast::lit_ lit)
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/extenv-no-args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:malformed #env call

fn main() {
#env();
}
5 changes: 5 additions & 0 deletions src/test/compile-fail/extenv-not-string-literal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:malformed #env call

fn main() {
#env(10);
}
5 changes: 5 additions & 0 deletions src/test/compile-fail/extenv-too-many-args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// error-pattern:malformed #env call

fn main() {
#env("one", "two");
}

0 comments on commit dac75ff

Please sign in to comment.