libsyntax: Introduce the new assert! macro; make assert no longer a keyword

This commit is contained in:
Patrick Walton 2013-03-22 13:11:03 -07:00
parent fa70709e07
commit eba3367404
5 changed files with 16 additions and 12 deletions

View File

@ -291,7 +291,7 @@ pub fn test() {
}
}
fail_unless!(seq_range(10, 15) == @[10, 11, 12, 13, 14]);
assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]);
fail_unless!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
fail_unless!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
}

View File

@ -464,6 +464,19 @@ pub fn core_macros() -> ~str {
}
)
macro_rules! assert(
($cond:expr) => {
if !$cond {
::core::sys::fail_assert(stringify!($cond), file!(), line!())
}
};
($cond:expr, $msg:expr) => {
if !$cond {
::core::sys::fail_assert($msg, file!(), line!())
}
}
)
macro_rules! assert_eq (
($given:expr , $expected:expr) =>
({let given_val = $given;

View File

@ -51,7 +51,6 @@ pub enum ObsoleteSyntax {
ObsoleteTraitImplVisibility,
ObsoleteRecordType,
ObsoleteRecordPattern,
ObsoleteAssertion,
ObsoletePostFnTySigil,
ObsoleteBareFnType,
ObsoleteNewtypeEnum,
@ -165,10 +164,6 @@ pub impl Parser {
"structural record pattern",
"use a structure instead"
),
ObsoleteAssertion => (
"assertion",
"use `fail_unless!()` instead"
),
ObsoletePostFnTySigil => (
"fn sigil in postfix position",
"Rather than `fn@`, `fn~`, or `fn&`, \

View File

@ -76,7 +76,7 @@ use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax};
use parse::obsolete::{ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer};
use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility};
use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern};
use parse::obsolete::{ObsoleteAssertion, ObsoletePostFnTySigil};
use parse::obsolete::{ObsoletePostFnTySigil};
use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum};
use parse::obsolete::{ObsoleteMode, ObsoleteImplicitSelf};
use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer};
@ -1217,10 +1217,6 @@ pub impl Parser {
ex = expr_log(ast::log_other, lvl, e);
hi = self.span.hi;
self.expect(&token::RPAREN);
} else if self.eat_keyword(&~"assert") {
let e = self.parse_expr();
ex = expr_copy(e); // whatever
self.obsolete(*self.last_span, ObsoleteAssertion);
} else if self.eat_keyword(&~"return") {
if can_begin_expr(&*self.token) {
let e = self.parse_expr();

View File

@ -488,7 +488,7 @@ pub fn temporary_keyword_table() -> HashMap<~str, ()> {
pub fn strict_keyword_table() -> HashMap<~str, ()> {
let words = HashMap();
let keys = ~[
~"as", ~"assert",
~"as",
~"break",
~"const", ~"copy",
~"do", ~"drop",