Skip to content

Commit 6827661

Browse files
committed
Auto merge of #29951 - fhahn:fix-plugin-compiler-example, r=steveklabnik
PR for #29930. Adds missing #![feature(slice_patterns)] to make compiler plugin example compile again.
2 parents e5f8a3d + c53722d commit 6827661

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/doc/book/compiler-plugins.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,21 @@ use rustc::plugin::Registry;
5454
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
5555
-> Box<MacResult + 'static> {
5656
57-
static NUMERALS: &'static [(&'static str, u32)] = &[
57+
static NUMERALS: &'static [(&'static str, usize)] = &[
5858
("M", 1000), ("CM", 900), ("D", 500), ("CD", 400),
5959
("C", 100), ("XC", 90), ("L", 50), ("XL", 40),
6060
("X", 10), ("IX", 9), ("V", 5), ("IV", 4),
6161
("I", 1)];
6262
63-
let text = match args {
64-
[TokenTree::Token(_, token::Ident(s, _))] => s.to_string(),
63+
if args.len() != 1 {
64+
cx.span_err(
65+
sp,
66+
&format!("argument should be a single identifier, but got {} arguments", args.len()));
67+
return DummyResult::any(sp);
68+
}
69+
70+
let text = match args[0] {
71+
TokenTree::Token(_, token::Ident(s, _)) => s.to_string(),
6572
_ => {
6673
cx.span_err(sp, "argument should be a single identifier");
6774
return DummyResult::any(sp);
@@ -83,7 +90,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
8390
}
8491
}
8592
86-
MacEager::expr(cx.expr_u32(sp, total))
93+
MacEager::expr(cx.expr_usize(sp, total))
8794
}
8895
8996
#[plugin_registrar]

src/test/auxiliary/roman_numerals.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
3939
("X", 10), ("IX", 9), ("V", 5), ("IV", 4),
4040
("I", 1)];
4141

42-
let text = match args {
43-
[TokenTree::Token(_, token::Ident(s, _))] => s.to_string(),
42+
if args.len() != 1 {
43+
cx.span_err(
44+
sp,
45+
&format!("argument should be a single identifier, but got {} arguments", args.len()));
46+
return DummyResult::any(sp);
47+
}
48+
49+
let text = match args[0] {
50+
TokenTree::Token(_, token::Ident(s, _)) => s.to_string(),
4451
_ => {
4552
cx.span_err(sp, "argument should be a single identifier");
4653
return DummyResult::any(sp);

0 commit comments

Comments
 (0)