TLDR
Question: What's the ecosystem convention for unsafe code relying on correctness?
Answer: Unsafe code may assume the direct dependencies of its crate to be correct.
Rationale: Even though this allows safe programs to cause undefined behavior, this is the most practical option at this time.
The alternative option would be for unsafe code to only rely on what it can trust (either by verification or by assumption of a safety documentation). That's the strongest option and the one argued by the Rustonomicon. To verify a direct dependency, it must first be pinned. This is the major downside of this option. Also, crates rarely document safety guarantees (if at all).
If the type system provided a syntax for safety guarantees (the same way it provides one for safety requirements), then maybe crates would document safety guarantees. This was suggested in the unsafe mental model. The main issue being that it is not always clear what the safety requirements of a function should be, since it depends how unsafe code plans to use it.
Updated details
Original details
For example, let's assume primes is a crate published on crates.io with the following public API:
/// Returns the prime numbers fitting `u32` in order.
pub fn iter() -> impl Iterator<Item = u32>;
Let's assume another crate crypto also published on crates.io with the following unsafe code:
let first_prime = primes::iter().next().unwrap();
// SAFETY: The first prime number is 2 and it fits `u32`.
unsafe { std::hint::assert_unchecked(first_prime == 2) };
Finally, let's assume primes::iter() is implemented as follows:
pub fn iter() -> impl Iterator<Item = u32> {
1..10
}
Which crate should get a "soundness issue" advisory from RUSTSEC?
I thought the convention (and uncontested opinion) was that it should be crypto (because it relies on a correctness guarantee without checking the implementation and pinning the version), but I've recently seen knowledgeable people argue it should be primes (because it is incorrect and crates on crates.io should be correct). So now I'm unsure and I can't find any official or authoritative documentation in that regard.
My rationalization of the convention I thought was in place (crypto is unsound), is that the Rust type system only provides safety guarantees, not correctness guarantees. On the one hand, while the ecosystem should aim for publishing correct crates only, there is little hope of enforcing that at scale. On the other hand, enforcing that only sound crates (more generally "correct for safety" crates) are published is more realistic. Safe crates are proved sound by the type system (for free). For the minority (about 25%) of crates with unsafe code, enforcement is either passive through soundness bug reports or active through unsafe code reviews.
Note that this is only about crates.io. Other cargo registries or build systems can have their own conventions.