(&mut self, pattern: &'a Pattern)
| 2276 | |
| 2277 | impl<'a, Ctx: SemanticSyntaxContext> MatchPatternVisitor<'a, Ctx> { |
| 2278 | fn visit_pattern(&mut self, pattern: &'a Pattern) { |
| 2279 | // test_ok class_keyword_in_case_pattern |
| 2280 | // match 2: |
| 2281 | // case Class(x=x): ... |
| 2282 | |
| 2283 | // test_err multiple_assignment_in_case_pattern |
| 2284 | // match 2: |
| 2285 | // case [y, z, y]: ... # MatchSequence |
| 2286 | // case [y, z, *y]: ... # MatchSequence |
| 2287 | // case [y, y, y]: ... # MatchSequence multiple |
| 2288 | // case {1: x, 2: x}: ... # MatchMapping duplicate pattern |
| 2289 | // case {1: x, **x}: ... # MatchMapping duplicate in **rest |
| 2290 | // case Class(x, x): ... # MatchClass positional |
| 2291 | // case Class(y=x, z=x): ... # MatchClass keyword |
| 2292 | // case [x] | {1: x} | Class(y=x, z=x): ... # MatchOr |
| 2293 | // case x as x: ... # MatchAs |
| 2294 | |
| 2295 | // test_err multiple_starred_names_in_sequence_pattern |
| 2296 | // match subject: |
| 2297 | // case *first, *second, *third: ... |
| 2298 | match pattern { |
| 2299 | Pattern::MatchValue(_) | Pattern::MatchSingleton(_) => {} |
| 2300 | Pattern::MatchStar(ast::PatternMatchStar { name, .. }) => { |
| 2301 | if let Some(name) = name { |
| 2302 | self.insert(name); |
| 2303 | } |
| 2304 | } |
| 2305 | Pattern::MatchSequence(ast::PatternMatchSequence { patterns, .. }) => { |
| 2306 | let mut seen_star_pattern = false; |
| 2307 | for pattern in patterns { |
| 2308 | if pattern.is_match_star() { |
| 2309 | if seen_star_pattern { |
| 2310 | SemanticSyntaxChecker::add_error( |
| 2311 | self.ctx, |
| 2312 | SemanticSyntaxErrorKind::MultipleStarredNamesInSequencePattern, |
| 2313 | pattern.range(), |
| 2314 | ); |
| 2315 | } |
| 2316 | seen_star_pattern = true; |
| 2317 | } |
| 2318 | self.visit_pattern(pattern); |
| 2319 | } |
| 2320 | } |
| 2321 | Pattern::MatchMapping(ast::PatternMatchMapping { |
| 2322 | keys, |
| 2323 | patterns, |
| 2324 | rest, |
| 2325 | .. |
| 2326 | }) => { |
| 2327 | for pattern in patterns { |
| 2328 | self.visit_pattern(pattern); |
| 2329 | } |
| 2330 | if let Some(rest) = rest { |
| 2331 | self.insert(rest); |
| 2332 | } |
| 2333 | |
| 2334 | let mut seen = FxHashSet::default(); |
| 2335 | for key in keys |
no test coverage detected