Skip to content

Fix custom functions for optional number types#315

Merged
Keats merged 3 commits into
Keats:fix-bugsfrom
kyrias:computed-number-types
Mar 29, 2024
Merged

Fix custom functions for optional number types#315
Keats merged 3 commits into
Keats:fix-bugsfrom
kyrias:computed-number-types

Conversation

@kyrias

@kyrias kyrias commented Mar 28, 2024

Copy link
Copy Markdown
Contributor

No description provided.

kyrias added 2 commits March 28, 2024 13:49
Round-tripping these through `quote!().to_token_stream().to_string()`
lets us ensure that the resulting strings always match.

Signed-off-by: Johannes Löthberg <johannes.loethberg@elokon.com>
Signed-off-by: Johannes Löthberg <johannes.loethberg@elokon.com>
Signed-off-by: Johannes Löthberg <johannes.loethberg@elokon.com>
@kyrias kyrias force-pushed the computed-number-types branch from 6696839 to 0482b99 Compare March 28, 2024 13:01
quote!(f64),
];
let mut tys = Vec::with_capacity(number_types.len() * 3);
for ty in number_types {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for loop are still not available in const fn right? :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can be worked around by using a while loop, the bigger issue is that we can't use to_string() because trait methods can't be const yet, and I think quote!() also doesn't work in const fns. (Which is actually the reason for loops can't be used as well.)

@Keats Keats merged commit 01229b9 into Keats:fix-bugs Mar 29, 2024
@kyrias kyrias deleted the computed-number-types branch March 29, 2024 15:18
Keats pushed a commit that referenced this pull request Apr 5, 2024
* Dynamically build the list of number types

Round-tripping these through `quote!().to_token_stream().to_string()`
lets us ensure that the resulting strings always match.

Signed-off-by: Johannes Löthberg <johannes.loethberg@elokon.com>

* Don't destructure number types by reference

Signed-off-by: Johannes Löthberg <johannes.loethberg@elokon.com>

* Add test for custom fns on number types not taking a reference

Signed-off-by: Johannes Löthberg <johannes.loethberg@elokon.com>

---------

Signed-off-by: Johannes Löthberg <johannes.loethberg@elokon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants