Closed
Description
I decided to implement linked lists on my own for educational reasons, mainly as a gateway to learning Unsafe Rust. However, I soon ran into UB, which my compiler didn't error about. I decided to go over and try my code on the Rust playground, where I discovered that my code errors out on the stable branch of the compiler but compiles just fine on the nightly one.
Here is a playground link to my code(I tried removing everything that was unnecessary in reproducing the issue)
I expected to see this happen: the nightly compiler to error out wrong code, just like the stable compiler does
Instead, this happened: the nightly compiler compiled my code just fine, which had undefined behaviour
Meta
rustc --version --verbose
:
rustc 1.53.0-nightly (5a4ab2645 2021-04-18)
binary: rustc
commit-hash: 5a4ab26459a1ccf17ef5bb4c841d3ae5517b2890
commit-date: 2021-04-18
host: x86_64-pc-windows-msvc
release: 1.53.0-nightly
LLVM version: 12.0.0
Backtrace
Finished test [unoptimized + debuginfo] target(s) in 0.86s
Running unittests (target\debug\deps\rustc_issue-cf6511440e82a02d.exe)
running 1 test
test tests::test_get ... FAILED
failures:
---- tests::test_get stdout ----
thread 'tests::test_get' panicked at 'assertion failed: `(left == right)`
left: `Some(2)`,
right: `Some(0)`', src\lib.rs:72:9
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/5a4ab26459a1ccf17ef5bb4c841d3ae5517b2890\/library\std\src\panicking.rs:493
1: core::panicking::panic_fmt
at /rustc/5a4ab26459a1ccf17ef5bb4c841d3ae5517b2890\/library\core\src\panicking.rs:92
2: core::fmt::Arguments::new_v1
at /rustc/5a4ab26459a1ccf17ef5bb4c841d3ae5517b2890\/library\core\src\fmt\mod.rs:316
3: core::panicking::assert_failed_inner
at /rustc/5a4ab26459a1ccf17ef5bb4c841d3ae5517b2890\/library\core\src\panicking.rs:160
4: core::panicking::assert_failed<core::option::Option<i32*>,core::option::Option<i32*>>
at C:\Users\BlueGhost\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panicking.rs:117
5: rustc_issue::tests::test_get
at .\src\lib.rs:72
6: rustc_issue::tests::test_get::{{closure}}
at .\src\lib.rs:64
7: core::ops::function::FnOnce::call_once<closure-0,tuple<>>
at C:\Users\BlueGhost\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
8: core::ops::function::FnOnce::call_once
at /rustc/5a4ab26459a1ccf17ef5bb4c841d3ae5517b2890\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
failures:
tests::test_get
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s
error: test failed, to rerun pass '--lib'