Skip to content

Commit 9d79091

Browse files
committed
moved renamed docs formatted | diverging-fallback-method-chain.rs
1 parent f3590d7 commit 9d79091

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

tests/ui/diverging-fallback-method-chain.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Test type inference in method chains with diverging fallback.
2+
//! Verifies that closure type in `unwrap_or_else` is properly inferred
3+
//! when chained with other combinators and contains a diverging path.
4+
5+
//@ run-pass
6+
7+
#![allow(unused)]
8+
9+
use std::num::ParseIntError;
10+
11+
fn produce<T>() -> Result<&'static str, T> {
12+
Ok("22")
13+
}
14+
15+
fn main() {
16+
// The closure's error type `T` must unify with `ParseIntError`,
17+
// while the success type must be `usize` (from parse())
18+
let x: usize = produce()
19+
.and_then(|x| x.parse::<usize>()) // Explicit turbofish for clarity
20+
.unwrap_or_else(|_| panic!()); // Diverging fallback
21+
22+
assert_eq!(x, 22);
23+
}

0 commit comments

Comments
 (0)