Skip to content

Commit e89bb24

Browse files
committed
Auto merge of #26071 - petrochenkov:assert1, r=alexcrichton
`assert_eq!` has better diagnostics than `assert!` and is more helpful when something actually breaks, but the diagnostics has it's price - `assert_eq!` generate some formatting code which is slower to compile and possibly run. [My measurements](https://internals.rust-lang.org/t/assert-a-b-or-assert-eq-a-b/1367/12?u=petrochenkov) show that presence of this formatting code doesn't affect compilation + execution time of the test suite significantly, so `assert_eq!` can be used instead of `assert!` consistently. (Some tests doesn't reside in src/test, they are not affected by these changes, I'll probably open a separate PR for them later)
2 parents cc44423 + bddb685 commit e89bb24

File tree

150 files changed

+396
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+396
-383
lines changed

Diff for: src/test/auxiliary/extern_calling_convention.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#[inline(never)]
1515
#[cfg(target_arch = "x86_64")]
1616
pub extern "win64" fn foo(a: isize, b: isize, c: isize, d: isize) {
17-
assert!(a == 1);
18-
assert!(b == 2);
19-
assert!(c == 3);
20-
assert!(d == 4);
17+
assert_eq!(a, 1);
18+
assert_eq!(b, 2);
19+
assert_eq!(c, 3);
20+
assert_eq!(d, 4);
2121

2222
println!("a: {}, b: {}, c: {}, d: {}",
2323
a, b, c, d)
@@ -26,10 +26,10 @@ pub extern "win64" fn foo(a: isize, b: isize, c: isize, d: isize) {
2626
#[inline(never)]
2727
#[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "aarch64"))]
2828
pub extern fn foo(a: isize, b: isize, c: isize, d: isize) {
29-
assert!(a == 1);
30-
assert!(b == 2);
31-
assert!(c == 3);
32-
assert!(d == 4);
29+
assert_eq!(a, 1);
30+
assert_eq!(b, 2);
31+
assert_eq!(c, 3);
32+
assert_eq!(d, 4);
3333

3434
println!("a: {}, b: {}, c: {}, d: {}",
3535
a, b, c, d)

Diff for: src/test/bench/shootout-mandelbrot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const LIMIT: f64 = 2.0;
5454
const WORKERS: usize = 16;
5555

5656
fn mandelbrot<W: Write>(w: usize, mut out: W) -> io::Result<()> {
57-
assert!(WORKERS % 2 == 0);
57+
assert_eq!(WORKERS % 2, 0);
5858

5959
// Ensure w and h are multiples of 8.
6060
let w = (w + 7) / 8 * 8;
@@ -76,7 +76,7 @@ fn mandelbrot<W: Write>(w: usize, mut out: W) -> io::Result<()> {
7676
let v_consts = f64x2(1.5, 1.0);
7777

7878
// A lot of this code assumes this (so do other lang benchmarks)
79-
assert!(w == h);
79+
assert_eq!(w, h);
8080
let mut precalc_r = Vec::with_capacity(w);
8181
let mut precalc_i = Vec::with_capacity(h);
8282

Diff for: src/test/compile-fail/builtin-superkinds-self-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ impl <T: Sync> Foo for T { }
2323
fn main() {
2424
let (tx, rx) = channel();
2525
1193182.foo(tx);
26-
assert!(rx.recv() == 1193182);
26+
assert_eq!(rx.recv(), 1193182);
2727
}

Diff for: src/test/compile-fail/match-static-const-lc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn f() {
2222
//~^ ERROR constant in pattern `a` should have an upper case name such as `A`
2323
(x, y) => 1 + x + y,
2424
};
25-
assert!(r == 1);
25+
assert_eq!(r, 1);
2626
}
2727

2828
mod m {
@@ -37,7 +37,7 @@ fn g() {
3737
//~^ ERROR constant in pattern `aha` should have an upper case name such as `AHA`
3838
(x, y) => 1 + x + y,
3939
};
40-
assert!(r == 1);
40+
assert_eq!(r, 1);
4141
}
4242

4343
mod n {
@@ -51,7 +51,7 @@ fn h() {
5151
//~^ ERROR constant in pattern `not_okay` should have an upper case name such as `NOT_OKAY`
5252
(x, y) => 1 + x + y,
5353
};
54-
assert!(r == 1);
54+
assert_eq!(r, 1);
5555
}
5656

5757
fn main () {

Diff for: src/test/compile-fail/mod_file_correct_spans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
mod mod_file_aux;
1414

1515
fn main() {
16-
assert!(mod_file_aux::bar() == 10); //~ ERROR unresolved name
16+
assert_eq!(mod_file_aux::bar(), 10); //~ ERROR unresolved name
1717
}

Diff for: src/test/compile-fail/private-struct-field-cross-crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ use cci_class::kitties::cat;
1414

1515
fn main() {
1616
let nyan : cat = cat(52, 99);
17-
assert!((nyan.meows == 52));
17+
assert_eq!(nyan.meows, 52);
1818
//~^ ERROR field `meows` of struct `cci_class::kitties::cat` is private
1919
}

Diff for: src/test/compile-fail/private-struct-field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ mod cat {
2020

2121
fn main() {
2222
let nyan = cat::new_cat();
23-
assert!(nyan.meows == 52); //~ ERROR field `meows` of struct `cat::Cat` is private
23+
assert_eq!(nyan.meows, 52); //~ ERROR field `meows` of struct `cat::Cat` is private
2424
}

Diff for: src/test/compile-fail/syntax-extension-minor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ pub fn main() {
1717
assert_eq!(concat_idents!(asd, f_f, dsa), "<.<".to_string());
1818
//~^ ERROR: unresolved name `asdf_fdsa`
1919

20-
assert!(stringify!(use_mention_distinction) ==
21-
"use_mention_distinction");
20+
assert_eq!(stringify!(use_mention_distinction), "use_mention_distinction");
2221
}

Diff for: src/test/parse-fail/macros-no-semicolon.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// compile-flags: -Z parse-only
1212

1313
fn main() {
14-
assert!(1 == 2)
15-
assert!(3 == 4) //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `assert`
14+
assert_eq!(1, 2)
15+
assert_eq!(3, 4) //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `assert_eq`
1616
println!("hello");
1717
}

Diff for: src/test/pretty/do1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
fn f<F>(f: F) where F: Fn(isize) { f(10) }
1414

15-
fn main() { f(|i| { assert!(i == 10) }) }
15+
fn main() { f(|i| { assert_eq!(i , 10) }) }

Diff for: src/test/run-fail/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
// except according to those terms.
1010

1111
// error-pattern:1 == 2
12-
fn main() { assert!((1 == 2)); }
12+
fn main() { assert!(1 == 2); }

Diff for: src/test/run-make/extern-flag-disambiguates/d.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ extern crate c;
1616
fn t(a: &'static usize) -> usize { a as *const _ as usize }
1717

1818
fn main() {
19-
assert!(t(a::token()) == t(b::a_token()));
19+
assert_eq!(t(a::token()), t(b::a_token()));
2020
assert!(t(a::token()) != t(c::a_token()));
2121
}

Diff for: src/test/run-make/static-unwinding/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
}).join().err().unwrap();
2929

3030
unsafe {
31-
assert!(lib::statik == 1);
32-
assert!(statik == 1);
31+
assert_eq!(lib::statik, 1);
32+
assert_eq!(statik, 1);
3333
}
3434
}

Diff for: src/test/run-pass-fulldeps/compiler-calls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ fn main() {
7878
// we should never get use this filename, but lets make sure they are valid args.
7979
let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
8080
rustc_driver::run_compiler(&args, &mut tc);
81-
assert!(tc.count == 30);
81+
assert_eq!(tc.count, 30);
8282
}

Diff for: src/test/run-pass-valgrind/dst-dtor-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pub fn main() {
2727
let _x: Box<Fat<[Foo]>> = Box::<Fat<[Foo; 3]>>::new(Fat { f: [Foo, Foo, Foo] });
2828
}
2929
unsafe {
30-
assert!(DROP_RAN == 3);
30+
assert_eq!(DROP_RAN, 3);
3131
}
3232
}

Diff for: src/test/run-pass/arith-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313

1414
pub fn main() {
1515
let i32_c: isize = 0x10101010;
16-
assert!(i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3) ==
16+
assert_eq!(i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3),
1717
i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3));
1818
}

Diff for: src/test/run-pass/artificial-block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
fn f() -> isize { { return 3; } }
1313

14-
pub fn main() { assert!((f() == 3)); }
14+
pub fn main() { assert_eq!(f(), 3); }

Diff for: src/test/run-pass/assignability-trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn length<A, T: iterable<A>>(x: T) -> usize {
4343
pub fn main() {
4444
let x: Vec<isize> = vec!(0,1,2,3);
4545
// Call a method
46-
x.iterate(|y| { assert!(x[*y as usize] == *y); true });
46+
x.iterate(|y| { assert_eq!(x[*y as usize], *y); true });
4747
// Call a parameterized function
4848
assert_eq!(length(x.clone()), x.len());
4949
// Call a parameterized function, with type arguments that require

Diff for: src/test/run-pass/associated-types-return.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub trait Foo {
1616
fn boo(&self) -> <Self as Foo>::A;
1717
}
1818

19-
#[derive(PartialEq)]
19+
#[derive(PartialEq, Debug)]
2020
pub struct Bar;
2121

2222
impl Foo for isize {
@@ -44,12 +44,12 @@ fn foo2<I: Foo>(x: I) -> <I as Foo>::A {
4444

4545
pub fn main() {
4646
let a = 42;
47-
assert!(foo2(a) == 42);
47+
assert_eq!(foo2(a), 42);
4848

4949
let a = Bar;
50-
assert!(foo2(a) == 43);
50+
assert_eq!(foo2(a), 43);
5151

5252
let a = 'a';
5353
foo1(a);
54-
assert!(foo2(a) == Bar);
54+
assert_eq!(foo2(a), Bar);
5555
}

Diff for: src/test/run-pass/bool.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ fn main() {
7474
assert!(true >= false);
7575
assert!(!(true <= false));
7676

77-
assert!(true.cmp(&true) == Equal);
78-
assert!(false.cmp(&false) == Equal);
79-
assert!(true.cmp(&false) == Greater);
80-
assert!(false.cmp(&true) == Less);
77+
assert_eq!(true.cmp(&true), Equal);
78+
assert_eq!(false.cmp(&false), Equal);
79+
assert_eq!(true.cmp(&false), Greater);
80+
assert_eq!(false.cmp(&true), Less);
8181
}

Diff for: src/test/run-pass/builtin-superkinds-capabilities-transitive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ fn foo<T: Foo + 'static>(val: T, chan: Sender<T>) {
3030
pub fn main() {
3131
let (tx, rx) = channel();
3232
foo(31337, tx);
33-
assert!(rx.recv().unwrap() == 31337);
33+
assert_eq!(rx.recv().unwrap(), 31337);
3434
}

Diff for: src/test/run-pass/builtin-superkinds-capabilities-xc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern crate trait_superkinds_in_metadata;
2020
use std::sync::mpsc::{channel, Sender, Receiver};
2121
use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare};
2222

23-
#[derive(PartialEq)]
23+
#[derive(PartialEq, Debug)]
2424
struct X<T>(T);
2525

2626
impl <T: Sync> RequiresShare for X<T> { }
@@ -33,5 +33,5 @@ fn foo<T: RequiresRequiresShareAndSend + 'static>(val: T, chan: Sender<T>) {
3333
pub fn main() {
3434
let (tx, rx): (Sender<X<isize>>, Receiver<X<isize>>) = channel();
3535
foo(X(31337), tx);
36-
assert!(rx.recv().unwrap() == X(31337));
36+
assert_eq!(rx.recv().unwrap(), X(31337));
3737
}

Diff for: src/test/run-pass/builtin-superkinds-capabilities.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ fn foo<T: Foo + 'static>(val: T, chan: Sender<T>) {
2626
pub fn main() {
2727
let (tx, rx): (Sender<isize>, Receiver<isize>) = channel();
2828
foo(31337, tx);
29-
assert!(rx.recv().unwrap() == 31337);
29+
assert_eq!(rx.recv().unwrap(), 31337);
3030
}

Diff for: src/test/run-pass/builtin-superkinds-self-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ impl <T: Send + 'static> Foo for T { }
2525
pub fn main() {
2626
let (tx, rx) = channel();
2727
1193182.foo(tx);
28-
assert!(rx.recv().unwrap() == 1193182);
28+
assert_eq!(rx.recv().unwrap(), 1193182);
2929
}

Diff for: src/test/run-pass/c-stack-returning-int64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ fn atoll(s: String) -> i64 {
3737

3838
pub fn main() {
3939
assert_eq!(atol("1024".to_string()) * 10, atol("10240".to_string()));
40-
assert!((atoll("11111111111111111".to_string()) * 10) ==
40+
assert_eq!((atoll("11111111111111111".to_string()) * 10),
4141
atoll("111111111111111110".to_string()));
4242
}

Diff for: src/test/run-pass/cci_impl_exe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ pub fn main() {
2222

2323
//let bt1 = sys::frame_address();
2424
//println!("%?", bt1);
25-
//assert!(bt0 == bt1);
25+
//assert_eq!(bt0, bt1);
2626
})
2727
}

Diff for: src/test/run-pass/cci_iter_exe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ pub fn main() {
1717
//println!("%?", bt0);
1818
cci_iter_lib::iter(&[1, 2, 3], |i| {
1919
println!("{}", *i);
20-
//assert!(bt0 == sys::rusti::frame_address(2));
20+
//assert_eq!(bt0, sys::rusti::frame_address(2));
2121
})
2222
}

Diff for: src/test/run-pass/check-static-slice.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ static cf: isize = af[2];
2828

2929
fn main () {
3030
let b: &[isize] = &[1, 2, 3];
31-
assert!(ac == b);
32-
assert!(ad == b);
33-
assert!(af == b);
31+
assert_eq!(ac, b);
32+
assert_eq!(ad, b);
33+
assert_eq!(af, b);
3434

35-
assert!(ca == 1);
36-
assert!(cb == 2);
37-
assert!(cc == 3);
38-
assert!(cd == 1);
39-
assert!(ce == 2);
40-
assert!(cf == 3);
35+
assert_eq!(ca, 1);
36+
assert_eq!(cb, 2);
37+
assert_eq!(cc, 3);
38+
assert_eq!(cd, 1);
39+
assert_eq!(ce, 2);
40+
assert_eq!(cf, 3);
4141
}

Diff for: src/test/run-pass/class-impl-very-parameterized-trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<T> cat<T> {
104104
pub fn main() {
105105
let mut nyan: cat<String> = cat::new(0, 2, "nyan".to_string());
106106
for _ in 1_usize..5 { nyan.speak(); }
107-
assert!(*nyan.find(&1).unwrap() == "nyan".to_string());
107+
assert_eq!(*nyan.find(&1).unwrap(), "nyan".to_string());
108108
assert_eq!(nyan.find(&10), None);
109109
let mut spotty: cat<cat_type> = cat::new(2, 57, cat_type::tuxedo);
110110
for _ in 0_usize..6 { spotty.speak(); }

Diff for: src/test/run-pass/cmp-default.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::cmp::Ordering;
1313

1414
// Test default methods in PartialOrd and PartialEq
1515
//
16+
#[derive(Debug)]
1617
struct Fool(bool);
1718

1819
impl PartialEq for Fool {
@@ -74,8 +75,8 @@ pub fn main() {
7475
assert!(RevInt(1) >= RevInt(2));
7576
assert!(RevInt(1) >= RevInt(1));
7677

77-
assert!(Fool(true) == Fool(false));
78+
assert_eq!(Fool(true), Fool(false));
7879
assert!(Fool(true) != Fool(true));
7980
assert!(Fool(false) != Fool(false));
80-
assert!(Fool(false) == Fool(true));
81+
assert_eq!(Fool(false), Fool(true));
8182
}

Diff for: src/test/run-pass/const-big-enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn main() {
2323
_ => panic!()
2424
}
2525
match Y {
26-
Foo::Bar(s) => assert!(s == 2654435769),
26+
Foo::Bar(s) => assert_eq!(s, 2654435769),
2727
_ => panic!()
2828
}
2929
match Z {

Diff for: src/test/run-pass/const-enum-structlike.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ static C: E = E::S1 { u: 23 };
1919
pub fn main() {
2020
match C {
2121
E::S0 { .. } => panic!(),
22-
E::S1 { u } => assert!(u == 23)
22+
E::S1 { u } => assert_eq!(u, 23)
2323
}
2424
}

Diff for: src/test/run-pass/const-enum-vec-index.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn main() {
2323
_ => panic!()
2424
}
2525
match C1 {
26-
E::V1(n) => assert!(n == 0xDEADBEE),
26+
E::V1(n) => assert_eq!(n, 0xDEADBEE),
2727
_ => panic!()
2828
}
2929

@@ -32,7 +32,7 @@ pub fn main() {
3232
_ => panic!()
3333
}
3434
match D1 {
35-
E::V1(n) => assert!(n == 0xDEADBEE),
35+
E::V1(n) => assert_eq!(n, 0xDEADBEE),
3636
_ => panic!()
3737
}
3838
}

Diff for: src/test/run-pass/const-enum-vec-ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static C: &'static [E] = &[E::V0, E::V1(0xDEADBEE), E::V0];
1414

1515
pub fn main() {
1616
match C[1] {
17-
E::V1(n) => assert!(n == 0xDEADBEE),
17+
E::V1(n) => assert_eq!(n, 0xDEADBEE),
1818
_ => panic!()
1919
}
2020
match C[2] {

Diff for: src/test/run-pass/const-enum-vector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static C: [E; 3] = [E::V0, E::V1(0xDEADBEE), E::V0];
1414

1515
pub fn main() {
1616
match C[1] {
17-
E::V1(n) => assert!(n == 0xDEADBEE),
17+
E::V1(n) => assert_eq!(n, 0xDEADBEE),
1818
_ => panic!()
1919
}
2020
match C[2] {

0 commit comments

Comments
 (0)