Skip to content

Commit aa5ca28

Browse files
committed
Get tests passing
1 parent b2ddd93 commit aa5ca28

File tree

4 files changed

+35
-81
lines changed

4 files changed

+35
-81
lines changed

src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ impl<'a> TraitDef<'a> {
398398
generics)
399399
}
400400
_ => {
401-
cx.span_err(mitem.span, "`derive` may only be applied to structs and enums");
401+
cx.span_err(mitem.span,
402+
"`derive` may only be applied to structs and enums");
402403
return;
403404
}
404405
};
@@ -417,7 +418,7 @@ impl<'a> TraitDef<'a> {
417418
})))
418419
}
419420
_ => {
420-
cx.span_err(mitem.span, "`derive` may only be applied to structs and enums");
421+
cx.span_err(mitem.span, "`derive` may only be applied to structs and enums");
421422
}
422423
}
423424
}

src/test/auxiliary/custom_derive_plugin.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern crate rustc;
1919

2020
use syntax::ast;
2121
use syntax::codemap::Span;
22-
use syntax::ext::base::{Decorator, ExtCtxt};
22+
use syntax::ext::base::{Decorator, ExtCtxt, Annotatable};
2323
use syntax::ext::build::AstBuilder;
2424
use syntax::ext::deriving::generic::{cs_fold, TraitDef, MethodDef, combine_substructure};
2525
use syntax::ext::deriving::generic::ty::{Literal, LifetimeBounds, Path, borrowed_explicit_self};
@@ -70,5 +70,13 @@ fn expand(cx: &mut ExtCtxt,
7070
],
7171
};
7272

73-
trait_def.expand(cx, mitem, item, push)
73+
trait_def.expand(cx,
74+
mitem,
75+
Annotatable::Item(P(item.clone())),
76+
&mut |i| {
77+
match i {
78+
Annotatable::Item(i) => push(i),
79+
_ => panic!("Not an item")
80+
}
81+
})
7482
}

src/test/auxiliary/macro_crate_test.rs

Lines changed: 16 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010

1111
// force-host
1212

13-
#![feature(plugin_registrar, quote)]
14-
#![feature(box_syntax, rustc_private)]
13+
#![feature(plugin_registrar, quote, rustc_private)]
1514

1615
extern crate syntax;
1716
extern crate rustc;
1817

19-
use syntax::ast::{self, TokenTree, Item, MetaItem, Method, ImplItem, TraitItem};
18+
use syntax::ast::{self, TokenTree, Item, MetaItem, ImplItem, TraitItem};
2019
use syntax::codemap::Span;
2120
use syntax::ext::base::*;
2221
use syntax::parse::{self, token};
@@ -25,7 +24,6 @@ use rustc::plugin::Registry;
2524

2625
#[macro_export]
2726
macro_rules! exported_macro { () => (2) }
28-
2927
macro_rules! unexported_macro { () => (3) }
3028

3129
#[plugin_registrar]
@@ -42,7 +40,8 @@ pub fn plugin_registrar(reg: &mut Registry) {
4240
MultiModifier(Box::new(expand_into_foo_multi)));
4341
reg.register_syntax_extension(
4442
token::intern("duplicate"),
45-
MultiDecorator(box expand_duplicate));
43+
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
44+
MultiDecorator(Box::new(expand_duplicate)));
4645
}
4746

4847
fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
@@ -109,13 +108,13 @@ fn expand_into_foo_multi(cx: &mut ExtCtxt,
109108
fn expand_duplicate(cx: &mut ExtCtxt,
110109
sp: Span,
111110
mi: &MetaItem,
112-
it: &Annotatable,
113-
mut push: Box<FnMut(Annotatable)>)
111+
it: Annotatable,
112+
push: &mut FnMut(Annotatable))
114113
{
115114
let copy_name = match mi.node {
116115
ast::MetaItem_::MetaList(_, ref xs) => {
117116
if let ast::MetaItem_::MetaWord(ref w) = xs[0].node {
118-
token::str_to_ident(w.get())
117+
token::str_to_ident(&w)
119118
} else {
120119
cx.span_err(mi.span, "Expected word");
121120
return;
@@ -136,75 +135,18 @@ fn expand_duplicate(cx: &mut ExtCtxt,
136135
push(Annotatable::Item(P(new_it)));
137136
}
138137
Annotatable::ImplItem(it) => {
139-
match it {
140-
ImplItem::MethodImplItem(m) => {
141-
let mut new_m = (*m).clone();
142-
new_m.attrs.clear();
143-
replace_method_name(&mut new_m.node, copy_name);
144-
push(Annotatable::ImplItem(ImplItem::MethodImplItem(P(new_m))));
145-
}
146-
ImplItem::TypeImplItem(t) => {
147-
let mut new_t = (*t).clone();
148-
new_t.attrs.clear();
149-
new_t.ident = copy_name;
150-
push(Annotatable::ImplItem(ImplItem::TypeImplItem(P(new_t))));
151-
}
152-
}
153-
}
154-
Annotatable::TraitItem(it) => {
155-
match it {
156-
TraitItem::RequiredMethod(rm) => {
157-
let mut new_rm = rm.clone();
158-
new_rm.attrs.clear();
159-
new_rm.ident = copy_name;
160-
push(Annotatable::TraitItem(TraitItem::RequiredMethod(new_rm)));
161-
}
162-
TraitItem::ProvidedMethod(pm) => {
163-
let mut new_pm = (*pm).clone();
164-
new_pm.attrs.clear();
165-
replace_method_name(&mut new_pm.node, copy_name);
166-
push(Annotatable::TraitItem(TraitItem::ProvidedMethod(P(new_pm))));
167-
}
168-
TraitItem::TypeTraitItem(t) => {
169-
let mut new_t = (*t).clone();
170-
new_t.attrs.clear();
171-
new_t.ty_param.ident = copy_name;
172-
push(Annotatable::TraitItem(TraitItem::TypeTraitItem(P(new_t))));
173-
}
174-
}
138+
let mut new_it = (*it).clone();
139+
new_it.attrs.clear();
140+
new_it.ident = copy_name;
141+
push(Annotatable::ImplItem(P(new_it)));
175142
}
176-
}
177-
178-
fn replace_method_name(m: &mut ast::Method_, i: ast::Ident) {
179-
if let &mut ast::Method_::MethDecl(ref mut ident, _, _, _, _, _, _, _) = m {
180-
*ident = i
143+
Annotatable::TraitItem(tt) => {
144+
let mut new_it = (*tt).clone();
145+
new_it.attrs.clear();
146+
new_it.ident = copy_name;
147+
push(Annotatable::TraitItem(P(new_it)));
181148
}
182149
}
183150
}
184151

185-
fn expand_forged_ident(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResult+'static> {
186-
use syntax::ext::quote::rt::*;
187-
188-
if !tts.is_empty() {
189-
cx.span_fatal(sp, "forged_ident takes no arguments");
190-
}
191-
192-
// Most of this is modelled after the expansion of the `quote_expr!`
193-
// macro ...
194-
let parse_sess = cx.parse_sess();
195-
let cfg = cx.cfg();
196-
197-
// ... except this is where we inject a forged identifier,
198-
// and deliberately do not call `cx.parse_tts_with_hygiene`
199-
// (because we are testing that this will be *rejected*
200-
// by the default parser).
201-
202-
let expr = {
203-
let tt = cx.parse_tts("\x00name_2,ctxt_0\x00".to_string());
204-
let mut parser = new_parser_from_tts(parse_sess, cfg, tt);
205-
parser.parse_expr()
206-
};
207-
MacEager::expr(expr)
208-
}
209-
210152
pub fn foo() {}

src/test/run-pass-fulldeps/macro-crate-multi-decorator.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
// aux-build:macro_crate_test.rs
1212
// ignore-stage1
1313

14-
#![feature(plugin)]
14+
#![feature(plugin, custom_attribute)]
15+
#![plugin(macro_crate_test)]
1516

16-
#[plugin] #[no_link]
17+
#[macro_use]
18+
#[no_link]
1719
extern crate macro_crate_test;
1820

19-
// The duplicate macro will create a copy of the item with the given identifier
21+
// The duplicate macro will create a copy of the item with the given identifier.
22+
2023
#[duplicate(MyCopy)]
2124
struct MyStruct {
2225
number: i32

0 commit comments

Comments
 (0)