Skip to content

Commit a261d16

Browse files
Failing tests for "consider borrowing"
1 parent 6de3a73 commit a261d16

8 files changed

+125
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
let x = if true {
3+
&true
4+
} else if false { //~ ERROR `if` and `else` have incompatible types [E0308]
5+
true //~ HELP consider borrowing here
6+
} else {
7+
true
8+
};
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0308]: `if` and `else` have incompatible types
2+
--> $DIR/consider-borrowing-141810-1.rs:4:12
3+
|
4+
LL | let x = if true {
5+
| ______________-
6+
LL | | &true
7+
| | ----- expected because of this
8+
LL | | } else if false {
9+
| | ____________^
10+
LL | || true
11+
LL | || } else {
12+
LL | || true
13+
LL | || };
14+
| || ^
15+
| ||_____|
16+
| |_____`if` and `else` have incompatible types
17+
| expected `&bool`, found `bool`
18+
|
19+
help: consider borrowing here
20+
|
21+
LL | } else &if false {
22+
| +
23+
24+
error: aborting due to 1 previous error
25+
26+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let x = if true {
3+
&()
4+
} else if false { //~ ERROR `if` and `else` have incompatible types [E0308]
5+
} else {
6+
};
7+
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0308]: `if` and `else` have incompatible types
2+
--> $DIR/consider-borrowing-141810-2.rs:4:12
3+
|
4+
LL | let x = if true {
5+
| ______________-
6+
LL | | &()
7+
| | --- expected because of this
8+
LL | | } else if false {
9+
| | ____________^
10+
LL | || } else {
11+
LL | || };
12+
| || ^
13+
| ||_____|
14+
| |_____`if` and `else` have incompatible types
15+
| expected `&()`, found `()`
16+
|
17+
help: consider borrowing here
18+
|
19+
LL | } else &if false {
20+
| +
21+
22+
error: aborting due to 1 previous error
23+
24+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let x = if true {
3+
&()
4+
} else if false { //~ ERROR `if` and `else` have incompatible types [E0308]
5+
6+
};
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0308]: `if` and `else` have incompatible types
2+
--> $DIR/consider-borrowing-141810-3.rs:4:12
3+
|
4+
LL | let x = if true {
5+
| ______________-
6+
LL | | &()
7+
| | --- expected because of this
8+
LL | | } else if false {
9+
| | ____________^
10+
LL | ||
11+
LL | || };
12+
| || ^
13+
| ||_____|
14+
| |_____`if` and `else` have incompatible types
15+
| expected `&()`, found `()`
16+
|
17+
= note: `if` expressions without `else` evaluate to `()`
18+
= note: consider adding an `else` block that evaluates to the expected type
19+
help: consider borrowing here
20+
|
21+
LL | } else &if false {
22+
| +
23+
24+
error: aborting due to 1 previous error
25+
26+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn baz(x: &String) {}
2+
3+
fn bar() {
4+
baz({
5+
String::from("hi") //~ ERROR mismatched types
6+
});
7+
}
8+
9+
fn main() {
10+
bar();
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/consider-borrowing-141810-4.rs:5:9
3+
|
4+
LL | String::from("hi")
5+
| ^^^^^^^^^^^^^^^^^^ expected `&String`, found `String`
6+
|
7+
help: consider borrowing here
8+
|
9+
LL | &String::from("hi")
10+
| +
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)