Failing tests for "consider borrowing"
This commit is contained in:
parent
6de3a73312
commit
a261d167ac
8 changed files with 125 additions and 0 deletions
9
tests/ui/typeck/consider-borrowing-141810-1.rs
Normal file
9
tests/ui/typeck/consider-borrowing-141810-1.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn main() {
|
||||
let x = if true {
|
||||
&true
|
||||
} else if false { //~ ERROR `if` and `else` have incompatible types [E0308]
|
||||
true //~ HELP consider borrowing here
|
||||
} else {
|
||||
true
|
||||
};
|
||||
}
|
||||
26
tests/ui/typeck/consider-borrowing-141810-1.stderr
Normal file
26
tests/ui/typeck/consider-borrowing-141810-1.stderr
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
error[E0308]: `if` and `else` have incompatible types
|
||||
--> $DIR/consider-borrowing-141810-1.rs:4:12
|
||||
|
|
||||
LL | let x = if true {
|
||||
| ______________-
|
||||
LL | | &true
|
||||
| | ----- expected because of this
|
||||
LL | | } else if false {
|
||||
| | ____________^
|
||||
LL | || true
|
||||
LL | || } else {
|
||||
LL | || true
|
||||
LL | || };
|
||||
| || ^
|
||||
| ||_____|
|
||||
| |_____`if` and `else` have incompatible types
|
||||
| expected `&bool`, found `bool`
|
||||
|
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | } else &if false {
|
||||
| +
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
8
tests/ui/typeck/consider-borrowing-141810-2.rs
Normal file
8
tests/ui/typeck/consider-borrowing-141810-2.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fn main() {
|
||||
let x = if true {
|
||||
&()
|
||||
} else if false { //~ ERROR `if` and `else` have incompatible types [E0308]
|
||||
} else {
|
||||
};
|
||||
|
||||
}
|
||||
24
tests/ui/typeck/consider-borrowing-141810-2.stderr
Normal file
24
tests/ui/typeck/consider-borrowing-141810-2.stderr
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
error[E0308]: `if` and `else` have incompatible types
|
||||
--> $DIR/consider-borrowing-141810-2.rs:4:12
|
||||
|
|
||||
LL | let x = if true {
|
||||
| ______________-
|
||||
LL | | &()
|
||||
| | --- expected because of this
|
||||
LL | | } else if false {
|
||||
| | ____________^
|
||||
LL | || } else {
|
||||
LL | || };
|
||||
| || ^
|
||||
| ||_____|
|
||||
| |_____`if` and `else` have incompatible types
|
||||
| expected `&()`, found `()`
|
||||
|
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | } else &if false {
|
||||
| +
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
7
tests/ui/typeck/consider-borrowing-141810-3.rs
Normal file
7
tests/ui/typeck/consider-borrowing-141810-3.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fn main() {
|
||||
let x = if true {
|
||||
&()
|
||||
} else if false { //~ ERROR `if` and `else` have incompatible types [E0308]
|
||||
|
||||
};
|
||||
}
|
||||
26
tests/ui/typeck/consider-borrowing-141810-3.stderr
Normal file
26
tests/ui/typeck/consider-borrowing-141810-3.stderr
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
error[E0308]: `if` and `else` have incompatible types
|
||||
--> $DIR/consider-borrowing-141810-3.rs:4:12
|
||||
|
|
||||
LL | let x = if true {
|
||||
| ______________-
|
||||
LL | | &()
|
||||
| | --- expected because of this
|
||||
LL | | } else if false {
|
||||
| | ____________^
|
||||
LL | ||
|
||||
LL | || };
|
||||
| || ^
|
||||
| ||_____|
|
||||
| |_____`if` and `else` have incompatible types
|
||||
| expected `&()`, found `()`
|
||||
|
|
||||
= note: `if` expressions without `else` evaluate to `()`
|
||||
= note: consider adding an `else` block that evaluates to the expected type
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | } else &if false {
|
||||
| +
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
11
tests/ui/typeck/consider-borrowing-141810-4.rs
Normal file
11
tests/ui/typeck/consider-borrowing-141810-4.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn baz(x: &String) {}
|
||||
|
||||
fn bar() {
|
||||
baz({
|
||||
String::from("hi") //~ ERROR mismatched types
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {
|
||||
bar();
|
||||
}
|
||||
14
tests/ui/typeck/consider-borrowing-141810-4.stderr
Normal file
14
tests/ui/typeck/consider-borrowing-141810-4.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/consider-borrowing-141810-4.rs:5:9
|
||||
|
|
||||
LL | String::from("hi")
|
||||
| ^^^^^^^^^^^^^^^^^^ expected `&String`, found `String`
|
||||
|
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | &String::from("hi")
|
||||
| +
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue