Skip to content

Commit 22f788c

Browse files
Stop macro calls in structs for proc_macro_derive from panicing
1 parent 6c9bb42 commit 22f788c

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

Diff for: src/librustc_resolve/macros.rs

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use syntax::ext::hygiene::Mark;
2929
use syntax::ext::tt::macro_rules;
3030
use syntax::feature_gate::{emit_feature_err, GateIssue};
3131
use syntax::fold::Folder;
32+
use syntax::fold;
3233
use syntax::ptr::P;
3334
use syntax::symbol::keywords;
3435
use syntax::util::lev_distance::find_best_match_for_name;
@@ -117,6 +118,10 @@ impl<'a> base::Resolver for Resolver<'a> {
117118
}
118119
path
119120
}
121+
122+
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
123+
fold::noop_fold_mac(mac, self)
124+
}
120125
}
121126

122127
EliminateCrateVar(self).fold_item(item).expect_one("")

Diff for: src/libsyntax_ext/deriving/custom.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::panic;
1212

1313
use errors::FatalError;
1414
use proc_macro::{TokenStream, __internal};
15-
use syntax::ast::{self, ItemKind, Attribute};
15+
use syntax::ast::{self, ItemKind, Attribute, Mac};
1616
use syntax::attr::{mark_used, mark_known};
1717
use syntax::codemap::Span;
1818
use syntax::ext::base::*;
@@ -28,6 +28,9 @@ impl<'a> Visitor<'a> for MarkAttrs<'a> {
2828
mark_known(attr);
2929
}
3030
}
31+
32+
fn visit_mac(&mut self, _mac: &Mac) {
33+
}
3134
}
3235

3336
pub struct CustomDerive {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 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+
// no-prefer-dynamic
12+
13+
#![crate_type = "proc-macro"]
14+
#![feature(proc_macro)]
15+
#![feature(proc_macro_lib)]
16+
17+
extern crate proc_macro;
18+
19+
use proc_macro::TokenStream;
20+
21+
#[proc_macro_derive(Nothing)]
22+
pub fn nothing(input: TokenStream) -> TokenStream {
23+
"".parse().unwrap()
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2016 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:derive-nothing.rs
12+
// ignore-stage1
13+
14+
#![feature(proc_macro)]
15+
16+
#[macro_use]
17+
extern crate derive_nothing;
18+
19+
macro_rules! int {
20+
() => { i32 }
21+
}
22+
23+
#[derive(Nothing)]
24+
struct S {
25+
x: int!(),
26+
}
27+
28+
fn main() {
29+
}

0 commit comments

Comments
 (0)