rust/tests/ui/did_you_mean/compatible-variants.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
1.6 KiB
Rust
Raw Normal View History

enum Hey<A, B> {
A(A),
B(B),
}
struct Foo {
bar: Option<i32>,
}
fn f() {}
fn a() -> Option<()> {
while false {
//~^ ERROR mismatched types
f();
}
//~^ HELP try adding an expression
}
fn b() -> Result<(), ()> {
f()
//~^ ERROR mismatched types
//~| HELP try adding an expression
}
fn c() -> Option<()> {
for _ in [1, 2] {
//~^ ERROR mismatched types
f();
}
//~^ HELP try adding an expression
}
fn d() -> Option<()> {
c()?
//~^ ERROR incompatible types
//~| HELP try removing this `?`
//~| HELP try adding an expression
}
fn main() {
let _: Option<()> = while false {};
//~^ ERROR mismatched types
//~| HELP try wrapping
let _: Option<()> = {
while false {}
//~^ ERROR mismatched types
//~| HELP try adding an expression
};
let _: Result<i32, i32> = 1;
//~^ ERROR mismatched types
//~| HELP try wrapping
let _: Option<i32> = 1;
//~^ ERROR mismatched types
//~| HELP try wrapping
let _: Hey<i32, i32> = 1;
//~^ ERROR mismatched types
//~| HELP try wrapping
let _: Hey<i32, bool> = false;
//~^ ERROR mismatched types
//~| HELP try wrapping
let bar = 1i32;
let _ = Foo { bar };
//~^ ERROR mismatched types
//~| HELP try wrapping
}
enum A {
2022-07-31 14:09:39 +00:00
B { b: B },
}
struct A2(B);
enum B {
Fst,
Snd,
}
fn foo() {
let a: A = B::Fst;
//~^ ERROR mismatched types
2022-07-31 14:09:39 +00:00
//~| HELP try wrapping
}
fn bar() {
let a: A2 = B::Fst;
//~^ ERROR mismatched types
//~| HELP try wrapping
}