about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2015-11-20 12:19:05 +0100
committerFlorian Hahn <flo@fhahn.com>2015-11-20 14:31:04 +0100
commitc53722daae1a80d28f1fa101c05046ef2a2de8b5 (patch)
tree1f8394307cefab6b9f8e7b5131c3cb1608b2704e /src
parent2228bacd62ca8970a7a59401e78d0c5a34fc0f87 (diff)
downloadrust-c53722daae1a80d28f1fa101c05046ef2a2de8b5.tar.gz
rust-c53722daae1a80d28f1fa101c05046ef2a2de8b5.zip
Remove slice pattern from compiler plugin example
closes #29930
Diffstat (limited to 'src')
-rw-r--r--src/doc/book/compiler-plugins.md15
-rw-r--r--src/test/auxiliary/roman_numerals.rs11
2 files changed, 20 insertions, 6 deletions
diff --git a/src/doc/book/compiler-plugins.md b/src/doc/book/compiler-plugins.md
index 42dfaa1a809..2cb62cdfca5 100644
--- a/src/doc/book/compiler-plugins.md
+++ b/src/doc/book/compiler-plugins.md
@@ -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);
@@ -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]
diff --git a/src/test/auxiliary/roman_numerals.rs b/src/test/auxiliary/roman_numerals.rs
index 3abc6f4a9f5..c9249fb3357 100644
--- a/src/test/auxiliary/roman_numerals.rs
+++ b/src/test/auxiliary/roman_numerals.rs
@@ -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);