Skip to content

Commit 0ea79d0

Browse files
authored
feat!: Add non_exhaustive to various enums (#952)
Mainly to `std_extensions` definitions and error enums. This missing caused #942 to be a breaking change, since it adds new variants to the `FloatOps` and `IntOpDef` extensions. See the failing semver-checks in #928.
1 parent 8cd3ee9 commit 0ea79d0

26 files changed

+31
-0
lines changed

hugr/src/algorithm/nest_cfgs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl<H: HugrMut> CfgNester<Node> for IdentityCfgMap<H> {
278278

279279
/// An error trying to get the blocks of a SESE (single-entry-single-exit) region
280280
#[derive(Clone, Debug, Error)]
281+
#[non_exhaustive]
281282
pub enum RegionBlocksError<T> {
282283
/// The specified exit edge did not exist in the CFG
283284
ExitEdgeNotPresent(T, T),

hugr/src/builder/conditional.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use thiserror::Error;
3030
pub type CaseBuilder<B> = DFGWrapper<B, BuildHandle<CaseID>>;
3131

3232
#[derive(Debug, Clone, PartialEq, Eq, Error)]
33+
#[non_exhaustive]
3334
pub enum ConditionalBuildError {
3435
/// Case already built.
3536
#[error("Case {case} of Conditional node {conditional:?} has already been built.")]

hugr/src/extension/declarative.rs

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ struct DeclarationContext<'a> {
175175

176176
/// Errors that can occur while loading an extension set.
177177
#[derive(Debug, thiserror::Error)]
178+
#[non_exhaustive]
178179
pub enum ExtensionDeclarationError {
179180
/// An error occurred while deserializing the extension set.
180181
#[error("Error while parsing the extension set yaml: {0}")]

hugr/src/extension/infer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ enum Constraint {
6363
}
6464

6565
#[derive(Debug, Clone, PartialEq, Error)]
66+
#[non_exhaustive]
6667
/// Errors which arise during unification
6768
pub enum InferExtensionError {
6869
#[error("Mismatched extension sets {expected} and {actual}")]

hugr/src/extension/simple_op.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use thiserror::Error;
2020
#[derive(Debug, Error, PartialEq)]
2121
#[error("{0}")]
2222
#[allow(missing_docs)]
23+
#[non_exhaustive]
2324
pub enum OpLoadError {
2425
#[error("Op with name {0} is not a member of this set.")]
2526
NotMember(String),

hugr/src/extension/validate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ impl ExtensionValidator {
159159
/// Errors that can occur while validating a Hugr.
160160
#[derive(Debug, Clone, PartialEq, Error)]
161161
#[allow(missing_docs)]
162+
#[non_exhaustive]
162163
pub enum ExtensionError {
163164
/// Missing lift node
164165
#[error("Extensions at target node {to:?} ({to_extensions}) exceed those at source {from:?} ({from_extensions})")]

hugr/src/hugr/rewrite/consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct RemoveLoadConstant(pub Node);
1414

1515
/// Error from an [`RemoveConst`] or [`RemoveLoadConstant`] operation.
1616
#[derive(Debug, Clone, Error, PartialEq, Eq)]
17+
#[non_exhaustive]
1718
pub enum RemoveError {
1819
/// Invalid node.
1920
#[error("Node is invalid (either not in HUGR or not correct operation).")]

hugr/src/hugr/rewrite/inline_dfg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct InlineDFG(pub DfgID);
1111

1212
/// Errors from an [InlineDFG] rewrite.
1313
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
14+
#[non_exhaustive]
1415
pub enum InlineDFGError {
1516
/// Node to inline was not a DFG. (E.g. node has been overwritten since the DfgID originated.)
1617
#[error("Node {0} was not a DFG")]

hugr/src/hugr/rewrite/insert_identity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ impl IdentityInsertion {
3232

3333
/// Error from an [`IdentityInsertion`] operation.
3434
#[derive(Debug, Clone, Error, PartialEq, Eq)]
35+
#[non_exhaustive]
3536
pub enum IdentityInsertionError {
3637
/// Invalid parent node.
3738
#[error("Parent node is invalid.")]

hugr/src/hugr/rewrite/outline_cfg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ impl Rewrite for OutlineCfg {
219219

220220
/// Errors that can occur in expressing an OutlineCfg rewrite.
221221
#[derive(Debug, Error)]
222+
#[non_exhaustive]
222223
pub enum OutlineCfgError {
223224
/// The set of blocks were not siblings
224225
#[error("The nodes did not all have the same parent")]

hugr/src/hugr/rewrite/replace.rs

+1
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ fn transfer_edges<'a>(
384384

385385
/// Error in a [`Replacement`]
386386
#[derive(Clone, Debug, PartialEq, Eq, Error)]
387+
#[non_exhaustive]
387388
pub enum ReplaceError {
388389
/// The node(s) to replace had no parent i.e. were root(s).
389390
// (Perhaps if there is only one node to replace we should be able to?)

hugr/src/hugr/rewrite/simple_replace.rs

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ impl Rewrite for SimpleReplacement {
181181

182182
/// Error from a [`SimpleReplacement`] operation.
183183
#[derive(Debug, Clone, Error, PartialEq, Eq)]
184+
#[non_exhaustive]
184185
pub enum SimpleReplacementError {
185186
/// Invalid parent node.
186187
#[error("Parent node is invalid.")]

hugr/src/hugr/serialize.rs

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct SerHugrV1 {
6161

6262
/// Errors that can occur while serializing a HUGR.
6363
#[derive(Debug, Clone, PartialEq, Error)]
64+
#[non_exhaustive]
6465
pub enum HUGRSerializationError {
6566
/// Unexpected hierarchy error.
6667
#[error("Failed to attach child to parent: {0:?}.")]

hugr/src/hugr/validate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ impl<'a, 'b> ValidationContext<'a, 'b> {
591591
/// Errors that can occur while validating a Hugr.
592592
#[derive(Debug, Clone, PartialEq, Error)]
593593
#[allow(missing_docs)]
594+
#[non_exhaustive]
594595
pub enum ValidationError {
595596
/// The root node of the Hugr is not a root in the hierarchy.
596597
#[error("The root node of the Hugr {node:?} is not a root in the hierarchy.")]
@@ -706,6 +707,7 @@ pub enum ValidationError {
706707
/// Errors related to the inter-graph edge validations.
707708
#[derive(Debug, Clone, PartialEq, Error)]
708709
#[allow(missing_docs)]
710+
#[non_exhaustive]
709711
pub enum InterGraphEdgeError {
710712
/// Inter-Graph edges can only carry copyable data.
711713
#[error("Inter-graph edges can only carry copyable data. In an inter-graph edge from {from:?} ({from_offset:?}) to {to:?} ({to_offset:?}) with type {ty:?}.")]

hugr/src/hugr/views/sibling_subgraph.rs

+3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ fn has_other_edge<H: HugrView>(hugr: &H, node: Node, dir: Direction) -> bool {
625625

626626
/// Errors that can occur while constructing a [`SimpleReplacement`].
627627
#[derive(Debug, Clone, PartialEq, Eq, Error)]
628+
#[non_exhaustive]
628629
pub enum InvalidReplacement {
629630
/// No DataflowParent root in replacement graph.
630631
#[error("No DataflowParent root in replacement graph.")]
@@ -642,6 +643,7 @@ pub enum InvalidReplacement {
642643

643644
/// Errors that can occur while constructing a [`SiblingSubgraph`].
644645
#[derive(Debug, Clone, PartialEq, Eq, Error)]
646+
#[non_exhaustive]
645647
pub enum InvalidSubgraph {
646648
/// The subgraph is not convex.
647649
#[error("The subgraph is not convex.")]
@@ -659,6 +661,7 @@ pub enum InvalidSubgraph {
659661

660662
/// Errors that can occur while constructing a [`SiblingSubgraph`].
661663
#[derive(Debug, Clone, PartialEq, Eq, Error)]
664+
#[non_exhaustive]
662665
pub enum InvalidSubgraphBoundary {
663666
/// A boundary port's node is not in the set of nodes.
664667
#[error("(node {0:?}, port {1:?}) is in the boundary, but node {0:?} is not in the set.")]

hugr/src/ops/constant.rs

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl PartialEq for ExtensionConst {
7171

7272
/// Struct for custom type check fails.
7373
#[derive(Clone, Debug, PartialEq, Eq, Error)]
74+
#[non_exhaustive]
7475
pub enum CustomCheckFailure {
7576
/// The value had a specific type that was not what was expected
7677
#[error("Expected type: {expected} but value was of type: {found}")]
@@ -87,6 +88,7 @@ pub enum CustomCheckFailure {
8788

8889
/// Errors that arise from typechecking constants
8990
#[derive(Clone, Debug, PartialEq, Error)]
91+
#[non_exhaustive]
9092
pub enum ConstTypeError {
9193
/// Invalid sum type definition.
9294
#[error("{0}")]

hugr/src/ops/custom.rs

+1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ pub fn resolve_opaque_op(
397397
/// Errors that arise after loading a Hugr containing opaque ops (serialized just as their names)
398398
/// when trying to resolve the serialized names against a registry of known Extensions.
399399
#[derive(Clone, Debug, Error, PartialEq)]
400+
#[non_exhaustive]
400401
pub enum CustomOpError {
401402
/// The Extension was found but did not contain the expected OpDef
402403
#[error("Operation {0} not found in Extension {1}")]

hugr/src/ops/validate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ impl ValidateOp for super::CFG {
159159
/// Errors that can occur while checking the children of a node.
160160
#[derive(Debug, Clone, PartialEq, Error)]
161161
#[allow(missing_docs)]
162+
#[non_exhaustive]
162163
pub enum ChildrenValidationError {
163164
/// An CFG graph has an exit operation as a non-second child.
164165
#[error("Exit basic blocks are only allowed as the second child in a CFG graph")]
@@ -208,6 +209,7 @@ impl ChildrenValidationError {
208209
/// Errors that can occur while checking the edges between children of a node.
209210
#[derive(Debug, Clone, PartialEq, Error)]
210211
#[allow(missing_docs)]
212+
#[non_exhaustive]
211213
pub enum EdgeValidationError {
212214
/// The dataflow signature of two connected basic blocks does not match.
213215
#[error("The dataflow signature of two connected basic blocks does not match. Output signature: {source_op:?}, input signature: {target_op:?}",

hugr/src/std_extensions/arithmetic/conversions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("arithmetic.con
2626
/// Extension for conversions between floats and integers.
2727
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
2828
#[allow(missing_docs, non_camel_case_types)]
29+
#[non_exhaustive]
2930
pub enum ConvertOpDef {
3031
trunc_u,
3132
trunc_s,

hugr/src/std_extensions/arithmetic/float_ops.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("arithmetic.flo
2121
/// Integer extension operation definitions.
2222
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
2323
#[allow(missing_docs, non_camel_case_types)]
24+
#[non_exhaustive]
2425
pub enum FloatOps {
2526
feq,
2627
fne,

hugr/src/std_extensions/arithmetic/int_ops.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl ValidateJustArgs for IOValidator {
4545
/// Integer extension operation definitions.
4646
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
4747
#[allow(missing_docs, non_camel_case_types)]
48+
#[non_exhaustive]
4849
pub enum IntOpDef {
4950
iwiden_u,
5051
iwiden_s,

hugr/src/std_extensions/collections.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ fn list_and_elem_type_vars(list_type_def: &TypeDef) -> (Type, Type) {
204204

205205
/// A list operation
206206
#[derive(Debug, Clone, PartialEq)]
207+
#[non_exhaustive]
207208
pub enum ListOp {
208209
/// Pop from end of list
209210
Pop,

hugr/src/std_extensions/logic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub const TRUE_NAME: &str = "TRUE";
2626
/// Logic extension operation definitions.
2727
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, EnumIter, IntoStaticStr, EnumString)]
2828
#[allow(missing_docs)]
29+
#[non_exhaustive]
2930
pub enum NaryLogic {
3031
And,
3132
Or,

hugr/src/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub(crate) fn least_upper_bound(mut tags: impl Iterator<Item = TypeBound>) -> Ty
115115

116116
#[derive(Clone, PartialEq, Debug, Eq, Serialize, Deserialize)]
117117
#[serde(tag = "s")]
118+
#[non_exhaustive]
118119
/// Representation of a Sum type.
119120
/// Either store the types of the variants, or in the special (but common) case
120121
/// of a UnitSum (sum over empty tuples), store only the size of the Sum.

hugr/src/types/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::ops::Const;
77

88
/// Errors that arise from typechecking constants
99
#[derive(Clone, Debug, PartialEq, Error)]
10+
#[non_exhaustive]
1011
pub enum SumTypeError {
1112
/// The type of the variant doesn't match the type of the value.
1213
#[error("Expected type {expected} for element {index} of variant #{tag}, but found {}", .found.const_type())]

hugr/src/types/type_param.rs

+1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ pub fn check_type_args(args: &[TypeArg], params: &[TypeParam]) -> Result<(), Typ
340340

341341
/// Errors that can occur fitting a [TypeArg] into a [TypeParam]
342342
#[derive(Clone, Debug, PartialEq, Eq, Error)]
343+
#[non_exhaustive]
343344
pub enum TypeArgError {
344345
#[allow(missing_docs)]
345346
/// For now, general case of a type arg not fitting a param.

0 commit comments

Comments
 (0)