Skip to content

Commit d156ea3

Browse files
committed
flow-control: Rename MissingMatchArm and change its message.
commit-id:d22d6adb
1 parent 6eccd3b commit d156ea3

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

crates/cairo-lang-lowering/src/diagnostic.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,18 @@ impl<'db> MatchError<'db> {
151151
(MatchDiagnostic::UnsupportedMatchArmNonSequential, MatchKind::Match) => {
152152
"Unsupported match - numbers must be sequential starting from 0.".into()
153153
}
154-
(MatchDiagnostic::NonExhaustiveMatchValue, MatchKind::Match) => {
155-
"Match is non exhaustive - add a wildcard pattern (`_`).".into()
156-
}
157154
(
158155
MatchDiagnostic::UnsupportedMatchArmNotALiteral
159-
| MatchDiagnostic::UnsupportedMatchArmNonSequential
160-
| MatchDiagnostic::NonExhaustiveMatchValue,
156+
| MatchDiagnostic::UnsupportedMatchArmNonSequential,
161157
MatchKind::IfLet | MatchKind::WhileLet(_, _),
162158
) => unreachable!("Numeric values are not supported in if/while-let conditions."),
163-
(MatchDiagnostic::MissingMatchArm(variant), MatchKind::Match) => {
164-
format!("Missing match arm: `{variant}` not covered.")
159+
(MatchDiagnostic::NonExhaustiveMatch(variant), MatchKind::Match) => {
160+
format!("Match is non-exhaustive: `{variant}` not covered.")
165161
}
166-
(MatchDiagnostic::MissingMatchArm(_), MatchKind::IfLet) => {
162+
(MatchDiagnostic::NonExhaustiveMatch(_), MatchKind::IfLet) => {
167163
unreachable!("If-let is not required to be exhaustive.")
168164
}
169-
(MatchDiagnostic::MissingMatchArm(_), MatchKind::WhileLet(_, _)) => {
165+
(MatchDiagnostic::NonExhaustiveMatch(_), MatchKind::WhileLet(_, _)) => {
170166
unreachable!("While-let is not required to be exhaustive.")
171167
}
172168
(MatchDiagnostic::UnreachableMatchArm, MatchKind::Match) => {
@@ -259,10 +255,9 @@ pub enum MatchDiagnostic {
259255
UnsupportedMatchArmNotATuple,
260256

261257
UnreachableMatchArm,
262-
MissingMatchArm(String),
258+
NonExhaustiveMatch(String),
263259

264260
UnsupportedMatchArmNotALiteral,
265261
UnsupportedMatchArmNonSequential,
266-
NonExhaustiveMatchValue,
267262
UnsupportedNumericInLetCondition,
268263
}

crates/cairo-lang-lowering/src/lower/flow_control/create_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn create_graph_expr_match<'db>(
148148
// If no arm is available, report a non-exhaustive match error.
149149
let kind = LoweringDiagnosticKind::MatchError(MatchError {
150150
kind: MatchKind::Match,
151-
error: MatchDiagnostic::MissingMatchArm(path),
151+
error: MatchDiagnostic::NonExhaustiveMatch(path),
152152
});
153153
return graph.report_with_missing_node(expr.stable_ptr.untyped(), kind);
154154
};

crates/cairo-lang-lowering/src/lower/flow_control/test_data/match

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ Root: 9
14131413
//! > semantic_diagnostics
14141414

14151415
//! > lowering_diagnostics
1416-
error: Missing match arm: `MyStruct{a: Some(None(_)), b: (Some(_), _, _)}` not covered.
1416+
error: Match is non-exhaustive: `MyStruct{a: Some(None(_)), b: (Some(_), _, _)}` not covered.
14171417
--> lib.cairo:6:5-9:5
14181418
match x {
14191419
_____^
@@ -1542,7 +1542,7 @@ Root: 1
15421542
//! > semantic_diagnostics
15431543

15441544
//! > lowering_diagnostics
1545-
error: Missing match arm: `_` not covered.
1545+
error: Match is non-exhaustive: `_` not covered.
15461546
--> lib.cairo:2:5
15471547
match x {}
15481548
^^^^^^^^^^
@@ -1604,7 +1604,7 @@ Root: 1
16041604
//! > semantic_diagnostics
16051605

16061606
//! > lowering_diagnostics
1607-
error: Missing match arm: `_` not covered.
1607+
error: Match is non-exhaustive: `_` not covered.
16081608
--> lib.cairo:5:5
16091609
match x {}
16101610
^^^^^^^^^^

crates/cairo-lang-lowering/src/lower/lower_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ fn report_missing_arm_error<'db>(
18431843
location.long(ctx.db).clone(),
18441844
MatchError(MatchError {
18451845
kind: match_type,
1846-
error: MatchDiagnostic::MissingMatchArm(variants_string),
1846+
error: MatchDiagnostic::NonExhaustiveMatch(variants_string),
18471847
}),
18481848
)
18491849
}

crates/cairo-lang-lowering/src/test_data/match

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ foo
257257
//! > semantic_diagnostics
258258

259259
//! > lowering_diagnostics
260-
error: Missing match arm: `_` not covered.
260+
error: Match is non-exhaustive: `_` not covered.
261261
--> lib.cairo:3:5-6:5
262262
match x {
263263
_____^
@@ -474,7 +474,7 @@ foo
474474
//! > semantic_diagnostics
475475

476476
//! > lowering_diagnostics
477-
error: Missing match arm: `_` not covered.
477+
error: Match is non-exhaustive: `_` not covered.
478478
--> lib.cairo:2:5
479479
match Some(5) {};
480480
^^^^^^^^^^^^^^^^
@@ -532,7 +532,7 @@ foo
532532
//! > semantic_diagnostics
533533

534534
//! > lowering_diagnostics
535-
error: Missing match arm: `_` not covered.
535+
error: Match is non-exhaustive: `_` not covered.
536536
--> lib.cairo:2:5
537537
match felt252_is_zero(5) {};
538538
^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -878,7 +878,7 @@ foo
878878
//! > semantic_diagnostics
879879

880880
//! > lowering_diagnostics
881-
error: Missing match arm: `Some(None(_))` not covered.
881+
error: Match is non-exhaustive: `Some(None(_))` not covered.
882882
--> lib.cairo:2:5-5:5
883883
match a {
884884
_____^
@@ -918,7 +918,7 @@ enum A {
918918
//! > semantic_diagnostics
919919

920920
//! > lowering_diagnostics
921-
error: Missing match arm: `Three(_)` not covered.
921+
error: Match is non-exhaustive: `Three(_)` not covered.
922922
--> lib.cairo:8:5-11:5
923923
match a {
924924
_____^
@@ -1346,7 +1346,7 @@ enum A {
13461346
//! > semantic_diagnostics
13471347

13481348
//! > lowering_diagnostics
1349-
error: Missing match arm: `(One(_), Two(_))` not covered.
1349+
error: Match is non-exhaustive: `(One(_), Two(_))` not covered.
13501350
--> lib.cairo:9:5-15:5
13511351
match (a, b) {
13521352
_____^
@@ -2540,7 +2540,7 @@ enum A {
25402540
//! > semantic_diagnostics
25412541

25422542
//! > lowering_diagnostics
2543-
error: Missing match arm: `Some(None(_))` not covered.
2543+
error: Match is non-exhaustive: `Some(None(_))` not covered.
25442544
--> lib.cairo:7:5-12:5
25452545
match a {
25462546
_____^
@@ -2889,7 +2889,7 @@ type C = Result<(), ()>;
28892889
//! > semantic_diagnostics
28902890

28912891
//! > lowering_diagnostics
2892-
error: Missing match arm: `Ok(Ok(Ok(_)))` not covered.
2892+
error: Match is non-exhaustive: `Ok(Ok(Ok(_)))` not covered.
28932893
--> lib.cairo:5:5-14:5
28942894
match a {
28952895
_____^
@@ -2932,7 +2932,7 @@ type C = Result<(), ()>;
29322932
//! > semantic_diagnostics
29332933

29342934
//! > lowering_diagnostics
2935-
error: Missing match arm: `Ok(Err(_))` not covered.
2935+
error: Match is non-exhaustive: `Ok(Err(_))` not covered.
29362936
--> lib.cairo:5:5-14:5
29372937
match a {
29382938
_____^
@@ -2975,7 +2975,7 @@ type C = Result<(), ()>;
29752975
//! > semantic_diagnostics
29762976

29772977
//! > lowering_diagnostics
2978-
error: Missing match arm: `Ok(_)` not covered.
2978+
error: Match is non-exhaustive: `Ok(_)` not covered.
29792979
--> lib.cairo:5:5-14:5
29802980
match a {
29812981
_____^

0 commit comments

Comments
 (0)