Error messages in release/debug binary only

Hello

Today I decided to find some text in release binary file and was surprised that there are a lot of error messages in the release executable file.
I agree that it may be correct error messages, but why I do not get them during run compilation or when I execute app. There is not any messages in the console where I compile app with cargo run or cargo build ....
Messages look like this:
called `Result::unwrap()` on an `Err` value
Unable to write filestruct
failed to fill whole buffer
unsafe precondition(s) violated: invalid value for `char`
capacity overflowunsafe precondition(s) violated: ptr::sub_ptr requires `self >= origin`called `Result::unwrap()` on an `Err` valueTrustedLen iterator's size hint is not exact: TryFromSliceError

I would be happy to fix some of them - but how to see them during execution?

Thank you in advance

1 Like

Assuming the strings in question don't actually show up in your source code, these messages are presumably for things that can — theoretically — go wrong in the Rust standard library and/or your project's dependencies. It may not even be possible to see some of them under normal execution conditions. I don't believe you should be trying to spend time "fixing" them.

I agree with it and I know that there is not any errors.
If those are hypothetical errors - how to stop such suppositions go to executable release file?

Regards

The unsafe precondtion(s) ones do seem like ones that should only be in the debug binary. If they're in the release binary, I don't have an explanation offhand.

Whether an error will happen at run time or not is always knowable at compile time. That said, even some errors which your particular program can't reach will remain unless you use nightly features to rebuild the standard library.[1] I don't recommend that route without a very compelling reason.


  1. and enable LTO, but that part's stable ↩︎

Great. This is good that compile sees some potential errors.
Question is how to see all those errors in normal human mode?
For example to say: "Compiler please analyse and show me all errors that exist in my code", so I can pay attention or at least think about it?

Regards

This is roughly equivalent to asking “what parts of my code could panic?”. I don’t know of any tool that can list all panic sites, but no-panic could let you try writing code that has no panic cases. It can be unreliable because it depends on the panic branches getting optimized out, and there are no guarantees what the optimizer will do, but it might be informative to play with.