MCPcopy Create free account
hub / github.com/astral-sh/ruff / irrefutable_match_case

Method irrefutable_match_case

crates/ruff_python_parser/src/semantic_errors.rs:834–875  ·  view source on GitHub ↗
(stmt: &ast::StmtMatch, ctx: &Ctx)

Source from the content-addressed store, hash-verified

832 }
833
834 fn irrefutable_match_case<Ctx: SemanticSyntaxContext>(stmt: &ast::StmtMatch, ctx: &Ctx) {
835 // test_ok irrefutable_case_pattern_at_end
836 // match x:
837 // case 2: ...
838 // case var: ...
839 // match x:
840 // case 2: ...
841 // case _: ...
842 // match x:
843 // case var if True: ... # don't try to refute a guarded pattern
844 // case 2: ...
845
846 // test_err irrefutable_case_pattern
847 // match x:
848 // case var: ... # capture pattern
849 // case 2: ...
850 // match x:
851 // case _: ...
852 // case 2: ... # wildcard pattern
853 // match x:
854 // case var1 as var2: ... # as pattern with irrefutable left-hand side
855 // case 2: ...
856 // match x:
857 // case enum.variant | var: ... # or pattern with irrefutable part
858 // case 2: ...
859 for case in stmt
860 .cases
861 .iter()
862 .rev()
863 .skip(1)
864 .filter_map(|case| match case.guard {
865 Some(_) => None,
866 None => case.pattern.irrefutable_pattern(),
867 })
868 {
869 Self::add_error(
870 ctx,
871 SemanticSyntaxErrorKind::IrrefutableCasePattern(case.kind),
872 case.range,
873 );
874 }
875 }
876
877 /// Check `stmt` for semantic syntax errors and update the checker's internal state.
878 ///

Callers

nothing calls this directly

Calls 2

irrefutable_patternMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected