Skip to content

Commit ae75ef9

Browse files
committed
Auto merge of #28137 - nrc:remove-non-multi, r=huonw
This is a [breaking-change] for syntax extension authors. The fix is to use MultiModifier or MultiDecorator, which have the same functionality but are more flexible. Users of syntax extensions are unaffected.
2 parents 4ad128b + 20e1ea2 commit ae75ef9

File tree

5 files changed

+3
-173
lines changed

5 files changed

+3
-173
lines changed

src/librustc/plugin/registry.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use lint::{LintPassObject, LintId, Lint};
1414
use session::Session;
1515

1616
use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT};
17-
use syntax::ext::base::{IdentTT, Decorator, Modifier, MultiModifier, MultiDecorator};
17+
use syntax::ext::base::{IdentTT, MultiModifier, MultiDecorator};
1818
use syntax::ext::base::{MacroExpanderFn, MacroRulesTT};
1919
use syntax::codemap::Span;
2020
use syntax::parse::token;
@@ -98,9 +98,7 @@ impl<'a> Registry<'a> {
9898
IdentTT(ext, _, allow_internal_unstable) => {
9999
IdentTT(ext, Some(self.krate_span), allow_internal_unstable)
100100
}
101-
Decorator(ext) => Decorator(ext),
102101
MultiDecorator(ext) => MultiDecorator(ext),
103-
Modifier(ext) => Modifier(ext),
104102
MultiModifier(ext) => MultiModifier(ext),
105103
MacroRulesTT => {
106104
self.sess.err("plugin tried to register a new MacroRulesTT");

src/libsyntax/ext/base.rs

-68
Original file line numberDiff line numberDiff line change
@@ -31,60 +31,6 @@ use std::collections::HashMap;
3131
use std::rc::Rc;
3232
use std::default::Default;
3333

34-
#[unstable(feature = "rustc_private")]
35-
#[deprecated(since = "1.0.0", reason = "replaced by MultiItemDecorator")]
36-
pub trait ItemDecorator {
37-
fn expand(&self,
38-
ecx: &mut ExtCtxt,
39-
sp: Span,
40-
meta_item: &ast::MetaItem,
41-
item: &ast::Item,
42-
push: &mut FnMut(P<ast::Item>));
43-
}
44-
45-
#[allow(deprecated)]
46-
#[unstable(feature = "rustc_private")]
47-
#[deprecated(since = "1.0.0", reason = "replaced by MultiItemDecorator")]
48-
impl<F> ItemDecorator for F
49-
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, &mut FnMut(P<ast::Item>))
50-
{
51-
fn expand(&self,
52-
ecx: &mut ExtCtxt,
53-
sp: Span,
54-
meta_item: &ast::MetaItem,
55-
item: &ast::Item,
56-
push: &mut FnMut(P<ast::Item>)) {
57-
(*self)(ecx, sp, meta_item, item, push)
58-
}
59-
}
60-
61-
#[unstable(feature = "rustc_private")]
62-
#[deprecated(since = "1.0.0", reason = "replaced by MultiItemModifier")]
63-
pub trait ItemModifier {
64-
fn expand(&self,
65-
ecx: &mut ExtCtxt,
66-
span: Span,
67-
meta_item: &ast::MetaItem,
68-
item: P<ast::Item>)
69-
-> P<ast::Item>;
70-
}
71-
72-
#[allow(deprecated)]
73-
#[unstable(feature = "rustc_private")]
74-
#[deprecated(since = "1.0.0", reason = "replaced by MultiItemModifier")]
75-
impl<F> ItemModifier for F
76-
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, P<ast::Item>) -> P<ast::Item>
77-
{
78-
79-
fn expand(&self,
80-
ecx: &mut ExtCtxt,
81-
span: Span,
82-
meta_item: &ast::MetaItem,
83-
item: P<ast::Item>)
84-
-> P<ast::Item> {
85-
(*self)(ecx, span, meta_item, item)
86-
}
87-
}
8834

8935
#[derive(Debug,Clone)]
9036
pub enum Annotatable {
@@ -460,26 +406,12 @@ impl MacResult for DummyResult {
460406

461407
/// An enum representing the different kinds of syntax extensions.
462408
pub enum SyntaxExtension {
463-
/// A syntax extension that is attached to an item and creates new items
464-
/// based upon it.
465-
#[unstable(feature = "rustc_private")]
466-
#[deprecated(since = "1.0.0", reason = "replaced by MultiDecorator")]
467-
#[allow(deprecated)]
468-
Decorator(Box<ItemDecorator + 'static>),
469-
470409
/// A syntax extension that is attached to an item and creates new items
471410
/// based upon it.
472411
///
473412
/// `#[derive(...)]` is a `MultiItemDecorator`.
474413
MultiDecorator(Box<MultiItemDecorator + 'static>),
475414

476-
/// A syntax extension that is attached to an item and modifies it
477-
/// in-place.
478-
#[unstable(feature = "rustc_private")]
479-
#[deprecated(since = "1.0.0", reason = "replaced by MultiModifier")]
480-
#[allow(deprecated)]
481-
Modifier(Box<ItemModifier + 'static>),
482-
483415
/// A syntax extension that is attached to an item and modifies it
484416
/// in-place. More flexible version than Modifier.
485417
MultiModifier(Box<MultiItemModifier + 'static>),

src/libsyntax/ext/expand.rs

+2-83
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,9 @@ macro_rules! with_exts_frame {
636636
// When we enter a module, record it, for the sake of `module!`
637637
pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
638638
-> SmallVector<P<ast::Item>> {
639-
let it = expand_item_modifiers(it, fld);
639+
let it = expand_item_multi_modifier(Annotatable::Item(it), fld);
640640

641-
expand_annotatable(Annotatable::Item(it), fld)
641+
expand_annotatable(it, fld)
642642
.into_iter().map(|i| i.expect_item()).collect()
643643
}
644644

@@ -1275,11 +1275,9 @@ macro_rules! partition {
12751275
}
12761276
}
12771277

1278-
partition!(modifiers, Modifier);
12791278
partition!(multi_modifiers, MultiModifier);
12801279

12811280

1282-
#[allow(deprecated)] // The `allow` is needed because the `Decorator` variant is used.
12831281
fn expand_decorators(a: Annotatable,
12841282
fld: &mut MacroExpander,
12851283
decorator_items: &mut SmallVector<Annotatable>,
@@ -1289,33 +1287,6 @@ fn expand_decorators(a: Annotatable,
12891287
let mname = intern(&attr.name());
12901288
match fld.cx.syntax_env.find(&mname) {
12911289
Some(rc) => match *rc {
1292-
Decorator(ref dec) => {
1293-
attr::mark_used(&attr);
1294-
1295-
fld.cx.bt_push(ExpnInfo {
1296-
call_site: attr.span,
1297-
callee: NameAndSpan {
1298-
format: MacroAttribute(mname),
1299-
span: Some(attr.span),
1300-
// attributes can do whatever they like,
1301-
// for now.
1302-
allow_internal_unstable: true,
1303-
}
1304-
});
1305-
1306-
// we'd ideally decorator_items.push_all(expand_item(item, fld)),
1307-
// but that double-mut-borrows fld
1308-
let mut items: SmallVector<Annotatable> = SmallVector::zero();
1309-
dec.expand(fld.cx,
1310-
attr.span,
1311-
&attr.node.value,
1312-
&a.clone().expect_item(),
1313-
&mut |item| items.push(Annotatable::Item(item)));
1314-
decorator_items.extend(items.into_iter()
1315-
.flat_map(|ann| expand_annotatable(ann, fld).into_iter()));
1316-
1317-
fld.cx.bt_pop();
1318-
}
13191290
MultiDecorator(ref dec) => {
13201291
attr::mark_used(&attr);
13211292

@@ -1392,58 +1363,6 @@ fn expand_item_multi_modifier(mut it: Annotatable,
13921363
expand_item_multi_modifier(it, fld)
13931364
}
13941365

1395-
#[allow(deprecated)] // This is needed because the `ItemModifier` trait is used
1396-
fn expand_item_modifiers(mut it: P<ast::Item>,
1397-
fld: &mut MacroExpander)
1398-
-> P<ast::Item> {
1399-
// partition the attributes into ItemModifiers and others
1400-
let (modifiers, other_attrs) = modifiers(&it.attrs, fld);
1401-
1402-
// update the attrs, leave everything else alone. Is this mutation really a good idea?
1403-
it = P(ast::Item {
1404-
attrs: other_attrs,
1405-
..(*it).clone()
1406-
});
1407-
1408-
if modifiers.is_empty() {
1409-
let it = expand_item_multi_modifier(Annotatable::Item(it), fld);
1410-
return it.expect_item();
1411-
}
1412-
1413-
for attr in &modifiers {
1414-
let mname = intern(&attr.name());
1415-
1416-
match fld.cx.syntax_env.find(&mname) {
1417-
Some(rc) => match *rc {
1418-
Modifier(ref mac) => {
1419-
attr::mark_used(attr);
1420-
fld.cx.bt_push(ExpnInfo {
1421-
call_site: attr.span,
1422-
callee: NameAndSpan {
1423-
format: MacroAttribute(mname),
1424-
span: Some(attr.span),
1425-
// attributes can do whatever they like,
1426-
// for now
1427-
allow_internal_unstable: true,
1428-
}
1429-
});
1430-
it = mac.expand(fld.cx, attr.span, &*attr.node.value, it);
1431-
fld.cx.bt_pop();
1432-
}
1433-
_ => unreachable!()
1434-
},
1435-
_ => unreachable!()
1436-
}
1437-
}
1438-
1439-
// Expansion may have added new ItemModifiers.
1440-
// It is possible, that an item modifier could expand to a multi-modifier or
1441-
// vice versa. In this case we will expand all modifiers before multi-modifiers,
1442-
// which might give an odd ordering. However, I think it is unlikely that the
1443-
// two kinds will be mixed, and old-style multi-modifiers are deprecated.
1444-
expand_item_modifiers(it, fld)
1445-
}
1446-
14471366
fn expand_impl_item(ii: P<ast::ImplItem>, fld: &mut MacroExpander)
14481367
-> SmallVector<P<ast::ImplItem>> {
14491368
match ii.node {

src/test/auxiliary/macro_crate_test.rs

-12
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ macro_rules! unexported_macro { () => (3) }
3030
pub fn plugin_registrar(reg: &mut Registry) {
3131
reg.register_macro("make_a_1", expand_make_a_1);
3232
reg.register_macro("identity", expand_identity);
33-
reg.register_syntax_extension(
34-
token::intern("into_foo"),
35-
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
36-
Modifier(Box::new(expand_into_foo)));
3733
reg.register_syntax_extension(
3834
token::intern("into_multi_foo"),
3935
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
@@ -62,14 +58,6 @@ fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree])
6258
MacEager::expr(quote_expr!(&mut *cx, $expr))
6359
}
6460

65-
fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: &MetaItem, it: P<Item>)
66-
-> P<Item> {
67-
P(Item {
68-
attrs: it.attrs.clone(),
69-
..(*quote_item!(cx, enum Foo { Bar, Baz }).unwrap()).clone()
70-
})
71-
}
72-
7361
fn expand_into_foo_multi(cx: &mut ExtCtxt,
7462
sp: Span,
7563
attr: &MetaItem,

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

-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
#[macro_use] #[no_link]
1818
extern crate macro_crate_test;
1919

20-
#[into_foo]
21-
#[derive(PartialEq, Clone, Debug)]
22-
fn foo() -> AFakeTypeThatHadBetterGoAway {}
23-
2420
#[into_multi_foo]
2521
#[derive(PartialEq, Clone, Debug)]
2622
fn foo() -> AnotherFakeTypeThatHadBetterGoAway {}
@@ -41,9 +37,6 @@ pub fn main() {
4137
assert_eq!(1, make_a_1!());
4238
assert_eq!(2, exported_macro!());
4339

44-
assert_eq!(Foo::Bar, Foo::Bar);
45-
test(None::<Foo>);
46-
4740
assert_eq!(Foo2::Bar2, Foo2::Bar2);
4841
test(None::<Foo2>);
4942

0 commit comments

Comments
 (0)