Skip to content

Instantly share code, notes, and snippets.

@whipsch
Created January 6, 2016 02:37
Show Gist options
  • Save whipsch/9053cc076083248b2c13 to your computer and use it in GitHub Desktop.
Save whipsch/9053cc076083248b2c13 to your computer and use it in GitHub Desktop.
rustc stable 1.5.0, beta, 1.6.0-beta.1, 1.7.0-nightly (d5e229057) ICE, `-Z unstable-options --pretty normal src/lib.rs`
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:366
stack backtrace:
1: 0x7f2723300d70 - sys::backtrace::tracing::imp::write::h1fe79f3711caca0eUnt
2: 0x7f2723307685 - panicking::log_panic::_<closure>::closure.39701
3: 0x7f27233070f5 - panicking::log_panic::hffc6d029fed602571nx
4: 0x7f27232ca663 - sys_common::unwind::begin_unwind_inner::h7045c1c64d9ab8edYgs
5: 0x7f27232cafc8 - sys_common::unwind::begin_unwind_fmt::h40ee994bfe85f7a54fs
6: 0x7f27232fec31 - rust_begin_unwind
7: 0x7f272335226f - panicking::panic_fmt::h4c8d12e3c05f3b8cZEK
8: 0x7f272334c818 - panicking::panic::hb8a57f0c8013c90awDK
9: 0x7f271dced38a - print::pprust::_<impl>::bclose_maybe_open::h37355ecf49953be2XtY
10: 0x7f271dcecf44 - print::pprust::_<impl>::print_mac::hc75ea26b8c9d79336F0
11: 0x7f271dcdf524 - print::pprust::_<impl>::print_stmt::h5f88115daf2f26f5Gk0
12: 0x7f271dcf2f23 - print::pprust::_<impl>::print_block_maybe_unclosed::hf7ad1da05081d4e4uq0
13: 0x7f271dce209e - print::pprust::_<impl>::print_item::h7e0f2b203ddfcd92P3Y
14: 0x7f271dccd47e - print::pprust::print_crate::ha70da7fc58cc53ecBoX
15: 0x7f2723867ea7 - pretty::pretty_print_input::_<closure>::closure.30268
16: 0x7f2723864d75 - pretty::pretty_print_input::he4ab854e00707a30IYb
17: 0x7f27238ed5fc - run_compiler::h9d54ca8784090b78sqc
18: 0x7f27238eab36 - sys_common::unwind::try::try_fn::try_fn::h11041572279465146525
19: 0x7f27232fea98 - __rust_try
20: 0x7f27232f2aeb - sys_common::unwind::try::inner_try::h0c3b0e63f018cc29wds
21: 0x7f27238eae84 - boxed::_<impl>::call_box::call_box::h7023908653336004374
22: 0x7f2723306153 - sys::thread::_<impl>::new::thread_start::h85eb4d682b5d5d4ffGw
23: 0x7f271d41a554 - start_thread
24: 0x7f2722f8eb9c - __clone
25: 0x0 - <unknown>
#[macro_use] mod middleware;
mod foo {
pub mod bar {
some_middleware! {
def Blah(num: i32) -> (A, B, C) {
Ok(match num {
_ if num > 0 => A,
_ if num < 0 => B,
_ => C
})
}
}
}
}
mod biff {
some_middleware! {
def Quux(x: &mut isize) -> (Inc, Dec) {
match *x & 3 {
0 => { *x += 1; Ok(Inc) },
1 => { *x -= 1; Ok(Dec) },
_ => Err(())
}
}
}
}
some_middleware! {
def Zing(s: &str) -> (Whatever) {
match s {
"hello" => Ok(Whatever),
_ => Err(())
}
}
}
#[cfg(test)]
fn doit() -> Result<(), ()> {
let mut x = 5;
some_middleware! {
use foo::bar::Blah;
biff::Quux(&mut x),
Blah(-1) in { A, B },
Zing("hello") in { Zing::Whatever }
}
println!("x: {}", x);
Ok(())
}
#[test] fn bla() {
assert!(doit().is_ok());
}
#[macro_export]
macro_rules! some_middleware {
(
use $($($imports: ident)::+),+;
$(
$($rule: ident)::+($($params: expr),*) $(in {
$($variant: pat),+
}),*
),+
) => ({
$(
use self::$($imports)::+;
#[allow(unused_imports)] use self::$($imports)::+::*;
);+
$(try!(
some_middleware!(MAKE_MATCH $($rule)::+($($params),*) $(in { $($variant),+ }),*)
));+
});
(
$(
$($rule: ident)::+($($params: expr),*) $(in {
$($variant: pat),+
}),*
),+
) => ({
$(try!(
some_middleware!(MAKE_MATCH $($rule)::+($($params),*) $(in { $($variant),+ }),*)
));+
});
(MAKE_MATCH
$($rule: ident)::+($($params: expr),*)
) => ({
match $($rule)::+::process($($params),*) {
Ok(_) => Ok(()),
_ => Err(())
}
});
(MAKE_MATCH
$($rule: ident)::+($($params: expr),*) in {
$($variant: pat),+
}
) => ({
match $($rule)::+::process($($params),*) {
$(Ok($variant) => Ok(())),+,
_ => Err(())
}
});
(
$(
def $rule: ident($($param_names: ident: $param_types: ty),*) -> ($($variants: ident),+)
$body: block
)+
) => (
$(
#[allow(dead_code)]
#[derive(Debug)]
pub enum $rule {
$($variants),+
}
impl $rule {
#[allow(dead_code, unused_variables)]
pub fn process($($param_names: $param_types),*) -> Result<$rule, ()> {
use self::$rule::*;
$body
}
}
)+
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment