Skip to content

Commit 50c4e3e

Browse files
committed
Auto merge of #40664 - jseyfried:fix_derive_bug, r=nrc
macros: fix bug in legacy custom derive processing Fixes #40663. r? @nrc
2 parents cab4bff + bd862d2 commit 50c4e3e

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/librustc_resolve/macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ impl<'a> base::Resolver for Resolver<'a> {
230230
attrs.remove(i);
231231
} else {
232232
let mut tokens = Vec::new();
233-
for (i, path) in traits.iter().enumerate() {
234-
if i > 0 {
233+
for (j, path) in traits.iter().enumerate() {
234+
if j > 0 {
235235
tokens.push(TokenTree::Token(attrs[i].span, Token::Comma).into());
236236
}
237-
for (j, segment) in path.segments.iter().enumerate() {
238-
if j > 0 {
237+
for (k, segment) in path.segments.iter().enumerate() {
238+
if k > 0 {
239239
tokens.push(TokenTree::Token(path.span, Token::ModSep).into());
240240
}
241241
let tok = Token::Ident(segment.identifier);

src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin.rs

+6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ pub fn plugin_registrar(reg: &mut Registry) {
3434
reg.register_custom_derive(
3535
Symbol::intern("derive_TotalSum"),
3636
MultiDecorator(box expand));
37+
38+
reg.register_custom_derive(
39+
Symbol::intern("derive_Nothing"),
40+
MultiDecorator(box noop));
3741
}
3842

43+
fn noop(_: &mut ExtCtxt, _: Span, _: &ast::MetaItem, _: &Annotatable, _: &mut FnMut(Annotatable)) {}
44+
3945
fn expand(cx: &mut ExtCtxt,
4046
span: Span,
4147
mitem: &ast::MetaItem,
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:custom_derive_plugin.rs
12+
13+
#![feature(plugin, custom_derive)]
14+
#![plugin(custom_derive_plugin)]
15+
16+
#[derive(Nothing, Nothing, Nothing)]
17+
struct S;
18+
19+
fn main() {}

0 commit comments

Comments
 (0)