Skip to content

Commit cf242fc

Browse files
committed
syntax: don't pass an (unused) MetaItem to builtin derives.
1 parent 53300bd commit cf242fc

File tree

15 files changed

+32
-57
lines changed

15 files changed

+32
-57
lines changed

src/libsyntax/ext/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
pub use self::SyntaxExtension::*;
1212

13-
use ast::{self, Attribute, Name, PatKind, MetaItem};
13+
use ast::{self, Attribute, Name, PatKind};
1414
use attr::HasAttrs;
1515
use source_map::{self, SourceMap, Spanned, respan};
1616
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
@@ -571,7 +571,7 @@ impl MacResult for DummyResult {
571571
}
572572

573573
pub type BuiltinDeriveFn =
574-
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut dyn FnMut(Annotatable));
574+
for<'cx> fn(&'cx mut ExtCtxt, Span, &Annotatable, &mut dyn FnMut(Annotatable));
575575

576576
/// Represents different kinds of macro invocations that can be resolved.
577577
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -912,12 +912,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
912912

913913
let pretty_name = Symbol::intern(&format!("derive({})", path));
914914
let span = path.span;
915-
let attr = ast::Attribute {
916-
path, span,
917-
tokens: TokenStream::empty(),
918-
// irrelevant:
919-
id: ast::AttrId(0), style: ast::AttrStyle::Outer, is_sugared_doc: false,
920-
};
921915

922916
let mut expn_info = ExpnInfo {
923917
call_site: span,
@@ -946,11 +940,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
946940
invoc.expansion_data.mark.set_expn_info(expn_info);
947941
let span = span.with_ctxt(self.cx.backtrace());
948942
let mut items = Vec::new();
949-
func(self.cx, span, &attr.meta()?, &item, &mut |a| items.push(a));
943+
func(self.cx, span, &item, &mut |a| items.push(a));
950944
Some(invoc.fragment_kind.expect_from_annotatables(items))
951945
}
952946
_ => {
953-
let msg = &format!("macro `{}` may not be used for derive attributes", attr.path);
947+
let msg = &format!("macro `{}` may not be used for derive attributes", path);
954948
self.cx.span_err(span, msg);
955949
self.cx.trace_macros_diag();
956950
invoc.fragment_kind.dummy(span)

src/libsyntax_ext/deriving/bounds.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@
1111
use deriving::path_std;
1212
use deriving::generic::*;
1313
use deriving::generic::ty::*;
14-
use syntax::ast::MetaItem;
1514
use syntax::ext::base::{Annotatable, ExtCtxt};
1615
use syntax_pos::Span;
1716

1817
pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt,
1918
span: Span,
20-
_: &MetaItem,
2119
_: &Annotatable,
2220
_: &mut dyn FnMut(Annotatable)) {
2321
cx.span_err(span, "this unsafe trait should be implemented explicitly");
2422
}
2523

2624
pub fn expand_deriving_copy(cx: &mut ExtCtxt,
2725
span: Span,
28-
mitem: &MetaItem,
2926
item: &Annotatable,
3027
push: &mut dyn FnMut(Annotatable)) {
3128
let trait_def = TraitDef {
@@ -40,5 +37,5 @@ pub fn expand_deriving_copy(cx: &mut ExtCtxt,
4037
associated_types: Vec::new(),
4138
};
4239

43-
trait_def.expand(cx, mitem, item, push);
40+
trait_def.expand(cx, item, push);
4441
}

src/libsyntax_ext/deriving/clone.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use deriving::path_std;
1212
use deriving::generic::*;
1313
use deriving::generic::ty::*;
1414

15-
use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData};
15+
use syntax::ast::{self, Expr, Generics, ItemKind, VariantData};
1616
use syntax::ast::GenericArg;
1717
use syntax::attr;
1818
use syntax::ext::base::{Annotatable, ExtCtxt};
@@ -23,7 +23,6 @@ use syntax_pos::Span;
2323

2424
pub fn expand_deriving_clone(cx: &mut ExtCtxt,
2525
span: Span,
26-
mitem: &MetaItem,
2726
item: &Annotatable,
2827
push: &mut dyn FnMut(Annotatable)) {
2928
// check if we can use a short form
@@ -111,7 +110,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
111110
associated_types: Vec::new(),
112111
};
113112

114-
trait_def.expand_ext(cx, mitem, item, push, is_shallow)
113+
trait_def.expand_ext(cx, item, push, is_shallow)
115114
}
116115

117116
fn cs_clone_shallow(name: &str,

src/libsyntax_ext/deriving/cmp/eq.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use deriving::path_std;
1212
use deriving::generic::*;
1313
use deriving::generic::ty::*;
1414

15-
use syntax::ast::{self, Expr, MetaItem, GenericArg};
15+
use syntax::ast::{self, Expr, GenericArg};
1616
use syntax::ext::base::{Annotatable, ExtCtxt};
1717
use syntax::ext::build::AstBuilder;
1818
use syntax::ptr::P;
@@ -21,7 +21,6 @@ use syntax_pos::Span;
2121

2222
pub fn expand_deriving_eq(cx: &mut ExtCtxt,
2323
span: Span,
24-
mitem: &MetaItem,
2524
item: &Annotatable,
2625
push: &mut dyn FnMut(Annotatable)) {
2726
let inline = cx.meta_word(span, Symbol::intern("inline"));
@@ -51,7 +50,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
5150
}],
5251
associated_types: Vec::new(),
5352
};
54-
trait_def.expand_ext(cx, mitem, item, push, true)
53+
trait_def.expand_ext(cx, item, push, true)
5554
}
5655

5756
fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {

src/libsyntax_ext/deriving/cmp/ord.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use deriving::path_std;
1212
use deriving::generic::*;
1313
use deriving::generic::ty::*;
1414

15-
use syntax::ast::{self, Expr, MetaItem};
15+
use syntax::ast::{self, Expr};
1616
use syntax::ext::base::{Annotatable, ExtCtxt};
1717
use syntax::ext::build::AstBuilder;
1818
use syntax::ptr::P;
@@ -21,7 +21,6 @@ use syntax_pos::Span;
2121

2222
pub fn expand_deriving_ord(cx: &mut ExtCtxt,
2323
span: Span,
24-
mitem: &MetaItem,
2524
item: &Annotatable,
2625
push: &mut dyn FnMut(Annotatable)) {
2726
let inline = cx.meta_word(span, Symbol::intern("inline"));
@@ -50,7 +49,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
5049
associated_types: Vec::new(),
5150
};
5251

53-
trait_def.expand(cx, mitem, item, push)
52+
trait_def.expand(cx, item, push)
5453
}
5554

5655

src/libsyntax_ext/deriving/cmp/partial_eq.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use deriving::{path_local, path_std};
1212
use deriving::generic::*;
1313
use deriving::generic::ty::*;
1414

15-
use syntax::ast::{BinOpKind, Expr, MetaItem};
15+
use syntax::ast::{BinOpKind, Expr};
1616
use syntax::ext::base::{Annotatable, ExtCtxt};
1717
use syntax::ext::build::AstBuilder;
1818
use syntax::ptr::P;
@@ -21,7 +21,6 @@ use syntax_pos::Span;
2121

2222
pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
2323
span: Span,
24-
mitem: &MetaItem,
2524
item: &Annotatable,
2625
push: &mut dyn FnMut(Annotatable)) {
2726
// structures are equal if all fields are equal, and non equal, if
@@ -109,5 +108,5 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
109108
methods,
110109
associated_types: Vec::new(),
111110
};
112-
trait_def.expand(cx, mitem, item, push)
111+
trait_def.expand(cx, item, push)
113112
}

src/libsyntax_ext/deriving/cmp/partial_ord.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use deriving::{path_local, pathvec_std, path_std};
1414
use deriving::generic::*;
1515
use deriving::generic::ty::*;
1616

17-
use syntax::ast::{self, BinOpKind, Expr, MetaItem};
17+
use syntax::ast::{self, BinOpKind, Expr};
1818
use syntax::ext::base::{Annotatable, ExtCtxt};
1919
use syntax::ext::build::AstBuilder;
2020
use syntax::ptr::P;
@@ -23,7 +23,6 @@ use syntax_pos::Span;
2323

2424
pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
2525
span: Span,
26-
mitem: &MetaItem,
2726
item: &Annotatable,
2827
push: &mut dyn FnMut(Annotatable)) {
2928
macro_rules! md {
@@ -93,7 +92,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
9392
methods,
9493
associated_types: Vec::new(),
9594
};
96-
trait_def.expand(cx, mitem, item, push)
95+
trait_def.expand(cx, item, push)
9796
}
9897

9998
#[derive(Copy, Clone)]

src/libsyntax_ext/deriving/debug.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ use deriving::generic::ty::*;
1515
use rustc_data_structures::thin_vec::ThinVec;
1616

1717
use syntax::ast::{self, Ident};
18-
use syntax::ast::{Expr, MetaItem};
18+
use syntax::ast::Expr;
1919
use syntax::ext::base::{Annotatable, ExtCtxt};
2020
use syntax::ext::build::AstBuilder;
2121
use syntax::ptr::P;
2222
use syntax_pos::{DUMMY_SP, Span};
2323

2424
pub fn expand_deriving_debug(cx: &mut ExtCtxt,
2525
span: Span,
26-
mitem: &MetaItem,
2726
item: &Annotatable,
2827
push: &mut dyn FnMut(Annotatable)) {
2928
// &mut ::std::fmt::Formatter
@@ -53,7 +52,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt,
5352
}],
5453
associated_types: Vec::new(),
5554
};
56-
trait_def.expand(cx, mitem, item, push)
55+
trait_def.expand(cx, item, push)
5756
}
5857

5958
/// We use the debug builders to do the heavy lifting here

src/libsyntax_ext/deriving/decodable.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use deriving::generic::ty::*;
1616
use deriving::warn_if_deprecated;
1717

1818
use syntax::ast;
19-
use syntax::ast::{Expr, MetaItem, Mutability};
19+
use syntax::ast::{Expr, Mutability};
2020
use syntax::ext::base::{Annotatable, ExtCtxt};
2121
use syntax::ext::build::AstBuilder;
2222
use syntax::ptr::P;
@@ -25,24 +25,21 @@ use syntax_pos::Span;
2525

2626
pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt,
2727
span: Span,
28-
mitem: &MetaItem,
2928
item: &Annotatable,
3029
push: &mut dyn FnMut(Annotatable)) {
31-
expand_deriving_decodable_imp(cx, span, mitem, item, push, "rustc_serialize")
30+
expand_deriving_decodable_imp(cx, span, item, push, "rustc_serialize")
3231
}
3332

3433
pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
3534
span: Span,
36-
mitem: &MetaItem,
3735
item: &Annotatable,
3836
push: &mut dyn FnMut(Annotatable)) {
3937
warn_if_deprecated(cx, span, "Decodable");
40-
expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize")
38+
expand_deriving_decodable_imp(cx, span, item, push, "serialize")
4139
}
4240

4341
fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
4442
span: Span,
45-
mitem: &MetaItem,
4643
item: &Annotatable,
4744
push: &mut dyn FnMut(Annotatable),
4845
krate: &'static str) {
@@ -86,7 +83,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
8683
associated_types: Vec::new(),
8784
};
8885

89-
trait_def.expand(cx, mitem, item, push)
86+
trait_def.expand(cx, item, push)
9087
}
9188

9289
fn decodable_substructure(cx: &mut ExtCtxt,

src/libsyntax_ext/deriving/default.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use deriving::path_std;
1212
use deriving::generic::*;
1313
use deriving::generic::ty::*;
1414

15-
use syntax::ast::{Expr, MetaItem};
15+
use syntax::ast::Expr;
1616
use syntax::ext::base::{Annotatable, ExtCtxt};
1717
use syntax::ext::build::AstBuilder;
1818
use syntax::ptr::P;
@@ -21,7 +21,6 @@ use syntax_pos::Span;
2121

2222
pub fn expand_deriving_default(cx: &mut ExtCtxt,
2323
span: Span,
24-
mitem: &MetaItem,
2524
item: &Annotatable,
2625
push: &mut dyn FnMut(Annotatable)) {
2726
let inline = cx.meta_word(span, Symbol::intern("inline"));
@@ -49,7 +48,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
4948
}],
5049
associated_types: Vec::new(),
5150
};
52-
trait_def.expand(cx, mitem, item, push)
51+
trait_def.expand(cx, item, push)
5352
}
5453

5554
fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {

src/libsyntax_ext/deriving/encodable.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ use deriving::generic::*;
9797
use deriving::generic::ty::*;
9898
use deriving::warn_if_deprecated;
9999

100-
use syntax::ast::{Expr, ExprKind, MetaItem, Mutability};
100+
use syntax::ast::{Expr, ExprKind, Mutability};
101101
use syntax::ext::base::{Annotatable, ExtCtxt};
102102
use syntax::ext::build::AstBuilder;
103103
use syntax::ptr::P;
@@ -106,24 +106,21 @@ use syntax_pos::Span;
106106

107107
pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt,
108108
span: Span,
109-
mitem: &MetaItem,
110109
item: &Annotatable,
111110
push: &mut dyn FnMut(Annotatable)) {
112-
expand_deriving_encodable_imp(cx, span, mitem, item, push, "rustc_serialize")
111+
expand_deriving_encodable_imp(cx, span, item, push, "rustc_serialize")
113112
}
114113

115114
pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
116115
span: Span,
117-
mitem: &MetaItem,
118116
item: &Annotatable,
119117
push: &mut dyn FnMut(Annotatable)) {
120118
warn_if_deprecated(cx, span, "Encodable");
121-
expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize")
119+
expand_deriving_encodable_imp(cx, span, item, push, "serialize")
122120
}
123121

124122
fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
125123
span: Span,
126-
mitem: &MetaItem,
127124
item: &Annotatable,
128125
push: &mut dyn FnMut(Annotatable),
129126
krate: &'static str) {
@@ -169,7 +166,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
169166
associated_types: Vec::new(),
170167
};
171168

172-
trait_def.expand(cx, mitem, item, push)
169+
trait_def.expand(cx, item, push)
173170
}
174171

175172
fn encodable_substructure(cx: &mut ExtCtxt,

src/libsyntax_ext/deriving/generic/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,13 @@ fn find_type_parameters(ty: &ast::Ty,
397397
impl<'a> TraitDef<'a> {
398398
pub fn expand(self,
399399
cx: &mut ExtCtxt,
400-
mitem: &ast::MetaItem,
401400
item: &'a Annotatable,
402401
push: &mut dyn FnMut(Annotatable)) {
403-
self.expand_ext(cx, mitem, item, push, false);
402+
self.expand_ext(cx, item, push, false);
404403
}
405404

406405
pub fn expand_ext(self,
407406
cx: &mut ExtCtxt,
408-
mitem: &ast::MetaItem,
409407
item: &'a Annotatable,
410408
push: &mut dyn FnMut(Annotatable),
411409
from_scratch: bool) {
@@ -461,7 +459,7 @@ impl<'a> TraitDef<'a> {
461459
generics, from_scratch,
462460
use_temporaries)
463461
} else {
464-
cx.span_err(mitem.span,
462+
cx.span_err(self.span,
465463
"this trait cannot be derived for unions");
466464
return;
467465
}

src/libsyntax_ext/deriving/hash.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ use deriving::{self, pathvec_std, path_std};
1212
use deriving::generic::*;
1313
use deriving::generic::ty::*;
1414

15-
use syntax::ast::{Expr, MetaItem, Mutability};
15+
use syntax::ast::{Expr, Mutability};
1616
use syntax::ext::base::{Annotatable, ExtCtxt};
1717
use syntax::ext::build::AstBuilder;
1818
use syntax::ptr::P;
1919
use syntax_pos::Span;
2020

2121
pub fn expand_deriving_hash(cx: &mut ExtCtxt,
2222
span: Span,
23-
mitem: &MetaItem,
2423
item: &Annotatable,
2524
push: &mut dyn FnMut(Annotatable)) {
2625

@@ -57,7 +56,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
5756
associated_types: Vec::new(),
5857
};
5958

60-
hash_trait_def.expand(cx, mitem, item, push);
59+
hash_trait_def.expand(cx, item, push);
6160
}
6261

6362
fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {

0 commit comments

Comments
 (0)