Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite122949

Browse files
committed
Auto merge ofrust-lang#127706 - workingjubilee:rollup-d07ij30, r=workingjubilee
Rollup of 6 pull requestsSuccessful merges: -rust-lang#122300 (Add FileCheck annotations to mir-opt/dest-prop tests) -rust-lang#127434 (use "bootstrap" instead of "rustbuild" in comments and docs) -rust-lang#127477 (Clear `inner_attr_ranges` regularly.) -rust-lang#127558 (More attribute cleanups) -rust-lang#127659 (Use ManuallyDrop in BufWriter::into_parts) -rust-lang#127671 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 8))r? `@ghost``@rustbot` modify labels: rollup
2 parentse9eb7de +3033120 commite122949

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

‎std/src/io/buffered/bufwriter.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::fmt;
33
usecrate::io::{
44
self,ErrorKind,IntoInnerError,IoSlice,Seek,SeekFrom,Write,DEFAULT_BUF_SIZE,
55
};
6-
usecrate::mem;
6+
usecrate::mem::{self,ManuallyDrop};
77
usecrate::ptr;
88

99
/// Wraps a writer and buffers its output.
@@ -164,13 +164,13 @@ impl<W: Write> BufWriter<W> {
164164
/// assert_eq!(&buffered_data.unwrap(), b"ata");
165165
/// ```
166166
#[stable(feature ="bufwriter_into_parts", since ="1.56.0")]
167-
pubfninto_parts(mutself) ->(W,Result<Vec<u8>,WriterPanicked>){
168-
let buf = mem::take(&mutself.buf);
169-
let buf =if !self.panicked{Ok(buf)}else{Err(WriterPanicked{ buf})};
167+
pubfninto_parts(self) ->(W,Result<Vec<u8>,WriterPanicked>){
168+
letmut this =ManuallyDrop::new(self);
169+
let buf = mem::take(&mut this.buf);
170+
let buf =if !this.panicked{Ok(buf)}else{Err(WriterPanicked{ buf})};
170171

171-
// SAFETY: forget(self) prevents double dropping inner
172-
let inner =unsafe{ ptr::read(&self.inner)};
173-
mem::forget(self);
172+
// SAFETY: double-drops are prevented by putting `this` in a ManuallyDrop that is never dropped
173+
let inner =unsafe{ ptr::read(&this.inner)};
174174

175175
(inner, buf)
176176
}

‎std/src/io/buffered/tests.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,3 +1067,13 @@ fn bufreader_full_initialize() {
10671067
// But we initialized the whole buffer!
10681068
assert_eq!(reader.initialized(), reader.capacity());
10691069
}
1070+
1071+
/// This is a regression test for https://github.com/rust-lang/rust/issues/127584.
1072+
#[test]
1073+
fnbufwriter_aliasing(){
1074+
usecrate::io::{BufWriter,Cursor};
1075+
letmut v =vec![0;1024];
1076+
let c =Cursor::new(&mut v);
1077+
let w =BufWriter::new(Box::new(c));
1078+
let _ = w.into_parts();
1079+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp