Skip to content

Commit 8230483

Browse files
committed
Rust: Add type inference examples
1 parent cf0b3b5 commit 8230483

File tree

2 files changed

+276
-240
lines changed

2 files changed

+276
-240
lines changed

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,27 @@ mod m9 {
432432

433433
let x6 = MyOption::MySome(MyOption::<S>::MyNone());
434434
println!("{:?}", MyOption::<MyOption<S>>::flatten(x6));
435+
436+
let from_if = if 1 + 1 > 2 {
437+
MyOption::MyNone() // missing type `S` at `T``
438+
} else {
439+
MyOption::MySome(S)
440+
};
441+
println!("{:?}", from_if);
442+
443+
let from_match = match 1 + 1 > 2 {
444+
true => MyOption::MyNone(), // missing type `S` at `T``
445+
false => MyOption::MySome(S),
446+
};
447+
println!("{:?}", from_match);
448+
449+
let from_loop = loop {
450+
if 1 + 1 > 2 {
451+
break MyOption::MyNone(); // missing type `S` at `T``
452+
}
453+
break MyOption::MySome(S);
454+
};
455+
println!("{:?}", from_loop);
435456
}
436457
}
437458

0 commit comments

Comments
 (0)