Skip to content

Instantly share code, notes, and snippets.

@jroweboy
Created June 20, 2014 19:40
Show Gist options
  • Select an option

  • Save jroweboy/1cbb9b94eede5627f256 to your computer and use it in GitHub Desktop.

Select an option

Save jroweboy/1cbb9b94eede5627f256 to your computer and use it in GitHub Desktop.
Segfault
#![feature(plugin_registrar, quote, phase)]
#![crate_type = "dylib"]
extern crate syntax;
use syntax::{ast, codemap};
use syntax::ext::base::{
SyntaxExtension, ExtCtxt, MacResult, MacExpr,
NormalTT, BasicMacroExpander,
};
use syntax::parse::token;
#[plugin_registrar]
pub fn macro_registrar(register: |ast::Name, SyntaxExtension|) {
let expander = box BasicMacroExpander{expander: broken_macro, span: None};
register(token::intern("test"), NormalTT(expander, None));
}
#[allow(unused_variable)]
fn broken_macro(cx: &mut ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree]) -> Box<MacResult> {
MacExpr::new(quote_expr!(cx, true))
}
#![feature(phase)]
#[phase(plugin)]
extern crate broken_macro;
fn main() {
println!("{}", test!());
}
To build, download both files to the same directory and run
rustc broken_macro.rs
rustc -L ./ broken_macro_test.rs
and on the most recent rust nightly, it will cause a Segmentation fault instead of having a graceful error returned. The fix for the issue is to upgrade the macro_registrar function to use the correct syntax, but maybe rustc should catch that and print an error message about it?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment