tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

Added unreachable macro to alleged unreachable code rather than using hidden default value (#169)

* Added unreachable macro to alleged unreachable code rather than using hidden default value

* Added comment warning

* Fixed formatting

Co-authored-by: Troels Peter Jessen <trojes@tuta.io>

90ca73fcec69bf4a1b2fdcb21125cf19df393d8a · by Troels Jessen · (4 years ago) · parent 95934288c · browse the tree at this commit

Semantic delta · 2

2 files · +5 −2

diff --git a/src/flexbox.rs b/src/flexbox.rs
index a56526a92..072eeb4c7 100644
--- a/src/flexbox.rs
+++ b/src/flexbox.rs
@@ -1199,7 +1199,7 @@ impl Forest {
         constants: &AlgoConstants,
     ) -> f32 {
         match child_style.align_self(&self.nodes[node].style) {
-            AlignSelf::Auto => 0.0, // Should never happen
+            AlignSelf::Auto => unreachable!(),
             AlignSelf::FlexStart => {
                 if constants.is_wrap_reverse {
                     free_space
@@ -1512,7 +1512,7 @@ impl Forest {
                 free_cross_space - end_cross.unwrap_or(0.0) - constants.border.cross_end(constants.dir)
             } else {
                 match child_style.align_self(&self.nodes[node].style) {
-                    AlignSelf::Auto => 0.0, // Should never happen
+                    AlignSelf::Auto => unreachable!(),
                     AlignSelf::FlexStart => {
                         if constants.is_wrap_reverse {
                             free_cross_space - constants.padding_border.cross_end(constants.dir)
diff --git a/src/style.rs b/src/style.rs
index 8a946665c..8403093ed 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -495,6 +495,9 @@ impl FlexboxLayout {
 
     /// Computes the final alignment of this item based on the parent's [`AlignItems`] and this item's [`AlignSelf`]
     pub(crate) fn align_self(&self, parent: &FlexboxLayout) -> AlignSelf {
+        // FUTURE WARNING: This function should never return AlignSelf::Auto
+        // See #169 https://github.com/DioxusLabs/taffy/pull/169#issuecomment-1157698840
+
         if self.align_self == AlignSelf::Auto {
             match parent.align_items {
                 AlignItems::FlexStart => AlignSelf::FlexStart,