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

Assertions #457

Closed
ricvelozo opened this issue Mar 9, 2023 · 3 comments
Closed

Assertions #457

ricvelozo opened this issue Mar 9, 2023 · 3 comments

Comments

@ricvelozo
Copy link
Contributor

I want to use assertions in verify() functions to simplify the code. Does the error output need to be exact? Example:

if left != right {
    eprintln!("{left} != {right}");
    process::exit(-1);
}

Will become just:

assert_eq!(left, right);

The error output:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `80`,
 right: `82`', src/main.rs:2:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@ricvelozo
Copy link
Contributor Author

ricvelozo commented Mar 9, 2023

And the verify() function needs to be called in release mode? Because in Swift we must disable the -Ounchecked flag to the assertion don't be optimized away.

@nuald
Copy link
Collaborator

nuald commented Mar 10, 2023

The code is not tested in debug mode at all, so whatever verification is used, should work in the release mode too.

@ricvelozo
Copy link
Contributor Author

The code is not tested in debug mode at all, so whatever verification is used, should work in the release mode too.

Alright, I will use fatalError() in Swift (not optimized away). But the -Ounchecked flag is another one to go to the #290 discussion.

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

No branches or pull requests

2 participants