Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when using a macros 1.1 custom derive on a struct containing a macro invocation #38737

Merged
merged 2 commits into from
Dec 31, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use syntax::ext::hygiene::Mark;
use syntax::ext::tt::macro_rules;
use syntax::feature_gate::{emit_feature_err, GateIssue};
use syntax::fold::Folder;
use syntax::fold;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use syntax::fold::{self, Folder}.

use syntax::ptr::P;
use syntax::symbol::keywords;
use syntax::util::lev_distance::find_best_match_for_name;
Expand Down Expand Up @@ -117,6 +118,10 @@ impl<'a> base::Resolver for Resolver<'a> {
}
path
}

fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
fold::noop_fold_mac(mac, self)
}
}

EliminateCrateVar(self).fold_item(item).expect_one("")
Expand Down
5 changes: 4 additions & 1 deletion src/libsyntax_ext/deriving/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::panic;

use errors::FatalError;
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::codemap::Span;
use syntax::ext::base::*;
Expand All @@ -28,6 +28,9 @@ impl<'a> Visitor<'a> for MarkAttrs<'a> {
mark_known(attr);
}
}

fn visit_mac(&mut self, _mac: &Mac) {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I believe using a single line for empty functions (i.e. fn f(...) {}) is more idiomatic, at least in the compiler.

}

pub struct CustomDerive {
Expand Down
24 changes: 24 additions & 0 deletions src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-nothing.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions src/test/run-pass-fulldeps/proc-macro/struct-field-macro.rs
Original file line number Diff line number Diff line change
@@ -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() {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same here)