Skip to content

Commit c933d44

Browse files
committed
std: Remove #[allow] directives in sys modules
These were suppressing lots of interesting warnings! Turns out there was also quite a bit of dead code.
1 parent 206ee0e commit c933d44

35 files changed

+86
-176
lines changed

src/libstd/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,14 @@ pub mod collections;
273273
pub mod thread;
274274
pub mod sync;
275275

276+
#[macro_use]
277+
#[path = "sys/common/mod.rs"] mod sys_common;
278+
276279
#[cfg(unix)]
277280
#[path = "sys/unix/mod.rs"] mod sys;
278281
#[cfg(windows)]
279282
#[path = "sys/windows/mod.rs"] mod sys;
280283

281-
#[path = "sys/common/mod.rs"] mod sys_common;
282-
283284
pub mod rt;
284285
mod panicking;
285286

src/libstd/rt/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int {
108108
// but we just do this to name the main thread and to give it correct
109109
// info about the stack bounds.
110110
let thread: Thread = NewThread::new(Some("<main>".to_string()));
111-
thread_info::set((my_stack_bottom, my_stack_top),
112-
sys::thread::guard::main(),
113-
thread);
111+
thread_info::set(sys::thread::guard::main(), thread);
114112

115113
// By default, some platforms will send a *signal* when a EPIPE error
116114
// would otherwise be delivered. This runtime doesn't install a SIGPIPE

src/libstd/sys/common/helper_thread.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ struct RaceBox(helper_signal::signal);
7070
unsafe impl Send for RaceBox {}
7171
unsafe impl Sync for RaceBox {}
7272

73+
macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => (
74+
static $name: Helper<$m> = Helper {
75+
lock: ::sync::MUTEX_INIT,
76+
cond: ::sync::CONDVAR_INIT,
77+
chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
78+
signal: ::cell::UnsafeCell { value: 0 },
79+
initialized: ::cell::UnsafeCell { value: false },
80+
shutdown: ::cell::UnsafeCell { value: false },
81+
};
82+
) }
83+
7384
impl<M: Send> Helper<M> {
7485
/// Lazily boots a helper thread, becoming a no-op if the helper has already
7586
/// been spawned.

src/libstd/sys/common/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
#![allow(missing_docs)]
12-
#![allow(dead_code)]
1312

1413
use old_io::{self, IoError, IoResult};
1514
use prelude::v1::*;
@@ -19,9 +18,10 @@ use num::Int;
1918
use old_path::BytesContainer;
2019
use collections;
2120

21+
#[macro_use] pub mod helper_thread;
22+
2223
pub mod backtrace;
2324
pub mod condvar;
24-
pub mod helper_thread;
2525
pub mod mutex;
2626
pub mod net;
2727
pub mod net2;

src/libstd/sys/common/net.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ use str;
2626
use sys::{self, retry, c, sock_t, last_error, last_net_error, last_gai_error, close_sock,
2727
wrlen, msglen_t, os, wouldblock, set_nonblocking, timer, ms_to_timeval,
2828
decode_error_detailed};
29-
use sync::{Arc, Mutex, MutexGuard};
29+
use sync::{Arc, Mutex};
30+
#[cfg(not(target_os = "linux"))]
31+
use sync::MutexGuard;
3032
use sys_common::{self, keep_going, short_write, timeout};
3133
use cmp;
3234
use old_io;
@@ -620,11 +622,13 @@ impl Drop for Inner {
620622
fn drop(&mut self) { unsafe { close_sock(self.fd); } }
621623
}
622624

625+
#[cfg(not(target_os = "linux"))]
623626
pub struct Guard<'a> {
624627
pub fd: sock_t,
625628
pub guard: MutexGuard<'a, ()>,
626629
}
627630

631+
#[cfg(not(target_os = "linux"))]
628632
#[unsafe_destructor]
629633
impl<'a> Drop for Guard<'a> {
630634
fn drop(&mut self) {

src/libstd/sys/common/net2.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use io::{self, Error, ErrorKind};
1515
use libc::{self, c_int, c_char, c_void, socklen_t};
1616
use mem;
1717
use net::{IpAddr, SocketAddr, Shutdown};
18-
use num::Int;
1918
use sys::c;
2019
use sys::net::{cvt, cvt_r, cvt_gai, Socket, init, wrlen_t};
2120
use sys_common::{AsInner, FromInner, IntoInner};
@@ -24,9 +23,6 @@ use sys_common::{AsInner, FromInner, IntoInner};
2423
// sockaddr and misc bindings
2524
////////////////////////////////////////////////////////////////////////////////
2625

27-
fn hton<I: Int>(i: I) -> I { i.to_be() }
28-
fn ntoh<I: Int>(i: I) -> I { Int::from_be(i) }
29-
3026
fn setsockopt<T>(sock: &Socket, opt: c_int, val: c_int,
3127
payload: T) -> io::Result<()> {
3228
unsafe {
@@ -39,7 +35,7 @@ fn setsockopt<T>(sock: &Socket, opt: c_int, val: c_int,
3935

4036
#[allow(dead_code)]
4137
fn getsockopt<T: Copy>(sock: &Socket, opt: c_int,
42-
val: c_int) -> io::Result<T> {
38+
val: c_int) -> io::Result<T> {
4339
unsafe {
4440
let mut slot: T = mem::zeroed();
4541
let mut len = mem::size_of::<T>() as socklen_t;

src/libstd/sys/common/stack.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -121,37 +121,6 @@ pub unsafe fn record_os_managed_stack_bounds(stack_lo: uint, _stack_hi: uint) {
121121
record_sp_limit(stack_lo + RED_ZONE);
122122
}
123123

124-
#[inline(always)]
125-
pub unsafe fn record_rust_managed_stack_bounds(stack_lo: uint, stack_hi: uint) {
126-
// When the old runtime had segmented stacks, it used a calculation that was
127-
// "limit + RED_ZONE + FUDGE". The red zone was for things like dynamic
128-
// symbol resolution, llvm function calls, etc. In theory this red zone
129-
// value is 0, but it matters far less when we have gigantic stacks because
130-
// we don't need to be so exact about our stack budget. The "fudge factor"
131-
// was because LLVM doesn't emit a stack check for functions < 256 bytes in
132-
// size. Again though, we have giant stacks, so we round all these
133-
// calculations up to the nice round number of 20k.
134-
record_sp_limit(stack_lo + RED_ZONE);
135-
136-
return target_record_stack_bounds(stack_lo, stack_hi);
137-
138-
#[cfg(not(windows))] #[inline(always)]
139-
unsafe fn target_record_stack_bounds(_stack_lo: uint, _stack_hi: uint) {}
140-
141-
#[cfg(all(windows, target_arch = "x86"))] #[inline(always)]
142-
unsafe fn target_record_stack_bounds(stack_lo: uint, stack_hi: uint) {
143-
// stack range is at TIB: %fs:0x04 (top) and %fs:0x08 (bottom)
144-
asm!("mov $0, %fs:0x04" :: "r"(stack_hi) :: "volatile");
145-
asm!("mov $0, %fs:0x08" :: "r"(stack_lo) :: "volatile");
146-
}
147-
#[cfg(all(windows, target_arch = "x86_64"))] #[inline(always)]
148-
unsafe fn target_record_stack_bounds(stack_lo: uint, stack_hi: uint) {
149-
// stack range is at TIB: %gs:0x08 (top) and %gs:0x10 (bottom)
150-
asm!("mov $0, %gs:0x08" :: "r"(stack_hi) :: "volatile");
151-
asm!("mov $0, %gs:0x10" :: "r"(stack_lo) :: "volatile");
152-
}
153-
}
154-
155124
/// Records the current limit of the stack as specified by `end`.
156125
///
157126
/// This is stored in an OS-dependent location, likely inside of the thread

src/libstd/sys/common/thread_info.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![allow(dead_code)] // stack_guard isn't used right now on all platforms
12+
1113
use core::prelude::*;
1214

1315
use cell::RefCell;
@@ -16,10 +18,6 @@ use thread::Thread;
1618
use thread_local::State;
1719

1820
struct ThreadInfo {
19-
// This field holds the known bounds of the stack in (lo, hi)
20-
// form. Not all threads necessarily know their precise bounds,
21-
// hence this is optional.
22-
stack_bounds: (uint, uint),
2321
stack_guard: uint,
2422
thread: Thread,
2523
}
@@ -36,7 +34,6 @@ impl ThreadInfo {
3634
THREAD_INFO.with(move |c| {
3735
if c.borrow().is_none() {
3836
*c.borrow_mut() = Some(ThreadInfo {
39-
stack_bounds: (0, 0),
4037
stack_guard: 0,
4138
thread: NewThread::new(None),
4239
})
@@ -54,10 +51,9 @@ pub fn stack_guard() -> uint {
5451
ThreadInfo::with(|info| info.stack_guard)
5552
}
5653

57-
pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) {
54+
pub fn set(stack_guard: uint, thread: Thread) {
5855
THREAD_INFO.with(|c| assert!(c.borrow().is_none()));
5956
THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{
60-
stack_bounds: stack_bounds,
6157
stack_guard: stack_guard,
6258
thread: thread,
6359
}));

src/libstd/sys/common/thread_local.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
5757
#![allow(non_camel_case_types)]
5858
#![unstable(feature = "thread_local_internals")]
59+
#![allow(dead_code)] // sys isn't exported yet
5960

6061
use prelude::v1::*;
6162

src/libstd/sys/common/wtf8.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
//! nor can it decode WTF-8 from arbitrary bytes.
2222
//! WTF-8 strings can be obtained from UTF-8, UTF-16, or code points.
2323
24+
// this module is imported from @SimonSapin's repo and has tons of dead code on
25+
// unix (it's mostly used on windows), so don't worry about dead code here.
26+
#![allow(dead_code)]
27+
2428
use core::prelude::*;
2529

2630
use core::char::{encode_utf8_raw, encode_utf16_raw};

0 commit comments

Comments
 (0)