Skip to content

Commit d7e80e1

Browse files
committed
moved renamed docs formatted | diverging-fallback-method-chain.rs
1 parent ef843b3 commit d7e80e1

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

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

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
#![allow(unused)] // Less intrusive than allow(unused_imports)
6+
7+
use std::num::ParseIntError;
8+
9+
fn produce<T>() -> Result<&'static str, T> {
10+
Ok("22")
11+
}
12+
13+
fn main() {
14+
// The closure's error type `T` must unify with `ParseIntError`,
15+
// while the success type must be `usize` (from parse())
16+
let x: usize = produce()
17+
.and_then(|x| x.parse::<usize>()) // Explicit turbofish for clarity
18+
.unwrap_or_else(|_| panic!()); // Diverging fallback
19+
20+
assert_eq!(x, 22);
21+
}

0 commit comments

Comments
 (0)