Skip to content

Commit 30e4a87

Browse files
authored
Rollup merge of #62422 - lzutao:remove-some-mem-uinit, r=alexcrichton
Remove some uses of mem::uninitialized cc #62397 r? @RalfJung
2 parents 154726c + 7646d49 commit 30e4a87

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/librustc_codegen_llvm/common.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ impl CodegenCx<'ll, 'tcx> {
170170
pub fn const_get_real(&self, v: &'ll Value) -> Option<(f64, bool)> {
171171
unsafe {
172172
if self.is_const_real(v) {
173-
#[allow(deprecated)]
174-
let mut loses_info: llvm::Bool = ::std::mem::uninitialized();
173+
let mut loses_info: llvm::Bool = 0;
175174
let r = llvm::LLVMConstRealGetDouble(v, &mut loses_info);
176175
let loses_info = if loses_info == 1 { true } else { false };
177176
Some((r, loses_info))

src/libterm/win.rs

+29-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
// FIXME (#13400): this is only a tiny fraction of the Windows console api
44

5-
extern crate libc;
6-
75
use std::io;
86
use std::io::prelude::*;
97

@@ -20,19 +18,36 @@ pub struct WinConsole<T> {
2018
background: color::Color,
2119
}
2220

21+
type SHORT = i16;
2322
type WORD = u16;
2423
type DWORD = u32;
2524
type BOOL = i32;
2625
type HANDLE = *mut u8;
2726

27+
#[allow(non_snake_case)]
28+
#[repr(C)]
29+
struct SMALL_RECT {
30+
Left: SHORT,
31+
Top: SHORT,
32+
Right: SHORT,
33+
Bottom: SHORT,
34+
}
35+
36+
#[allow(non_snake_case)]
37+
#[repr(C)]
38+
struct COORD {
39+
X: SHORT,
40+
Y: SHORT,
41+
}
42+
2843
#[allow(non_snake_case)]
2944
#[repr(C)]
3045
struct CONSOLE_SCREEN_BUFFER_INFO {
31-
dwSize: [libc::c_short; 2],
32-
dwCursorPosition: [libc::c_short; 2],
46+
dwSize: COORD,
47+
dwCursorPosition: COORD,
3348
wAttributes: WORD,
34-
srWindow: [libc::c_short; 4],
35-
dwMaximumWindowSize: [libc::c_short; 2],
49+
srWindow: SMALL_RECT,
50+
dwMaximumWindowSize: COORD,
3651
}
3752

3853
#[allow(non_snake_case)]
@@ -105,12 +120,17 @@ impl<T: Write + Send + 'static> WinConsole<T> {
105120

106121
/// Returns `None` whenever the terminal cannot be created for some reason.
107122
pub fn new(out: T) -> io::Result<WinConsole<T>> {
123+
use std::mem::MaybeUninit;
124+
108125
let fg;
109126
let bg;
110127
unsafe {
111-
#[allow(deprecated)]
112-
let mut buffer_info = ::std::mem::uninitialized();
113-
if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), &mut buffer_info) != 0 {
128+
let mut buffer_info = MaybeUninit::<CONSOLE_SCREEN_BUFFER_INFO>::uninit();
129+
if GetConsoleScreenBufferInfo(
130+
GetStdHandle(-11i32 as DWORD),
131+
buffer_info.as_mut_ptr()
132+
) != 0 {
133+
let buffer_info = buffer_info.assume_init() ;
114134
fg = bits_to_color(buffer_info.wAttributes);
115135
bg = bits_to_color(buffer_info.wAttributes >> 4);
116136
} else {

0 commit comments

Comments
 (0)