Skip to content

Commit

Permalink
Remove slice pattern from compiler plugin example
Browse files Browse the repository at this point in the history
closes #29930
  • Loading branch information
fhahn committed Nov 20, 2015
1 parent 2228bac commit c53722d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/doc/book/compiler-plugins.md
Expand Up @@ -54,14 +54,21 @@ use rustc::plugin::Registry;
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
-> Box<MacResult + 'static> {
static NUMERALS: &'static [(&'static str, u32)] = &[
static NUMERALS: &'static [(&'static str, usize)] = &[
("M", 1000), ("CM", 900), ("D", 500), ("CD", 400),
("C", 100), ("XC", 90), ("L", 50), ("XL", 40),
("X", 10), ("IX", 9), ("V", 5), ("IV", 4),
("I", 1)];
let text = match args {
[TokenTree::Token(_, token::Ident(s, _))] => s.to_string(),
if args.len() != 1 {
cx.span_err(
sp,
&format!("argument should be a single identifier, but got {} arguments", args.len()));
return DummyResult::any(sp);
}
let text = match args[0] {
TokenTree::Token(_, token::Ident(s, _)) => s.to_string(),
_ => {
cx.span_err(sp, "argument should be a single identifier");
return DummyResult::any(sp);
Expand All @@ -83,7 +90,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
}
}
MacEager::expr(cx.expr_u32(sp, total))
MacEager::expr(cx.expr_usize(sp, total))
}
#[plugin_registrar]
Expand Down
11 changes: 9 additions & 2 deletions src/test/auxiliary/roman_numerals.rs
Expand Up @@ -39,8 +39,15 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
("X", 10), ("IX", 9), ("V", 5), ("IV", 4),
("I", 1)];

let text = match args {
[TokenTree::Token(_, token::Ident(s, _))] => s.to_string(),
if args.len() != 1 {
cx.span_err(
sp,
&format!("argument should be a single identifier, but got {} arguments", args.len()));
return DummyResult::any(sp);
}

let text = match args[0] {
TokenTree::Token(_, token::Ident(s, _)) => s.to_string(),
_ => {
cx.span_err(sp, "argument should be a single identifier");
return DummyResult::any(sp);
Expand Down

0 comments on commit c53722d

Please sign in to comment.