-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.