Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename assert to enforce, add debug_assert #12108

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn parse_config(args: ~[~str]) -> config {
optflag("h", "help", "show this message"),
];

assert!(!args.is_empty());
fail_unless!(!args.is_empty());
let argv0 = args[0].clone();
let args_ = args.tail();
if args[1] == ~"-h" || args[1] == ~"--help" {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
let mut env = os::env();

// Make sure we include the aux directory in the path
assert!(prog.ends_with(".exe"));
fail_unless!(prog.ends_with(".exe"));
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ".libaux";

env = env.map(|pair| {
Expand Down
12 changes: 6 additions & 6 deletions src/doc/guide-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ into a single value:
~~~
let xs = [1, 9, 2, 3, 14, 12];
let result = xs.iter().fold(0, |accumulator, item| accumulator - *item);
assert_eq!(result, -41);
fail_unless_eq!(result, -41);
~~~

Most adaptors return an adaptor object implementing the `Iterator` trait itself:
Expand All @@ -165,7 +165,7 @@ Most adaptors return an adaptor object implementing the `Iterator` trait itself:
let xs = [1, 9, 2, 3, 14, 12];
let ys = [5, 2, 1, 8];
let sum = xs.iter().chain(ys.iter()).fold(0, |a, b| a + *b);
assert_eq!(sum, 57);
fail_unless_eq!(sum, 57);
~~~

Some iterator adaptors may return `None` before exhausting the underlying
Expand Down Expand Up @@ -200,7 +200,7 @@ let mut calls = 0;
it.next();
}

assert_eq!(calls, 3);
fail_unless_eq!(calls, 3);
~~~

## For loops
Expand Down Expand Up @@ -256,7 +256,7 @@ for (x, y) in it {
println!("last: {:?}", it.next());

// the iterator is now fully consumed
assert!(it.next().is_none());
fail_unless!(it.next().is_none());
~~~

## Conversion
Expand All @@ -266,7 +266,7 @@ Iterators offer generic conversion to containers with the `collect` adaptor:
~~~
let xs = [0, 1, 1, 2, 3, 5, 8];
let ys = xs.rev_iter().skip(1).map(|&x| x * 2).collect::<~[int]>();
assert_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
fail_unless_eq!(ys, ~[10, 6, 4, 2, 2, 0]);
~~~

The method requires a type hint for the container type, if the surrounding code
Expand Down Expand Up @@ -384,7 +384,7 @@ the trailing underscore is a workaround for issue #5898 and will be removed.
~~~
let mut ys = [1, 2, 3, 4, 5];
ys.mut_iter().reverse_();
assert_eq!(ys, [5, 4, 3, 2, 1]);
fail_unless_eq!(ys, [5, 4, 3, 2, 1]);
~~~

## Random-access iterators
Expand Down
2 changes: 1 addition & 1 deletion src/doc/guide-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<T: Send> Unique<T> {
pub fn new(value: T) -> Unique<T> {
unsafe {
let ptr = malloc(std::mem::size_of::<T>() as size_t) as *mut T;
assert!(!ptr.is_null());
fail_unless!(!ptr.is_null());
// `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it
// move_val_init moves a value into this memory without
// attempting to drop the original value.
Expand Down
10 changes: 5 additions & 5 deletions src/doc/guide-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ The `arc` module also implements Arcs around mutable data that are not covered h

Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
(which can also be written with an error string as an argument: `fail!(
~reason)`) and the `assert!` construct (which effectively calls `fail!()`
~reason)`) and the `fail_unless!` construct (which effectively calls `fail!()`
if a boolean expression is false) are both ways to raise exceptions. When a
task raises an exception the task unwinds its stack---running destructors and
freeing memory along the way---and then exits. Unlike exceptions in C++,
Expand Down Expand Up @@ -455,7 +455,7 @@ let result: Result<int, ()> = task::try(proc() {
fail!("oops!");
}
});
assert!(result.is_err());
fail_unless!(result.is_err());
~~~

Unlike `spawn`, the function spawned using `try` may return a value,
Expand Down Expand Up @@ -540,13 +540,13 @@ spawn(proc() {
});

from_child.send(22);
assert!(from_child.recv() == ~"22");
fail_unless!(from_child.recv() == ~"22");

from_child.send(23);
from_child.send(0);

assert!(from_child.recv() == ~"23");
assert!(from_child.recv() == ~"0");
fail_unless!(from_child.recv() == ~"23");
fail_unless!(from_child.recv() == ~"0");

# }
~~~~
Expand Down
2 changes: 1 addition & 1 deletion src/doc/guide-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn return_two() -> int {
#[test]
fn return_two_test() {
let x = return_two();
assert!(x == 2);
fail_unless!(x == 2);
}
~~~

Expand Down
16 changes: 8 additions & 8 deletions src/doc/po/ja/complement-cheatsheet.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ msgstr ""
#: src/doc/complement-cheatsheet.md:13
#, fuzzy
#| msgid ""
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; fail_unless!(y == 4u); ~~~~"
msgid "~~~ let x: int = 42; let y: ~str = x.to_str(); ~~~"
msgstr ""
"~~~~\n"
"let x: f64 = 4.0;\n"
"let y: uint = x as uint;\n"
"assert!(y == 4u);\n"
"fail_unless!(y == 4u);\n"
"~~~~"

#. type: Plain text
Expand All @@ -60,13 +60,13 @@ msgstr ""
#: src/doc/complement-cheatsheet.md:22
#, fuzzy
#| msgid ""
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; fail_unless!(y == 4u); ~~~~"
msgid "~~~ let x: Option<int> = from_str(\"42\"); let y: int = x.unwrap(); ~~~"
msgstr ""
"~~~~\n"
"let x: f64 = 4.0;\n"
"let y: uint = x as uint;\n"
"assert!(y == 4u);\n"
"fail_unless!(y == 4u);\n"
"~~~~"

#. type: Plain text
Expand Down Expand Up @@ -95,13 +95,13 @@ msgstr ""
#: src/doc/complement-cheatsheet.md:33
#, fuzzy
#| msgid ""
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; fail_unless!(y == 4u); ~~~~"
msgid "let x: int = 42; let y: ~str = x.to_str_radix(16); ~~~"
msgstr ""
"~~~~\n"
"let x: f64 = 4.0;\n"
"let y: uint = x as uint;\n"
"assert!(y == 4u);\n"
"fail_unless!(y == 4u);\n"
"~~~~"

#. type: Plain text
Expand Down Expand Up @@ -131,15 +131,15 @@ msgstr ""
#: src/doc/complement-cheatsheet.md:44
#, fuzzy
#| msgid ""
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; fail_unless!(y == 4u); ~~~~"
msgid ""
"let x: Option<i64> = from_str_radix(\"deadbeef\", 16); let y: i64 = x."
"unwrap(); ~~~"
msgstr ""
"~~~~\n"
"let x: f64 = 4.0;\n"
"let y: uint = x as uint;\n"
"assert!(y == 4u);\n"
"fail_unless!(y == 4u);\n"
"~~~~"

#. type: Plain text
Expand Down
14 changes: 7 additions & 7 deletions src/doc/po/ja/rust.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -1190,15 +1190,15 @@ msgstr ""
#: src/doc/rust.md:2637
#, fuzzy
#| msgid ""
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; fail_unless!(y == 4u); ~~~~"
msgid ""
"let x: int = add(1, 2); let pi: Option<f32> = FromStr::from_str(\"3.14\"); "
"~~~~"
msgstr ""
"~~~~\n"
"let x: f64 = 4.0;\n"
"let y: uint = x as uint;\n"
"assert!(y == 4u);\n"
"fail_unless!(y == 4u);\n"
"~~~~"

#. type: Plain text
Expand Down Expand Up @@ -1354,7 +1354,7 @@ msgstr "## 構文拡張"
msgid ""
"fn main() {\n"
" let a = Cons(6, ~Cons(7, ~Cons(42, ~Nil)));\n"
" assert!(is_sorted(&a));\n"
" fail_unless!(is_sorted(&a));\n"
"}\n"
msgstr ""
"~~~~ {.ignore}\n"
Expand Down Expand Up @@ -1498,14 +1498,14 @@ msgstr "## 最小限の例"
#: src/doc/rust.md:3129
#, fuzzy
#| msgid ""
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; fail_unless!(y == 4u); ~~~~"
msgid ""
"~~~~ let v: &[int] = &[7, 5, 3]; let i: int = v[2]; assert!(i == 3); ~~~~"
"~~~~ let v: &[int] = &[7, 5, 3]; let i: int = v[2]; fail_unless!(i == 3); ~~~~"
msgstr ""
"~~~~\n"
"let x: f64 = 4.0;\n"
"let y: uint = x as uint;\n"
"assert!(y == 4u);\n"
"fail_unless!(y == 4u);\n"
"~~~~"

#. type: Plain text
Expand Down Expand Up @@ -1795,7 +1795,7 @@ msgstr ""
#| "~~~ # struct Point { x: f64, y: f64 } let point = &@~Point { x: 10f, y: "
#| "20f }; println(fmt!(\"%f\", point.x)); ~~~"
msgid ""
"~~~~ struct Foo { y: int } let x = @Foo{y: 10}; assert!(x.y == 10); ~~~~"
"~~~~ struct Foo { y: int } let x = @Foo{y: 10}; fail_unless!(x.y == 10); ~~~~"
msgstr ""
"~~~\n"
"# struct Point { x: f64, y: f64 }\n"
Expand Down
10 changes: 5 additions & 5 deletions src/doc/po/ja/tutorial.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -990,12 +990,12 @@ msgstr ""

#. type: Plain text
#: src/doc/tutorial.md:383
msgid "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
msgid "~~~~ let x: f64 = 4.0; let y: uint = x as uint; fail_unless!(y == 4u); ~~~~"
msgstr ""
"~~~~\n"
"let x: f64 = 4.0;\n"
"let y: uint = x as uint;\n"
"assert!(y == 4u);\n"
"fail_unless!(y == 4u);\n"
"~~~~"

#. type: Plain text
Expand Down Expand Up @@ -1980,10 +1980,10 @@ msgstr ""

#. type: Plain text
#: src/doc/tutorial.md:875
msgid "assert!(8 == line(5, 3, 1)); assert!(() == oops(5, 3, 1)); ~~~~"
msgid "fail_unless!(8 == line(5, 3, 1)); fail_unless!(() == oops(5, 3, 1)); ~~~~"
msgstr ""
"assert!(8 == line(5, 3, 1));\n"
"assert!(() == oops(5, 3, 1));\n"
"fail_unless!(8 == line(5, 3, 1));\n"
"fail_unless!(() == oops(5, 3, 1));\n"
"~~~~"

#. type: Plain text
Expand Down
12 changes: 6 additions & 6 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2926,8 +2926,8 @@ fn is_symmetric(list: &[uint]) -> bool {
fn main() {
let sym = &[0, 1, 4, 2, 4, 1, 0];
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
assert!(is_symmetric(sym));
assert!(!is_symmetric(not_sym));
fail_unless!(is_symmetric(sym));
fail_unless!(!is_symmetric(not_sym));
}
~~~~

Expand Down Expand Up @@ -2995,7 +2995,7 @@ fn is_sorted(list: &List) -> bool {

fn main() {
let a = Cons(6, ~Cons(7, ~Cons(42, ~Nil)));
assert!(is_sorted(&a));
fail_unless!(is_sorted(&a));
}

~~~~
Expand All @@ -3009,7 +3009,7 @@ on `x: &int` are equivalent:
let y = match *x { 0 => "zero", _ => "some" };
let z = match x { &0 => "zero", _ => "some" };

assert_eq!(y, z);
fail_unless_eq!(y, z);
~~~~

A pattern that's just an identifier, like `Nil` in the previous example,
Expand Down Expand Up @@ -3163,7 +3163,7 @@ An example of a tuple type and its use:
type Pair<'a> = (int,&'a str);
let p: Pair<'static> = (10,"hello");
let (a, b) = p;
assert!(b != "world");
fail_unless!(b != "world");
~~~~

### Vector types
Expand All @@ -3189,7 +3189,7 @@ An example of a vector type and its use:
~~~~
let v: &[int] = &[7, 5, 3];
let i: int = v[2];
assert!(i == 3);
fail_unless!(i == 3);
~~~~

All in-bounds elements of a vector are always initialized,
Expand Down
Loading