Open wubin28 opened 1 month ago
The docs for sort have this to say:
May panic if the implementation of Ord for T does not implement a total order.
The release announcement you have linked is a little more vague, but I interpret the "will now panic" portion as "will now panic [in some cases where it didn't previously]."
EDIT: #130122 seems to be related, where there was some confusion over the new wording in the docs
<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. -->I tried this code by running
rustup run 1.81.0 cargo run
:I expected to see this happen: explanation The program would panic on the line "vec.sort();" since "the new sort algorithms try to detect incorrect implementations of Ord that prevent them from being able to produce a meaningfully sorted result, and will now panic on such cases rather than returning effectively randomly arranged data.", according to the "New sort implementations" in https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html.
Instead, this happened: explanation The program paniced on the line "assert!(BadOrd(1) < BadOrd(2));". Here is the output:
Before sorting: [BadOrd(3), BadOrd(2), BadOrd(4), BadOrd(1)] After sorting: [BadOrd(2), BadOrd(4), BadOrd(3), BadOrd(1)] thread 'main' panicked at src/main.rs:53:5: assertion failed: BadOrd(1) < BadOrd(2) note: run with
RUST_BACKTRACE=1
environment variable to display a backtraceMeta
rustc --version --verbose
:Backtrace
``` RUST_BACKTRACE=1 rustup run 1.81.0 cargo run Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.16s Running `target/debug/new_sort_implementations_in_1_81_0_stable_rust` Before sorting: [BadOrd(3), BadOrd(2), BadOrd(4), BadOrd(1)] After sorting: [BadOrd(2), BadOrd(4), BadOrd(3), BadOrd(1)] thread 'main' panicked at src/main.rs:53:5: assertion failed: BadOrd(1) < BadOrd(2) stack backtrace: 0: rust_begin_unwind at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5 1: core::panicking::panic_fmt at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14 2: core::panicking::panic at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:148:5 3: new_sort_implementations_in_1_81_0_stable_rust::main at ./src/main.rs:53:5 4: core::ops::function::FnOnce::call_once at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```