Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightly compiler doesn't error on UB while the stable one does #84711

Closed
BlueGhostAlt opened this issue Apr 29, 2021 · 2 comments
Closed

Nightly compiler doesn't error on UB while the stable one does #84711

BlueGhostAlt opened this issue Apr 29, 2021 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@BlueGhostAlt
Copy link

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'

@BlueGhostAlt BlueGhostAlt added the C-bug Category: This is a bug. label Apr 29, 2021
@jonas-schievink
Copy link
Contributor

NonNull::as_ref was changed to allow unconstrained output lifetimes in #80771

@BlueGhostAlt
Copy link
Author

My bad, I didn't spot this difference!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants