Skip to content

Commit 2b712c7

Browse files
committed
Add dropck unsafe escape hatch (UGEH) to vec::IntoIter.
Fix #29166
1 parent 3e268f2 commit 2b712c7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/libcollections/vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ impl<T> ExactSizeIterator for IntoIter<T> {}
15771577

15781578
#[stable(feature = "rust1", since = "1.0.0")]
15791579
impl<T> Drop for IntoIter<T> {
1580+
#[unsafe_destructor_blind_to_params]
15801581
fn drop(&mut self) {
15811582
// destroy the remaining elements
15821583
for _x in self {}

src/test/run-pass/issue-29166.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This test ensures that vec.into_iter does not overconstrain element lifetime.
12+
13+
pub fn main() {
14+
original_report();
15+
revision_1();
16+
revision_2();
17+
}
18+
19+
fn original_report() {
20+
drop(vec![&()].into_iter())
21+
}
22+
23+
fn revision_1() {
24+
// below is what above `vec!` expands into at time of this writing.
25+
drop(<[_]>::into_vec(::std::boxed::Box::new([&()])).into_iter())
26+
}
27+
28+
fn revision_2() {
29+
drop((match (Vec::new(), &()) { (mut v, b) => { v.push(b); v } }).into_iter())
30+
}

0 commit comments

Comments
 (0)