mirror of
https://github.com/rust-lang/rust
synced 2024-10-14 12:33:57 +00:00
Stop macro calls in structs for proc_macro_derive from panicing
This commit is contained in:
parent
6c9bb42ecc
commit
22f788c644
|
@ -29,6 +29,7 @@
|
||||||
use syntax::ext::tt::macro_rules;
|
use syntax::ext::tt::macro_rules;
|
||||||
use syntax::feature_gate::{emit_feature_err, GateIssue};
|
use syntax::feature_gate::{emit_feature_err, GateIssue};
|
||||||
use syntax::fold::Folder;
|
use syntax::fold::Folder;
|
||||||
|
use syntax::fold;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::keywords;
|
||||||
use syntax::util::lev_distance::find_best_match_for_name;
|
use syntax::util::lev_distance::find_best_match_for_name;
|
||||||
|
@ -117,6 +118,10 @@ fn fold_path(&mut self, mut path: ast::Path) -> ast::Path {
|
||||||
}
|
}
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
|
||||||
|
fold::noop_fold_mac(mac, self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EliminateCrateVar(self).fold_item(item).expect_one("")
|
EliminateCrateVar(self).fold_item(item).expect_one("")
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
use errors::FatalError;
|
use errors::FatalError;
|
||||||
use proc_macro::{TokenStream, __internal};
|
use proc_macro::{TokenStream, __internal};
|
||||||
use syntax::ast::{self, ItemKind, Attribute};
|
use syntax::ast::{self, ItemKind, Attribute, Mac};
|
||||||
use syntax::attr::{mark_used, mark_known};
|
use syntax::attr::{mark_used, mark_known};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::ext::base::*;
|
use syntax::ext::base::*;
|
||||||
|
@ -28,6 +28,9 @@ fn visit_attribute(&mut self, attr: &Attribute) {
|
||||||
mark_known(attr);
|
mark_known(attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_mac(&mut self, _mac: &Mac) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CustomDerive {
|
pub struct CustomDerive {
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
#![crate_type = "proc-macro"]
|
||||||
|
#![feature(proc_macro)]
|
||||||
|
#![feature(proc_macro_lib)]
|
||||||
|
|
||||||
|
extern crate proc_macro;
|
||||||
|
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
|
||||||
|
#[proc_macro_derive(Nothing)]
|
||||||
|
pub fn nothing(input: TokenStream) -> TokenStream {
|
||||||
|
"".parse().unwrap()
|
||||||
|
}
|
29
src/test/run-pass-fulldeps/proc-macro/struct-field-macro.rs
Normal file
29
src/test/run-pass-fulldeps/proc-macro/struct-field-macro.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// aux-build:derive-nothing.rs
|
||||||
|
// ignore-stage1
|
||||||
|
|
||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate derive_nothing;
|
||||||
|
|
||||||
|
macro_rules! int {
|
||||||
|
() => { i32 }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Nothing)]
|
||||||
|
struct S {
|
||||||
|
x: int!(),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
Loading…
Reference in a new issue