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

Wrong value gets pushed back in VecDeque after make_contiguous is called #80338

Closed
Aratz opened this issue Dec 23, 2020 · 1 comment
Closed
Labels
C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@Aratz
Copy link

Aratz commented Dec 23, 2020

Hi!

While playing around with VecDeque, I encountered what seems to be a rather specific bug with the following code (if you're wondering, it's related to day 22 from Advent of Code):

use std::collections::VecDeque;

fn main() {
    let mut v = VecDeque::new();
    v.push_back(43);
    v.push_back(37);
    v.push_back(30);
    v.push_back(19);
    v.push_back(36);
    v.push_back(9);
    v.push_back(45);
    v.push_back(10);

    v.push_front(1);
    v.push_front(41);
    v.push_front(15);
    v.push_front(46);
    v.push_front(6);
    v.push_front(4);
    v.push_front(5);
    v.push_front(8);
    v.push_front(24);
    v.push_front(32);
    v.push_front(22);
    v.push_front(23);
    v.push_front(3);
    v.push_front(33);
    v.push_front(28);
    v.push_front(39);
    v.push_front(11);
    
    dbg!(v.as_slices());

    let card = v.pop_front().unwrap();
    v.make_contiguous();
    v.push_back(card);

    assert_eq!(&card, v.back().unwrap())
}

As far as I understand, the last line should always be true, and in fact if I comment out v.make_contiguous() or if I insert the elements in a different order, or if I insert one value less, or one value more, this works totally fine.

However, when the VecDeque is in this specific configuration, the back of the vector is equal to 43, instead of 11.

Meta

rustc --version --verbose:

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-unknown-linux-gnu
release: 1.48.0
LLVM version: 11.0

I've also run this in the playground in both beta and nightly but the code works fine then.

Backtrace

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `11`,
 right: `43`', src/bin/testvec1.rs:38:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: std::panicking::begin_panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:437
   2: testvec1::main
             at ./src/bin/testvec1.rs:38
   3: core::ops::function::FnOnce::call_once
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/ops/function.rs:227

@Aratz Aratz added the C-bug Category: This is a bug. label Dec 23, 2020
@Mark-Simulacrum Mark-Simulacrum added the I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness label Dec 23, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 23, 2020
@Mark-Simulacrum Mark-Simulacrum added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 23, 2020
@Mark-Simulacrum
Copy link
Member

Probably fixed by #79814; marking as unsound but closing.

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. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants