(&mut self, pattern: &'a Pattern)
| 2120 | |
| 2121 | impl<'a, Ctx: SemanticSyntaxContext> MatchPatternVisitor<'a, Ctx> { |
| 2122 | fn visit_pattern(&mut self, pattern: &'a Pattern) { |
| 2123 | // test_ok class_keyword_in_case_pattern |
| 2124 | // match 2: |
| 2125 | // case Class(x=x): ... |
| 2126 | |
| 2127 | // test_err multiple_assignment_in_case_pattern |
| 2128 | // match 2: |
| 2129 | // case [y, z, y]: ... # MatchSequence |
| 2130 | // case [y, z, *y]: ... # MatchSequence |
| 2131 | // case [y, y, y]: ... # MatchSequence multiple |
| 2132 | // case {1: x, 2: x}: ... # MatchMapping duplicate pattern |
| 2133 | // case {1: x, **x}: ... # MatchMapping duplicate in **rest |
| 2134 | // case Class(x, x): ... # MatchClass positional |
| 2135 | // case Class(y=x, z=x): ... # MatchClass keyword |
| 2136 | // case [x] | {1: x} | Class(y=x, z=x): ... # MatchOr |
| 2137 | // case x as x: ... # MatchAs |
| 2138 | |
| 2139 | // test_err multiple_starred_names_in_sequence_pattern |
| 2140 | // match subject: |
| 2141 | // case *first, *second, *third: ... |
| 2142 | match pattern { |
| 2143 | Pattern::MatchValue(_) | Pattern::MatchSingleton(_) => {} |
| 2144 | Pattern::MatchStar(ast::PatternMatchStar { name, .. }) => { |
| 2145 | if let Some(name) = name { |
| 2146 | self.insert(name); |
| 2147 | } |
| 2148 | } |
| 2149 | Pattern::MatchSequence(ast::PatternMatchSequence { patterns, .. }) => { |
| 2150 | let mut seen_star_pattern = false; |
| 2151 | for pattern in patterns { |
| 2152 | if pattern.is_match_star() { |
| 2153 | if seen_star_pattern { |
| 2154 | SemanticSyntaxChecker::add_error( |
| 2155 | self.ctx, |
| 2156 | SemanticSyntaxErrorKind::MultipleStarredNamesInSequencePattern, |
| 2157 | pattern.range(), |
| 2158 | ); |
| 2159 | } |
| 2160 | seen_star_pattern = true; |
| 2161 | } |
| 2162 | self.visit_pattern(pattern); |
| 2163 | } |
| 2164 | } |
| 2165 | Pattern::MatchMapping(ast::PatternMatchMapping { |
| 2166 | keys, |
| 2167 | patterns, |
| 2168 | rest, |
| 2169 | .. |
| 2170 | }) => { |
| 2171 | for pattern in patterns { |
| 2172 | self.visit_pattern(pattern); |
| 2173 | } |
| 2174 | if let Some(rest) = rest { |
| 2175 | self.insert(rest); |
| 2176 | } |
| 2177 | |
| 2178 | let mut seen = FxHashSet::default(); |
| 2179 | for key in keys |
no test coverage detected