-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Roman numeral plugin example fails to run #27271
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Minimal example:
|
I'm not getting an error with rustc 1.3.0-dev (7276d8b 2015-07-25) |
Still broken here I'm afraid: |
Here's what I did:
#![crate_type="dylib"]
#![feature(plugin_registrar, rustc_private)]
#![feature(slice_patterns)]
extern crate syntax;
extern crate rustc;
use syntax::codemap::Span;
use syntax::parse::token;
use syntax::ast::{TokenTree, TtToken};
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::build::AstBuilder; // trait for expr_usize
use rustc::plugin::Registry;
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
-> Box<MacResult + 'static> {
static NUMERALS: &'static [(&'static str, u32)] = &[
("M", 1000), ("CM", 900), ("D", 500), ("CD", 400),
("C", 100), ("XC", 90), ("L", 50), ("XL", 40),
("X", 10), ("IX", 9), ("V", 5), ("IV", 4),
("I", 1)];
let text = match args {
[TtToken(_, token::Ident(s, _))] => token::get_ident(s).to_string(),
_ => {
cx.span_err(sp, "argument should be a single identifier");
return DummyResult::any(sp);
}
};
let mut text = &*text;
let mut total = 0;
while !text.is_empty() {
match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) {
Some(&(rn, val)) => {
total += val;
text = &text[rn.len()..];
}
None => {
cx.span_err(sp, "invalid Roman numeral");
return DummyResult::any(sp);
}
}
}
MacEager::expr(cx.expr_u32(sp, total))
}
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("rn", expand_rn);
}
#![feature(plugin)]
#![plugin(plugin)]
fn main() {
println!(rn!(I));
}
Does that work for you? I cannot compile
|
That doesn't work for me either - I've copied the source you plug above, then
|
Just got the nightly (so both 8b83557) working on my linux install, and it's running fine. So it appears to be an OS X only issue. |
I guess that would explain something. I forgot to mention that I'm on linux:
|
I actually am reproducing this issue still on homebrew (the Mac OS X package manager) nightlies, but not when I build myself from source. Very strange.
|
Working fine on OS X with rustc 1.13.0-nightly. Should this be closed? |
Yup, this now seems to be working with the latest version of rust from homebrew, so closing |
The roman numeral demo plugin compiles successfully, but fails with an ICE when run (the same as #26488).
The text was updated successfully, but these errors were encountered: