Created
June 20, 2014 19:40
-
-
Save jroweboy/1cbb9b94eede5627f256 to your computer and use it in GitHub Desktop.
Segfault
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #![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)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #![feature(phase)] | |
| #[phase(plugin)] | |
| extern crate broken_macro; | |
| fn main() { | |
| println!("{}", test!()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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