Skip to content

Commit bf47742

Browse files
committed
Fix wrong tests and improve some other
1 parent bdd6d2c commit bf47742

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

tests/compile-fail/formatting.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,32 @@ fn foo() -> bool { true }
1111
fn main() {
1212
// weird `else if` formatting:
1313
if foo() {
14-
} if foo() { //~ERROR this looks like an `else if` but the `else` is missing
14+
} if foo() {
15+
//~^ ERROR this looks like an `else if` but the `else` is missing
16+
//~| NOTE add the missing `else` or
1517
}
1618

1719
let _ = {
1820
if foo() {
19-
} if foo() { //~ERROR this looks like an `else if` but the `else` is missing
21+
} if foo() {
22+
//~^ ERROR this looks like an `else if` but the `else` is missing
23+
//~| NOTE add the missing `else` or
2024
}
2125
else {
2226
}
2327
};
2428

2529
if foo() {
26-
} else //~ERROR this is an `else if` but the formatting might hide it
30+
} else
31+
//~^ ERROR this is an `else if` but the formatting might hide it
32+
//~| NOTE remove the `else` or
2733
if foo() { // the span of the above error should continue here
2834
}
2935

3036
if foo() {
31-
} //~ERROR this is an `else if` but the formatting might hide it
37+
}
38+
//~^ ERROR this is an `else if` but the formatting might hide it
39+
//~| NOTE remove the `else` or
3240
else
3341
if foo() { // the span of the above error should continue here
3442
}

tests/compile-fail/let_return.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
fn test() -> i32 {
88
let _y = 0; // no warning
9-
let x = 5; //~NOTE
9+
let x = 5; //~NOTE this expression can be directly returned
1010
x //~ERROR returning the result of a let binding
1111
}
1212

1313
fn test_inner() -> i32 {
1414
if true {
15-
let x = 5;
15+
let x = 5; //~NOTE this expression can be directly returned
1616
x //~ERROR returning the result of a let binding
1717
} else {
1818
0

tests/compile-fail/mut_mut.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ fn main() {
3838
***y + **x;
3939
}
4040

41-
let mut z = mut_ptr!(&mut 3u32); //~ NOTE in this expansion of mut_ptr!
41+
let mut z = mut_ptr!(&mut 3u32);
42+
//~^ NOTE in this expansion of mut_ptr!
43+
//~| NOTE in this expansion of mut_ptr!
4244
}

tests/compile-fail/needless_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn x(y: &i32) -> i32 {
1010
fn main() {
1111
let a = 5;
1212
let b = x(&a);
13-
let c = x(&&a); //~ ERROR: needless_borrow
13+
let c = x(&&a); //~ ERROR: this expression borrows a reference that is immediately dereferenced by the compiler
1414
let s = &String::from("hi");
1515
let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not
1616
let g_val = g(&Vec::new()); // should not error, because `&Vec<T>` derefs to `&[T]`

tests/compile-fail/no_effect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn main() {
6262
//~|SUGGESTION get_number();
6363
Struct { ..get_struct() }; //~ERROR statement can be reduced
6464
//~^HELP replace it with
65-
//~|SUGGESTION get_number();
65+
//~|SUGGESTION get_struct();
6666
Enum::Tuple(get_number()); //~ERROR statement can be reduced
6767
//~^HELP replace it with
6868
//~|SUGGESTION get_number();
@@ -74,7 +74,7 @@ fn main() {
7474
//~|SUGGESTION 5;get_number();
7575
*&get_number(); //~ERROR statement can be reduced
7676
//~^HELP replace it with
77-
//~|SUGGESTION &get_number();
77+
//~|SUGGESTION get_number();
7878
&get_number(); //~ERROR statement can be reduced
7979
//~^HELP replace it with
8080
//~|SUGGESTION get_number();

tests/compile-fail/swap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ fn main() {
1717
//~| SUGGESTION std::mem::swap(&mut a, &mut b);
1818
//~| NOTE or maybe you should use `std::mem::replace`?
1919

20-
let t = a;
20+
; let t = a;
2121
a = b;
2222
b = t;
2323
//~^^^ ERROR this looks like you are swapping `a` and `b` manually
2424
//~| HELP try
25-
//~| SUGGESTION std::mem::swap(&mut a, &mut b);
25+
//~| SUGGESTION ; std::mem::swap(&mut a, &mut b);
2626
//~| NOTE or maybe you should use `std::mem::replace`?
2727

2828
let mut c = Foo(42);
@@ -34,11 +34,11 @@ fn main() {
3434
//~| SUGGESTION std::mem::swap(&mut c.0, &mut a);
3535
//~| NOTE or maybe you should use `std::mem::replace`?
3636

37-
let t = c.0;
37+
; let t = c.0;
3838
c.0 = a;
3939
a = t;
4040
//~^^^ ERROR this looks like you are swapping `c.0` and `a` manually
4141
//~| HELP try
42-
//~| SUGGESTION std::mem::swap(&mut c.0, &mut a);
42+
//~| SUGGESTION ; std::mem::swap(&mut c.0, &mut a);
4343
//~| NOTE or maybe you should use `std::mem::replace`?
4444
}

0 commit comments

Comments
 (0)