Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add panic method to stdlib #5849

Closed
jfecher opened this issue Aug 28, 2024 · 0 comments · Fixed by #5966
Closed

Add panic method to stdlib #5849

jfecher opened this issue Aug 28, 2024 · 0 comments · Fixed by #5966
Assignees
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Aug 28, 2024

Problem

We should add a panic method to stdlib as a way to halt computation and return a value of any type, since we know it can't be used. assert(false) alone is insufficient since it returns a unit type.

Happy Case

We add the function:

fn panic<T, U, let N: u32>(message: fmtstr<N, T>) -> U {
    assert(false, message);
    std::meta::zeroed()
}

The prelude would be a good place for it since users will be used to panic!() being available in rust without import.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@jfecher jfecher added the enhancement New feature or request label Aug 28, 2024
@asterite asterite self-assigned this Sep 6, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 9, 2024
# Description

## Problem

Resolves #5849

## Summary

Adds a `panic` method exactly as proposed in #5849 , and uses it in a
couple of places where `panic` would have been useful to have.

## Additional Context

Is it okay in `std::panic::panic`? Where should we document this? (maybe
in a new `panic.md` file, or somewhere else?)

## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: jfecher <jake@aztecprotocol.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants