Skip to content

Commit ab4cc22

Browse files
committed
---
yaml --- r: 174328 b: refs/heads/snap-stage3 c: 43f2c19 h: refs/heads/master v: v3
1 parent 4319fc0 commit ab4cc22

File tree

18 files changed

+186
-133
lines changed

18 files changed

+186
-133
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: a833337943300db1c310a4cf9c84b7b4ef4e9468
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 25a4adc62f4a743b6696a248ef365aaaaee06362
4+
refs/heads/snap-stage3: 43f2c199e4e87d7ccd15658c52ad8dc5a1d54fb9
55
refs/heads/try: 08f6380a9f0b866796080094f44fe25ea5636547
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/liblibc/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,10 +2207,10 @@ pub mod consts {
22072207
pub const IPPROTO_TCP: c_int = 6;
22082208
pub const IPPROTO_IP: c_int = 0;
22092209
pub const IPPROTO_IPV6: c_int = 41;
2210-
pub const IP_MULTICAST_TTL: c_int = 3;
2211-
pub const IP_MULTICAST_LOOP: c_int = 4;
2212-
pub const IP_ADD_MEMBERSHIP: c_int = 5;
2213-
pub const IP_DROP_MEMBERSHIP: c_int = 6;
2210+
pub const IP_MULTICAST_TTL: c_int = 10;
2211+
pub const IP_MULTICAST_LOOP: c_int = 11;
2212+
pub const IP_ADD_MEMBERSHIP: c_int = 12;
2213+
pub const IP_DROP_MEMBERSHIP: c_int = 13;
22142214
pub const IPV6_ADD_MEMBERSHIP: c_int = 5;
22152215
pub const IPV6_DROP_MEMBERSHIP: c_int = 6;
22162216
pub const IP_TTL: c_int = 4;

branches/snap-stage3/src/librustc/middle/infer/error_reporting.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
11771177
ast::Return(ref ret_ty) => ast::Return(
11781178
self.rebuild_arg_ty_or_output(&**ret_ty, lifetime, anon_nums, region_names)
11791179
),
1180+
ast::DefaultReturn(span) => ast::DefaultReturn(span),
11801181
ast::NoReturn(span) => ast::NoReturn(span)
11811182
}
11821183
}

branches/snap-stage3/src/librustc_trans/trans/debuginfo.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,18 +1450,15 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
14501450
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);
14511451

14521452
// Return type -- llvm::DIBuilder wants this at index 0
1453-
match fn_decl.output {
1454-
ast::Return(ref ret_ty) if ret_ty.node == ast::TyTup(vec![]) =>
1455-
signature.push(ptr::null_mut()),
1456-
_ => {
1457-
assert_type_for_node_id(cx, fn_ast_id, error_reporting_span);
1458-
1459-
let return_type = ty::node_id_to_type(cx.tcx(), fn_ast_id);
1460-
let return_type = monomorphize::apply_param_substs(cx.tcx(),
1461-
param_substs,
1462-
&return_type);
1463-
signature.push(type_metadata(cx, return_type, codemap::DUMMY_SP));
1464-
}
1453+
assert_type_for_node_id(cx, fn_ast_id, error_reporting_span);
1454+
let return_type = ty::node_id_to_type(cx.tcx(), fn_ast_id);
1455+
let return_type = monomorphize::apply_param_substs(cx.tcx(),
1456+
param_substs,
1457+
&return_type);
1458+
if ty::type_is_nil(return_type) {
1459+
signature.push(ptr::null_mut())
1460+
} else {
1461+
signature.push(type_metadata(cx, return_type, codemap::DUMMY_SP));
14651462
}
14661463

14671464
// Arguments types

branches/snap-stage3/src/librustc_trans/trans/foreign.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,8 @@ fn gate_simd_ffi(tcx: &ty::ctxt, decl: &ast::FnDecl, ty: &ty::BareFnTy) {
445445
for (input, ty) in decl.inputs.iter().zip(sig.inputs.iter()) {
446446
check(&*input.ty, *ty)
447447
}
448-
match decl.output {
449-
ast::NoReturn(_) => {}
450-
ast::Return(ref ty) => check(&**ty, sig.output.unwrap())
448+
if let ast::Return(ref ty) = decl.output {
449+
check(&**ty, sig.output.unwrap())
451450
}
452451
}
453452
}

branches/snap-stage3/src/librustc_typeck/astconv.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,8 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
13591359
implied_output_region,
13601360
lifetimes_for_params,
13611361
&**output)),
1362-
ast::NoReturn(_) => ty::FnDiverging
1362+
ast::DefaultReturn(..) => ty::FnConverging(ty::mk_nil(this.tcx())),
1363+
ast::NoReturn(..) => ty::FnDiverging
13631364
};
13641365

13651366
(ty::BareFnTy {
@@ -1486,14 +1487,21 @@ pub fn ty_of_closure<'tcx>(
14861487

14871488
let expected_ret_ty = expected_sig.map(|e| e.output);
14881489

1490+
let is_infer = match decl.output {
1491+
ast::Return(ref output) if output.node == ast::TyInfer => true,
1492+
ast::DefaultReturn(..) => true,
1493+
_ => false
1494+
};
1495+
14891496
let output_ty = match decl.output {
1490-
ast::Return(ref output) if output.node == ast::TyInfer && expected_ret_ty.is_some() =>
1497+
_ if is_infer && expected_ret_ty.is_some() =>
14911498
expected_ret_ty.unwrap(),
1492-
ast::Return(ref output) if output.node == ast::TyInfer =>
1493-
ty::FnConverging(this.ty_infer(output.span)),
1499+
_ if is_infer =>
1500+
ty::FnConverging(this.ty_infer(decl.output.span())),
14941501
ast::Return(ref output) =>
14951502
ty::FnConverging(ast_ty_to_ty(this, &rb, &**output)),
1496-
ast::NoReturn(_) => ty::FnDiverging
1503+
ast::DefaultReturn(..) => unreachable!(),
1504+
ast::NoReturn(..) => ty::FnDiverging
14971505
};
14981506

14991507
debug!("ty_of_closure: input_tys={}", input_tys.repr(this.tcx()));

branches/snap-stage3/src/librustc_typeck/collect.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,9 @@ fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
14881488
let output = match decl.output {
14891489
ast::Return(ref ty) =>
14901490
ty::FnConverging(ast_ty_to_ty(ccx, &rb, &**ty)),
1491-
ast::NoReturn(_) =>
1491+
ast::DefaultReturn(..) =>
1492+
ty::FnConverging(ty::mk_nil(ccx.tcx)),
1493+
ast::NoReturn(..) =>
14921494
ty::FnDiverging
14931495
};
14941496

branches/snap-stage3/src/librustdoc/clean/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,14 +1141,16 @@ impl Clean<Argument> for ast::Arg {
11411141
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Show)]
11421142
pub enum FunctionRetTy {
11431143
Return(Type),
1144+
DefaultReturn,
11441145
NoReturn
11451146
}
11461147

11471148
impl Clean<FunctionRetTy> for ast::FunctionRetTy {
11481149
fn clean(&self, cx: &DocContext) -> FunctionRetTy {
11491150
match *self {
11501151
ast::Return(ref typ) => Return(typ.clean(cx)),
1151-
ast::NoReturn(_) => NoReturn
1152+
ast::DefaultReturn(..) => DefaultReturn,
1153+
ast::NoReturn(..) => NoReturn
11521154
}
11531155
}
11541156
}

branches/snap-stage3/src/librustdoc/html/format.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ impl fmt::String for clean::FunctionRetTy {
557557
match *self {
558558
clean::Return(clean::Tuple(ref tys)) if tys.is_empty() => Ok(()),
559559
clean::Return(ref ty) => write!(f, " -&gt; {}", ty),
560+
clean::DefaultReturn => Ok(()),
560561
clean::NoReturn => write!(f, " -&gt; !")
561562
}
562563
}

branches/snap-stage3/src/libstd/dynamic_lib.rs

Lines changed: 98 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,14 @@ impl DynamicLibrary {
5252
/// Lazily open a dynamic library. When passed None it gives a
5353
/// handle to the calling process
5454
pub fn open(filename: Option<&Path>) -> Result<DynamicLibrary, String> {
55-
unsafe {
56-
let maybe_library = dl::check_for_errors_in(|| {
57-
match filename {
58-
Some(name) => dl::open_external(name.as_vec()),
59-
None => dl::open_internal()
60-
}
61-
});
62-
63-
// The dynamic library must not be constructed if there is
64-
// an error opening the library so the destructor does not
65-
// run.
66-
match maybe_library {
67-
Err(err) => Err(err),
68-
Ok(handle) => Ok(DynamicLibrary { handle: handle })
69-
}
55+
let maybe_library = dl::open(filename.map(|path| path.as_vec()));
56+
57+
// The dynamic library must not be constructed if there is
58+
// an error opening the library so the destructor does not
59+
// run.
60+
match maybe_library {
61+
Err(err) => Err(err),
62+
Ok(handle) => Ok(DynamicLibrary { handle: handle })
7063
}
7164
}
7265

@@ -198,22 +191,34 @@ mod test {
198191
target_os = "ios",
199192
target_os = "freebsd",
200193
target_os = "dragonfly"))]
201-
pub mod dl {
202-
pub use self::Rtld::*;
194+
mod dl {
203195
use prelude::v1::*;
204196

205197
use ffi::{self, CString};
206198
use str;
207199
use libc;
208200
use ptr;
209201

210-
pub unsafe fn open_external(filename: &[u8]) -> *mut u8 {
202+
pub fn open(filename: Option<&[u8]>) -> Result<*mut u8, String> {
203+
check_for_errors_in(|| {
204+
unsafe {
205+
match filename {
206+
Some(filename) => open_external(filename),
207+
None => open_internal(),
208+
}
209+
}
210+
})
211+
}
212+
213+
const LAZY: libc::c_int = 1;
214+
215+
unsafe fn open_external(filename: &[u8]) -> *mut u8 {
211216
let s = CString::from_slice(filename);
212-
dlopen(s.as_ptr(), Lazy as libc::c_int) as *mut u8
217+
dlopen(s.as_ptr(), LAZY) as *mut u8
213218
}
214219

215-
pub unsafe fn open_internal() -> *mut u8 {
216-
dlopen(ptr::null(), Lazy as libc::c_int) as *mut u8
220+
unsafe fn open_internal() -> *mut u8 {
221+
dlopen(ptr::null(), LAZY) as *mut u8
217222
}
218223

219224
pub fn check_for_errors_in<T, F>(f: F) -> Result<T, String> where
@@ -249,14 +254,6 @@ pub mod dl {
249254
dlclose(handle as *mut libc::c_void); ()
250255
}
251256

252-
#[derive(Copy)]
253-
pub enum Rtld {
254-
Lazy = 1,
255-
Now = 2,
256-
Global = 256,
257-
Local = 0,
258-
}
259-
260257
#[link_name = "dl"]
261258
extern {
262259
fn dlopen(filename: *const libc::c_char,
@@ -269,11 +266,13 @@ pub mod dl {
269266
}
270267

271268
#[cfg(target_os = "windows")]
272-
pub mod dl {
269+
mod dl {
273270
use iter::IteratorExt;
274271
use libc;
272+
use libc::consts::os::extra::ERROR_CALL_NOT_IMPLEMENTED;
275273
use ops::FnOnce;
276274
use os;
275+
use option::Option::{self, Some, None};
277276
use ptr;
278277
use result::Result;
279278
use result::Result::{Ok, Err};
@@ -282,19 +281,75 @@ pub mod dl {
282281
use str;
283282
use string::String;
284283
use vec::Vec;
284+
use sys::c::compat::kernel32::SetThreadErrorMode;
285+
286+
pub fn open(filename: Option<&[u8]>) -> Result<*mut u8, String> {
287+
// disable "dll load failed" error dialog.
288+
let mut use_thread_mode = true;
289+
let prev_error_mode = unsafe {
290+
// SEM_FAILCRITICALERRORS 0x01
291+
let new_error_mode = 1;
292+
let mut prev_error_mode = 0;
293+
// Windows >= 7 supports thread error mode.
294+
let result = SetThreadErrorMode(new_error_mode, &mut prev_error_mode);
295+
if result == 0 {
296+
let err = os::errno();
297+
if err as libc::c_int == ERROR_CALL_NOT_IMPLEMENTED {
298+
use_thread_mode = false;
299+
// SetThreadErrorMode not found. use fallback solution: SetErrorMode()
300+
// Note that SetErrorMode is process-wide so this can cause race condition!
301+
// However, since even Windows APIs do not care of such problem (#20650),
302+
// we just assume SetErrorMode race is not a great deal.
303+
prev_error_mode = SetErrorMode(new_error_mode);
304+
}
305+
}
306+
prev_error_mode
307+
};
285308

286-
pub unsafe fn open_external(filename: &[u8]) -> *mut u8 {
287-
// Windows expects Unicode data
288-
let filename_str = str::from_utf8(filename).unwrap();
289-
let mut filename_str: Vec<u16> = filename_str.utf16_units().collect();
290-
filename_str.push(0);
291-
LoadLibraryW(filename_str.as_ptr() as *const libc::c_void) as *mut u8
292-
}
309+
unsafe {
310+
SetLastError(0);
311+
}
312+
313+
let result = match filename {
314+
Some(filename) => {
315+
let filename_str = str::from_utf8(filename).unwrap();
316+
let mut filename_str: Vec<u16> = filename_str.utf16_units().collect();
317+
filename_str.push(0);
318+
let result = unsafe {
319+
LoadLibraryW(filename_str.as_ptr() as *const libc::c_void)
320+
};
321+
// beware: Vec/String may change errno during drop!
322+
// so we get error here.
323+
if result == ptr::null_mut() {
324+
let errno = os::errno();
325+
Err(os::error_string(errno))
326+
} else {
327+
Ok(result as *mut u8)
328+
}
329+
}
330+
None => {
331+
let mut handle = ptr::null_mut();
332+
let succeeded = unsafe {
333+
GetModuleHandleExW(0 as libc::DWORD, ptr::null(), &mut handle)
334+
};
335+
if succeeded == libc::FALSE {
336+
let errno = os::errno();
337+
Err(os::error_string(errno))
338+
} else {
339+
Ok(handle as *mut u8)
340+
}
341+
}
342+
};
343+
344+
unsafe {
345+
if use_thread_mode {
346+
SetThreadErrorMode(prev_error_mode, ptr::null_mut());
347+
} else {
348+
SetErrorMode(prev_error_mode);
349+
}
350+
}
293351

294-
pub unsafe fn open_internal() -> *mut u8 {
295-
let mut handle = ptr::null_mut();
296-
GetModuleHandleExW(0 as libc::DWORD, ptr::null(), &mut handle);
297-
handle as *mut u8
352+
result
298353
}
299354

300355
pub fn check_for_errors_in<T, F>(f: F) -> Result<T, String> where
@@ -326,10 +381,10 @@ pub mod dl {
326381
fn SetLastError(error: libc::size_t);
327382
fn LoadLibraryW(name: *const libc::c_void) -> *mut libc::c_void;
328383
fn GetModuleHandleExW(dwFlags: libc::DWORD, name: *const u16,
329-
handle: *mut *mut libc::c_void)
330-
-> *mut libc::c_void;
384+
handle: *mut *mut libc::c_void) -> libc::BOOL;
331385
fn GetProcAddress(handle: *mut libc::c_void,
332386
name: *const libc::c_char) -> *mut libc::c_void;
333387
fn FreeLibrary(handle: *mut libc::c_void);
388+
fn SetErrorMode(uMode: libc::c_uint) -> libc::c_uint;
334389
}
335390
}

branches/snap-stage3/src/libstd/sys/windows/c.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub mod compat {
226226
/// * `CreateSymbolicLinkW`: Windows XP, Windows Server 2003
227227
/// * `GetFinalPathNameByHandleW`: Windows XP, Windows Server 2003
228228
pub mod kernel32 {
229+
use libc::c_uint;
229230
use libc::types::os::arch::extra::{DWORD, LPCWSTR, BOOLEAN, HANDLE};
230231
use libc::consts::os::extra::ERROR_CALL_NOT_IMPLEMENTED;
231232

@@ -249,6 +250,12 @@ pub mod compat {
249250
unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 }
250251
}
251252
}
253+
254+
compat_fn! {
255+
kernel32::SetThreadErrorMode(_dwNewMode: DWORD, _lpOldMode: *mut DWORD) -> c_uint {
256+
unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 }
257+
}
258+
}
252259
}
253260
}
254261

branches/snap-stage3/src/libsyntax/ast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,10 @@ pub enum FunctionRetTy {
13901390
/// Functions with return type ! that always
13911391
/// raise an error or exit (i.e. never return to the caller)
13921392
NoReturn(Span),
1393+
/// Return type is not specified. Functions default to () and
1394+
/// closures default to inference. Span points to where return
1395+
/// type would be inserted.
1396+
DefaultReturn(Span),
13931397
/// Everything else
13941398
Return(P<Ty>),
13951399
}
@@ -1398,6 +1402,7 @@ impl FunctionRetTy {
13981402
pub fn span(&self) -> Span {
13991403
match *self {
14001404
NoReturn(span) => span,
1405+
DefaultReturn(span) => span,
14011406
Return(ref ty) => ty.span
14021407
}
14031408
}

0 commit comments

Comments
 (0)