]> git.lizzy.rs Git - rust.git/blob - tests/ui/try-operator-hygiene.rs
Modify existing bounds if they exist
[rust.git] / tests / ui / try-operator-hygiene.rs
1 // run-pass
2
3 #![allow(non_upper_case_globals)]
4 #![allow(dead_code)]
5 // `expr?` expands to:
6 //
7 // match expr {
8 //     Ok(val) => val,
9 //     Err(err) => return Err(From::from(err)),
10 // }
11 //
12 // This test verifies that the expansion is hygienic, i.e., it's not affected by other `val` and
13 // `err` bindings that may be in scope.
14
15 use std::num::ParseIntError;
16
17 fn main() {
18     assert_eq!(parse(), Ok(1));
19 }
20
21 fn parse() -> Result<i32, ParseIntError> {
22     const val: char = 'a';
23     const err: char = 'b';
24
25     Ok("1".parse::<i32>()?)
26 }