rustc now can use integer literals in attributes

This commit is contained in:
Oliver Schneider 2016-09-07 10:27:57 +02:00
parent 35e8882553
commit f5a89d297c
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
5 changed files with 15 additions and 15 deletions

View file

@ -41,12 +41,12 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
let mut memory_size = 100*1024*1024; // 100MB
let mut step_limit = 1000_000;
let mut stack_limit = 100;
fn extract_str(lit: &syntax::ast::Lit) -> syntax::parse::token::InternedString {
let extract_int = |lit: &syntax::ast::Lit| -> u64 {
match lit.node {
syntax::ast::LitKind::Str(ref s, _) => s.clone(),
_ => bug!("attribute values need to be strings"),
syntax::ast::LitKind::Int(i, _) => i,
_ => state.session.span_fatal(lit.span, "expected an integer literal"),
}
}
};
for attr in krate.attrs.iter() {
match attr.node.value.node {
MetaItemKind::List(ref name, _) if name != "miri" => {}
@ -55,9 +55,9 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
NestedMetaItemKind::MetaItem(ref inner) => match inner.node {
MetaItemKind::NameValue(ref name, ref value) => {
match &**name {
"memory_size" => memory_size = extract_str(value).parse().expect("not a number"),
"step_limit" => step_limit = extract_str(value).parse().expect("not a number"),
"stack_limit" => stack_limit = extract_str(value).parse().expect("not a number"),
"memory_size" => memory_size = extract_int(value) as usize,
"step_limit" => step_limit = extract_int(value),
"stack_limit" => stack_limit = extract_int(value) as usize,
_ => state.session.span_err(item.span, "unknown miri attribute"),
}
}

View file

@ -1,5 +1,5 @@
#![feature(custom_attribute)]
#![miri(memory_size="0")]
#![feature(custom_attribute, attr_literals)]
#![miri(memory_size=0)]
fn bar() {
let x = 5;

View file

@ -1,5 +1,5 @@
#![feature(custom_attribute)]
#![miri(memory_size="1000")]
#![feature(custom_attribute, attr_literals)]
#![miri(memory_size=1000)]
fn bar(i: i32) {
if i < 1000 {

View file

@ -1,5 +1,5 @@
#![feature(custom_attribute)]
#![miri(stack_limit="2")]
#![feature(custom_attribute, attr_literals)]
#![miri(stack_limit=2)]
fn bar() {
foo();

View file

@ -1,6 +1,6 @@
//error-pattern: reached the configured maximum execution time
#![feature(custom_attribute)]
#![miri(step_limit="1000")]
#![feature(custom_attribute, attr_literals)]
#![miri(step_limit=1000)]
fn main() {
for i in 0..1000000 {