News for hackers. Stuff that matters.
Re:Rust: Box Is a Unique Type by mmastrac on Thursday May 02, 2024 @03:39PM (#40240574)
I'm not aware of any UB that can 1) be caused by unique pointer violations from Box and 2) are undetectable by Miri (assuming good code coverage), but I might be wrong about this.
Re:Rust: Box Is a Unique Type by IshKebab on Thursday May 02, 2024 @03:52PM (#40240701)
Well for a start, if your tests don't cover that code then it can't possibly detect it.
Re:Rust: Box Is a Unique Type by mmastrac on Thursday May 02, 2024 @04:13PM (#40240898)
This is trivially solved by putting code coverage and Miri into the same project, however.
Re:Rust: Box Is a Unique Type by IshKebab on Thursday May 02, 2024 @05:32PM (#40241586)
It's trivial to measure code coverage. It's definitely not trivial to achieve 100% code coverage.

This is the sort of "just do things perfectly" nonsense we get from C programmers. I'm surprised to see it from Rust devs, given the whole ethos of Rust is that it acknowledges that programmers are not perfect and helping them avoid bugs as much as possible is a good thing.

Re:Rust: Box Is a Unique Type by mmastrac on Thursday May 02, 2024 @06:35PM (#40242131)
It's not nonsense. It's really not difficult to structure code for 100% coverage of unsafe code if you're thinking about it from the start.

You're also perfectly fine to write code that is free of `unsafe`, freeing you from this onerous task. We're pulling out Miri _because_ we're going outside the normal guardrails.

You also don't _need_ to get 100% coverage of all your unsafe code if you can be confident of the usage of unsafe. The most complex unsafe code should almost certainly be covered, but there are a lot of trivial uses of unsafe that can be shown to be correct through reasoning.

Where possible I prefer to split code into safe and unsafe portions, and test the unsafe portions under Miri with as much coverage as gives me confidence in the code.

I've made UB mistakes before with unsafe, but since adding Miri and code coverage, the numbers of mistakes I've made has dropped dramatically. No programmer is perfect, but one would be pretty foolish to ignore the tools at one's disposal.

Re:Rust: Box Is a Unique Type by remram on Thursday May 02, 2024 @05:46PM (#40241711)
I agree in general, but if you have unsafe code you should definitely make sure it is covered.
Re:Rust: Box Is a Unique Type by LegionMammal978 on Thursday May 02, 2024 @06:03PM (#40241870)
If you have an object that's !Unpin, then Miri will not apply uniqueness rules to anything containing it [0], including boxes and &mut references. (In the example code, replacing the PhantomPinned with a () will make Miri complain again.) This is considered a temporary (if long-lived) measure to allow async executors to manipulate pinned futures without invalidating all their internal borrows. Thus, it might be seen as undetected UB, in lieu of a permanent solution.

[0] https://play.rust-lang.org/?version=stable&mode=debug&editio...

Re:Rust: Box Is a Unique Type by mmastrac on Thursday May 02, 2024 @06:34PM (#40242123)
I forgot about this. I actually had to ignore a test in Miri because of this exact issue.

https://github.com/denoland/deno_core/blob/98b09fa4f77db1131...

Anxiously waiting on https://github.com/rust-lang/rfcs/pull/3467