diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/did_you_mean/compatible-variants.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/did_you_mean/compatible-variants.rs')
-rw-r--r-- | src/test/ui/did_you_mean/compatible-variants.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/test/ui/did_you_mean/compatible-variants.rs b/src/test/ui/did_you_mean/compatible-variants.rs new file mode 100644 index 000000000..b1c7dc2a7 --- /dev/null +++ b/src/test/ui/did_you_mean/compatible-variants.rs @@ -0,0 +1,89 @@ +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 { + B { b: B }, +} + +struct A2(B); + +enum B { + Fst, + Snd, +} + +fn foo() { + let a: A = B::Fst; + //~^ ERROR mismatched types + //~| HELP try wrapping +} + +fn bar() { + let a: A2 = B::Fst; + //~^ ERROR mismatched types + //~| HELP try wrapping +} |