diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a11e9a7d68053..c3851dcc8f1ed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -238,7 +238,7 @@ are: * Don't be afraid to ask! The Rust community is friendly and helpful. [gdfrustc]: http://manishearth.github.io/rust-internals-docs/rustc/ -[gsearchdocs]: https://www.google.de/search?q=site:doc.rust-lang.org+your+query+here +[gsearchdocs]: https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here [rif]: http://internals.rust-lang.org [rr]: https://doc.rust-lang.org/book/README.html [tlgba]: http://tomlee.co/2014/04/03/a-more-detailed-tour-of-the-rust-compiler/ diff --git a/configure b/configure index 6e2d3060bc3c0..df76d805f824b 100755 --- a/configure +++ b/configure @@ -521,15 +521,18 @@ then # if configure is running in an interactive bash shell. /usr/bin/env # exists *everywhere*. BIN_TO_PROBE="$SHELL" - if [ -z "$BIN_TO_PROBE" -a -e "/usr/bin/env" ]; then - BIN_TO_PROBE="/usr/bin/env" + if [ ! -r "$BIN_TO_PROBE" ]; then + if [ -r "/usr/bin/env" ]; then + BIN_TO_PROBE="/usr/bin/env" + else + warn "Cannot check if the userland is i686 or x86_64" + fi + fi + file -L "$BIN_TO_PROBE" | grep -q "x86[_-]64" + if [ $? != 0 ]; then + msg "i686 userland on x86_64 Linux kernel" + CFG_CPUTYPE=i686 fi - if [ -n "$BIN_TO_PROBE" ]; then - file -L "$BIN_TO_PROBE" | grep -q "x86[_-]64" - if [ $? != 0 ]; then - CFG_CPUTYPE=i686 - fi - fi fi @@ -587,7 +590,7 @@ opt fast-make 0 "use .gitmodules as timestamp for submodule deps" opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds" opt local-rust 0 "use an installed rustc rather than downloading a snapshot" opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM" -opt rpath 0 "build rpaths into rustc itself" +opt rpath 1 "build rpaths into rustc itself" opt stage0-landing-pads 1 "enable landing pads during bootstrap with stage0" # This is used by the automation to produce single-target nightlies opt dist-host-only 0 "only install bins for the host architecture" diff --git a/mk/cfg/x86_64-unknown-openbsd.mk b/mk/cfg/x86_64-unknown-openbsd.mk index 261616ecf1fda..e6f28482284e0 100644 --- a/mk/cfg/x86_64-unknown-openbsd.mk +++ b/mk/cfg/x86_64-unknown-openbsd.mk @@ -20,3 +20,4 @@ CFG_LDPATH_x86_64-unknown-openbsd := CFG_RUN_x86_64-unknown-openbsd=$(2) CFG_RUN_TARG_x86_64-unknown-openbsd=$(call CFG_RUN_x86_64-unknown-openbsd,,$(2)) CFG_GNU_TRIPLE_x86_64-unknown-openbsd := x86_64-unknown-openbsd +RUSTC_FLAGS_x86_64-unknown-openbsd=-C linker=$(call FIND_COMPILER,$(CC)) diff --git a/mk/crates.mk b/mk/crates.mk index 2b66baed45b94..2597c724da96f 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -71,7 +71,7 @@ DEPS_rustc_bitflags := core DEPS_rustc_unicode := core DEPS_std := core libc rand alloc collections rustc_unicode \ - native:rust_builtin native:backtrace \ + native:backtrace \ alloc_system DEPS_arena := std DEPS_glob := std diff --git a/mk/main.mk b/mk/main.mk index 110bf0408d63c..2de18c9871a8d 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -131,11 +131,7 @@ endif ifdef CFG_ENABLE_DEBUGINFO $(info cfg: enabling debuginfo (CFG_ENABLE_DEBUGINFO)) - # FIXME: Re-enable -g in stage0 after new snapshot - #CFG_RUSTC_FLAGS += -g - RUSTFLAGS_STAGE1 += -g - RUSTFLAGS_STAGE2 += -g - RUSTFLAGS_STAGE3 += -g + CFG_RUSTC_FLAGS += -g endif ifdef SAVE_TEMPS diff --git a/mk/platform.mk b/mk/platform.mk index fd8416e8a6e61..04cab379de3c7 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -215,16 +215,6 @@ define CFG_MAKE_TOOLCHAIN ifeq ($$(findstring $(HOST_$(1)),arm aarch64 mips mipsel powerpc),) - # On OpenBSD, we need to pass the path of libstdc++.so to the linker - # (use path of libstdc++.a which is a known name for the same path) - ifeq ($(OSTYPE_$(1)),unknown-openbsd) - STDCPP_LIBDIR_RUSTFLAGS_$(1)= \ - -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \ - -print-file-name=lib$(CFG_STDCPP_NAME).a))" - else - STDCPP_LIBDIR_RUSTFLAGS_$(1)= - endif - # On Bitrig, we need the relocation model to be PIC for everything ifeq (,$(filter $(OSTYPE_$(1)),bitrig)) LLVM_MC_RELOCATION_MODEL="pic" diff --git a/mk/rt.mk b/mk/rt.mk index 8433b588e6ba4..9dbbcbebb979d 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -35,7 +35,7 @@ # that's per-target so you're allowed to conditionally add files based on the # target. ################################################################################ -NATIVE_LIBS := rust_builtin hoedown miniz rust_test_helpers +NATIVE_LIBS := hoedown miniz rust_test_helpers # $(1) is the target triple define NATIVE_LIBRARIES @@ -50,8 +50,6 @@ NATIVE_DEPS_hoedown_$(1) := hoedown/src/autolink.c \ hoedown/src/stack.c \ hoedown/src/version.c NATIVE_DEPS_miniz_$(1) = miniz.c -NATIVE_DEPS_rust_builtin_$(1) := rust_builtin.c \ - rust_android_dummy.c NATIVE_DEPS_rust_test_helpers_$(1) := rust_test_helpers.c ################################################################################ @@ -128,12 +126,25 @@ define DEF_THIRD_PARTY_TARGETS # $(1) is the target triple -ifeq ($$(CFG_WINDOWSY_$(1)), 1) - # This isn't necessarily a desired option, but it's harmless and works around - # what appears to be a mingw-w64 bug. +ifeq ($$(CFG_WINDOWSY_$(1)),1) + # A bit of history here, this used to be --enable-lazy-lock added in #14006 + # which was filed with jemalloc in jemalloc/jemalloc#83 which was also + # reported to MinGW: http://sourceforge.net/p/mingw-w64/bugs/395/ + # + # When updating jemalloc to 4.0, however, it was found that binaries would + # exit with the status code STATUS_RESOURCE_NOT_OWNED indicating that a thread + # was unlocking a mutex it never locked. Disabling this "lazy lock" option + # seems to fix the issue, but it was enabled by default for MinGW targets in + # 13473c7 for jemalloc. + # + # As a result of all that, force disabling lazy lock on Windows, and after + # reading some code it at least *appears* that the initialization of mutexes + # is otherwise ok in jemalloc, so shouldn't cause problems hopefully... # - # https://sourceforge.net/p/mingw-w64/bugs/395/ - JEMALLOC_ARGS_$(1) := --enable-lazy-lock + # tl;dr: make windows behave like other platforms by disabling lazy locking, + # but requires passing an option due to a historical default with + # jemalloc. + JEMALLOC_ARGS_$(1) := --disable-lazy-lock else ifeq ($(OSTYPE_$(1)), apple-ios) JEMALLOC_ARGS_$(1) := --disable-tls else ifeq ($(findstring android, $(OSTYPE_$(1))), android) diff --git a/mk/target.mk b/mk/target.mk index 9d5e633c3c6c1..f90b09479c985 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -95,7 +95,6 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \ $$(RUSTFLAGS_$(4)) \ $$(RUSTFLAGS$(1)_$(4)) \ $$(RUSTFLAGS$(1)_$(4)_T_$(2)) \ - $$(STDCPP_LIBDIR_RUSTFLAGS_$(2)) \ --out-dir $$(@D) \ -C extra-filename=-$$(CFG_FILENAME_EXTRA) \ $$< @@ -130,7 +129,6 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \ | $$(TBIN$(1)_T_$(2)_H_$(3))/ @$$(call E, rustc: $$@) $$(STAGE$(1)_T_$(2)_H_$(3)) \ - $$(STDCPP_LIBDIR_RUSTFLAGS_$(2)) \ $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \ -o $$@ $$< --cfg $(4) diff --git a/mk/tests.mk b/mk/tests.mk index bd7414a3bb639..0f30ff8711e5e 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -393,8 +393,7 @@ $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \ $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \ -L "$$(RT_OUTPUT_DIR_$(2))" \ $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \ - $$(RUSTFLAGS_$(4)) \ - $$(STDCPP_LIBDIR_RUSTFLAGS_$(2)) + $$(RUSTFLAGS_$(4)) endef @@ -664,9 +663,9 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \ --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \ --adb-path=$(CFG_ADB) \ --adb-test-dir=$(CFG_ADB_TEST_DIR) \ - --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3)) $$(STDCPP_LIBDIR_RUSTFLAGS_$(3))" \ + --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \ --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \ - --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2)) $$(STDCPP_LIBDIR_RUSTFLAGS_$(2))" \ + --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \ $$(CTEST_TESTARGS) ifdef CFG_VALGRIND_RPASS diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 57389bdc493cb..de41a8fe03b61 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -182,7 +182,7 @@ analysis is the only way to get at the value stored inside an `Option`. This means that you, as the programmer, must handle the case when an `Option` is `None` instead of `Some(t)`. -But wait, what about `unwrap`,which we used [`previously`](#code-unwrap-double)? +But wait, what about `unwrap`, which we used [previously](#code-unwrap-double)? There was no case analysis there! Instead, the case analysis was put inside the `unwrap` method for you. You could define it yourself if you want: diff --git a/src/doc/book/no-stdlib.md b/src/doc/book/no-stdlib.md index 3a4d4c306dc72..da84c6a337416 100644 --- a/src/doc/book/no-stdlib.md +++ b/src/doc/book/no-stdlib.md @@ -151,7 +151,7 @@ extern fn panic_fmt(args: &core::fmt::Arguments, # fn main() {} ``` -Note that there is one extra lang item here which differs from the examples +Note that there is one lang item here whose signature differs from the examples above, `panic_fmt`. This must be defined by consumers of libcore because the core library declares panics, but it does not define it. The `panic_fmt` lang item is this crate's definition of panic, and it must be guaranteed to diff --git a/src/doc/book/syntax-index.md b/src/doc/book/syntax-index.md index 528c0b537f396..01f06f718f857 100644 --- a/src/doc/book/syntax-index.md +++ b/src/doc/book/syntax-index.md @@ -234,5 +234,5 @@ [Traits (Multiple Trait Bounds)]: traits.html#multiple-trait-bounds [Traits]: traits.html [Unsafe]: unsafe.html -[Unsized Types (`?Sized`)]: unsized-types.html#?sized +[Unsized Types (`?Sized`)]: unsized-types.html#sized [Variable Bindings]: variable-bindings.html diff --git a/src/jemalloc b/src/jemalloc index e24a1a025a1f2..f84e30927284b 160000 --- a/src/jemalloc +++ b/src/jemalloc @@ -1 +1 @@ -Subproject commit e24a1a025a1f214e40eedafe3b9c7b1d69937922 +Subproject commit f84e30927284b0c500ed3eaf09e8e159da20ddaf diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 9479d47943eab..755e44899fc86 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -80,10 +80,8 @@ use core::mem::{align_of_val, size_of_val}; use core::intrinsics::abort; use core::mem; use core::ops::Deref; -#[cfg(not(stage0))] use core::ops::CoerceUnsized; use core::ptr::{self, Shared}; -#[cfg(not(stage0))] use core::marker::Unsize; use core::hash::{Hash, Hasher}; use core::{usize, isize}; @@ -135,8 +133,6 @@ unsafe impl Send for Arc {} #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Sync for Arc {} -// remove cfg after new snapshot -#[cfg(not(stage0))] #[unstable(feature = "coerce_unsized", issue = "27732")] impl, U: ?Sized> CoerceUnsized> for Arc {} @@ -157,8 +153,6 @@ unsafe impl Send for Weak {} #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Sync for Weak {} -// remove cfg after new snapshot -#[cfg(not(stage0))] #[unstable(feature = "coerce_unsized", issue = "27732")] impl, U: ?Sized> CoerceUnsized> for Weak {} diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index f665b1e19241c..93b84cdedd4cd 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -56,11 +56,8 @@ //! The [`heap`](heap/index.html) module defines the low-level interface to the //! default global allocator. It is not compatible with the libc allocator API. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "alloc"] #![crate_type = "rlib"] -#![cfg_attr(stage0, staged_api)] #![allow(unused_attributes)] #![unstable(feature = "alloc", reason = "this library is unlikely to be stabilized in its current \ @@ -72,11 +69,8 @@ issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] #![no_std] -#![cfg_attr(not(stage0), needs_allocator)] +#![needs_allocator] -#![cfg_attr(stage0, feature(rustc_attrs))] -#![cfg_attr(stage0, feature(no_std))] -#![cfg_attr(stage0, allow(unused_attributes))] #![feature(allocator)] #![feature(box_syntax)] #![feature(coerce_unsized)] @@ -84,7 +78,6 @@ #![feature(custom_attribute)] #![feature(fundamental)] #![feature(lang_items)] -#![feature(nonzero)] #![feature(num_bits_bytes)] #![feature(optin_builtin_traits)] #![feature(placement_in_syntax)] @@ -95,23 +88,15 @@ #![feature(unboxed_closures)] #![feature(unique)] #![feature(unsafe_no_drop_flag, filling_drop)] -// SNAP 1af31d4 -#![allow(unused_features)] -// SNAP 1af31d4 -#![allow(unused_attributes)] #![feature(dropck_parametricity)] #![feature(unsize)] #![feature(drop_in_place)] #![feature(fn_traits)] -#![cfg_attr(stage0, feature(alloc_system))] -#![cfg_attr(not(stage0), feature(needs_allocator))] +#![feature(needs_allocator)] #![cfg_attr(test, feature(test, rustc_private, box_heap))] -#[cfg(stage0)] -extern crate alloc_system; - // Allow testing this library #[cfg(test)] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 8f00605d33b37..52f035b67bdc9 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -162,11 +162,9 @@ use core::fmt; use core::hash::{Hasher, Hash}; use core::intrinsics::{assume, abort}; use core::marker; -#[cfg(not(stage0))] use core::marker::Unsize; use core::mem::{self, align_of_val, size_of_val, forget}; use core::ops::Deref; -#[cfg(not(stage0))] use core::ops::CoerceUnsized; use core::ptr::{self, Shared}; use core::convert::From; @@ -196,8 +194,6 @@ impl !marker::Send for Rc {} #[stable(feature = "rust1", since = "1.0.0")] impl !marker::Sync for Rc {} -// remove cfg after new snapshot -#[cfg(not(stage0))] #[unstable(feature = "coerce_unsized", issue = "27732")] impl, U: ?Sized> CoerceUnsized> for Rc {} @@ -723,8 +719,6 @@ impl !marker::Send for Weak {} #[stable(feature = "rust1", since = "1.0.0")] impl !marker::Sync for Weak {} -// remove cfg after new snapshot -#[cfg(not(stage0))] #[unstable(feature = "coerce_unsized", issue = "27732")] impl, U: ?Sized> CoerceUnsized> for Weak {} diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs index ec6c6ae31c17e..eaaa9391d3115 100644 --- a/src/liballoc_jemalloc/lib.rs +++ b/src/liballoc_jemalloc/lib.rs @@ -8,13 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "alloc_jemalloc"] #![crate_type = "rlib"] -#![cfg_attr(stage0, staged_api)] #![no_std] -#![cfg_attr(not(stage0), allocator)] -#![cfg_attr(stage0, allow(improper_ctypes))] +#![allocator] #![unstable(feature = "alloc_jemalloc", reason = "this library is unlikely to be stabilized in its current \ form or name", @@ -22,7 +19,6 @@ #![feature(allocator)] #![feature(libc)] #![feature(staged_api)] -#![cfg_attr(stage0, feature(no_std))] extern crate libc; @@ -112,3 +108,14 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { let flags = align_to_flags(align); unsafe { je_nallocx(size as size_t, flags) as usize } } + +// These symbols are used by jemalloc on android but the really old android +// we're building on doesn't have them defined, so just make sure the symbols +// are available. +#[no_mangle] +#[cfg(target_os = "android")] +pub extern fn pthread_atfork(_prefork: *mut u8, + _postfork_parent: *mut u8, + _postfork_child: *mut u8) -> i32 { + 0 +} diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index a6e89d5d00cb8..fccc024603ebd 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -8,13 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "alloc_system"] #![crate_type = "rlib"] -#![cfg_attr(stage0, staged_api)] #![no_std] -#![cfg_attr(not(stage0), allocator)] -#![cfg_attr(stage0, allow(improper_ctypes))] +#![allocator] #![unstable(feature = "alloc_system", reason = "this library is unlikely to be stabilized in its current \ form or name", @@ -22,7 +19,6 @@ #![feature(allocator)] #![feature(libc)] #![feature(staged_api)] -#![cfg_attr(stage0, feature(no_std))] extern crate libc; diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 7871135e9c214..b5107e411e851 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -19,11 +19,8 @@ //! arena but can only hold objects of a single type, and `Arena`, which is a //! more complex, slower arena which can hold objects of any type. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "arena"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -42,11 +39,6 @@ #![feature(dropck_parametricity)] #![cfg_attr(test, feature(test))] -// SNAP 1af31d4 -#![allow(unused_features)] -// SNAP 1af31d4 -#![allow(unused_attributes)] - extern crate alloc; use std::cell::{Cell, RefCell}; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index a7797d4b0d047..000ec4f0f6610 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -13,10 +13,7 @@ //! See [std::collections](../std/collections) for a detailed discussion of //! collections in Rust. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "collections"] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![unstable(feature = "collections", reason = "library is unlikely to be stabilized with the current \ @@ -32,17 +29,14 @@ #![allow(trivial_casts)] #![cfg_attr(test, allow(deprecated))] // rand -// SNAP 1af31d4 -#![allow(unused_features)] -// SNAP 1af31d4 -#![allow(unused_attributes)] - -#![cfg_attr(stage0, feature(rustc_attrs))] -#![cfg_attr(stage0, allow(unused_attributes))] #![feature(alloc)] #![feature(box_patterns)] #![feature(box_syntax)] +#![feature(clone_from_slice)] #![feature(core_intrinsics)] +#![feature(decode_utf16)] +#![feature(drop_in_place)] +#![feature(dropck_parametricity)] #![feature(fmt_internals)] #![feature(fmt_radix)] #![feature(heap_api)] @@ -53,7 +47,6 @@ #![feature(oom)] #![feature(pattern)] #![feature(ptr_as_ref)] -#![feature(ref_slice)] #![feature(slice_bytes)] #![feature(slice_patterns)] #![feature(staged_api)] @@ -62,14 +55,9 @@ #![feature(unboxed_closures)] #![feature(unicode)] #![feature(unique)] -#![feature(dropck_parametricity)] #![feature(unsafe_no_drop_flag, filling_drop)] -#![feature(decode_utf16)] -#![feature(drop_in_place)] -#![feature(clone_from_slice)] #![cfg_attr(test, feature(clone_from_slice, rand, test))] -#![cfg_attr(stage0, feature(no_std))] #![no_std] extern crate rustc_unicode; diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index a094bcd0192d2..568c4e143e04b 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -512,164 +512,32 @@ extern "rust-intrinsic" { /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero. pub fn roundf64(x: f64) -> f64; - /// Returns the number of bits set in a `u8`. - #[cfg(stage0)] - pub fn ctpop8(x: u8) -> u8; - /// Returns the number of bits set in a `u16`. - #[cfg(stage0)] - pub fn ctpop16(x: u16) -> u16; - /// Returns the number of bits set in a `u32`. - #[cfg(stage0)] - pub fn ctpop32(x: u32) -> u32; - /// Returns the number of bits set in a `u64`. - #[cfg(stage0)] - pub fn ctpop64(x: u64) -> u64; /// Returns the number of bits set in an integer type `T` - #[cfg(not(stage0))] pub fn ctpop(x: T) -> T; - /// Returns the number of leading bits unset in a `u8`. - #[cfg(stage0)] - pub fn ctlz8(x: u8) -> u8; - /// Returns the number of leading bits unset in a `u16`. - #[cfg(stage0)] - pub fn ctlz16(x: u16) -> u16; - /// Returns the number of leading bits unset in a `u32`. - #[cfg(stage0)] - pub fn ctlz32(x: u32) -> u32; - /// Returns the number of leading bits unset in a `u64`. - #[cfg(stage0)] - pub fn ctlz64(x: u64) -> u64; /// Returns the number of leading bits unset in an integer type `T` - #[cfg(not(stage0))] pub fn ctlz(x: T) -> T; - /// Returns the number of trailing bits unset in a `u8`. - #[cfg(stage0)] - pub fn cttz8(x: u8) -> u8; - /// Returns the number of trailing bits unset in a `u16`. - #[cfg(stage0)] - pub fn cttz16(x: u16) -> u16; - /// Returns the number of trailing bits unset in a `u32`. - #[cfg(stage0)] - pub fn cttz32(x: u32) -> u32; - /// Returns the number of trailing bits unset in a `u64`. - #[cfg(stage0)] - pub fn cttz64(x: u64) -> u64; /// Returns the number of trailing bits unset in an integer type `T` - #[cfg(not(stage0))] pub fn cttz(x: T) -> T; - /// Reverses the bytes in a `u16`. - #[cfg(stage0)] - pub fn bswap16(x: u16) -> u16; - /// Reverses the bytes in a `u32`. - #[cfg(stage0)] - pub fn bswap32(x: u32) -> u32; - /// Reverses the bytes in a `u64`. - #[cfg(stage0)] - pub fn bswap64(x: u64) -> u64; /// Reverses the bytes in an integer type `T`. - #[cfg(not(stage0))] pub fn bswap(x: T) -> T; - /// Performs checked `i8` addition. - #[cfg(stage0)] - pub fn i8_add_with_overflow(x: i8, y: i8) -> (i8, bool); - /// Performs checked `i16` addition. - #[cfg(stage0)] - pub fn i16_add_with_overflow(x: i16, y: i16) -> (i16, bool); - /// Performs checked `i32` addition. - #[cfg(stage0)] - pub fn i32_add_with_overflow(x: i32, y: i32) -> (i32, bool); - /// Performs checked `i64` addition. - #[cfg(stage0)] - pub fn i64_add_with_overflow(x: i64, y: i64) -> (i64, bool); - - /// Performs checked `u8` addition. - #[cfg(stage0)] - pub fn u8_add_with_overflow(x: u8, y: u8) -> (u8, bool); - /// Performs checked `u16` addition. - #[cfg(stage0)] - pub fn u16_add_with_overflow(x: u16, y: u16) -> (u16, bool); - /// Performs checked `u32` addition. - #[cfg(stage0)] - pub fn u32_add_with_overflow(x: u32, y: u32) -> (u32, bool); - /// Performs checked `u64` addition. - #[cfg(stage0)] - pub fn u64_add_with_overflow(x: u64, y: u64) -> (u64, bool); - /// Performs checked integer addition. - #[cfg(not(stage0))] pub fn add_with_overflow(x: T, y: T) -> (T, bool); - /// Performs checked `i8` subtraction. - #[cfg(stage0)] - pub fn i8_sub_with_overflow(x: i8, y: i8) -> (i8, bool); - /// Performs checked `i16` subtraction. - #[cfg(stage0)] - pub fn i16_sub_with_overflow(x: i16, y: i16) -> (i16, bool); - /// Performs checked `i32` subtraction. - #[cfg(stage0)] - pub fn i32_sub_with_overflow(x: i32, y: i32) -> (i32, bool); - /// Performs checked `i64` subtraction. - #[cfg(stage0)] - pub fn i64_sub_with_overflow(x: i64, y: i64) -> (i64, bool); - - /// Performs checked `u8` subtraction. - #[cfg(stage0)] - pub fn u8_sub_with_overflow(x: u8, y: u8) -> (u8, bool); - /// Performs checked `u16` subtraction. - #[cfg(stage0)] - pub fn u16_sub_with_overflow(x: u16, y: u16) -> (u16, bool); - /// Performs checked `u32` subtraction. - #[cfg(stage0)] - pub fn u32_sub_with_overflow(x: u32, y: u32) -> (u32, bool); - /// Performs checked `u64` subtraction. - #[cfg(stage0)] - pub fn u64_sub_with_overflow(x: u64, y: u64) -> (u64, bool); - /// Performs checked integer subtraction - #[cfg(not(stage0))] pub fn sub_with_overflow(x: T, y: T) -> (T, bool); - /// Performs checked `i8` multiplication. - #[cfg(stage0)] - pub fn i8_mul_with_overflow(x: i8, y: i8) -> (i8, bool); - /// Performs checked `i16` multiplication. - #[cfg(stage0)] - pub fn i16_mul_with_overflow(x: i16, y: i16) -> (i16, bool); - /// Performs checked `i32` multiplication. - #[cfg(stage0)] - pub fn i32_mul_with_overflow(x: i32, y: i32) -> (i32, bool); - /// Performs checked `i64` multiplication. - #[cfg(stage0)] - pub fn i64_mul_with_overflow(x: i64, y: i64) -> (i64, bool); - - /// Performs checked `u8` multiplication. - #[cfg(stage0)] - pub fn u8_mul_with_overflow(x: u8, y: u8) -> (u8, bool); - /// Performs checked `u16` multiplication. - #[cfg(stage0)] - pub fn u16_mul_with_overflow(x: u16, y: u16) -> (u16, bool); - /// Performs checked `u32` multiplication. - #[cfg(stage0)] - pub fn u32_mul_with_overflow(x: u32, y: u32) -> (u32, bool); - /// Performs checked `u64` multiplication. - #[cfg(stage0)] - pub fn u64_mul_with_overflow(x: u64, y: u64) -> (u64, bool); - /// Performs checked integer multiplication - #[cfg(not(stage0))] pub fn mul_with_overflow(x: T, y: T) -> (T, bool); /// Performs an unchecked division, resulting in undefined behavior /// where y = 0 or x = `T::min_value()` and y = -1 - #[cfg(not(stage0))] pub fn unchecked_div(x: T, y: T) -> T; /// Returns the remainder of an unchecked division, resulting in /// undefined behavior where y = 0 or x = `T::min_value()` and y = -1 - #[cfg(not(stage0))] pub fn unchecked_rem(x: T, y: T) -> T; /// Returns (a + b) mod 2^N, where N is the width of T in bits. diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index cde86230d7509..e8803976937d2 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -43,11 +43,8 @@ // Since libcore defines many fundamental lang items, all tests live in a // separate crate, libcoretest, to avoid bizarre issues. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "core"] #![stable(feature = "core", since = "1.6.0")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", @@ -60,8 +57,6 @@ #![no_core] #![deny(missing_docs)] -#![cfg_attr(stage0, feature(rustc_attrs))] -#![cfg_attr(stage0, allow(unused_attributes))] #![feature(allow_internal_unstable)] #![feature(associated_type_defaults)] #![feature(concat_idents)] @@ -75,8 +70,7 @@ #![feature(optin_builtin_traits)] #![feature(reflect)] #![feature(unwind_attributes)] -#![cfg_attr(stage0, feature(simd))] -#![cfg_attr(not(stage0), feature(repr_simd, platform_intrinsics))] +#![feature(repr_simd, platform_intrinsics)] #![feature(staged_api)] #![feature(unboxed_closures)] diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index c4ca3fa384e96..92bbc4efb7cc1 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -38,31 +38,13 @@ unsafe impl Zeroable for u64 {} #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)] pub struct NonZero(T); -#[cfg(stage0)] -macro_rules! nonzero_new { - () => ( - /// Creates an instance of NonZero with the provided value. - /// You must indeed ensure that the value is actually "non-zero". - #[inline(always)] - pub unsafe fn new(inner: T) -> NonZero { - NonZero(inner) - } - ) -} -#[cfg(not(stage0))] -macro_rules! nonzero_new { - () => ( - /// Creates an instance of NonZero with the provided value. - /// You must indeed ensure that the value is actually "non-zero". - #[inline(always)] - pub const unsafe fn new(inner: T) -> NonZero { - NonZero(inner) - } - ) -} - impl NonZero { - nonzero_new!{} + /// Creates an instance of NonZero with the provided value. + /// You must indeed ensure that the value is actually "non-zero". + #[inline(always)] + pub const unsafe fn new(inner: T) -> NonZero { + NonZero(inner) + } } impl Deref for NonZero { diff --git a/src/libcore/num/bignum.rs b/src/libcore/num/bignum.rs index 5d15ada4e7509..66c6deb361564 100644 --- a/src/libcore/num/bignum.rs +++ b/src/libcore/num/bignum.rs @@ -55,15 +55,6 @@ macro_rules! impl_full_ops { ($($ty:ty: add($addfn:path), mul/div($bigty:ident);)*) => ( $( impl FullOps for $ty { - #[cfg(stage0)] - fn full_add(self, other: $ty, carry: bool) -> (bool, $ty) { - // this cannot overflow, the output is between 0 and 2*2^nbits - 1 - // FIXME will LLVM optimize this into ADC or similar??? - let (v, carry1) = unsafe { $addfn(self, other) }; - let (v, carry2) = unsafe { $addfn(v, if carry {1} else {0}) }; - (carry1 || carry2, v) - } - #[cfg(not(stage0))] fn full_add(self, other: $ty, carry: bool) -> (bool, $ty) { // this cannot overflow, the output is between 0 and 2*2^nbits - 1 // FIXME will LLVM optimize this into ADC or similar??? diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 8abb12706a5e3..f180a513b869d 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -115,11 +115,6 @@ macro_rules! zero_one_impl_float { } zero_one_impl_float! { f32 f64 } -// Just for stage0; a byte swap on a byte is a no-op -// Delete this once it becomes unused -#[cfg(stage0)] -unsafe fn bswap8(x: u8) -> u8 { x } - macro_rules! checked_op { ($U:ty, $op:path, $x:expr, $y:expr) => {{ let (result, overflowed) = unsafe { $op($x as $U, $y as $U) }; @@ -785,15 +780,6 @@ macro_rules! int_impl { } #[lang = "i8"] -#[cfg(stage0)] -impl i8 { - int_impl! { i8, u8, 8, - intrinsics::i8_add_with_overflow, - intrinsics::i8_sub_with_overflow, - intrinsics::i8_mul_with_overflow } -} -#[lang = "i8"] -#[cfg(not(stage0))] impl i8 { int_impl! { i8, u8, 8, intrinsics::add_with_overflow, @@ -802,15 +788,6 @@ impl i8 { } #[lang = "i16"] -#[cfg(stage0)] -impl i16 { - int_impl! { i16, u16, 16, - intrinsics::i16_add_with_overflow, - intrinsics::i16_sub_with_overflow, - intrinsics::i16_mul_with_overflow } -} -#[lang = "i16"] -#[cfg(not(stage0))] impl i16 { int_impl! { i16, u16, 16, intrinsics::add_with_overflow, @@ -819,15 +796,6 @@ impl i16 { } #[lang = "i32"] -#[cfg(stage0)] -impl i32 { - int_impl! { i32, u32, 32, - intrinsics::i32_add_with_overflow, - intrinsics::i32_sub_with_overflow, - intrinsics::i32_mul_with_overflow } -} -#[lang = "i32"] -#[cfg(not(stage0))] impl i32 { int_impl! { i32, u32, 32, intrinsics::add_with_overflow, @@ -836,15 +804,6 @@ impl i32 { } #[lang = "i64"] -#[cfg(stage0)] -impl i64 { - int_impl! { i64, u64, 64, - intrinsics::i64_add_with_overflow, - intrinsics::i64_sub_with_overflow, - intrinsics::i64_mul_with_overflow } -} -#[lang = "i64"] -#[cfg(not(stage0))] impl i64 { int_impl! { i64, u64, 64, intrinsics::add_with_overflow, @@ -854,16 +813,6 @@ impl i64 { #[cfg(target_pointer_width = "32")] #[lang = "isize"] -#[cfg(stage0)] -impl isize { - int_impl! { i32, u32, 32, - intrinsics::i32_add_with_overflow, - intrinsics::i32_sub_with_overflow, - intrinsics::i32_mul_with_overflow } -} -#[cfg(target_pointer_width = "32")] -#[lang = "isize"] -#[cfg(not(stage0))] impl isize { int_impl! { i32, u32, 32, intrinsics::add_with_overflow, @@ -873,16 +822,6 @@ impl isize { #[cfg(target_pointer_width = "64")] #[lang = "isize"] -#[cfg(stage0)] -impl isize { - int_impl! { i64, u64, 64, - intrinsics::i64_add_with_overflow, - intrinsics::i64_sub_with_overflow, - intrinsics::i64_mul_with_overflow } -} -#[cfg(target_pointer_width = "64")] -#[lang = "isize"] -#[cfg(not(stage0))] impl isize { int_impl! { i64, u64, 64, intrinsics::add_with_overflow, @@ -980,25 +919,6 @@ macro_rules! uint_impl { unsafe { $ctlz(self as $ActualT) as u32 } } - #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(stage0)] - #[inline] - pub fn trailing_zeros(self) -> u32 { - // As of LLVM 3.6 the codegen for the zero-safe cttz8 intrinsic - // emits two conditional moves on x86_64. By promoting the value to - // u16 and setting bit 8, we get better code without any conditional - // operations. - // FIXME: There's a LLVM patch (http://reviews.llvm.org/D9284) - // pending, remove this workaround once LLVM generates better code - // for cttz8. - unsafe { - if $BITS == 8 { - intrinsics::cttz16(self as u16 | 0x100) as u32 - } else { - $cttz(self as $ActualT) as u32 - } - } - } /// Returns the number of trailing zeros in the binary representation /// of `self`. /// @@ -1012,7 +932,6 @@ macro_rules! uint_impl { /// assert_eq!(n.trailing_zeros(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(stage0))] #[inline] pub fn trailing_zeros(self) -> u32 { // As of LLVM 3.6 the codegen for the zero-safe cttz8 intrinsic @@ -1563,19 +1482,6 @@ macro_rules! uint_impl { } #[lang = "u8"] -#[cfg(stage0)] -impl u8 { - uint_impl! { u8, 8, - intrinsics::ctpop8, - intrinsics::ctlz8, - intrinsics::cttz8, - bswap8, - intrinsics::u8_add_with_overflow, - intrinsics::u8_sub_with_overflow, - intrinsics::u8_mul_with_overflow } -} -#[lang = "u8"] -#[cfg(not(stage0))] impl u8 { uint_impl! { u8, 8, intrinsics::ctpop, @@ -1588,19 +1494,6 @@ impl u8 { } #[lang = "u16"] -#[cfg(stage0)] -impl u16 { - uint_impl! { u16, 16, - intrinsics::ctpop16, - intrinsics::ctlz16, - intrinsics::cttz16, - intrinsics::bswap16, - intrinsics::u16_add_with_overflow, - intrinsics::u16_sub_with_overflow, - intrinsics::u16_mul_with_overflow } -} -#[lang = "u16"] -#[cfg(not(stage0))] impl u16 { uint_impl! { u16, 16, intrinsics::ctpop, @@ -1613,19 +1506,6 @@ impl u16 { } #[lang = "u32"] -#[cfg(stage0)] -impl u32 { - uint_impl! { u32, 32, - intrinsics::ctpop32, - intrinsics::ctlz32, - intrinsics::cttz32, - intrinsics::bswap32, - intrinsics::u32_add_with_overflow, - intrinsics::u32_sub_with_overflow, - intrinsics::u32_mul_with_overflow } -} -#[lang = "u32"] -#[cfg(not(stage0))] impl u32 { uint_impl! { u32, 32, intrinsics::ctpop, @@ -1638,19 +1518,6 @@ impl u32 { } #[lang = "u64"] -#[cfg(stage0)] -impl u64 { - uint_impl! { u64, 64, - intrinsics::ctpop64, - intrinsics::ctlz64, - intrinsics::cttz64, - intrinsics::bswap64, - intrinsics::u64_add_with_overflow, - intrinsics::u64_sub_with_overflow, - intrinsics::u64_mul_with_overflow } -} -#[lang = "u64"] -#[cfg(not(stage0))] impl u64 { uint_impl! { u64, 64, intrinsics::ctpop, @@ -1664,20 +1531,6 @@ impl u64 { #[cfg(target_pointer_width = "32")] #[lang = "usize"] -#[cfg(stage0)] -impl usize { - uint_impl! { u32, 32, - intrinsics::ctpop32, - intrinsics::ctlz32, - intrinsics::cttz32, - intrinsics::bswap32, - intrinsics::u32_add_with_overflow, - intrinsics::u32_sub_with_overflow, - intrinsics::u32_mul_with_overflow } -} -#[cfg(target_pointer_width = "32")] -#[lang = "usize"] -#[cfg(not(stage0))] impl usize { uint_impl! { u32, 32, intrinsics::ctpop, @@ -1691,20 +1544,6 @@ impl usize { #[cfg(target_pointer_width = "64")] #[lang = "usize"] -#[cfg(stage0)] -impl usize { - uint_impl! { u64, 64, - intrinsics::ctpop64, - intrinsics::ctlz64, - intrinsics::cttz64, - intrinsics::bswap64, - intrinsics::u64_add_with_overflow, - intrinsics::u64_sub_with_overflow, - intrinsics::u64_mul_with_overflow } -} -#[cfg(target_pointer_width = "64")] -#[lang = "usize"] -#[cfg(not(stage0))] impl usize { uint_impl! { u64, 64, intrinsics::ctpop, diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 88f71e63da682..a7d5fcafd5603 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -12,30 +12,7 @@ #![unstable(feature = "wrapping", reason = "may be removed or relocated", issue = "27755")] -#[cfg(stage0)] -pub use intrinsics::{ - u8_add_with_overflow, i8_add_with_overflow, - u16_add_with_overflow, i16_add_with_overflow, - u32_add_with_overflow, i32_add_with_overflow, - u64_add_with_overflow, i64_add_with_overflow, - - u8_sub_with_overflow, i8_sub_with_overflow, - u16_sub_with_overflow, i16_sub_with_overflow, - u32_sub_with_overflow, i32_sub_with_overflow, - u64_sub_with_overflow, i64_sub_with_overflow, - - u8_mul_with_overflow, i8_mul_with_overflow, - u16_mul_with_overflow, i16_mul_with_overflow, - u32_mul_with_overflow, i32_mul_with_overflow, - u64_mul_with_overflow, i64_mul_with_overflow, -}; - -#[cfg(not(stage0))] -pub use intrinsics::{ - add_with_overflow, - sub_with_overflow, - mul_with_overflow, -}; +pub use intrinsics::{add_with_overflow, sub_with_overflow, mul_with_overflow}; use super::Wrapping; @@ -203,42 +180,18 @@ macro_rules! signed_overflowing_impl { ($($t:ident)*) => ($( impl OverflowingOps for $t { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _add_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: $t) -> ($t, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _sub_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: $t) -> ($t, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _mul_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: $t) -> ($t, bool) { unsafe { mul_with_overflow(self, rhs) @@ -289,42 +242,18 @@ macro_rules! unsigned_overflowing_impl { ($($t:ident)*) => ($( impl OverflowingOps for $t { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _add_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: $t) -> ($t, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _sub_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: $t) -> ($t, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: $t) -> ($t, bool) { - unsafe { - concat_idents!($t, _mul_with_overflow)(self, rhs) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: $t) -> ($t, bool) { unsafe { mul_with_overflow(self, rhs) @@ -365,45 +294,18 @@ unsigned_overflowing_impl! { u8 u16 u32 u64 } #[cfg(target_pointer_width = "64")] impl OverflowingOps for usize { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u64_add_with_overflow(self as u64, rhs as u64); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: usize) -> (usize, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u64_sub_with_overflow(self as u64, rhs as u64); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: usize) -> (usize, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u64_mul_with_overflow(self as u64, rhs as u64); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: usize) -> (usize, bool) { unsafe { mul_with_overflow(self, rhs) @@ -439,45 +341,18 @@ impl OverflowingOps for usize { #[cfg(target_pointer_width = "32")] impl OverflowingOps for usize { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u32_add_with_overflow(self as u32, rhs as u32); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: usize) -> (usize, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u32_sub_with_overflow(self as u32, rhs as u32); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: usize) -> (usize, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: usize) -> (usize, bool) { - unsafe { - let res = u32_mul_with_overflow(self as u32, rhs as u32); - (res.0 as usize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: usize) -> (usize, bool) { unsafe { mul_with_overflow(self, rhs) @@ -513,45 +388,18 @@ impl OverflowingOps for usize { #[cfg(target_pointer_width = "64")] impl OverflowingOps for isize { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i64_add_with_overflow(self as i64, rhs as i64); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: isize) -> (isize, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i64_sub_with_overflow(self as i64, rhs as i64); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: isize) -> (isize, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i64_mul_with_overflow(self as i64, rhs as i64); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: isize) -> (isize, bool) { unsafe { mul_with_overflow(self, rhs) @@ -587,45 +435,18 @@ impl OverflowingOps for isize { #[cfg(target_pointer_width = "32")] impl OverflowingOps for isize { #[inline(always)] - #[cfg(stage0)] - fn overflowing_add(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i32_add_with_overflow(self as i32, rhs as i32); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_add(self, rhs: isize) -> (isize, bool) { unsafe { add_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_sub(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i32_sub_with_overflow(self as i32, rhs as i32); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_sub(self, rhs: isize) -> (isize, bool) { unsafe { sub_with_overflow(self, rhs) } } #[inline(always)] - #[cfg(stage0)] - fn overflowing_mul(self, rhs: isize) -> (isize, bool) { - unsafe { - let res = i32_mul_with_overflow(self as i32, rhs as i32); - (res.0 as isize, res.1) - } - } - #[inline(always)] - #[cfg(not(stage0))] fn overflowing_mul(self, rhs: isize) -> (isize, bool) { unsafe { mul_with_overflow(self, rhs) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index dd4702376d43c..edbe64db08086 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -441,7 +441,6 @@ macro_rules! rem_impl_integer { rem_impl_integer! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 } -#[cfg(not(stage0))] macro_rules! rem_impl_float { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] @@ -456,48 +455,8 @@ macro_rules! rem_impl_float { )*) } -#[cfg(not(stage0))] rem_impl_float! { f32 f64 } -#[stable(feature = "rust1", since = "1.0.0")] -#[cfg(stage0)] -impl Rem for f32 { - type Output = f32; - - // The builtin f32 rem operator is broken when targeting - // MSVC; see comment in std::f32::floor. - // FIXME: See also #27859. - #[inline] - #[cfg(target_env = "msvc")] - fn rem(self, other: f32) -> f32 { - (self as f64).rem(other as f64) as f32 - } - - #[inline] - #[cfg(not(target_env = "msvc"))] - fn rem(self, other: f32) -> f32 { - extern { fn fmodf(a: f32, b: f32) -> f32; } - unsafe { fmodf(self, other) } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -#[cfg(stage0)] -impl Rem for f64 { - type Output = f64; - - #[inline] - fn rem(self, other: f64) -> f64 { - extern { fn fmod(a: f64, b: f64) -> f64; } - unsafe { fmod(self, other) } - } -} - -#[cfg(stage0)] -forward_ref_binop! { impl Rem, rem for f64, f64 } -#[cfg(stage0)] -forward_ref_binop! { impl Rem, rem for f32, f32 } - /// The `Neg` trait is used to specify the functionality of unary `-`. /// /// # Examples @@ -954,7 +913,6 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize } /// foo += Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "add_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait AddAssign { @@ -962,7 +920,6 @@ pub trait AddAssign { fn add_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! add_assign_impl { ($($t:ty)+) => ($( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -973,7 +930,6 @@ macro_rules! add_assign_impl { )+) } -#[cfg(not(stage0))] add_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `SubAssign` trait is used to specify the functionality of `-=`. @@ -1004,7 +960,6 @@ add_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// foo -= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "sub_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait SubAssign { @@ -1012,7 +967,6 @@ pub trait SubAssign { fn sub_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! sub_assign_impl { ($($t:ty)+) => ($( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1023,7 +977,6 @@ macro_rules! sub_assign_impl { )+) } -#[cfg(not(stage0))] sub_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `MulAssign` trait is used to specify the functionality of `*=`. @@ -1054,7 +1007,6 @@ sub_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// foo *= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "mul_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait MulAssign { @@ -1062,7 +1014,6 @@ pub trait MulAssign { fn mul_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! mul_assign_impl { ($($t:ty)+) => ($( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1073,7 +1024,6 @@ macro_rules! mul_assign_impl { )+) } -#[cfg(not(stage0))] mul_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `DivAssign` trait is used to specify the functionality of `/=`. @@ -1104,7 +1054,6 @@ mul_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// foo /= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "div_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait DivAssign { @@ -1112,7 +1061,6 @@ pub trait DivAssign { fn div_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! div_assign_impl { ($($t:ty)+) => ($( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1123,7 +1071,6 @@ macro_rules! div_assign_impl { )+) } -#[cfg(not(stage0))] div_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `RemAssign` trait is used to specify the functionality of `%=`. @@ -1154,7 +1101,6 @@ div_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// foo %= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "rem_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait RemAssign { @@ -1162,7 +1108,6 @@ pub trait RemAssign { fn rem_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! rem_assign_impl { ($($t:ty)+) => ($( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1173,7 +1118,6 @@ macro_rules! rem_assign_impl { )+) } -#[cfg(not(stage0))] rem_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `BitAndAssign` trait is used to specify the functionality of `&=`. @@ -1204,7 +1148,6 @@ rem_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// foo &= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "bitand_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait BitAndAssign { @@ -1212,7 +1155,6 @@ pub trait BitAndAssign { fn bitand_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! bitand_assign_impl { ($($t:ty)+) => ($( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1223,7 +1165,6 @@ macro_rules! bitand_assign_impl { )+) } -#[cfg(not(stage0))] bitand_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `BitOrAssign` trait is used to specify the functionality of `|=`. @@ -1254,7 +1195,6 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// foo |= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "bitor_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait BitOrAssign { @@ -1262,7 +1202,6 @@ pub trait BitOrAssign { fn bitor_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! bitor_assign_impl { ($($t:ty)+) => ($( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1273,7 +1212,6 @@ macro_rules! bitor_assign_impl { )+) } -#[cfg(not(stage0))] bitor_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `BitXorAssign` trait is used to specify the functionality of `^=`. @@ -1304,7 +1242,6 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// foo ^= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "bitxor_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait BitXorAssign { @@ -1312,7 +1249,6 @@ pub trait BitXorAssign { fn bitxor_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! bitxor_assign_impl { ($($t:ty)+) => ($( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1323,7 +1259,6 @@ macro_rules! bitxor_assign_impl { )+) } -#[cfg(not(stage0))] bitxor_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `ShlAssign` trait is used to specify the functionality of `<<=`. @@ -1354,7 +1289,6 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// foo <<= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "shl_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait ShlAssign { @@ -1362,7 +1296,6 @@ pub trait ShlAssign { fn shl_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! shl_assign_impl { ($t:ty, $f:ty) => ( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1375,7 +1308,6 @@ macro_rules! shl_assign_impl { ) } -#[cfg(not(stage0))] macro_rules! shl_assign_impl_all { ($($t:ty)*) => ($( shl_assign_impl! { $t, u8 } @@ -1392,7 +1324,6 @@ macro_rules! shl_assign_impl_all { )*) } -#[cfg(not(stage0))] shl_assign_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize } /// The `ShrAssign` trait is used to specify the functionality of `>>=`. @@ -1423,7 +1354,6 @@ shl_assign_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize } /// foo >>= Foo; /// } /// ``` -#[cfg(not(stage0))] #[lang = "shr_assign"] #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] pub trait ShrAssign { @@ -1431,7 +1361,6 @@ pub trait ShrAssign { fn shr_assign(&mut self, Rhs); } -#[cfg(not(stage0))] macro_rules! shr_assign_impl { ($t:ty, $f:ty) => ( #[unstable(feature = "op_assign_traits", reason = "recently added", issue = "28235")] @@ -1444,7 +1373,6 @@ macro_rules! shr_assign_impl { ) } -#[cfg(not(stage0))] macro_rules! shr_assign_impl_all { ($($t:ty)*) => ($( shr_assign_impl! { $t, u8 } @@ -1461,7 +1389,6 @@ macro_rules! shr_assign_impl_all { )*) } -#[cfg(not(stage0))] shr_assign_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize } /// The `Index` trait is used to specify the functionality of indexing operations diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 53ef9cd09026b..e1e7869d548db 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -499,28 +499,12 @@ unsafe impl Send for Unique { } #[unstable(feature = "unique", issue = "27730")] unsafe impl Sync for Unique { } -#[cfg(stage0)] -macro_rules! unique_new { - () => ( - /// Creates a new `Unique`. - pub unsafe fn new(ptr: *mut T) -> Unique { - Unique { pointer: NonZero::new(ptr), _marker: PhantomData } - } - ) -} -#[cfg(not(stage0))] -macro_rules! unique_new { - () => ( - /// Creates a new `Unique`. - pub const unsafe fn new(ptr: *mut T) -> Unique { - Unique { pointer: NonZero::new(ptr), _marker: PhantomData } - } - ) -} - #[unstable(feature = "unique", issue = "27730")] impl Unique { - unique_new!{} + /// Creates a new `Unique`. + pub const unsafe fn new(ptr: *mut T) -> Unique { + Unique { pointer: NonZero::new(ptr), _marker: PhantomData } + } /// Dereferences the content. pub unsafe fn get(&self) -> &T { @@ -533,7 +517,6 @@ impl Unique { } } -#[cfg(not(stage0))] // remove cfg after new snapshot #[unstable(feature = "unique", issue = "27730")] impl CoerceUnsized> for Unique where T: Unsize { } @@ -598,7 +581,6 @@ impl Clone for Shared { #[unstable(feature = "shared", issue = "27730")] impl Copy for Shared { } -#[cfg(not(stage0))] // remove cfg after new snapshot #[unstable(feature = "shared", issue = "27730")] impl CoerceUnsized> for Shared where T: Unsize { } diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 02810bf668a0a..a60a1c67e175d 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -14,11 +14,8 @@ //! [def]: https://en.wikipedia.org/wiki/DEFLATE //! [mz]: https://code.google.com/p/miniz/ -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "flate"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -30,7 +27,6 @@ #![feature(staged_api)] #![feature(unique)] #![cfg_attr(test, feature(rustc_private, rand, vec_push_all))] -#![cfg_attr(stage0, allow(improper_ctypes))] #[cfg(test)] #[macro_use] diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 6e185c674a698..7a229ad522227 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -14,11 +14,8 @@ //! Parsing does not happen at runtime: structures of `std::fmt::rt` are //! generated instead. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "fmt_macros"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 228ceb92da661..57ce53e73b025 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -77,14 +77,10 @@ //! } //! ``` - -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "getopts"] #![unstable(feature = "rustc_private", reason = "use the crates.io `getopts` library instead", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index c1bd188d3a286..b9fd5cc1910fc 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -271,12 +271,9 @@ //! //! * [DOT language](http://www.graphviz.org/doc/info/lang.html) -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "graphviz"] #![unstable(feature = "rustc_private", issue = "27812")] #![feature(staged_api)] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/liblibc b/src/liblibc index 4b9b07c71997d..e0c0bf439add6 160000 --- a/src/liblibc +++ b/src/liblibc @@ -1 +1 @@ -Subproject commit 4b9b07c71997da23d5d1e3035cd16a5855b94ecc +Subproject commit e0c0bf439add63a6a25a25ba47e4aec9547bf9af diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 404bbd902bfd8..dbd553acd68fc 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -156,13 +156,10 @@ //! they're turned off (just a load and an integer comparison). This also means that //! if logging is disabled, none of the components of the log will be executed. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "log"] #![unstable(feature = "rustc_private", reason = "use the crates.io `log` library instead", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 013efb129d850..06f4c8dfd20a8 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -16,8 +16,6 @@ //! is not recommended to use this library directly, but rather the official //! interface through `std::rand`. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rand"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", @@ -26,7 +24,6 @@ html_playground_url = "https://play.rust-lang.org/", test(attr(deny(warnings))))] #![no_std] -#![cfg_attr(stage0, staged_api)] #![unstable(feature = "rand", reason = "use `rand` from crates.io", issue = "27703")] @@ -37,7 +34,6 @@ #![feature(step_by)] #![feature(custom_attribute)] #![allow(unused_attributes)] -#![cfg_attr(stage0, feature(no_std))] #![cfg_attr(test, feature(test, rand, rustc_private, iter_order_deprecated))] diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 3c0c9951613e3..d8d6ea93f7569 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -111,11 +111,8 @@ //! //! First 0x20 tags are reserved by RBML; custom tags start at 0x20. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rbml"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 0890594f2b116..00d6237b85564 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -14,11 +14,8 @@ //! //! This API is completely unstable and subject to change. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index ff3e99d487c9e..0273d1a76e9a8 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -242,8 +242,6 @@ impl OverloadedCallType { // mem_categorization, it requires a TYPER, which is a type that // supplies types from the tree. After type checking is complete, you // can just use the tcx as the typer. -// -// FIXME(stage0): the :'t here is probably only important for stage0 pub struct ExprUseVisitor<'d, 't, 'a: 't, 'tcx:'a+'d> { typer: &'t infer::InferCtxt<'a, 'tcx>, mc: mc::MemCategorizationContext<'t, 'a, 'tcx>, diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index e33fe9570c024..b275480a6fc68 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -660,6 +660,9 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { "windows" | "unix" => ret.push(attr::mk_word_item(fam)), _ => (), } + if sess.target.target.options.has_elf_tls { + ret.push(attr::mk_word_item(InternedString::new("target_thread_local"))); + } if sess.opts.debug_assertions { ret.push(attr::mk_word_item(InternedString::new("debug_assertions"))); } diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 2a3d9cfa6b888..b5d259d9ac999 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -90,7 +90,6 @@ fn get_resident() -> Option { } #[cfg(windows)] -#[cfg_attr(stage0, allow(improper_ctypes))] fn get_resident() -> Option { type BOOL = i32; type DWORD = u32; diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 700cfb645bf05..844f4925bd274 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -21,11 +21,8 @@ //! one that doesn't; the one that doesn't might get decent parallel //! build speedups. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_back"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_back/target/aarch64_unknown_linux_gnu.rs b/src/librustc_back/target/aarch64_unknown_linux_gnu.rs index 51abab6609a86..21bfd87e412dd 100644 --- a/src/librustc_back/target/aarch64_unknown_linux_gnu.rs +++ b/src/librustc_back/target/aarch64_unknown_linux_gnu.rs @@ -11,7 +11,8 @@ use target::Target; pub fn target() -> Target { - let base = super::linux_base::opts(); + let mut base = super::linux_base::opts(); + base.has_elf_tls = false; Target { llvm_target: "aarch64-unknown-linux-gnu".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_back/target/apple_base.rs b/src/librustc_back/target/apple_base.rs index 8b75bb3941477..ffcb6f971ae25 100644 --- a/src/librustc_back/target/apple_base.rs +++ b/src/librustc_back/target/apple_base.rs @@ -8,10 +8,30 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::env; + use target::TargetOptions; -use std::default::Default; pub fn opts() -> TargetOptions { + // ELF TLS is only available in OSX 10.7+. If you try to compile for 10.6 + // either the linker will complain if it is used or the binary will end up + // segfaulting at runtime when run on 10.6. Rust by default supports OSX + // 10.7+, but there is a standard environment variable, + // MACOSX_DEPLOYMENT_TARGET, which is used to signal targeting older + // versions of OSX. For example compiling on 10.10 with + // MACOSX_DEPLOYMENT_TARGET set to 10.6 will cause the linker to generate + // warnings about the usage of ELF TLS. + // + // Here we detect what version is being requested, defaulting to 10.7. ELF + // TLS is flagged as enabled if it looks to be supported. + let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok(); + let version = deployment_target.as_ref().and_then(|s| { + let mut i = s.splitn(2, "."); + i.next().and_then(|a| i.next().map(|b| (a, b))) + }).and_then(|(a, b)| { + a.parse::().and_then(|a| b.parse::().map(|b| (a, b))).ok() + }).unwrap_or((10, 7)); + TargetOptions { // OSX has -dead_strip, which doesn't rely on ffunction_sections function_sections: false, @@ -25,6 +45,7 @@ pub fn opts() -> TargetOptions { archive_format: "bsd".to_string(), pre_link_args: Vec::new(), exe_allocation_crate: super::maybe_jemalloc(), + has_elf_tls: version >= (10, 7), .. Default::default() } } diff --git a/src/librustc_back/target/apple_ios_base.rs b/src/librustc_back/target/apple_ios_base.rs index 77030f5d76827..d182fd9605640 100644 --- a/src/librustc_back/target/apple_ios_base.rs +++ b/src/librustc_back/target/apple_ios_base.rs @@ -88,6 +88,7 @@ pub fn opts(arch: Arch) -> TargetOptions { dynamic_linking: false, executables: true, pre_link_args: pre_link_args(arch), + has_elf_tls: false, .. super::apple_base::opts() } } diff --git a/src/librustc_back/target/arm_linux_androideabi.rs b/src/librustc_back/target/arm_linux_androideabi.rs index 732f1a353a8bd..7776aaacd00b1 100644 --- a/src/librustc_back/target/arm_linux_androideabi.rs +++ b/src/librustc_back/target/arm_linux_androideabi.rs @@ -13,6 +13,7 @@ use target::Target; pub fn target() -> Target { let mut base = super::android_base::opts(); base.features = "+v7".to_string(); + base.has_elf_tls = false; Target { llvm_target: "arm-linux-androideabi".to_string(), diff --git a/src/librustc_back/target/linux_base.rs b/src/librustc_back/target/linux_base.rs index 6492fa5015970..0efcf73ee8680 100644 --- a/src/librustc_back/target/linux_base.rs +++ b/src/librustc_back/target/linux_base.rs @@ -30,6 +30,7 @@ pub fn opts() -> TargetOptions { position_independent_executables: true, archive_format: "gnu".to_string(), exe_allocation_crate: super::maybe_jemalloc(), + has_elf_tls: true, .. Default::default() } } diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index f259698a220e2..666903b4eed42 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -195,6 +195,10 @@ pub struct TargetOptions { /// Default crate for allocation symbols to link against pub lib_allocation_crate: String, pub exe_allocation_crate: String, + + /// Flag indicating whether ELF TLS (e.g. #[thread_local]) is available for + /// this target. + pub has_elf_tls: bool, } impl Default for TargetOptions { @@ -240,6 +244,7 @@ impl Default for TargetOptions { lib_allocation_crate: "alloc_system".to_string(), exe_allocation_crate: "alloc_system".to_string(), allow_asm: true, + has_elf_tls: false, } } } diff --git a/src/librustc_bitflags/lib.rs b/src/librustc_bitflags/lib.rs index 97816a2b2ae84..e2a929f58e14d 100644 --- a/src/librustc_bitflags/lib.rs +++ b/src/librustc_bitflags/lib.rs @@ -9,14 +9,10 @@ // except according to those terms. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_bitflags"] #![feature(associated_consts)] #![feature(staged_api)] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] -#![cfg_attr(stage0, feature(no_std))] #![no_std] #![unstable(feature = "rustc_private", issue = "27812")] diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index 27cd9530c9be3..0e1102bd77e02 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -8,11 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_borrowck"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 0ea7cfa3902fa..3bba7d651ad71 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -16,13 +16,10 @@ //! //! This API is completely unstable and subject to change. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_data_structures"] #![unstable(feature = "rustc_private", issue = "27812")] #![crate_type = "dylib"] #![crate_type = "rlib"] -#![cfg_attr(stage0, staged_api)] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://www.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 5f2548a550467..89299c0119975 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -606,7 +606,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, feature_gated_cfgs.sort(); feature_gated_cfgs.dedup(); for cfg in &feature_gated_cfgs { - cfg.check_and_emit(sess.diagnostic(), &features); + cfg.check_and_emit(sess.diagnostic(), &features, sess.codemap()); } }); diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 8cfaec62f4775..210b1a26c21f1 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -14,11 +14,8 @@ //! //! This API is completely unstable and subject to change. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_driver"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -32,7 +29,6 @@ #![feature(rustc_private)] #![feature(set_stdio)] #![feature(staged_api)] -#![feature(raw)] // remove after snapshot extern crate arena; extern crate flate; @@ -105,24 +101,6 @@ pub mod target_features; const BUG_REPORT_URL: &'static str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\ md#bug-reports"; -// SNAP 1af31d4 -// This is a terrible hack. Our stage0 is older than 1.4 and does not -// support DST coercions, so this function performs the corecion -// manually. This should go away. -pub fn cstore_to_cratestore(a: Rc) -> Rc CrateStore<'s>> -{ - use std::mem; - use std::raw::TraitObject; - unsafe { - let TraitObject { vtable, .. } = - mem::transmute::<&for<'s> CrateStore<'s>, TraitObject>(&*a); - mem::transmute(TraitObject { - data: mem::transmute(a), - vtable: vtable - }) - } -} - pub fn run(args: Vec) -> isize { monitor(move || run_compiler(&args, &mut RustcDefaultCalls)); 0 @@ -159,8 +137,8 @@ pub fn run_compiler<'a>(args: &[String], callbacks: &mut CompilerCalls<'a>) { }; let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let cstore_ = cstore_to_cratestore(cstore.clone()); - let mut sess = build_session(sopts, input_file_path, descriptions, cstore_); + let mut sess = build_session(sopts, input_file_path, descriptions, + cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); if sess.unstable_options() { sess.opts.show_span = matches.opt_str("show-span"); @@ -356,8 +334,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { return None; } let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let cstore_ = cstore_to_cratestore(cstore.clone()); - let sess = build_session(sopts.clone(), None, descriptions.clone(), cstore_); + let sess = build_session(sopts.clone(), None, descriptions.clone(), + cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let should_stop = RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile); if should_stop == Compilation::Stop { diff --git a/src/librustc_front/lib.rs b/src/librustc_front/lib.rs index 60080854a6f17..b12c41d060a07 100644 --- a/src/librustc_front/lib.rs +++ b/src/librustc_front/lib.rs @@ -14,11 +14,8 @@ //! //! This API is completely unstable and subject to change. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_front"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index afd834a61d6ce..f99cdd39da2a8 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -1571,8 +1571,8 @@ pub fn lower_block_check_mode(lctx: &LoweringContext, b: &BlockCheckMode) -> hir pub fn lower_binding_mode(lctx: &LoweringContext, b: &BindingMode) -> hir::BindingMode { match *b { - BindByRef(m) => hir::BindByRef(lower_mutability(lctx, m)), - BindByValue(m) => hir::BindByValue(lower_mutability(lctx, m)), + BindingMode::ByRef(m) => hir::BindByRef(lower_mutability(lctx, m)), + BindingMode::ByValue(m) => hir::BindByValue(lower_mutability(lctx, m)), } } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 1d0c616c3b71b..80ef334fe189b 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -19,11 +19,8 @@ //! //! This API is completely unstable and subject to change. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_lint"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index ebb0caa0dfae2..e2217e367a08e 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -8,19 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] #![allow(dead_code)] #![allow(trivial_casts)] -#![cfg_attr(stage0, allow(improper_ctypes))] - #![crate_name = "rustc_llvm"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index c425ba1386e25..42332c4696979 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -8,10 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_metadata"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_platform_intrinsics/lib.rs b/src/librustc_platform_intrinsics/lib.rs index 3de6863652ab7..e857434682d15 100644 --- a/src/librustc_platform_intrinsics/lib.rs +++ b/src/librustc_platform_intrinsics/lib.rs @@ -8,10 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_platform_intrinsics"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![feature(staged_api, rustc_private)] diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs index 5dedef7ab6c79..333c226c2a373 100644 --- a/src/librustc_plugin/lib.rs +++ b/src/librustc_plugin/lib.rs @@ -50,10 +50,8 @@ //! See the [Plugins Chapter](../../book/compiler-plugins.html) of the book //! for more examples. -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_plugin"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 9a869b24b8f6d..d1a894c61f7e2 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -8,11 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_privacy"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 6896e8e534057..3647fd5ce190a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -8,11 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_resolve"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -33,7 +30,6 @@ extern crate syntax; #[no_link] extern crate rustc_bitflags; extern crate rustc_front; - extern crate rustc; use self::PatternBindingMode::*; @@ -69,7 +65,7 @@ use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64, TyF64, TyF32}; use syntax::attr::AttrMetaMethods; use syntax::parse::token::{self, special_names, special_idents}; use syntax::codemap::{self, Span, Pos}; -use syntax::util::lev_distance::{lev_distance, max_suggestion_distance}; +use syntax::util::lev_distance::find_best_match_for_name; use rustc_front::intravisit::{self, FnKind, Visitor}; use rustc_front::hir; @@ -94,7 +90,6 @@ use std::cell::{Cell, RefCell}; use std::fmt; use std::mem::replace; use std::rc::{Rc, Weak}; -use std::usize; use resolve_imports::{Target, ImportDirective, ImportResolutionPerNamespace}; use resolve_imports::Shadowable; @@ -121,7 +116,7 @@ macro_rules! execute_callback { enum SuggestionType { Macro(String), - Function(String), + Function(token::InternedString), NotFound, } @@ -179,7 +174,7 @@ pub enum ResolutionError<'a> { /// error E0424: `self` is not available in a static method SelfNotAvailableInStaticMethod, /// error E0425: unresolved name - UnresolvedName(&'a str, &'a str), + UnresolvedName(&'a str, &'a str, UnresolvedNameContext), /// error E0426: use of undeclared label UndeclaredLabel(&'a str), /// error E0427: cannot use `ref` binding mode with ... @@ -202,6 +197,21 @@ pub enum ResolutionError<'a> { AttemptToUseNonConstantValueInConstant, } +/// Context of where `ResolutionError::UnresolvedName` arose. +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum UnresolvedNameContext { + /// `PathIsMod(id)` indicates that a given path, used in + /// expression context, actually resolved to a module rather than + /// a value. The `id` attached to the variant is the node id of + /// the erroneous path expression. + PathIsMod(ast::NodeId), + + /// `Other` means we have no extra information about the context + /// of the unresolved name error. (Maybe we could eliminate all + /// such cases; but for now, this is an information-free default.) + Other, +} + fn resolve_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>, span: syntax::codemap::Span, resolution_error: ResolutionError<'b>) { @@ -402,13 +412,46 @@ fn resolve_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>, "`self` is not available in a static method. Maybe a `self` argument is \ missing?"); } - ResolutionError::UnresolvedName(path, name) => { + ResolutionError::UnresolvedName(path, msg, context) => { span_err!(resolver.session, span, E0425, "unresolved name `{}`{}", path, - name); + msg); + + match context { + UnresolvedNameContext::Other => {} // no help available + UnresolvedNameContext::PathIsMod(id) => { + let mut help_msg = String::new(); + let parent_id = resolver.ast_map.get_parent_node(id); + if let Some(hir_map::Node::NodeExpr(e)) = resolver.ast_map.find(parent_id) { + match e.node { + ExprField(_, ident) => { + help_msg = format!("To reference an item from the \ + `{module}` module, use \ + `{module}::{ident}`", + module = &*path, + ident = ident.node); + } + + ExprMethodCall(ident, _, _) => { + help_msg = format!("To call a function from the \ + `{module}` module, use \ + `{module}::{ident}(..)`", + module = &*path, + ident = ident.node); + } + + _ => {} // no help available + } + } + + if !help_msg.is_empty() { + resolver.session.fileline_help(span, &help_msg); + } + } + } } ResolutionError::UndeclaredLabel(name) => { span_err!(resolver.session, @@ -3377,39 +3420,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { NoSuggestion } - fn find_best_match_for_name(&mut self, name: &str) -> SuggestionType { - let mut maybes: Vec = Vec::new(); - let mut values: Vec = Vec::new(); - + fn find_best_match(&mut self, name: &str) -> SuggestionType { if let Some(macro_name) = self.session.available_macros - .borrow().iter().find(|n| n.as_str() == name) { + .borrow().iter().find(|n| n.as_str() == name) { return SuggestionType::Macro(format!("{}!", macro_name)); } - for rib in self.value_ribs.iter().rev() { - for (&k, _) in &rib.bindings { - maybes.push(k.as_str()); - values.push(usize::MAX); - } - } - - let mut smallest = 0; - for (i, other) in maybes.iter().enumerate() { - values[i] = lev_distance(name, &other); + let names = self.value_ribs + .iter() + .rev() + .flat_map(|rib| rib.bindings.keys()); - if values[i] <= values[smallest] { - smallest = i; + if let Some(found) = find_best_match_for_name(names, name, None) { + if name != &*found { + return SuggestionType::Function(found); } - } - - let max_distance = max_suggestion_distance(name); - if !values.is_empty() && values[smallest] <= max_distance && name != &maybes[smallest][..] { - - SuggestionType::Function(maybes[smallest].to_string()) - - } else { - SuggestionType::NotFound - } + } SuggestionType::NotFound } fn resolve_expr(&mut self, expr: &Expr) { @@ -3523,7 +3549,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { NoSuggestion => { // limit search to 5 to reduce the number // of stupid suggestions - match self.find_best_match_for_name(&path_name) { + match self.find_best_match(&path_name) { SuggestionType::Macro(s) => { format!("the macro `{}`", s) } @@ -3539,13 +3565,33 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { format!("to call `{}::{}`", path_str, path_name), }; + let mut context = UnresolvedNameContext::Other; if !msg.is_empty() { - msg = format!(". Did you mean {}?", msg) + msg = format!(". Did you mean {}?", msg); + } else { + // we check if this a module and if so, we display a help + // message + let name_path = path.segments.iter() + .map(|seg| seg.identifier.name) + .collect::>(); + let current_module = self.current_module.clone(); + + match self.resolve_module_path(current_module, + &name_path[..], + UseLexicalScope, + expr.span, + PathSearch) { + Success(_) => { + context = UnresolvedNameContext::PathIsMod(expr.id); + }, + _ => {}, + }; } resolve_error(self, expr.span, - ResolutionError::UnresolvedName(&*path_name, &*msg)); + ResolutionError::UnresolvedName( + &*path_name, &*msg, context)); } } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 69d5621ce73d9..8b35f4d68df3b 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -33,11 +33,11 @@ use rustc::middle::privacy::*; use syntax::ast::{NodeId, Name}; use syntax::attr::AttrMetaMethods; use syntax::codemap::Span; +use syntax::util::lev_distance::find_best_match_for_name; use std::mem::replace; use std::rc::Rc; - /// Contains data for specific types of import directives. #[derive(Copy, Clone,Debug)] pub enum ImportDirectiveSubclass { @@ -425,17 +425,22 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { }; // We need to resolve both namespaces for this to succeed. - // let mut value_result = UnknownResult; let mut type_result = UnknownResult; + let mut lev_suggestion = "".to_owned(); // Search for direct children of the containing module. build_reduced_graph::populate_module_if_necessary(self.resolver, &target_module); match target_module.children.borrow().get(&source) { None => { - // Continue. + let names = target_module.children.borrow(); + if let Some(name) = find_best_match_for_name(names.keys(), + &source.as_str(), + None) { + lev_suggestion = format!(". Did you mean to use `{}`?", name); + } } Some(ref child_name_bindings) => { // pub_err makes sure we don't give the same error twice. @@ -516,6 +521,17 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { // therefore accurately report that the names are // unbound. + if lev_suggestion.is_empty() { // skip if we already have a suggestion + let names = target_module.import_resolutions.borrow(); + if let Some(name) = find_best_match_for_name(names.keys(), + &source.as_str(), + None) { + lev_suggestion = + format!(". Did you mean to use the re-exported import `{}`?", + name); + } + } + if value_result.is_unknown() { value_result = UnboundResult; } @@ -693,9 +709,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { target); if value_result.is_unbound() && type_result.is_unbound() { - let msg = format!("There is no `{}` in `{}`", + let msg = format!("There is no `{}` in `{}`{}", source, - module_to_string(&target_module)); + module_to_string(&target_module), lev_suggestion); return ResolveResult::Failed(Some((directive.span, msg))); } let value_used_public = value_used_reexport || value_used_public; diff --git a/src/librustc_trans/back/msvc/mod.rs b/src/librustc_trans/back/msvc/mod.rs index 3b5b94381b372..6f0baa86579e0 100644 --- a/src/librustc_trans/back/msvc/mod.rs +++ b/src/librustc_trans/back/msvc/mod.rs @@ -152,8 +152,15 @@ pub fn link_exe_cmd(sess: &Session) -> Command { }).and_then(|root| { fs::read_dir(Path::new(&root).join("Lib")).ok() }).and_then(|readdir| { - let mut dirs: Vec<_> = readdir.filter_map(|dir| dir.ok()) - .map(|dir| dir.path()).collect(); + let mut dirs: Vec<_> = readdir.filter_map(|dir| { + dir.ok() + }).map(|dir| { + dir.path() + }).filter(|dir| { + dir.components().last().and_then(|c| { + c.as_os_str().to_str() + }).map(|c| c.starts_with("10.")).unwrap_or(false) + }).collect(); dirs.sort(); dirs.pop() }) diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 83d0106fd4cb3..a17e0a4ccd78d 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -14,11 +14,8 @@ //! //! This API is completely unstable and subject to change. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_trans"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index cc5322d7f9f46..501ab566f1c5a 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -697,8 +697,8 @@ impl<'v> Visitor<'v> for PathCollector { // Even if the ref is mut, you can't change the ref, only // the data pointed at, so showing the initialising expression // is still worthwhile. - ast::BindByRef(_) => ast::MutImmutable, - ast::BindByValue(mt) => mt, + ast::BindingMode::ByRef(_) => ast::MutImmutable, + ast::BindingMode::ByValue(mt) => mt, }; // collect path for either visit_local or visit_arm let path = ast_util::ident_to_path(path1.span, path1.node); diff --git a/src/librustc_trans/trans/mir/lvalue.rs b/src/librustc_trans/trans/mir/lvalue.rs index f3c2c3459796a..b167633909a4a 100644 --- a/src/librustc_trans/trans/mir/lvalue.rs +++ b/src/librustc_trans/trans/mir/lvalue.rs @@ -132,7 +132,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { mir::ProjectionElem::Index(ref index) => { let index = self.trans_operand(bcx, index); let llindex = self.prepare_index(bcx, index.immediate()); - (build::InBoundsGEP(bcx, tr_base.llval, &[llindex]), + let zero = common::C_uint(bcx.ccx(), 0u64); + (build::InBoundsGEP(bcx, tr_base.llval, &[zero, llindex]), ptr::null_mut()) } mir::ProjectionElem::ConstantIndex { offset, @@ -140,7 +141,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { min_length: _ } => { let lloffset = common::C_u32(bcx.ccx(), offset); let llindex = self.prepare_index(bcx, lloffset); - (build::InBoundsGEP(bcx, tr_base.llval, &[llindex]), + let zero = common::C_uint(bcx.ccx(), 0u64); + (build::InBoundsGEP(bcx, tr_base.llval, &[zero, llindex]), ptr::null_mut()) } mir::ProjectionElem::ConstantIndex { offset, @@ -150,7 +152,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { let lllen = self.lvalue_len(bcx, tr_base); let llindex = build::Sub(bcx, lllen, lloffset, DebugLoc::None); let llindex = self.prepare_index(bcx, llindex); - (build::InBoundsGEP(bcx, tr_base.llval, &[llindex]), + let zero = common::C_uint(bcx.ccx(), 0u64); + (build::InBoundsGEP(bcx, tr_base.llval, &[zero, llindex]), ptr::null_mut()) } mir::ProjectionElem::Downcast(..) => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e8eb479a1c36f..72d0e5b53321e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -121,7 +121,7 @@ use syntax::attr::AttrMetaMethods; use syntax::codemap::{self, Span, Spanned}; use syntax::parse::token::{self, InternedString}; use syntax::ptr::P; -use syntax::util::lev_distance::lev_distance; +use syntax::util::lev_distance::find_best_match_for_name; use rustc_front::intravisit::{self, Visitor}; use rustc_front::hir; @@ -2981,28 +2981,22 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, tcx: &ty::ctxt<'tcx>, skip : Vec) { let name = field.node.as_str(); + let names = variant.fields + .iter() + .filter_map(|ref field| { + // ignore already set fields and private fields from non-local crates + if skip.iter().any(|x| *x == field.name.as_str()) || + (variant.did.krate != LOCAL_CRATE && field.vis != Visibility::Public) { + None + } else { + Some(&field.name) + } + }); + // only find fits with at least one matching letter - let mut best_dist = name.len(); - let mut best = None; - for elem in &variant.fields { - let n = elem.name.as_str(); - // ignore already set fields - if skip.iter().any(|x| *x == n) { - continue; - } - // ignore private fields from non-local crates - if variant.did.krate != LOCAL_CRATE && elem.vis != Visibility::Public { - continue; - } - let dist = lev_distance(&n, &name); - if dist < best_dist { - best = Some(n); - best_dist = dist; - } - } - if let Some(n) = best { + if let Some(name) = find_best_match_for_name(names, &name, Some(name.len())) { tcx.sess.span_help(field.span, - &format!("did you mean `{}`?", n)); + &format!("did you mean `{}`?", name)); } } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index c0ede6370f1b1..70c6d6f05c66a 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -62,11 +62,9 @@ independently: This API is completely unstable and subject to change. */ -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] + #![crate_name = "rustc_typeck"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/librustc_unicode/lib.rs b/src/librustc_unicode/lib.rs index 8bde24d2b0c42..161da07911061 100644 --- a/src/librustc_unicode/lib.rs +++ b/src/librustc_unicode/lib.rs @@ -20,11 +20,8 @@ //! provide for basic string-related manipulations. This crate does not //! (yet) aim to provide a full set of Unicode tables. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustc_unicode"] #![unstable(feature = "unicode", issue = "27783")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", @@ -34,9 +31,6 @@ test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] #![no_std] -#![cfg_attr(stage0, feature(rustc_attrs))] -#![cfg_attr(stage0, feature(no_std))] -#![cfg_attr(stage0, allow(unused_attributes))] #![feature(core_char_ext)] #![feature(lang_items)] #![feature(staged_api)] diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index c6c98851f7c34..d7190a4bea974 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -125,8 +125,8 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec, externs: Externs, codemap.clone()); let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone()); - let sess = session::build_session_(sessopts, cpath, diagnostic_handler, codemap, cstore_); + let sess = session::build_session_(sessopts, cpath, diagnostic_handler, + codemap, cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let mut cfg = config::build_configuration(&sess); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 09a2a1b1c0269..b9ebe977b7bd7 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1058,14 +1058,16 @@ impl DocFolder for Cache { } }); - self.search_index.push(IndexItem { - ty: shortty(&item), - name: s.to_string(), - path: path.join("::").to_string(), - desc: shorter(item.doc_value()), - parent: parent, - search_type: get_index_search_type(&item, parent_basename), - }); + if item.def_id.index != CRATE_DEF_INDEX { + self.search_index.push(IndexItem { + ty: shortty(&item), + name: s.to_string(), + path: path.join("::").to_string(), + desc: shorter(item.doc_value()), + parent: parent, + search_type: get_index_search_type(&item, parent_basename), + }); + } } (Some(parent), None) if is_method || (!self.privmod && !hidden_field)=> { if parent.is_local() { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 31fdc1170c026..ffda261c24f3d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -8,17 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "rustdoc"] #![unstable(feature = "rustdoc", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", - html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/", - html_playground_url = "https://play.rust-lang.org/")] + html_favicon_url = "https://doc.rust-lang.org/favicon.ico", + html_root_url = "https://doc.rust-lang.org/nightly/", + html_playground_url = "https://play.rust-lang.org/")] #![feature(box_patterns)] #![feature(box_syntax)] diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index fde8299d2d2e6..7aa97d3652f5a 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -80,12 +80,11 @@ pub fn run(input: &str, codemap.clone()); let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone()); let sess = session::build_session_(sessopts, Some(input_path.clone()), diagnostic_handler, codemap, - cstore_); + cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let mut cfg = config::build_configuration(&sess); @@ -235,12 +234,11 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec, libs: SearchPaths, let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter); let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone()); let sess = session::build_session_(sessopts, None, diagnostic_handler, codemap, - cstore_); + cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let outdir = TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir"); diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index c919c33564005..2941f6f8a026e 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -14,13 +14,10 @@ Core encoding and decoding interfaces. */ -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "serialize"] #![unstable(feature = "rustc_private", reason = "deprecated in favor of rustc-serialize on crates.io", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 62ec23ccb2000..4d805e17a7664 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -16,7 +16,7 @@ reason = "API has not been scrutinized and is highly likely to \ either disappear or change", issue = "27810")] -#![rustc_deprecated(since = "1.5.0", reason = "replaced with crates.io crates")] +#![rustc_deprecated(since = "1.5.0", reason = "replaced with 'dylib' on crates.io")] #![allow(missing_docs)] #![allow(deprecated)] diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 985dbdd895f84..120e56d8079a7 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -252,7 +252,7 @@ impl Stdin { /// /// - Pipe some text to it, e.g. `printf foo | path/to/executable` /// - Give it text interactively by running the executable directly, - // in which case it will wait for the Enter key to be pressed before + /// in which case it will wait for the Enter key to be pressed before /// continuing #[stable(feature = "rust1", since = "1.0.0")] pub fn read_line(&self, buf: &mut String) -> io::Result { diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index eba0c799cd2c1..e66cc49290adf 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -199,11 +199,8 @@ //! [other]: #what-is-in-the-standard-library-documentation //! [primitive types]: ../book/primitive-types.html -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "std"] #![stable(feature = "rust1", since = "1.0.0")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -214,12 +211,6 @@ test(no_crate_inject, attr(deny(warnings))), test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))] -#![cfg_attr(stage0, allow(unused_attributes))] -#![cfg_attr(stage0, allow(improper_ctypes))] - -#![cfg_attr(stage0, feature(rustc_attrs))] -#![cfg_attr(stage0, feature(no_std))] -#![cfg_attr(stage0, allow(unused_attributes))] #![feature(alloc)] #![feature(allow_internal_unstable)] #![feature(asm)] @@ -227,6 +218,7 @@ #![feature(borrow_state)] #![feature(box_syntax)] #![feature(cfg_target_vendor)] +#![feature(cfg_target_thread_local)] #![feature(char_internals)] #![feature(clone_from_slice)] #![feature(collections)] diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 13965ce810ddc..c7cb10a470748 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -182,8 +182,8 @@ mod imp { #[cfg(target_os = "openbsd")] mod imp { use io; + use libc; use mem; - use libc::c_long; use sys::os::errno; use rand::Rng; @@ -238,8 +238,6 @@ mod imp { #[cfg(target_os = "ios")] mod imp { - #[cfg(stage0)] use prelude::v1::*; - use io; use mem; use ptr; diff --git a/src/libstd/rtdeps.rs b/src/libstd/rtdeps.rs index 8383b3ec18972..9b1046f39a7b3 100644 --- a/src/libstd/rtdeps.rs +++ b/src/libstd/rtdeps.rs @@ -12,11 +12,6 @@ //! the standard library This varies per-platform, but these libraries are //! necessary for running libstd. -// A few small shims in C that haven't been translated to Rust yet -#[cfg(all(not(test), not(windows)))] -#[link(name = "rust_builtin", kind = "static")] -extern {} - // LLVM implements the `frem` instruction as a call to `fmod`, which lives in // libm. Hence, we must explicitly link to it. // diff --git a/src/libstd/sys/common/libunwind.rs b/src/libstd/sys/common/libunwind.rs index 75bb11216e1a2..feb05c7b56008 100644 --- a/src/libstd/sys/common/libunwind.rs +++ b/src/libstd/sys/common/libunwind.rs @@ -131,8 +131,6 @@ extern "C" { pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception); - // remove cfg after new snapshot - #[cfg(not(all(stage0, target_os="windows", target_arch="x86_64")))] #[unwind] pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !; } diff --git a/src/libstd/sys/common/unwind/mod.rs b/src/libstd/sys/common/unwind/mod.rs index aea5acc907176..0f10e7274614c 100644 --- a/src/libstd/sys/common/unwind/mod.rs +++ b/src/libstd/sys/common/unwind/mod.rs @@ -88,18 +88,8 @@ use sys_common::mutex::Mutex; #[path = "seh.rs"] #[doc(hidden)] pub mod imp; -// stage0: i686-pc-windows-gnu -#[cfg(all(stage0, windows, target_arch = "x86_64", target_env = "gnu"))] -#[path = "seh64_gnu.rs"] #[doc(hidden)] -pub mod imp; - -// stage0: x86_64-pc-windows-msvc -#[cfg(all(stage0, windows, target_arch = "x86_64", target_env = "msvc"))] -#[path = "seh.rs"] #[doc(hidden)] -pub mod imp; - // x86_64-pc-windows-* -#[cfg(all(not(stage0), windows, target_arch = "x86_64"))] +#[cfg(all(windows, target_arch = "x86_64"))] #[path = "seh64_gnu.rs"] #[doc(hidden)] pub mod imp; diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index e634c10d8b7dc..e8575a6c21cf1 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -14,7 +14,8 @@ use os::unix::prelude::*; use ffi::{CString, CStr, OsString, OsStr}; use fmt; use io::{self, Error, ErrorKind, SeekFrom}; -use libc::{self, c_int, off_t, c_char, mode_t}; +use libc::{dirent, readdir_r}; +use libc::{self, c_int, off_t, mode_t}; use mem; use path::{Path, PathBuf}; use ptr; @@ -43,7 +44,7 @@ unsafe impl Send for Dir {} unsafe impl Sync for Dir {} pub struct DirEntry { - buf: Vec, // actually *mut libc::dirent + entry: dirent, root: Arc, } @@ -126,32 +127,22 @@ impl Iterator for ReadDir { type Item = io::Result; fn next(&mut self) -> Option> { - extern { - fn rust_dirent_t_size() -> libc::size_t; - } - - let mut buf: Vec = Vec::with_capacity(unsafe { - rust_dirent_t_size() - }); - let ptr = buf.as_mut_ptr() as *mut libc::dirent; - - let mut entry_ptr = ptr::null_mut(); - loop { - if unsafe { libc::readdir_r(self.dirp.0, ptr, &mut entry_ptr) != 0 } { - return Some(Err(Error::last_os_error())) - } - if entry_ptr.is_null() { - return None - } - - let entry = DirEntry { - buf: buf, + unsafe { + let mut ret = DirEntry { + entry: mem::zeroed(), root: self.root.clone() }; - if entry.name_bytes() == b"." || entry.name_bytes() == b".." { - buf = entry.buf; - } else { - return Some(Ok(entry)) + let mut entry_ptr = ptr::null_mut(); + loop { + if readdir_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 { + return Some(Err(Error::last_os_error())) + } + if entry_ptr.is_null() { + return None + } + if ret.name_bytes() != b"." && ret.name_bytes() != b".." { + return Some(Ok(ret)) + } } } } @@ -166,7 +157,7 @@ impl Drop for Dir { impl DirEntry { pub fn path(&self) -> PathBuf { - self.root.join(::from_bytes(self.name_bytes())) + self.root.join(OsStr::from_bytes(self.name_bytes())) } pub fn file_name(&self) -> OsString { @@ -178,35 +169,64 @@ impl DirEntry { } pub fn file_type(&self) -> io::Result { - extern { - fn rust_dir_get_mode(ptr: *mut libc::dirent) -> c_int; - } - unsafe { - match rust_dir_get_mode(self.dirent()) { - -1 => lstat(&self.path()).map(|m| m.file_type()), - n => Ok(FileType { mode: n as mode_t }), - } + match self.entry.d_type { + libc::DT_CHR => Ok(FileType { mode: libc::S_IFCHR }), + libc::DT_FIFO => Ok(FileType { mode: libc::S_IFIFO }), + libc::DT_LNK => Ok(FileType { mode: libc::S_IFLNK }), + libc::DT_REG => Ok(FileType { mode: libc::S_IFREG }), + libc::DT_SOCK => Ok(FileType { mode: libc::S_IFSOCK }), + libc::DT_DIR => Ok(FileType { mode: libc::S_IFDIR }), + libc::DT_BLK => Ok(FileType { mode: libc::S_IFBLK }), + _ => lstat(&self.path()).map(|m| m.file_type()), } } + #[cfg(any(target_os = "macos", + target_os = "ios", + target_os = "linux"))] pub fn ino(&self) -> raw::ino_t { - extern { - fn rust_dir_get_ino(ptr: *mut libc::dirent) -> raw::ino_t; - } - unsafe { rust_dir_get_ino(self.dirent()) } + self.entry.d_ino + } + + #[cfg(target_os = "android")] + pub fn ino(&self) -> raw::ino_t { + self.entry.d_ino as raw::ino_t + } + + #[cfg(any(target_os = "freebsd", + target_os = "openbsd", + target_os = "bitrig", + target_os = "netbsd", + target_os = "dragonfly"))] + pub fn ino(&self) -> raw::ino_t { + self.entry.d_fileno } + #[cfg(any(target_os = "macos", + target_os = "ios", + target_os = "netbsd"))] fn name_bytes(&self) -> &[u8] { - extern { - fn rust_list_dir_val(ptr: *mut libc::dirent) -> *const c_char; + unsafe { + ::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8, + self.entry.d_namlen as usize) } + } + #[cfg(any(target_os = "freebsd", + target_os = "dragonfly", + target_os = "bitrig", + target_os = "openbsd"))] + fn name_bytes(&self) -> &[u8] { unsafe { - CStr::from_ptr(rust_list_dir_val(self.dirent())).to_bytes() + ::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8, + self.entry.d_namelen as usize) } } - - fn dirent(&self) -> *mut libc::dirent { - self.buf.as_ptr() as *mut _ + #[cfg(any(target_os = "android", + target_os = "linux"))] + fn name_bytes(&self) -> &[u8] { + unsafe { + CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() + } } } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 12b9d6191a05f..c62960d74cb1c 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -38,12 +38,17 @@ static ENV_LOCK: StaticMutex = StaticMutex::new(); /// Returns the platform-specific value of errno pub fn errno() -> i32 { extern { - #[cfg_attr(any(target_os = "linux", target_os = "android"), link_name = "__errno_location")] - #[cfg_attr(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd", + #[cfg_attr(any(target_os = "linux"), link_name = "__errno_location")] + #[cfg_attr(any(target_os = "bitrig", + target_os = "netbsd", + target_os = "openbsd", + target_os = "android", target_env = "newlib"), link_name = "__errno")] #[cfg_attr(target_os = "dragonfly", link_name = "__dfly_error")] - #[cfg_attr(any(target_os = "macos", target_os = "ios", target_os = "freebsd"), + #[cfg_attr(any(target_os = "macos", + target_os = "ios", + target_os = "freebsd"), link_name = "__error")] fn errno_location() -> *const c_int; } @@ -173,17 +178,19 @@ pub fn current_exe() -> io::Result { libc::KERN_PROC_PATHNAME as c_int, -1 as c_int]; let mut sz: libc::size_t = 0; - let err = libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, - ptr::null_mut(), &mut sz, ptr::null_mut(), - 0 as libc::size_t); - if err != 0 { return Err(io::Error::last_os_error()); } - if sz == 0 { return Err(io::Error::last_os_error()); } + try!(cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, + ptr::null_mut(), &mut sz, ptr::null_mut(), + 0 as libc::size_t))); + if sz == 0 { + return Err(io::Error::last_os_error()) + } let mut v: Vec = Vec::with_capacity(sz as usize); - let err = libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, - v.as_mut_ptr() as *mut libc::c_void, &mut sz, - ptr::null_mut(), 0 as libc::size_t); - if err != 0 { return Err(io::Error::last_os_error()); } - if sz == 0 { return Err(io::Error::last_os_error()); } + try!(cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, + v.as_mut_ptr() as *mut libc::c_void, &mut sz, + ptr::null_mut(), 0 as libc::size_t))); + if sz == 0 { + return Err(io::Error::last_os_error()); + } v.set_len(sz as usize - 1); // chop off trailing NUL Ok(PathBuf::from(OsString::from_vec(v))) } @@ -201,22 +208,28 @@ pub fn current_exe() -> io::Result { #[cfg(any(target_os = "bitrig", target_os = "openbsd"))] pub fn current_exe() -> io::Result { - use sync::StaticMutex; - static LOCK: StaticMutex = StaticMutex::new(); - - extern { - fn rust_current_exe() -> *const c_char; - } - - let _guard = LOCK.lock(); - unsafe { - let v = rust_current_exe(); - if v.is_null() { - Err(io::Error::last_os_error()) + let mut mib = [libc::CTL_KERN, + libc::KERN_PROC_ARGS, + libc::getpid(), + libc::KERN_PROC_ARGV]; + let mib = mib.as_mut_ptr(); + let mut argv_len = 0; + try!(cvt(libc::sysctl(mib, 4, 0 as *mut _, &mut argv_len, + 0 as *mut _, 0))); + let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize); + try!(cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, + &mut argv_len, 0 as *mut _, 0))); + argv.set_len(argv_len as usize); + if argv[0].is_null() { + return Err(io::Error::new(io::ErrorKind::Other, + "no current exe available")) + } + let argv0 = CStr::from_ptr(argv[0]).to_bytes(); + if argv0[0] == b'.' || argv0.iter().any(|b| *b == b'/') { + ::fs::canonicalize(OsStr::from_bytes(argv0)) } else { - let vec = CStr::from_ptr(v).to_bytes().to_vec(); - Ok(PathBuf::from(OsString::from_vec(vec))) + Ok(PathBuf::from(OsStr::from_bytes(argv0))) } } } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 5e0368f35cc74..34e32d0d5b62a 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -17,7 +17,7 @@ use os::raw::{c_char, c_short, c_ulonglong}; use libc::{wchar_t, size_t, c_void}; use ptr; -#[cfg_attr(not(stage0), repr(simd))] +#[repr(simd)] #[repr(C)] struct u64x2(u64, u64); diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 870247f7e82fc..ca0f103156253 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -15,10 +15,6 @@ use cell::UnsafeCell; use mem; -// Sure wish we had macro hygiene, no? -#[doc(hidden)] -pub use self::imp::Key as __KeyInner; - /// A thread local storage key which owns its contents. /// /// This key uses the fastest possible implementation available to it for the @@ -61,41 +57,27 @@ pub use self::imp::Key as __KeyInner; /// }); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub struct LocalKey { - // The key itself may be tagged with #[thread_local], and this `Key` is - // stored as a `static`, and it's not valid for a static to reference the - // address of another thread_local static. For this reason we kinda wonkily - // work around this by generating a shim function which will give us the - // address of the inner TLS key at runtime. +pub struct LocalKey { + // This outer `LocalKey` type is what's going to be stored in statics, + // but actual data inside will sometimes be tagged with #[thread_local]. + // It's not valid for a true static to reference a #[thread_local] static, + // so we get around that by exposing an accessor through a layer of function + // indirection (this thunk). + // + // Note that the thunk is itself unsafe because the returned lifetime of the + // slot where data lives, `'static`, is not actually valid. The lifetime + // here is actually `'thread`! // - // This is trivially devirtualizable by LLVM because we never store anything - // to this field and rustc can declare the `static` as constant as well. - inner: fn() -> &'static __KeyInner, + // Although this is an extra layer of indirection, it should in theory be + // trivially devirtualizable by LLVM because the value of `inner` never + // changes and the constant should be readonly within a crate. This mainly + // only runs into problems when TLS statics are exported across crates. + inner: unsafe fn() -> Option<&'static UnsafeCell>>, // initialization routine to invoke to create a value init: fn() -> T, } -// Macro pain #4586: -// -// When cross compiling, rustc will load plugins and macros from the *host* -// platform before search for macros from the target platform. This is primarily -// done to detect, for example, plugins. Ideally the macro below would be -// defined once per module below, but unfortunately this means we have the -// following situation: -// -// 1. We compile libstd for x86_64-unknown-linux-gnu, this thread_local!() macro -// will inject #[thread_local] statics. -// 2. We then try to compile a program for arm-linux-androideabi -// 3. The compiler has a host of linux and a target of android, so it loads -// macros from the *linux* libstd. -// 4. The macro generates a #[thread_local] field, but the android libstd does -// not use #[thread_local] -// 5. Compile error about structs with wrong fields. -// -// To get around this, we're forced to inject the #[cfg] logic into the macro -// itself. Woohoo. - /// Declare a new thread local storage key of type `std::thread::LocalKey`. /// /// See [LocalKey documentation](thread/struct.LocalKey.html) for more @@ -103,36 +85,14 @@ pub struct LocalKey { #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] #[allow_internal_unstable] -#[cfg(not(no_elf_tls))] -macro_rules! thread_local { - (static $name:ident: $t:ty = $init:expr) => ( - static $name: $crate::thread::LocalKey<$t> = - __thread_local_inner!($t, $init, - #[cfg_attr(all(any(target_os = "macos", target_os = "linux"), - not(target_arch = "aarch64")), - thread_local)]); - ); - (pub static $name:ident: $t:ty = $init:expr) => ( - pub static $name: $crate::thread::LocalKey<$t> = - __thread_local_inner!($t, $init, - #[cfg_attr(all(any(target_os = "macos", target_os = "linux"), - not(target_arch = "aarch64")), - thread_local)]); - ); -} - -#[macro_export] -#[stable(feature = "rust1", since = "1.0.0")] -#[allow_internal_unstable] -#[cfg(no_elf_tls)] macro_rules! thread_local { (static $name:ident: $t:ty = $init:expr) => ( static $name: $crate::thread::LocalKey<$t> = - __thread_local_inner!($t, $init, #[]); + __thread_local_inner!($t, $init); ); (pub static $name:ident: $t:ty = $init:expr) => ( pub static $name: $crate::thread::LocalKey<$t> = - __thread_local_inner!($t, $init, #[]); + __thread_local_inner!($t, $init); ); } @@ -143,12 +103,25 @@ macro_rules! thread_local { #[macro_export] #[allow_internal_unstable] macro_rules! __thread_local_inner { - ($t:ty, $init:expr, #[$($attr:meta),*]) => {{ - $(#[$attr])* - static __KEY: $crate::thread::__LocalKeyInner<$t> = - $crate::thread::__LocalKeyInner::new(); + ($t:ty, $init:expr) => {{ fn __init() -> $t { $init } - fn __getit() -> &'static $crate::thread::__LocalKeyInner<$t> { &__KEY } + + unsafe fn __getit() -> $crate::option::Option< + &'static $crate::cell::UnsafeCell< + $crate::option::Option<$t>>> + { + #[thread_local] + #[cfg(target_thread_local)] + static __KEY: $crate::thread::__ElfLocalKeyInner<$t> = + $crate::thread::__ElfLocalKeyInner::new(); + + #[cfg(not(target_thread_local))] + static __KEY: $crate::thread::__OsLocalKeyInner<$t> = + $crate::thread::__OsLocalKeyInner::new(); + + __KEY.get() + } + $crate::thread::LocalKey::new(__getit, __init) }} } @@ -190,11 +163,11 @@ impl LocalKey { #[unstable(feature = "thread_local_internals", reason = "recently added to create a key", issue = "0")] - pub const fn new(inner: fn() -> &'static __KeyInner, + pub const fn new(inner: unsafe fn() -> Option<&'static UnsafeCell>>, init: fn() -> T) -> LocalKey { LocalKey { inner: inner, - init: init + init: init, } } @@ -211,10 +184,10 @@ impl LocalKey { #[stable(feature = "rust1", since = "1.0.0")] pub fn with(&'static self, f: F) -> R where F: FnOnce(&T) -> R { - let slot = (self.inner)(); unsafe { - let slot = slot.get().expect("cannot access a TLS value during or \ - after it is destroyed"); + let slot = (self.inner)(); + let slot = slot.expect("cannot access a TLS value during or \ + after it is destroyed"); f(match *slot.get() { Some(ref inner) => inner, None => self.init(slot), @@ -270,7 +243,7 @@ impl LocalKey { issue = "27716")] pub fn state(&'static self) -> LocalKeyState { unsafe { - match (self.inner)().get() { + match (self.inner)() { Some(cell) => { match *cell.get() { Some(..) => LocalKeyState::Valid, @@ -283,11 +256,9 @@ impl LocalKey { } } -#[cfg(all(any(target_os = "macos", target_os = "linux"), - not(target_arch = "aarch64"), - not(no_elf_tls)))] +#[cfg(target_thread_local)] #[doc(hidden)] -mod imp { +pub mod elf { use cell::{Cell, UnsafeCell}; use intrinsics; use ptr; @@ -431,11 +402,8 @@ mod imp { } } -#[cfg(any(not(any(target_os = "macos", target_os = "linux")), - target_arch = "aarch64", - no_elf_tls))] #[doc(hidden)] -mod imp { +pub mod os { use prelude::v1::*; use cell::{Cell, UnsafeCell}; diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index d4f04d5d94f1f..0e525f394216c 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -191,7 +191,10 @@ pub use self::local::{LocalKey, LocalKeyState}; pub use self::scoped_tls::ScopedKey; #[unstable(feature = "libstd_thread_internals", issue = "0")] -#[doc(hidden)] pub use self::local::__KeyInner as __LocalKeyInner; +#[cfg(target_thread_local)] +#[doc(hidden)] pub use self::local::elf::Key as __ElfLocalKeyInner; +#[unstable(feature = "libstd_thread_internals", issue = "0")] +#[doc(hidden)] pub use self::local::os::Key as __OsLocalKeyInner; #[unstable(feature = "libstd_thread_internals", issue = "0")] #[doc(hidden)] pub use self::scoped_tls::__KeyInner as __ScopedKeyInner; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index abc44407eff73..0ad655ce00bb9 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::BindingMode::*; pub use self::BinOp_::*; pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; @@ -574,8 +573,8 @@ pub struct FieldPat { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum BindingMode { - BindByRef(Mutability), - BindByValue(Mutability), + ByRef(Mutability), + ByValue(Mutability), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -1655,7 +1654,7 @@ impl Arg { }), pat: P(Pat { id: DUMMY_NODE_ID, - node: PatIdent(BindByValue(mutability), path, None), + node: PatIdent(BindingMode::ByValue(mutability), path, None), span: span }), id: DUMMY_NODE_ID diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index d38b771814c28..70561b1eb551d 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -68,7 +68,7 @@ pub fn path_to_ident(path: &Path) -> Option { pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> P { P(Pat { id: id, - node: PatIdent(BindByValue(MutImmutable), codemap::Spanned{span:s, node:i}, None), + node: PatIdent(BindingMode::ByValue(MutImmutable), codemap::Spanned{span:s, node:i}, None), span: s }) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index f198460137d5f..f616420218e1a 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -24,7 +24,7 @@ use parse::token; use parse::token::{InternedString, intern, str_to_ident}; use ptr::P; use util::small_vector::SmallVector; -use util::lev_distance::{lev_distance, max_suggestion_distance}; +use util::lev_distance::find_best_match_for_name; use ext::mtwt; use fold::Folder; @@ -744,15 +744,8 @@ impl<'a> ExtCtxt<'a> { } pub fn suggest_macro_name(&mut self, name: &str, span: Span) { - let mut min: Option<(Name, usize)> = None; - let max_dist = max_suggestion_distance(name); - for macro_name in self.syntax_env.names.iter() { - let dist = lev_distance(name, ¯o_name.as_str()); - if dist <= max_dist && (min.is_none() || min.unwrap().1 > dist) { - min = Some((*macro_name, dist)); - } - } - if let Some((suggestion, _)) = min { + let names = &self.syntax_env.names; + if let Some(suggestion) = find_best_match_for_name(names.iter(), name, None) { self.fileline_help(span, &format!("did you mean `{}!`?", suggestion)); } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 46a39b98058a2..8c19a10b4b147 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -513,7 +513,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: P) -> P { let pat = if mutbl { - self.pat_ident_binding_mode(sp, ident, ast::BindByValue(ast::MutMutable)) + self.pat_ident_binding_mode(sp, ident, ast::BindingMode::ByValue(ast::MutMutable)) } else { self.pat_ident(sp, ident) }; @@ -537,7 +537,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ex: P) -> P { let pat = if mutbl { - self.pat_ident_binding_mode(sp, ident, ast::BindByValue(ast::MutMutable)) + self.pat_ident_binding_mode(sp, ident, ast::BindingMode::ByValue(ast::MutMutable)) } else { self.pat_ident(sp, ident) }; @@ -808,7 +808,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.pat(span, ast::PatLit(expr)) } fn pat_ident(&self, span: Span, ident: ast::Ident) -> P { - self.pat_ident_binding_mode(span, ident, ast::BindByValue(ast::MutImmutable)) + self.pat_ident_binding_mode(span, ident, ast::BindingMode::ByValue(ast::MutImmutable)) } fn pat_ident_binding_mode(&self, diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index b2989c42a9e92..4ea0fd76fea4a 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -236,6 +236,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option, Status // allow using type ascription in expressions ("type_ascription", "1.6.0", Some(23416), Active), + + // Allows cfg(target_thread_local) + ("cfg_target_thread_local", "1.7.0", Some(29594), Active), ]; // (changing above list without updating src/doc/reference.md makes @cmr sad) @@ -414,6 +417,8 @@ const GATED_CFGS: &'static [(&'static str, &'static str, fn(&Features) -> bool)] // (name in cfg, feature, function to check if the feature is enabled) ("target_feature", "cfg_target_feature", cfg_fn!(|x| x.cfg_target_feature)), ("target_vendor", "cfg_target_vendor", cfg_fn!(|x| x.cfg_target_vendor)), + ("target_thread_local", "cfg_target_thread_local", + cfg_fn!(|x| x.cfg_target_thread_local)), ]; #[derive(Debug, Eq, PartialEq)] @@ -449,10 +454,13 @@ impl PartialOrd for GatedCfgAttr { } impl GatedCfgAttr { - pub fn check_and_emit(&self, diagnostic: &Handler, features: &Features) { + pub fn check_and_emit(&self, + diagnostic: &Handler, + features: &Features, + codemap: &CodeMap) { match *self { GatedCfgAttr::GatedCfg(ref cfg) => { - cfg.check_and_emit(diagnostic, features); + cfg.check_and_emit(diagnostic, features, codemap); } GatedCfgAttr::GatedAttr(span) => { if !features.stmt_expr_attributes { @@ -479,9 +487,12 @@ impl GatedCfg { } }) } - fn check_and_emit(&self, diagnostic: &Handler, features: &Features) { + fn check_and_emit(&self, + diagnostic: &Handler, + features: &Features, + codemap: &CodeMap) { let (cfg, feature, has_feature) = GATED_CFGS[self.index]; - if !has_feature(features) { + if !has_feature(features) && !codemap.span_allows_unstable(self.span) { let explain = format!("`cfg({})` is experimental and subject to change", cfg); emit_feature_err(diagnostic, feature, self.span, GateIssue::Language, &explain); } @@ -541,6 +552,7 @@ pub struct Features { pub type_macros: bool, pub cfg_target_feature: bool, pub cfg_target_vendor: bool, + pub cfg_target_thread_local: bool, pub augmented_assignments: bool, pub braced_empty_structs: bool, pub staged_api: bool, @@ -575,6 +587,7 @@ impl Features { type_macros: false, cfg_target_feature: false, cfg_target_vendor: false, + cfg_target_thread_local: false, augmented_assignments: false, braced_empty_structs: false, staged_api: false, @@ -1157,6 +1170,7 @@ fn check_crate_inner(cm: &CodeMap, span_handler: &Handler, type_macros: cx.has_feature("type_macros"), cfg_target_feature: cx.has_feature("cfg_target_feature"), cfg_target_vendor: cx.has_feature("cfg_target_vendor"), + cfg_target_thread_local: cx.has_feature("cfg_target_thread_local"), augmented_assignments: cx.has_feature("augmented_assignments"), braced_empty_structs: cx.has_feature("braced_empty_structs"), staged_api: cx.has_feature("staged_api"), diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 47340d312242b..c09e35f1077a5 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -14,11 +14,8 @@ //! //! This API is completely unstable and subject to change. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "syntax"] #![unstable(feature = "rustc_private", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -26,8 +23,6 @@ html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))] -#![cfg_attr(stage0, feature(rustc_attrs))] -#![cfg_attr(stage0, allow(unused_attributes))] #![feature(associated_consts)] #![feature(filling_drop)] #![feature(libc)] diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index cff106f838af2..6951d6319acaf 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -892,7 +892,7 @@ mod tests { assert!(panictry!(parser.parse_pat()) == P(ast::Pat{ id: ast::DUMMY_NODE_ID, - node: ast::PatIdent(ast::BindByValue(ast::MutImmutable), + node: ast::PatIdent(ast::BindingMode::ByValue(ast::MutImmutable), Spanned{ span:sp(0, 1), node: str_to_ident("b") }, @@ -928,7 +928,7 @@ mod tests { pat: P(ast::Pat { id: ast::DUMMY_NODE_ID, node: ast::PatIdent( - ast::BindByValue(ast::MutImmutable), + ast::BindingMode::ByValue(ast::MutImmutable), Spanned{ span: sp(6,7), node: str_to_ident("b")}, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b625277f2a772..dbd34b49f7d9e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -14,7 +14,7 @@ use abi; use ast::BareFnTy; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::{Public, Unsafety}; -use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindByRef, BindByValue}; +use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindingMode}; use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, BiLt, Block}; use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; @@ -3278,10 +3278,10 @@ impl<'a> Parser<'a> { hi = self.last_span.hi; let bind_type = match (is_ref, is_mut) { - (true, true) => BindByRef(MutMutable), - (true, false) => BindByRef(MutImmutable), - (false, true) => BindByValue(MutMutable), - (false, false) => BindByValue(MutImmutable), + (true, true) => BindingMode::ByRef(MutMutable), + (true, false) => BindingMode::ByRef(MutImmutable), + (false, true) => BindingMode::ByValue(MutMutable), + (false, false) => BindingMode::ByValue(MutImmutable), }; let fieldpath = codemap::Spanned{span:self.last_span, node:fieldname}; let fieldpat = P(ast::Pat{ @@ -3376,11 +3376,11 @@ impl<'a> Parser<'a> { // At this point, token != _, &, &&, (, [ if try!(self.eat_keyword(keywords::Mut)) { // Parse mut ident @ pat - pat = try!(self.parse_pat_ident(BindByValue(MutMutable))); + pat = try!(self.parse_pat_ident(BindingMode::ByValue(MutMutable))); } else if try!(self.eat_keyword(keywords::Ref)) { // Parse ref ident @ pat / ref mut ident @ pat let mutbl = try!(self.parse_mutability()); - pat = try!(self.parse_pat_ident(BindByRef(mutbl))); + pat = try!(self.parse_pat_ident(BindingMode::ByRef(mutbl))); } else if try!(self.eat_keyword(keywords::Box)) { // Parse box pat let subpat = try!(self.parse_pat()); @@ -3409,7 +3409,7 @@ impl<'a> Parser<'a> { // Parse ident @ pat // This can give false positives and parse nullary enums, // they are dealt with later in resolve - pat = try!(self.parse_pat_ident(BindByValue(MutImmutable))); + pat = try!(self.parse_pat_ident(BindingMode::ByValue(MutImmutable))); } } else { let (qself, path) = if try!(self.eat_lt()) { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index ff01f0ac67e41..becccbf3d2421 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -856,8 +856,8 @@ impl<'a> State<'a> { indented: usize) -> io::Result<()> { self.bclose_maybe_open(span, indented, true) } - pub fn bclose_maybe_open (&mut self, span: codemap::Span, - indented: usize, close_box: bool) -> io::Result<()> { + pub fn bclose_maybe_open(&mut self, span: codemap::Span, + indented: usize, close_box: bool) -> io::Result<()> { try!(self.maybe_print_comment(span.hi)); try!(self.break_offset_if_not_bol(1, -(indented as isize))); try!(word(&mut self.s, "}")); @@ -2471,12 +2471,12 @@ impl<'a> State<'a> { ast::PatWild => try!(word(&mut self.s, "_")), ast::PatIdent(binding_mode, ref path1, ref sub) => { match binding_mode { - ast::BindByRef(mutbl) => { + ast::BindingMode::ByRef(mutbl) => { try!(self.word_nbsp("ref")); try!(self.print_mutability(mutbl)); } - ast::BindByValue(ast::MutImmutable) => {} - ast::BindByValue(ast::MutMutable) => { + ast::BindingMode::ByValue(ast::MutImmutable) => {} + ast::BindingMode::ByValue(ast::MutMutable) => { try!(self.word_nbsp("mut")); } } @@ -2682,7 +2682,7 @@ impl<'a> State<'a> { let m = match *explicit_self { ast::SelfStatic => ast::MutImmutable, _ => match decl.inputs[0].pat.node { - ast::PatIdent(ast::BindByValue(m), _, _) => m, + ast::PatIdent(ast::BindingMode::ByValue(m), _, _) => m, _ => ast::MutImmutable } }; diff --git a/src/libsyntax/util/lev_distance.rs b/src/libsyntax/util/lev_distance.rs index 9bf96311122e0..e0796c34e57ef 100644 --- a/src/libsyntax/util/lev_distance.rs +++ b/src/libsyntax/util/lev_distance.rs @@ -8,50 +8,64 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use ast::Name; use std::cmp; +use parse::token::InternedString; -pub fn lev_distance(me: &str, t: &str) -> usize { - if me.is_empty() { return t.chars().count(); } - if t.is_empty() { return me.chars().count(); } +/// To find the Levenshtein distance between two strings +pub fn lev_distance(a: &str, b: &str) -> usize { + // cases which don't require further computation + if a.is_empty() { + return b.chars().count(); + } else if b.is_empty() { + return a.chars().count(); + } - let mut dcol: Vec<_> = (0..t.len() + 1).collect(); + let mut dcol: Vec<_> = (0..b.len() + 1).collect(); let mut t_last = 0; - for (i, sc) in me.chars().enumerate() { - + for (i, sc) in a.chars().enumerate() { let mut current = i; dcol[0] = current + 1; - for (j, tc) in t.chars().enumerate() { - + for (j, tc) in b.chars().enumerate() { let next = dcol[j + 1]; - if sc == tc { dcol[j + 1] = current; } else { dcol[j + 1] = cmp::min(current, next); dcol[j + 1] = cmp::min(dcol[j + 1], dcol[j]) + 1; } - current = next; t_last = j; } - } - - dcol[t_last + 1] + } dcol[t_last + 1] } -pub fn max_suggestion_distance(name: &str) -> usize { - use std::cmp::max; - // As a loose rule to avoid obviously incorrect suggestions, clamp the - // maximum edit distance we will accept for a suggestion to one third of - // the typo'd name's length. - max(name.len(), 3) / 3 +/// To find the best match for a given string from an iterator of names +/// As a loose rule to avoid the obviously incorrect suggestions, it takes +/// an optional limit for the maximum allowable edit distance, which defaults +/// to one-third of the given word +pub fn find_best_match_for_name<'a, T>(iter_names: T, + lookup: &str, + dist: Option) -> Option + where T: Iterator { + let max_dist = dist.map_or_else(|| cmp::max(lookup.len(), 3) / 3, |d| d); + iter_names + .filter_map(|name| { + let dist = lev_distance(lookup, &name.as_str()); + match dist <= max_dist { // filter the unwanted cases + true => Some((name.as_str(), dist)), + false => None, + } + }) + .min_by_key(|&(_, val)| val) // extract the tuple containing the minimum edit distance + .map(|(s, _)| s) // and return only the string } #[test] fn test_lev_distance() { - use std::char::{ from_u32, MAX }; + use std::char::{from_u32, MAX}; // Test bytelength agnosticity for c in (0..MAX as u32) .filter_map(|i| from_u32(i)) diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 8f316649421a6..3af701739b431 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -1470,7 +1470,7 @@ impl<'a> TraitDef<'a> { -> Vec> { field_paths.iter().map(|path| { cx.pat(path.span, - ast::PatIdent(ast::BindByRef(mutbl), (*path).clone(), None)) + ast::PatIdent(ast::BindingMode::ByRef(mutbl), (*path).clone(), None)) }).collect() } diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 01dc9662588bf..a032666595ebe 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -17,8 +17,6 @@ html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] -#![cfg_attr(stage0, feature(custom_attribute))] -#![cfg_attr(stage0, staged_api)] #![unstable(feature = "rustc_private", issue = "27812")] #![feature(rustc_private)] diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 69ad55d790899..d4c9cb8e2541b 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -40,13 +40,10 @@ //! [win]: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682010%28v=vs.85%29.aspx //! [ti]: https://en.wikipedia.org/wiki/Terminfo -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "term"] #![unstable(feature = "rustc_private", reason = "use the crates.io `term` library instead", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index d1bf9090944c2..a844bdf1351d9 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -23,11 +23,8 @@ // running tests while providing a base that other test frameworks may // build off of. -// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) -#![cfg_attr(stage0, feature(custom_attribute))] #![crate_name = "test"] #![unstable(feature = "test", issue = "27812")] -#![cfg_attr(stage0, staged_api)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -909,10 +906,45 @@ fn get_concurrency() -> usize { } } - #[cfg(unix)] + #[cfg(any(target_os = "linux", + target_os = "macos", + target_os = "ios", + target_os = "android"))] fn num_cpus() -> usize { - extern { fn rust_get_num_cpus() -> libc::uintptr_t; } - unsafe { rust_get_num_cpus() as usize } + unsafe { + libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as usize + } + } + + #[cfg(any(target_os = "freebsd", + target_os = "dragonfly", + target_os = "bitrig", + target_os = "openbsd", + target_os = "netbsd"))] + fn num_cpus() -> usize { + let mut cpus: libc::c_uint = 0; + let mut CPUS_SIZE = std::mem::size_of_val(&cpus); + let mut mib = [libc::CTL_HW, libc::HW_AVAILCPU, 0, 0]; + + unsafe { + libc::sysctl(mib.as_mut_ptr(), 2, + &mut cpus as *mut _ as *mut _, + &mut CPUS_SIZE as *mut _ as *mut _, + 0 as *mut _, 0); + } + if cpus < 1 { + mib[1] = HW_NCPU; + unsafe { + libc::sysctl(mib.as_mut_ptr(), 2, + &mut cpus as *mut _ as *mut _, + &mut CPUS_SIZE as *mut _ as *mut _, + 0 as *mut _, 0); + } + if cpus < 1 { + cpus = 1; + } + } + cpus as usize } } diff --git a/src/rt/rust_android_dummy.c b/src/rt/rust_android_dummy.c deleted file mode 100644 index c322dc6706f72..0000000000000 --- a/src/rt/rust_android_dummy.c +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifdef __ANDROID__ - -#include "rust_android_dummy.h" -#include -#include - -int backtrace(void **array, int size) { return 0; } - -char **backtrace_symbols(void *const *array, int size) { return 0; } - -void backtrace_symbols_fd (void *const *array, int size, int fd) {} - -volatile int* __errno_location() { - return &errno; -} - -float log2f(float f) -{ - return logf( f ) / logf( 2 ); -} - -double log2( double n ) -{ - return log( n ) / log( 2 ); -} - -double exp10( double x ) -{ - return pow( 10, x ); -} - -void telldir() -{ -} - -void seekdir() -{ -} - -void mkfifo() -{ -} - -void abs() -{ -} - -void labs() -{ -} - -void rand() -{ -} - -void srand() -{ -} - -void atof() -{ -} - -int glob(const char *pattern, - int flags, - int (*errfunc) (const char *epath, int eerrno), - glob_t *pglob) -{ - return 0; -} - -void globfree(glob_t *pglob) -{ -} - -int pthread_atfork(void (*prefork)(void), - void (*postfork_parent)(void), - void (*postfork_child)(void)) -{ - return 0; -} - -int mlockall(int flags) -{ - return 0; -} - -int munlockall(void) -{ - return 0; -} - -int shm_open(const char *name, int oflag, mode_t mode) -{ - return 0; -} - -int shm_unlink(const char *name) -{ - return 0; -} - -int posix_madvise(void *addr, size_t len, int advice) -{ - return 0; -} - -#endif diff --git a/src/rt/rust_android_dummy.h b/src/rt/rust_android_dummy.h deleted file mode 100644 index d2329a46c831a..0000000000000 --- a/src/rt/rust_android_dummy.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef _RUST_ANDROID_DUMMY_H -#define _RUST_ANDROID_DUMMY_H - -int backtrace (void **__array, int __size); - -char **backtrace_symbols (void *__const *__array, int __size); - -void backtrace_symbols_fd (void *__const *__array, int __size, int __fd); - -#include - -struct stat; -typedef struct { - size_t gl_pathc; /* Count of total paths so far. */ - size_t gl_matchc; /* Count of paths matching pattern. */ - size_t gl_offs; /* Reserved at beginning of gl_pathv. */ - int gl_flags; /* Copy of flags parameter to glob. */ - char **gl_pathv; /* List of paths matching pattern. */ - /* Copy of errfunc parameter to glob. */ - int (*gl_errfunc)(const char *, int); - - /* - * Alternate filesystem access methods for glob; replacement - * versions of closedir(3), readdir(3), opendir(3), stat(2) - * and lstat(2). - */ - void (*gl_closedir)(void *); - struct dirent *(*gl_readdir)(void *); - void *(*gl_opendir)(const char *); - int (*gl_lstat)(const char *, struct stat *); -} glob_t; - -#endif diff --git a/src/rt/rust_builtin.c b/src/rt/rust_builtin.c deleted file mode 100644 index c2168d785b995..0000000000000 --- a/src/rt/rust_builtin.c +++ /dev/null @@ -1,470 +0,0 @@ -// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#if !defined(_WIN32) - -#include -#include -#include -#include -#include - - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#include -#include - -#if !(TARGET_OS_IPHONE) -#include -#endif -#endif - -char* -rust_list_dir_val(struct dirent* entry_ptr) { - return entry_ptr->d_name; -} - -// Android's struct dirent does have d_type from the very beginning -// (android-3). _DIRENT_HAVE_D_TYPE is not defined all the way to android-21 -// though... -#if defined(__ANDROID__) -# define _DIRENT_HAVE_D_TYPE -#endif - -int -rust_dir_get_mode(struct dirent* entry_ptr) { -#if defined(_DIRENT_HAVE_D_TYPE) || defined(__APPLE__) - switch (entry_ptr->d_type) { - case DT_BLK: return S_IFBLK; - case DT_CHR: return S_IFCHR; - case DT_FIFO: return S_IFIFO; - case DT_LNK: return S_IFLNK; - case DT_REG: return S_IFREG; - case DT_SOCK: return S_IFSOCK; - case DT_DIR: return S_IFDIR; - } -#endif - return -1; -} - -ino_t -rust_dir_get_ino(struct dirent* entry_ptr) { - return entry_ptr->d_ino; -} - -DIR* -rust_opendir(char *dirname) { - return opendir(dirname); -} - -int -rust_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { - return readdir_r(dirp, entry, result); -} - -size_t -rust_dirent_t_size() { - return sizeof(struct dirent); -} - -#if defined(__BSD__) -static int -get_num_cpus() { - /* swiped from http://stackoverflow.com/questions/150355/ - programmatically-find-the-number-of-cores-on-a-machine */ - - unsigned int numCPU; - int mib[4]; - size_t len = sizeof(numCPU); - - /* set the mib for hw.ncpu */ - mib[0] = CTL_HW; - mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU; - - /* get the number of CPUs from the system */ - sysctl(mib, 2, &numCPU, &len, NULL, 0); - - if( numCPU < 1 ) { - mib[1] = HW_NCPU; - sysctl( mib, 2, &numCPU, &len, NULL, 0 ); - - if( numCPU < 1 ) { - numCPU = 1; - } - } - return numCPU; -} -#elif defined(__GNUC__) -static int -get_num_cpus() { - return sysconf(_SC_NPROCESSORS_ONLN); -} -#endif - -uintptr_t -rust_get_num_cpus() { - return get_num_cpus(); -} - -#if defined(__DragonFly__) -#include -// In DragonFly __error() is an inline function and as such -// no symbol exists for it. -int *__dfly_error(void) { return __error(); } -#endif - -#if defined(__Bitrig__) -#include -#include -#include -#include - -int rust_get_path(void *p, size_t* sz) -{ - int mib[4]; - char *eq = NULL; - char *key = NULL; - char *val = NULL; - char **menv = NULL; - size_t maxlen, len; - int nenv = 0; - int i; - - if ((p == NULL) && (sz == NULL)) - return -1; - - /* get the argv array */ - mib[0] = CTL_KERN; - mib[1] = KERN_PROC_ARGS; - mib[2] = getpid(); - mib[3] = KERN_PROC_ENV; - - /* get the number of bytes needed to get the env */ - maxlen = 0; - if (sysctl(mib, 4, NULL, &maxlen, NULL, 0) == -1) - return -1; - - /* allocate the buffer */ - if ((menv = calloc(maxlen, sizeof(char))) == NULL) - return -1; - - /* get the env array */ - if (sysctl(mib, 4, menv, &maxlen, NULL, 0) == -1) - { - free(menv); - return -1; - } - - mib[3] = KERN_PROC_NENV; - len = sizeof(int); - /* get the length of env array */ - if (sysctl(mib, 4, &nenv, &len, NULL, 0) == -1) - { - free(menv); - return -1; - } - - /* find _ key and resolve the value */ - for (i = 0; i < nenv; i++) - { - if ((eq = strstr(menv[i], "=")) == NULL) - continue; - - key = menv[i]; - val = eq + 1; - *eq = '\0'; - - if (strncmp(key, "PATH", maxlen) != 0) - continue; - - if (p == NULL) - { - /* return the length of the value + NUL */ - *sz = strnlen(val, maxlen) + 1; - free(menv); - return 0; - } - else - { - /* copy *sz bytes to the output buffer */ - memcpy(p, val, *sz); - free(menv); - return 0; - } - } - - free(menv); - return -1; -} - -int rust_get_path_array(void * p, size_t * sz) -{ - char *path, *str; - char **buf; - int i, num; - size_t len; - - if ((p == NULL) && (sz == NULL)) - return -1; - - /* get the length of the PATH value */ - if (rust_get_path(NULL, &len) == -1) - return -1; - - if (len == 0) - return -1; - - /* allocate the buffer */ - if ((path = calloc(len, sizeof(char))) == NULL) - return -1; - - /* get the PATH value */ - if (rust_get_path(path, &len) == -1) - { - free(path); - return -1; - } - - /* count the number of parts in the PATH */ - num = 1; - for(str = path; *str != '\0'; str++) - { - if (*str == ':') - num++; - } - - /* calculate the size of the buffer for the 2D array */ - len = (num * sizeof(char*) + 1) + strlen(path) + 1; - - if (p == NULL) - { - free(path); - *sz = len; - return 0; - } - - /* make sure we have enough buffer space */ - if (*sz < len) - { - free(path); - return -1; - } - - /* zero out the buffer */ - buf = (char**)p; - memset(buf, 0, *sz); - - /* copy the data into the right place */ - str = p + ((num+1) * sizeof(char*)); - memcpy(str, path, strlen(path)); - - /* parse the path into it's parts */ - for (i = 0; i < num && (buf[i] = strsep(&str, ":")) != NULL; i++) {;} - buf[num] = NULL; - - free(path); - return 0; -} - -int rust_get_argv_zero(void* p, size_t* sz) -{ - int mib[4]; - char **argv = NULL; - size_t len; - - if ((p == NULL) && (sz == NULL)) - return -1; - - /* get the argv array */ - mib[0] = CTL_KERN; - mib[1] = KERN_PROC_ARGS; - mib[2] = getpid(); - mib[3] = KERN_PROC_ARGV; - - /* request KERN_PROC_ARGV size */ - len = 0; - if (sysctl(mib, 4, NULL, &len, NULL, 0) == -1) - return -1; - - /* allocate buffer to receive the values */ - if ((argv = malloc(len)) == NULL) - return -1; - - /* get the argv array */ - if (sysctl(mib, 4, argv, &len, NULL, 0) == -1) - { - free(argv); - return -1; - } - - /* get length of argv[0] */ - len = strnlen(argv[0], len) + 1; - - if (p == NULL) - { - *sz = len; - free(argv); - return 0; - } - - if (*sz < len) - { - free(argv); - return -1; - } - - memcpy(p, argv[0], len); - free(argv); - return 0; -} - -const char * rust_current_exe() -{ - static char *self = NULL; - char *argv0; - char **paths; - size_t sz; - int i; - /* If `PATH_MAX` is defined on the platform, `realpath` will truncate the - * resolved path up to `PATH_MAX`. While this can make the resolution fail if - * the executable is placed in a deep path, the usage of a buffer whose - * length depends on `PATH_MAX` is still memory safe. */ - char buf[2*PATH_MAX], exe[PATH_MAX]; - - if (self != NULL) - return self; - - if (rust_get_argv_zero(NULL, &sz) == -1) - return NULL; - if ((argv0 = calloc(sz, sizeof(char))) == NULL) - return NULL; - if (rust_get_argv_zero(argv0, &sz) == -1) - { - free(argv0); - return NULL; - } - - /* if argv0 is a relative or absolute path, resolve it with realpath */ - if ((*argv0 == '.') || (*argv0 == '/') || (strstr(argv0, "/") != NULL)) - { - self = realpath(argv0, NULL); - free(argv0); - return self; - } - - /* get the path array */ - if (rust_get_path_array(NULL, &sz) == -1) - { - free(argv0); - return NULL; - } - if ((paths = calloc(sz, sizeof(char))) == NULL) - { - free(argv0); - return NULL; - } - if (rust_get_path_array(paths, &sz) == -1) - { - free(argv0); - free(paths); - return NULL; - } - - for(i = 0; paths[i] != NULL; i++) - { - snprintf(buf, 2*PATH_MAX, "%s/%s", paths[i], argv0); - if (realpath(buf, exe) == NULL) - continue; - - if (access(exe, F_OK | X_OK) == -1) - continue; - - self = strdup(exe); - free(argv0); - free(paths); - return self; - } - - free(argv0); - free(paths); - return NULL; -} - -#elif defined(__OpenBSD__) - -#include -#include -#include - -const char * rust_current_exe() { - static char *self = NULL; - - if (self == NULL) { - int mib[4]; - char **argv = NULL; - size_t argv_len; - - /* initialize mib */ - mib[0] = CTL_KERN; - mib[1] = KERN_PROC_ARGS; - mib[2] = getpid(); - mib[3] = KERN_PROC_ARGV; - - /* request KERN_PROC_ARGV size */ - argv_len = 0; - if (sysctl(mib, 4, NULL, &argv_len, NULL, 0) == -1) - return (NULL); - - /* allocate size */ - if ((argv = malloc(argv_len)) == NULL) - return (NULL); - - /* request KERN_PROC_ARGV */ - if (sysctl(mib, 4, argv, &argv_len, NULL, 0) == -1) { - free(argv); - return (NULL); - } - - /* get realpath if possible */ - if ((argv[0] != NULL) && ((*argv[0] == '.') || (*argv[0] == '/') - || (strstr(argv[0], "/") != NULL))) - - self = realpath(argv[0], NULL); - else - self = NULL; - - /* cleanup */ - free(argv); - } - - return (self); -} - -#endif - -#endif // !defined(_WIN32) - -// -// Local Variables: -// mode: C++ -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: -// diff --git a/src/rtstartup/rsbegin.rs b/src/rtstartup/rsbegin.rs index a81eac279d062..d1b6fe6655ac6 100644 --- a/src/rtstartup/rsbegin.rs +++ b/src/rtstartup/rsbegin.rs @@ -22,8 +22,6 @@ // object (usually called `crtX.o), which then invokes initialization callbacks // of other runtime components (registered via yet another special image section). -#![cfg_attr(stage0, feature(no_std))] - #![crate_type="rlib"] #![no_std] #![allow(non_camel_case_types)] diff --git a/src/rtstartup/rsend.rs b/src/rtstartup/rsend.rs index e3b691ce2f7db..5e4e13ebd05e4 100644 --- a/src/rtstartup/rsend.rs +++ b/src/rtstartup/rsend.rs @@ -10,8 +10,6 @@ // See rsbegin.rs for details. -#![cfg_attr(stage0, feature(no_std))] - #![crate_type="rlib"] #![no_std] diff --git a/src/snapshots.txt b/src/snapshots.txt index c59170d523d7a..81ff9b051721d 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,3 +1,11 @@ +S 2015-12-18 3391630 + linux-i386 a09c4a4036151d0cb28e265101669731600e01f2 + linux-x86_64 97e2a5eb8904962df8596e95d6e5d9b574d73bf4 + macos-i386 ca52d2d3ba6497ed007705ee3401cf7efc136ca1 + macos-x86_64 3c44ffa18f89567c2b81f8d695e711c86d81ffc7 + winnt-i386 f9056ebd3db9611d31c2dc6dc5f96c7208d5d227 + winnt-x86_64 a85a40e535d828016181d3aa40afe34c3e36ab8c + S 2015-08-11 1af31d4 bitrig-x86_64 739e0635cd5a1b3635f1457aae3ef6390ea9a7a8 freebsd-i386 3cd4a44fb97b3135be3d1b760bea604a381e85dc diff --git a/src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs b/src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs new file mode 100644 index 0000000000000..ecf17fa84d7e3 --- /dev/null +++ b/src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs @@ -0,0 +1,60 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Beginners write `mod.item` when they should write `mod::item`. +// This tests that we suggest the latter when we encounter the former. + +pub mod a { + pub const I: i32 = 1; + + pub fn f() -> i32 { 2 } + + pub mod b { + pub const J: i32 = 3; + + pub fn g() -> i32 { 4 } + } +} + +fn h1() -> i32 { + a.I + //~^ ERROR E0425 + //~| HELP To reference an item from the `a` module, use `a::I` +} + +fn h2() -> i32 { + a.g() + //~^ ERROR E0425 + //~| HELP To call a function from the `a` module, use `a::g(..)` +} + +fn h3() -> i32 { + a.b.J + //~^ ERROR E0425 + //~| HELP To reference an item from the `a` module, use `a::b` +} + +fn h4() -> i32 { + a::b.J + //~^ ERROR E0425 + //~| HELP To reference an item from the `a::b` module, use `a::b::J` +} + +fn h5() -> i32 { + a.b.f() + //~^ ERROR E0425 + //~| HELP To reference an item from the `a` module, use `a::b` +} + +fn h6() -> i32 { + a::b.f() + //~^ ERROR E0425 + //~| HELP To call a function from the `a::b` module, use `a::b::f(..)` +} diff --git a/src/test/compile-fail/unresolved-import.rs b/src/test/compile-fail/unresolved-import.rs index 5edcf1d99a02b..b6207450d9835 100644 --- a/src/test/compile-fail/unresolved-import.rs +++ b/src/test/compile-fail/unresolved-import.rs @@ -8,24 +8,26 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-tidy-linelength + use foo::bar; //~ ERROR unresolved import `foo::bar`. Maybe a missing `extern crate foo`? -use bar::baz as x; //~ ERROR unresolved import `bar::baz`. There is no `baz` in `bar` +use bar::Baz as x; //~ ERROR unresolved import `bar::Baz`. There is no `Baz` in `bar`. Did you mean to use `Bar`? -use food::baz; //~ ERROR unresolved import `food::baz`. There is no `baz` in `food` +use food::baz; //~ ERROR unresolved import `food::baz`. There is no `baz` in `food`. Did you mean to use the re-exported import `bag`? -use food::{quux as beans}; //~ ERROR unresolved import `food::quux`. There is no `quux` in `food` +use food::{beens as Foo}; //~ ERROR unresolved import `food::beens`. There is no `beens` in `food`. Did you mean to use the re-exported import `beans`? mod bar { - struct bar; + pub struct Bar; } mod food { - pub use self::zug::baz::{self as bag, quux as beans}; + pub use self::zug::baz::{self as bag, foobar as beans}; mod zug { pub mod baz { - pub struct quux; + pub struct foobar; } } } diff --git a/src/test/run-make/execution-engine/test.rs b/src/test/run-make/execution-engine/test.rs index 20dd16872a653..928f2f996a028 100644 --- a/src/test/run-make/execution-engine/test.rs +++ b/src/test/run-make/execution-engine/test.rs @@ -215,9 +215,8 @@ fn compile_program(input: &str, sysroot: PathBuf) let handle = thread.spawn(move || { let opts = build_exec_options(sysroot); let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone()); let sess = build_session(opts, None, Registry::new(&rustc::DIAGNOSTICS), - cstore_); + cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let cfg = build_configuration(&sess); diff --git a/src/test/run-make/issue-19371/foo.rs b/src/test/run-make/issue-19371/foo.rs index 58bf5049cf13e..4b1c84ce64fee 100644 --- a/src/test/run-make/issue-19371/foo.rs +++ b/src/test/run-make/issue-19371/foo.rs @@ -55,8 +55,7 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc) { let descriptions = Registry::new(&rustc::DIAGNOSTICS); let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let cstore_ = ::rustc_driver::cstore_to_cratestore(cstore.clone()); - let sess = build_session(opts, None, descriptions, cstore_); + let sess = build_session(opts, None, descriptions, cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); (sess, cstore) } diff --git a/src/test/run-make/tools.mk b/src/test/run-make/tools.mk index 88cf2a2b031ee..efaf1197fbdba 100644 --- a/src/test/run-make/tools.mk +++ b/src/test/run-make/tools.mk @@ -85,11 +85,7 @@ ifeq ($(UNAME),Bitrig) else ifeq ($(UNAME),OpenBSD) EXTRACFLAGS := -lm -lpthread - # extend search lib for found estdc++ if build using gcc from - # ports under OpenBSD. This is needed for: - # - run-make/execution-engine - # - run-make/issue-19371 - RUSTC := $(RUSTC) -L/usr/local/lib + RUSTC := $(RUSTC) -C linker="$(word 1,$(CC:ccache=))" else EXTRACFLAGS := -lm -lrt -ldl -lpthread EXTRACXXFLAGS := -lstdc++