Skip to content

Commit 8a6d10d

Browse files
committed
use proper name instead of magic number
1 parent 725b38e commit 8a6d10d

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

test/src/bench.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn fmt_thousands_sep(mut n: f64, sep: char) -> String {
9898
(0, true) => write!(output, "{:06.2}", n / base as f64).unwrap(),
9999
(0, false) => write!(output, "{:.2}", n / base as f64).unwrap(),
100100
(_, true) => write!(output, "{:03}", n as usize / base).unwrap(),
101-
_ => write!(output, "{}", n as usize / base).unwrap()
101+
_ => write!(output, "{}", n as usize / base).unwrap(),
102102
}
103103
if pow != 0 {
104104
output.push(sep);

test/src/term/win.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type WORD = u16;
2222
type DWORD = u32;
2323
type BOOL = i32;
2424
type HANDLE = *mut u8;
25+
// https://docs.microsoft.com/en-us/windows/console/getstdhandle
26+
const STD_OUTPUT_HANDLE: DWORD = -11 as _;
2527

2628
#[allow(non_snake_case)]
2729
#[repr(C)]
@@ -99,16 +101,13 @@ impl<T: Write + Send + 'static> WinConsole<T> {
99101
accum |= color_to_bits(self.background) << 4;
100102

101103
unsafe {
102-
// Magic -11 means stdout, from
103-
// https://docs.microsoft.com/en-us/windows/console/getstdhandle
104-
//
105104
// You may be wondering, "but what about stderr?", and the answer
106105
// to that is that setting terminal attributes on the stdout
107106
// handle also sets them for stderr, since they go to the same
108107
// terminal! Admittedly, this is fragile, since stderr could be
109108
// redirected to a different console. This is good enough for
110109
// rustc though. See #13400.
111-
let out = GetStdHandle(-11i32 as DWORD);
110+
let out = GetStdHandle(STD_OUTPUT_HANDLE);
112111
SetConsoleTextAttribute(out, accum);
113112
}
114113
}
@@ -120,9 +119,8 @@ impl<T: Write + Send + 'static> WinConsole<T> {
120119
let bg;
121120
unsafe {
122121
let mut buffer_info = MaybeUninit::<CONSOLE_SCREEN_BUFFER_INFO>::uninit();
123-
if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), buffer_info.as_mut_ptr())
124-
!= 0
125-
{
122+
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
123+
if GetConsoleScreenBufferInfo(handle, buffer_info.as_mut_ptr()) != 0 {
126124
let buffer_info = buffer_info.assume_init();
127125
fg = bits_to_color(buffer_info.wAttributes);
128126
bg = bits_to_color(buffer_info.wAttributes >> 4);

0 commit comments

Comments
 (0)