Skip to content

Commit 29a8015

Browse files
committed
rustc: Fail better when the first argument to #fmt is not a string literal
1 parent c4e9d8f commit 29a8015

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/comp/front/extfmt.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ fn expr_to_str(@ast::expr expr) -> str {
7474
case (ast::lit_str(?s)) {
7575
ret s;
7676
}
77+
case (_) { /* fallthrough */ }
7778
}
7879
}
80+
case (_) { /* fallthrough */ }
7981
}
80-
// FIXME: Handle error correctly.
81-
log_err "malformed #fmt call";
82+
log_err "first argument to #fmt must be a string literal";
8283
fail;
8384
}
8485

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// xfail-stage0
2+
// error-pattern: literal
3+
4+
fn main() {
5+
// #fmt's first argument must be a literal. Hopefully this
6+
// restriction can be eased eventually to just require a
7+
// compile-time constant.
8+
auto x = #fmt("a" + "b");
9+
}

0 commit comments

Comments
 (0)