| 124 | } |
| 125 | |
| 126 | fn optional_not_found( |
| 127 | pattern: Node<'_>, |
| 128 | value: Node<'_>, |
| 129 | context: &mut Context<'_>, |
| 130 | ) -> Result<bool, &'static str> { |
| 131 | // A typed NotFound guard plus an absent optional value is an explicit |
| 132 | // absence contract, not an unexplained catch-all success fallback. |
| 133 | if context.compact(value)? != "Ok(None)" { |
| 134 | return Ok(false); |
| 135 | } |
| 136 | let pattern = context.compact(pattern)?; |
| 137 | let Some(rest) = pattern.strip_prefix("Err(") else { |
| 138 | return Ok(false); |
| 139 | }; |
| 140 | let Some((binding, guard)) = rest.split_once(")if") else { |
| 141 | return Ok(false); |
| 142 | }; |
| 143 | if binding.is_empty() |
| 144 | || !binding |
| 145 | .chars() |
| 146 | .all(|c| c.is_ascii_alphanumeric() || c == '_') |
| 147 | { |
| 148 | return Ok(false); |
| 149 | } |
| 150 | Ok( |
| 151 | guard == format!("{binding}.kind()==std::io::ErrorKind::NotFound") |
| 152 | || guard == format!("std::io::ErrorKind::NotFound=={binding}.kind()"), |
| 153 | ) |
| 154 | } |