diff --git a/mk/docs.mk b/mk/docs.mk index 4c2c1243c65a4..799871e2bd596 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -129,21 +129,21 @@ doc/: HTML_DEPS += doc/rust.css doc/rust.css: $(D)/rust.css | doc/ @$(call E, cp: $@) - $(Q)cp -a $< $@ 2> /dev/null + $(Q)cp -PRp $< $@ 2> /dev/null HTML_DEPS += doc/favicon.inc doc/favicon.inc: $(D)/favicon.inc | doc/ @$(call E, cp: $@) - $(Q)cp -a $< $@ 2> /dev/null + $(Q)cp -PRp $< $@ 2> /dev/null doc/full-toc.inc: $(D)/full-toc.inc | doc/ @$(call E, cp: $@) - $(Q)cp -a $< $@ 2> /dev/null + $(Q)cp -PRp $< $@ 2> /dev/null HTML_DEPS += doc/footer.inc doc/footer.inc: $(D)/footer.inc | doc/ @$(call E, cp: $@) - $(Q)cp -a $< $@ 2> /dev/null + $(Q)cp -PRp $< $@ 2> /dev/null # The (english) documentation for each doc item. diff --git a/mk/tests.mk b/mk/tests.mk index d8d77db1e0276..c5bb6ef81f6da 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -38,16 +38,11 @@ ifdef CHECK_IGNORED TESTARGS += --ignored endif - # Arguments to the cfail/rfail/rpass/bench tests ifdef CFG_VALGRIND CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)" endif -ifdef PLEASE_BENCH - TESTARGS += --bench -endif - # Arguments to the perf tests ifdef CFG_PERF_TOOL CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)" @@ -55,6 +50,11 @@ endif CTEST_TESTARGS := $(TESTARGS) +# --bench is only relevant for crate tests, not for the compile tests +ifdef PLEASE_BENCH + TESTARGS += --bench +endif + ifdef VERBOSE CTEST_TESTARGS += --verbose endif diff --git a/src/doc/reference.md b/src/doc/reference.md index 3223e2f262653..11b2afc1c8822 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -648,7 +648,7 @@ All of the above extensions are expressions with values. Users of `rustc` can define new syntax extensions in two ways: -* [Compiler plugins](book/syntax-extensions.html) can include arbitrary +* [Compiler plugins][plugin] can include arbitrary Rust code that manipulates syntax trees at compile time. * [Macros](book/macros.html) define new syntax in a higher-level, @@ -818,9 +818,8 @@ item : extern_crate_decl | use_decl | mod_item | fn_item | type_item | extern_block ; ``` -An _item_ is a component of a crate; some module items can be defined in crate -files, but most are defined in source files. Items are organized within a crate -by a nested set of [modules](#modules). Every crate has a single "outermost" +An _item_ is a component of a crate. Items are organized within a crate by a +nested set of [modules](#modules). Every crate has a single "outermost" anonymous module; all further items within the crate have [paths](#paths) within the module tree of the crate. diff --git a/src/doc/trpl/SUMMARY.md b/src/doc/trpl/SUMMARY.md index bfc1247dc3bc0..9e16414d225a9 100644 --- a/src/doc/trpl/SUMMARY.md +++ b/src/doc/trpl/SUMMARY.md @@ -37,3 +37,4 @@ * [Macros](macros.md) * [Compiler Plugins](plugins.md) * [Conclusion](conclusion.md) +* [Glossary](glossary.md) diff --git a/src/doc/trpl/compound-data-types.md b/src/doc/trpl/compound-data-types.md index dea19fa73fb49..db3202b30345f 100644 --- a/src/doc/trpl/compound-data-types.md +++ b/src/doc/trpl/compound-data-types.md @@ -47,7 +47,8 @@ This pattern is very powerful, and we'll see it repeated more later. There are also a few things you can do with a tuple as a whole, without destructuring. You can assign one tuple into another, if they have the same -arity and contained types. +contained types and arity. Tuples have the same arity when they have the same +length. ```rust let mut x = (1, 2); // x: (i32, i32) diff --git a/src/doc/trpl/glossary.md b/src/doc/trpl/glossary.md new file mode 100644 index 0000000000000..156f33748673b --- /dev/null +++ b/src/doc/trpl/glossary.md @@ -0,0 +1,16 @@ +% Glossary + +Not every Rustacean has a background in systems programming, nor in computer +science, so we've added explanations of terms that might be unfamiliar. + +### Arity + +Arity refers to the number of arguments a function or operation takes. + +```rust +let x = (2, 3); +let y = (4, 6); +let z = (8, 2, 6); +``` + +In the example above `x` and `y` have arity 2. `z` has arity 3. diff --git a/src/doc/trpl/hello-world.md b/src/doc/trpl/hello-world.md index 640f0109b0697..a3b5d655fa78b 100644 --- a/src/doc/trpl/hello-world.md +++ b/src/doc/trpl/hello-world.md @@ -89,7 +89,7 @@ This line does all of the work in our little program. There are a number of details that are important here. The first is that it's indented with four spaces, not tabs. Please configure your editor of choice to insert four spaces with the tab key. We provide some [sample configurations for various -editors](https://github.com/rust-lang/rust/tree/master/src/etc). +editors](https://github.com/rust-lang/rust/tree/master/src/etc/CONFIGS.md). The second point is the `println!()` part. This is calling a Rust *macro*, which is how metaprogramming is done in Rust. If it were a function instead, it diff --git a/src/doc/trpl/plugins.md b/src/doc/trpl/plugins.md index 3dea1a66ffd72..79502f3cd17f7 100644 --- a/src/doc/trpl/plugins.md +++ b/src/doc/trpl/plugins.md @@ -39,6 +39,16 @@ If present, arguments passed as `#![plugin(foo(... args ...))]` are not interpreted by rustc itself. They are provided to the plugin through the `Registry`'s [`args` method](../rustc/plugin/registry/struct.Registry.html#method.args). +In the vast majority of cases, a plugin should *only* be used through +`#![plugin]` and not through an `extern crate` item. Linking a plugin would +pull in all of libsyntax and librustc as dependencies of your crate. This is +generally unwanted unless you are building another plugin. The +`plugin_as_library` lint checks these guidelines. + +The usual practice is to put compiler plugins in their own crate, separate from +any `macro_rules!` macros or ordinary Rust code meant to be used by consumers +of a library. + # Syntax extensions Plugins can extend Rust's syntax in various ways. One kind of syntax extension diff --git a/src/doc/trpl/variable-bindings.md b/src/doc/trpl/variable-bindings.md index 41c0e9de9b505..88babd8659c2b 100644 --- a/src/doc/trpl/variable-bindings.md +++ b/src/doc/trpl/variable-bindings.md @@ -40,6 +40,11 @@ let x: i32 = 5; If I asked you to read this out loud to the rest of the class, you'd say "`x` is a binding with the type `i32` and the value `five`." +In this case we chose to represent `x` as a 32-bit signed integer. Rust has +many different primitive integer types. They begin with `i` for signed integers +and `u` for unsigned integers. The possible integer sizes are 8, 16, 32, and 64 +bits. + In future examples, we may annotate the type in a comment. The examples will look like this: diff --git a/src/etc/CONFIGS.md b/src/etc/CONFIGS.md new file mode 100644 index 0000000000000..036a2f7d4365b --- /dev/null +++ b/src/etc/CONFIGS.md @@ -0,0 +1,10 @@ +# Configs + +Here are some links to repos with configs which ease the use of rust: + +* [rust.vim](https://github.com/rust-lang/rust.vim) +* [emacs rust-mode](https://github.com/rust-lang/rust-mode) +* [gedit-config](https://github.com/rust-lang/gedit-config) +* [kate-config](https://github.com/rust-lang/kate-config) +* [nano-config](https://github.com/rust-lang/nano-config) +* [zsh-config](https://github.com/rust-lang/zsh-config) diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index 07e832d317adb..d4f1071c724b6 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -241,6 +241,9 @@ create_tmp_dir() { echo $TMP_DIR } +# Make `tr` locale independent +LC_CTYPE=C + probe_need CFG_CURL curl probe_need CFG_TAR tar probe_need CFG_FILE file diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 66374b639c1a6..1d994839d9941 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -655,6 +655,8 @@ impl FromIterator for BinaryHeap { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for BinaryHeap { type IntoIter = IntoIter; @@ -663,6 +665,18 @@ impl IntoIterator for BinaryHeap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for BinaryHeap { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a BinaryHeap where T: Ord { type IntoIter = Iter<'a, T>; @@ -671,6 +685,16 @@ impl<'a, T> IntoIterator for &'a BinaryHeap where T: Ord { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a BinaryHeap where T: Ord { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Extend for BinaryHeap { fn extend>(&mut self, iter: Iter) { diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 6d15a264172a1..ca598a8d4d292 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -1070,6 +1070,8 @@ impl<'a> RandomAccessIterator for Iter<'a> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a> IntoIterator for &'a Bitv { type IntoIter = Iter<'a>; @@ -1078,6 +1080,16 @@ impl<'a> IntoIterator for &'a Bitv { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a> IntoIterator for &'a Bitv { + type Item = bool; + type IntoIter = Iter<'a>; + + fn into_iter(self) -> Iter<'a> { + self.iter() + } +} + /// An implementation of a set using a bit vector as an underlying /// representation for holding unsigned numerical elements. /// @@ -1882,6 +1894,8 @@ impl<'a> Iterator for SymmetricDifference<'a> { #[inline] fn size_hint(&self) -> (usize, Option) { self.0.size_hint() } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a> IntoIterator for &'a BitvSet { type IntoIter = SetIter<'a>; @@ -1890,6 +1904,16 @@ impl<'a> IntoIterator for &'a BitvSet { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a> IntoIterator for &'a BitvSet { + type Item = usize; + type IntoIter = SetIter<'a>; + + fn into_iter(self) -> SetIter<'a> { + self.iter() + } +} + #[cfg(test)] mod tests { use prelude::*; diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 895fa076ab604..84f9825e989b3 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -462,6 +462,8 @@ impl BTreeMap { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for BTreeMap { type IntoIter = IntoIter; @@ -470,6 +472,18 @@ impl IntoIterator for BTreeMap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for BTreeMap { + type Item = (K, V); + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V> IntoIterator for &'a BTreeMap { type IntoIter = Iter<'a, K, V>; @@ -478,6 +492,18 @@ impl<'a, K, V> IntoIterator for &'a BTreeMap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V> IntoIterator for &'a BTreeMap { + type Item = (&'a K, &'a V); + type IntoIter = Iter<'a, K, V>; + + fn into_iter(self) -> Iter<'a, K, V> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V> IntoIterator for &'a mut BTreeMap { type IntoIter = IterMut<'a, K, V>; @@ -486,6 +512,16 @@ impl<'a, K, V> IntoIterator for &'a mut BTreeMap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V> IntoIterator for &'a mut BTreeMap { + type Item = (&'a K, &'a mut V); + type IntoIter = IterMut<'a, K, V>; + + fn into_iter(mut self) -> IterMut<'a, K, V> { + self.iter_mut() + } +} + /// A helper enum useful for deciding whether to continue a loop since we can't /// return from a closure enum Continuation { diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 8628879295b83..aecf594031192 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -480,6 +480,8 @@ impl FromIterator for BTreeSet { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for BTreeSet { type IntoIter = IntoIter; @@ -488,6 +490,18 @@ impl IntoIterator for BTreeSet { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for BTreeSet { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a BTreeSet { type IntoIter = Iter<'a, T>; @@ -496,6 +510,16 @@ impl<'a, T> IntoIterator for &'a BTreeSet { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a BTreeSet { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Extend for BTreeSet { #[inline] diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 423646e5acd04..27b282ee9a9c1 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -837,6 +837,8 @@ impl FromIterator for DList { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for DList { type IntoIter = IntoIter; @@ -845,7 +847,29 @@ impl IntoIterator for DList { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for DList { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a DList { + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a DList { + type Item = &'a T; type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { @@ -853,7 +877,19 @@ impl<'a, T> IntoIterator for &'a DList { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut DList { + type IntoIter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut DList { + type Item = &'a mut T; type IntoIter = IterMut<'a, T>; fn into_iter(mut self) -> IterMut<'a, T> { diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index da533d34703dd..5c37be188fea4 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -257,6 +257,8 @@ impl FromIterator for EnumSet { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, E> IntoIterator for &'a EnumSet where E: CLike { type IntoIter = Iter; @@ -265,6 +267,16 @@ impl<'a, E> IntoIterator for &'a EnumSet where E: CLike { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, E> IntoIterator for &'a EnumSet where E: CLike { + type Item = E; + type IntoIter = Iter; + + fn into_iter(self) -> Iter { + self.iter() + } +} + impl Extend for EnumSet { fn extend>(&mut self, iterator: I) { for element in iterator { diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index ec1e648939a54..0a4ccde923667 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1699,6 +1699,8 @@ impl FromIterator for RingBuf { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for RingBuf { type IntoIter = IntoIter; @@ -1707,6 +1709,18 @@ impl IntoIterator for RingBuf { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for RingBuf { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a RingBuf { type IntoIter = Iter<'a, T>; @@ -1715,6 +1729,18 @@ impl<'a, T> IntoIterator for &'a RingBuf { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a RingBuf { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a mut RingBuf { type IntoIter = IterMut<'a, T>; @@ -1723,6 +1749,16 @@ impl<'a, T> IntoIterator for &'a mut RingBuf { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a mut RingBuf { + type Item = &'a mut T; + type IntoIter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Extend for RingBuf { fn extend>(&mut self, iterator: T) { diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 8382acfe3da05..2d4dc2bcf30d3 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1285,7 +1285,8 @@ pub trait StrExt: Index { /// let v: Vec<&str> = some_words.words().collect(); /// assert_eq!(v, vec!["Mary", "had", "a", "little", "lamb"]); /// ``` - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "str_words", + reason = "the precise algorithm to use is unclear")] fn words(&self) -> Words { UnicodeStr::words(&self[]) } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 4e6e40ea693d1..f294dd3c3e0f6 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1414,6 +1414,8 @@ impl FromIterator for Vec { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for Vec { type IntoIter = IntoIter; @@ -1422,6 +1424,18 @@ impl IntoIterator for Vec { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for Vec { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a Vec { type IntoIter = slice::Iter<'a, T>; @@ -1430,7 +1444,29 @@ impl<'a, T> IntoIterator for &'a Vec { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a Vec { + type Item = &'a T; + type IntoIter = slice::Iter<'a, T>; + + fn into_iter(self) -> slice::Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut Vec { + type IntoIter = slice::IterMut<'a, T>; + + fn into_iter(mut self) -> slice::IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut Vec { + type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; fn into_iter(mut self) -> slice::IterMut<'a, T> { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index ba358ada0adac..7f9484c58a185 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -668,6 +668,8 @@ impl FromIterator<(usize, V)> for VecMap { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for VecMap { type IntoIter = IntoIter; @@ -676,7 +678,29 @@ impl IntoIterator for VecMap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for VecMap { + type Item = (usize, T); + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a VecMap { + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a VecMap { + type Item = (usize, &'a T); type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { @@ -684,7 +708,19 @@ impl<'a, T> IntoIterator for &'a VecMap { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut VecMap { + type IntoIter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut VecMap { + type Item = (usize, &'a mut T); type IntoIter = IterMut<'a, T>; fn into_iter(mut self) -> IterMut<'a, T> { diff --git a/src/libcore/array.rs b/src/libcore/array.rs index a596fe4a58809..abaa7594d0478 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -48,6 +48,8 @@ macro_rules! array_impls { } } + // NOTE(stage0): remove impl after a snapshot + #[cfg(stage0)] impl<'a, T> IntoIterator for &'a [T; $N] { type IntoIter = Iter<'a, T>; @@ -56,7 +58,29 @@ macro_rules! array_impls { } } + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + impl<'a, T> IntoIterator for &'a [T; $N] { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } + } + + // NOTE(stage0): remove impl after a snapshot + #[cfg(stage0)] + impl<'a, T> IntoIterator for &'a mut [T; $N] { + type IntoIter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } + } + + #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut [T; $N] { + type Item = &'a mut T; type IntoIter = IterMut<'a, T>; fn into_iter(self) -> IterMut<'a, T> { diff --git a/src/libcore/finally.rs b/src/libcore/finally.rs index 182851002d942..562a597cccf1d 100644 --- a/src/libcore/finally.rs +++ b/src/libcore/finally.rs @@ -72,7 +72,7 @@ impl Finally for F where F: FnMut() -> T { /// ``` /// use std::finally::try_finally; /// -/// struct State<'a> { buffer: &'a mut [u8], len: uint } +/// struct State<'a> { buffer: &'a mut [u8], len: usize } /// # let mut buf = []; /// let mut state = State { buffer: &mut buf, len: 0 }; /// try_finally( diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 06aba2cb08ef3..03c473ed96741 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -118,6 +118,8 @@ pub trait FromIterator { fn from_iter>(iterator: T) -> Self; } +// NOTE(stage0): remove trait after a snapshot +#[cfg(stage0)] /// Conversion into an `Iterator` pub trait IntoIterator { type IntoIter: Iterator; @@ -127,6 +129,19 @@ pub trait IntoIterator { fn into_iter(self) -> Self::IntoIter; } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +/// Conversion into an `Iterator` +pub trait IntoIterator { + type Item; + type IntoIter: Iterator; + + /// Consumes `Self` and returns an iterator over it + #[stable(feature = "rust1", since = "1.0.0")] + fn into_iter(self) -> Self::IntoIter; +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for I where I: Iterator { type IntoIter = I; @@ -135,6 +150,16 @@ impl IntoIterator for I where I: Iterator { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for I { + type Item = I::Item; + type IntoIter = I; + + fn into_iter(self) -> I { + self + } +} + /// A type growable from an `Iterator` implementation #[stable(feature = "rust1", since = "1.0.0")] pub trait Extend { @@ -1055,6 +1080,7 @@ pub trait RandomAccessIterator: Iterator { #[stable(feature = "rust1", since = "1.0.0")] pub trait ExactSizeIterator: Iterator { #[inline] + #[stable(feature = "rust1", since = "1.0.0")] /// Return the exact length of the iterator. fn len(&self) -> usize { let (lower, upper) = self.size_hint(); diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index a46536e341edd..fbd7f840da6e1 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -37,8 +37,8 @@ //! //! #[derive(Debug)] //! struct Point { -//! x: int, -//! y: int +//! x: i32, +//! y: i32 //! } //! //! impl Add for Point { @@ -206,7 +206,7 @@ macro_rules! add_impl { )*) } -add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } +add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Sub` trait is used to specify the functionality of `-`. /// @@ -259,7 +259,7 @@ macro_rules! sub_impl { )*) } -sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } +sub_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Mul` trait is used to specify the functionality of `*`. /// @@ -312,7 +312,7 @@ macro_rules! mul_impl { )*) } -mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } +mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Div` trait is used to specify the functionality of `/`. /// @@ -365,7 +365,7 @@ macro_rules! div_impl { )*) } -div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } +div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Rem` trait is used to specify the functionality of `%`. /// @@ -435,7 +435,7 @@ macro_rules! rem_float_impl { } } -rem_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } +rem_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 } rem_float_impl! { f32, fmodf } rem_float_impl! { f64, fmod } @@ -506,9 +506,9 @@ macro_rules! neg_uint_impl { } } -neg_impl! { int i8 i16 i32 i64 f32 f64 } +neg_impl! { isize i8 i16 i32 i64 f32 f64 } -neg_uint_impl! { uint, int } +neg_uint_impl! { usize, isize } neg_uint_impl! { u8, i8 } neg_uint_impl! { u16, i16 } neg_uint_impl! { u32, i32 } @@ -566,7 +566,7 @@ macro_rules! not_impl { )*) } -not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } +not_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `BitAnd` trait is used to specify the functionality of `&`. /// @@ -619,7 +619,7 @@ macro_rules! bitand_impl { )*) } -bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } +bitand_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `BitOr` trait is used to specify the functionality of `|`. /// @@ -672,7 +672,7 @@ macro_rules! bitor_impl { )*) } -bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } +bitor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `BitXor` trait is used to specify the functionality of `^`. /// @@ -725,7 +725,7 @@ macro_rules! bitxor_impl { )*) } -bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } +bitxor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 } /// The `Shl` trait is used to specify the functionality of `<<`. /// diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 081c895c3175c..3dc94ba555f35 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -60,19 +60,19 @@ //! the optional owned box, `Option>`. //! //! The following example uses `Option` to create an optional box of -//! `int`. Notice that in order to use the inner `int` value first the +//! `i32`. Notice that in order to use the inner `i32` value first the //! `check_optional` function needs to use pattern matching to //! determine whether the box has a value (i.e. it is `Some(...)`) or //! not (`None`). //! //! ``` -//! let optional: Option> = None; +//! let optional: Option> = None; //! check_optional(&optional); //! -//! let optional: Option> = Some(Box::new(9000)); +//! let optional: Option> = Some(Box::new(9000)); //! check_optional(&optional); //! -//! fn check_optional(optional: &Option>) { +//! fn check_optional(optional: &Option>) { //! match *optional { //! Some(ref p) => println!("have value {}", p), //! None => println!("have no value") @@ -108,7 +108,7 @@ //! Initialize a result to `None` before a loop: //! //! ``` -//! enum Kingdom { Plant(uint, &'static str), Animal(uint, &'static str) } +//! enum Kingdom { Plant(u32, &'static str), Animal(u32, &'static str) } //! //! // A list of data to search through. //! let all_the_big_things = [ @@ -188,10 +188,10 @@ impl Option { /// # Example /// /// ``` - /// let x: Option = Some(2); + /// let x: Option = Some(2); /// assert_eq!(x.is_some(), true); /// - /// let x: Option = None; + /// let x: Option = None; /// assert_eq!(x.is_some(), false); /// ``` #[inline] @@ -208,10 +208,10 @@ impl Option { /// # Example /// /// ``` - /// let x: Option = Some(2); + /// let x: Option = Some(2); /// assert_eq!(x.is_none(), false); /// - /// let x: Option = None; + /// let x: Option = None; /// assert_eq!(x.is_none(), true); /// ``` #[inline] @@ -228,7 +228,7 @@ impl Option { /// /// # Example /// - /// Convert an `Option` into an `Option`, preserving the original. + /// Convert an `Option` into an `Option`, preserving the original. /// The `map` method takes the `self` argument by value, consuming the original, /// so this technique uses `as_ref` to first take an `Option` to a reference /// to the value inside the original. @@ -237,7 +237,7 @@ impl Option { /// let num_as_str: Option = Some("10".to_string()); /// // First, cast `Option` to `Option<&String>` with `as_ref`, /// // then consume *that* with `map`, leaving `num_as_str` on the stack. - /// let num_as_int: Option = num_as_str.as_ref().map(|n| n.len()); + /// let num_as_int: Option = num_as_str.as_ref().map(|n| n.len()); /// println!("still can print num_as_str: {:?}", num_as_str); /// ``` #[inline] @@ -406,12 +406,12 @@ impl Option { /// /// # Example /// - /// Convert an `Option` into an `Option`, consuming the original: + /// Convert an `Option` into an `Option`, consuming the original: /// /// ``` /// let num_as_str: Option = Some("10".to_string()); /// // `Option::map` takes self *by value*, consuming `num_as_str` - /// let num_as_int: Option = num_as_str.map(|n| n.len()); + /// let num_as_int: Option = num_as_str.map(|n| n.len()); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -518,7 +518,7 @@ impl Option { /// let x = Some(4); /// assert_eq!(x.iter().next(), Some(&4)); /// - /// let x: Option = None; + /// let x: Option = None; /// assert_eq!(x.iter().next(), None); /// ``` #[inline] @@ -539,7 +539,7 @@ impl Option { /// } /// assert_eq!(x, Some(42)); /// - /// let mut x: Option = None; + /// let mut x: Option = None; /// assert_eq!(x.iter_mut().next(), None); /// ``` #[inline] @@ -581,7 +581,7 @@ impl Option { /// let y: Option<&str> = None; /// assert_eq!(x.and(y), None); /// - /// let x: Option = None; + /// let x: Option = None; /// let y = Some("foo"); /// assert_eq!(x.and(y), None); /// @@ -589,7 +589,7 @@ impl Option { /// let y = Some("foo"); /// assert_eq!(x.and(y), Some("foo")); /// - /// let x: Option = None; + /// let x: Option = None; /// let y: Option<&str> = None; /// assert_eq!(x.and(y), None); /// ``` @@ -608,8 +608,8 @@ impl Option { /// # Example /// /// ``` - /// fn sq(x: uint) -> Option { Some(x * x) } - /// fn nope(_: uint) -> Option { None } + /// fn sq(x: u32) -> Option { Some(x * x) } + /// fn nope(_: u32) -> Option { None } /// /// assert_eq!(Some(2).and_then(sq).and_then(sq), Some(16)); /// assert_eq!(Some(2).and_then(sq).and_then(nope), None); @@ -642,7 +642,7 @@ impl Option { /// let y = Some(100); /// assert_eq!(x.or(y), Some(2)); /// - /// let x: Option = None; + /// let x: Option = None; /// let y = None; /// assert_eq!(x.or(y), None); /// ``` @@ -690,7 +690,7 @@ impl Option { /// x.take(); /// assert_eq!(x, None); /// - /// let mut x: Option = None; + /// let mut x: Option = None; /// x.take(); /// assert_eq!(x, None); /// ``` @@ -789,7 +789,7 @@ impl Iterator for Item { } #[inline] - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { match self.opt { Some(_) => (1, Some(1)), None => (0, Some(0)), @@ -817,7 +817,7 @@ impl<'a, A> Iterator for Iter<'a, A> { #[inline] fn next(&mut self) -> Option<&'a A> { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -847,7 +847,7 @@ impl<'a, A> Iterator for IterMut<'a, A> { #[inline] fn next(&mut self) -> Option<&'a mut A> { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -870,7 +870,7 @@ impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { self.inner.next() } #[inline] - fn size_hint(&self) -> (uint, Option) { self.inner.size_hint() } + fn size_hint(&self) -> (usize, Option) { self.inner.size_hint() } } #[stable(feature = "rust1", since = "1.0.0")] @@ -896,11 +896,11 @@ impl> FromIterator> for Option { /// checking for overflow: /// /// ```rust - /// use std::uint; + /// use std::u16; /// /// let v = vec!(1, 2); - /// let res: Option> = v.iter().map(|&x: &uint| - /// if x == uint::MAX { None } + /// let res: Option> = v.iter().map(|&x: &u16| + /// if x == u16::MAX { None } /// else { Some(x + 1) } /// ).collect(); /// assert!(res == Some(vec!(2, 3))); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 1b8ec048f8de7..072c60c7036cf 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -27,10 +27,10 @@ //! ## 1. Coerce a reference (`&T`) or mutable reference (`&mut T`). //! //! ``` -//! let my_num: int = 10; -//! let my_num_ptr: *const int = &my_num; -//! let mut my_speed: int = 88; -//! let my_speed_ptr: *mut int = &mut my_speed; +//! let my_num: i32 = 10; +//! let my_num_ptr: *const i32 = &my_num; +//! let mut my_speed: i32 = 88; +//! let my_speed_ptr: *mut i32 = &mut my_speed; //! ``` //! //! This does not take ownership of the original allocation @@ -49,15 +49,15 @@ //! use std::mem; //! //! unsafe { -//! let my_num: Box = Box::new(10); -//! let my_num: *const int = mem::transmute(my_num); -//! let my_speed: Box = Box::new(88); -//! let my_speed: *mut int = mem::transmute(my_speed); +//! let my_num: Box = Box::new(10); +//! let my_num: *const i32 = mem::transmute(my_num); +//! let my_speed: Box = Box::new(88); +//! let my_speed: *mut i32 = mem::transmute(my_speed); //! //! // By taking ownership of the original `Box` though //! // we are obligated to transmute it back later to be destroyed. -//! drop(mem::transmute::<_, Box>(my_speed)); -//! drop(mem::transmute::<_, Box>(my_num)); +//! drop(mem::transmute::<_, Box>(my_speed)); +//! drop(mem::transmute::<_, Box>(my_num)); //! } //! ``` //! @@ -73,7 +73,7 @@ //! //! fn main() { //! unsafe { -//! let my_num: *mut int = libc::malloc(mem::size_of::() as libc::size_t) as *mut int; +//! let my_num: *mut i32 = libc::malloc(mem::size_of::() as libc::size_t) as *mut i32; //! if my_num.is_null() { //! panic!("failed to allocate memory"); //! } @@ -117,7 +117,7 @@ pub use intrinsics::set_memory; /// ``` /// use std::ptr; /// -/// let p: *const int = ptr::null(); +/// let p: *const i32 = ptr::null(); /// assert!(p.is_null()); /// ``` #[inline] @@ -131,7 +131,7 @@ pub fn null() -> *const T { 0 as *const T } /// ``` /// use std::ptr; /// -/// let p: *mut int = ptr::null_mut(); +/// let p: *mut i32 = ptr::null_mut(); /// assert!(p.is_null()); /// ``` #[inline] @@ -148,7 +148,7 @@ pub fn null_mut() -> *mut T { 0 as *mut T } #[inline] #[unstable(feature = "core", reason = "may play a larger role in std::ptr future extensions")] -pub unsafe fn zero_memory(dst: *mut T, count: uint) { +pub unsafe fn zero_memory(dst: *mut T, count: usize) { set_memory(dst, 0, count); } @@ -276,7 +276,7 @@ pub trait PtrExt: Sized { /// Otherwise `offset` invokes Undefined Behaviour, regardless of whether /// the pointer is used. #[stable(feature = "rust1", since = "1.0.0")] - unsafe fn offset(self, count: int) -> Self; + unsafe fn offset(self, count: isize) -> Self; } /// Methods on mutable raw pointers @@ -303,11 +303,11 @@ impl PtrExt for *const T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn is_null(self) -> bool { self as uint == 0 } + fn is_null(self) -> bool { self as usize == 0 } #[inline] #[stable(feature = "rust1", since = "1.0.0")] - unsafe fn offset(self, count: int) -> *const T { + unsafe fn offset(self, count: isize) -> *const T { intrinsics::offset(self, count) } @@ -330,11 +330,11 @@ impl PtrExt for *mut T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn is_null(self) -> bool { self as uint == 0 } + fn is_null(self) -> bool { self as usize == 0 } #[inline] #[stable(feature = "rust1", since = "1.0.0")] - unsafe fn offset(self, count: int) -> *mut T { + unsafe fn offset(self, count: isize) -> *mut T { intrinsics::offset(self, count) as *mut T } @@ -553,7 +553,7 @@ impl Unique { /// Return an (unsafe) pointer into the memory owned by `self`. #[unstable(feature = "core", reason = "recently added to this module")] - pub unsafe fn offset(self, offset: int) -> *mut T { + pub unsafe fn offset(self, offset: isize) -> *mut T { self.ptr.offset(offset) } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index d610962f8620c..1a874ee178ba0 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -311,10 +311,10 @@ impl Result { /// # Example /// /// ``` - /// let x: Result = Ok(2); + /// let x: Result = Ok(2); /// assert_eq!(x.ok(), Some(2)); /// - /// let x: Result = Err("Nothing here"); + /// let x: Result = Err("Nothing here"); /// assert_eq!(x.ok(), None); /// ``` #[inline] @@ -334,10 +334,10 @@ impl Result { /// # Example /// /// ``` - /// let x: Result = Ok(2); + /// let x: Result = Ok(2); /// assert_eq!(x.err(), None); /// - /// let x: Result = Err("Nothing here"); + /// let x: Result = Err("Nothing here"); /// assert_eq!(x.err(), Some("Nothing here")); /// ``` #[inline] @@ -359,10 +359,10 @@ impl Result { /// into the original, leaving the original in place. /// /// ``` - /// let x: Result = Ok(2); + /// let x: Result = Ok(2); /// assert_eq!(x.as_ref(), Ok(&2)); /// - /// let x: Result = Err("Error"); + /// let x: Result = Err("Error"); /// assert_eq!(x.as_ref(), Err(&"Error")); /// ``` #[inline] @@ -404,7 +404,7 @@ impl Result { /// Convert from `Result` to `&mut [T]` (without copying) /// /// ``` - /// let mut x: Result<&str, uint> = Ok("Gold"); + /// let mut x: Result<&str, u32> = Ok("Gold"); /// { /// let v = x.as_mut_slice(); /// assert!(v == ["Gold"]); @@ -413,7 +413,7 @@ impl Result { /// } /// assert_eq!(x, Ok("Silver")); /// - /// let mut x: Result<&str, uint> = Err(45); + /// let mut x: Result<&str, u32> = Err(45); /// assert!(x.as_mut_slice().is_empty()); /// ``` #[inline] @@ -481,12 +481,12 @@ impl Result { /// # Example /// /// ``` - /// fn stringify(x: uint) -> String { format!("error code: {}", x) } + /// fn stringify(x: u32) -> String { format!("error code: {}", x) } /// - /// let x: Result = Ok(2); + /// let x: Result = Ok(2); /// assert_eq!(x.map_err(stringify), Ok(2)); /// - /// let x: Result = Err(13); + /// let x: Result = Err(13); /// assert_eq!(x.map_err(stringify), Err("error code: 13".to_string())); /// ``` #[inline] @@ -507,10 +507,10 @@ impl Result { /// # Example /// /// ``` - /// let x: Result = Ok(7); + /// let x: Result = Ok(7); /// assert_eq!(x.iter().next(), Some(&7)); /// - /// let x: Result = Err("nothing!"); + /// let x: Result = Err("nothing!"); /// assert_eq!(x.iter().next(), None); /// ``` #[inline] @@ -524,14 +524,14 @@ impl Result { /// # Example /// /// ``` - /// let mut x: Result = Ok(7); + /// let mut x: Result = Ok(7); /// match x.iter_mut().next() { /// Some(&mut ref mut x) => *x = 40, /// None => {}, /// } /// assert_eq!(x, Ok(40)); /// - /// let mut x: Result = Err("nothing!"); + /// let mut x: Result = Err("nothing!"); /// assert_eq!(x.iter_mut().next(), None); /// ``` #[inline] @@ -545,12 +545,12 @@ impl Result { /// # Example /// /// ``` - /// let x: Result = Ok(5); - /// let v: Vec = x.into_iter().collect(); + /// let x: Result = Ok(5); + /// let v: Vec = x.into_iter().collect(); /// assert_eq!(v, vec![5]); /// - /// let x: Result = Err("nothing!"); - /// let v: Vec = x.into_iter().collect(); + /// let x: Result = Err("nothing!"); + /// let v: Vec = x.into_iter().collect(); /// assert_eq!(v, vec![]); /// ``` #[inline] @@ -568,19 +568,19 @@ impl Result { /// # Example /// /// ``` - /// let x: Result = Ok(2); + /// let x: Result = Ok(2); /// let y: Result<&str, &str> = Err("late error"); /// assert_eq!(x.and(y), Err("late error")); /// - /// let x: Result = Err("early error"); + /// let x: Result = Err("early error"); /// let y: Result<&str, &str> = Ok("foo"); /// assert_eq!(x.and(y), Err("early error")); /// - /// let x: Result = Err("not a 2"); + /// let x: Result = Err("not a 2"); /// let y: Result<&str, &str> = Err("late error"); /// assert_eq!(x.and(y), Err("not a 2")); /// - /// let x: Result = Ok(2); + /// let x: Result = Ok(2); /// let y: Result<&str, &str> = Ok("different result type"); /// assert_eq!(x.and(y), Ok("different result type")); /// ``` @@ -600,8 +600,8 @@ impl Result { /// # Example /// /// ``` - /// fn sq(x: uint) -> Result { Ok(x * x) } - /// fn err(x: uint) -> Result { Err(x) } + /// fn sq(x: u32) -> Result { Ok(x * x) } + /// fn err(x: u32) -> Result { Err(x) } /// /// assert_eq!(Ok(2).and_then(sq).and_then(sq), Ok(16)); /// assert_eq!(Ok(2).and_then(sq).and_then(err), Err(4)); @@ -622,20 +622,20 @@ impl Result { /// # Example /// /// ``` - /// let x: Result = Ok(2); - /// let y: Result = Err("late error"); + /// let x: Result = Ok(2); + /// let y: Result = Err("late error"); /// assert_eq!(x.or(y), Ok(2)); /// - /// let x: Result = Err("early error"); - /// let y: Result = Ok(2); + /// let x: Result = Err("early error"); + /// let y: Result = Ok(2); /// assert_eq!(x.or(y), Ok(2)); /// - /// let x: Result = Err("not a 2"); - /// let y: Result = Err("late error"); + /// let x: Result = Err("not a 2"); + /// let y: Result = Err("late error"); /// assert_eq!(x.or(y), Err("late error")); /// - /// let x: Result = Ok(2); - /// let y: Result = Ok(100); + /// let x: Result = Ok(2); + /// let y: Result = Ok(100); /// assert_eq!(x.or(y), Ok(2)); /// ``` #[inline] @@ -654,8 +654,8 @@ impl Result { /// # Example /// /// ``` - /// fn sq(x: uint) -> Result { Ok(x * x) } - /// fn err(x: uint) -> Result { Err(x) } + /// fn sq(x: u32) -> Result { Ok(x * x) } + /// fn err(x: u32) -> Result { Err(x) } /// /// assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); /// assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); @@ -678,10 +678,10 @@ impl Result { /// /// ``` /// let optb = 2; - /// let x: Result = Ok(9); + /// let x: Result = Ok(9); /// assert_eq!(x.unwrap_or(optb), 9); /// - /// let x: Result = Err("error"); + /// let x: Result = Err("error"); /// assert_eq!(x.unwrap_or(optb), optb); /// ``` #[inline] @@ -699,7 +699,7 @@ impl Result { /// # Example /// /// ``` - /// fn count(x: &str) -> uint { x.len() } + /// fn count(x: &str) -> usize { x.len() } /// /// assert_eq!(Ok(2).unwrap_or_else(count), 2); /// assert_eq!(Err("foo").unwrap_or_else(count), 3); @@ -726,12 +726,12 @@ impl Result { /// # Example /// /// ``` - /// let x: Result = Ok(2); + /// let x: Result = Ok(2); /// assert_eq!(x.unwrap(), 2); /// ``` /// /// ```{.should_fail} - /// let x: Result = Err("emergency failure"); + /// let x: Result = Err("emergency failure"); /// x.unwrap(); // panics with `emergency failure` /// ``` #[inline] @@ -757,12 +757,12 @@ impl Result { /// # Example /// /// ```{.should_fail} - /// let x: Result = Ok(2); + /// let x: Result = Ok(2); /// x.unwrap_err(); // panics with `2` /// ``` /// /// ``` - /// let x: Result = Err("emergency failure"); + /// let x: Result = Err("emergency failure"); /// assert_eq!(x.unwrap_err(), "emergency failure"); /// ``` #[inline] @@ -811,7 +811,7 @@ impl<'a, T> Iterator for Iter<'a, T> { #[inline] fn next(&mut self) -> Option<&'a T> { self.inner.take() } #[inline] - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { let n = if self.inner.is_some() {1} else {0}; (n, Some(n)) } @@ -841,7 +841,7 @@ impl<'a, T> Iterator for IterMut<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut T> { self.inner.take() } #[inline] - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { let n = if self.inner.is_some() {1} else {0}; (n, Some(n)) } @@ -867,7 +867,7 @@ impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { self.inner.take() } #[inline] - fn size_hint(&self) -> (uint, Option) { + fn size_hint(&self) -> (usize, Option) { let n = if self.inner.is_some() {1} else {0}; (n, Some(n)) } @@ -896,11 +896,11 @@ impl> FromIterator> for Result { /// checking for overflow: /// /// ```rust - /// use std::uint; + /// use std::u32; /// /// let v = vec!(1, 2); - /// let res: Result, &'static str> = v.iter().map(|&x: &uint| - /// if x == uint::MAX { Err("Overflow!") } + /// let res: Result, &'static str> = v.iter().map(|&x: &u32| + /// if x == u32::MAX { Err("Overflow!") } /// else { Ok(x + 1) } /// ).collect(); /// assert!(res == Ok(vec!(2, 3))); diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 097633b706312..cd91843f359ea 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -626,6 +626,8 @@ impl<'a, T> Default for &'a [T] { // Iterators // +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T> IntoIterator for &'a [T] { type IntoIter = Iter<'a, T>; @@ -634,7 +636,29 @@ impl<'a, T> IntoIterator for &'a [T] { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T> IntoIterator for &'a [T] { + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a, T> IntoIterator for &'a mut [T] { + type IntoIter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut [T] { + type Item = &'a mut T; type IntoIter = IterMut<'a, T>; fn into_iter(self) -> IterMut<'a, T> { diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 1dec23059e51d..4535e0b169195 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -2005,7 +2005,7 @@ pub mod types { use types::common::c95::{c_void}; use types::os::arch::c95::{c_char, c_int, c_uint}; - pub type socklen_t = c_int; + pub type socklen_t = u32; pub type sa_family_t = u8; pub type in_port_t = u16; pub type in_addr_t = u32; @@ -2114,8 +2114,8 @@ pub mod types { pub type c_double = f64; pub type size_t = u32; pub type ptrdiff_t = i32; - pub type clock_t = u32; - pub type time_t = i32; + pub type clock_t = c_ulong; + pub type time_t = c_long; pub type suseconds_t = i32; pub type wchar_t = i32; } @@ -2128,6 +2128,8 @@ pub mod types { pub type uintmax_t = u64; } pub mod posix88 { + use types::os::arch::c95::c_long; + pub type off_t = i64; pub type dev_t = i32; pub type ino_t = u64; @@ -2136,7 +2138,7 @@ pub mod types { pub type gid_t = u32; pub type useconds_t = u32; pub type mode_t = u16; - pub type ssize_t = i32; + pub type ssize_t = c_long; } pub mod posix01 { use types::common::c99::{int32_t, int64_t, uint32_t}; @@ -2145,8 +2147,8 @@ pub mod types { mode_t, off_t, uid_t}; pub type nlink_t = u16; - pub type blksize_t = i64; - pub type blkcnt_t = i32; + pub type blksize_t = i32; + pub type blkcnt_t = i64; #[repr(C)] #[derive(Copy)] pub struct stat { @@ -2217,8 +2219,8 @@ pub mod types { pub type c_double = f64; pub type size_t = u64; pub type ptrdiff_t = i64; - pub type clock_t = u64; - pub type time_t = i64; + pub type clock_t = c_ulong; + pub type time_t = c_long; pub type suseconds_t = i32; pub type wchar_t = i32; } @@ -2231,6 +2233,8 @@ pub mod types { pub type uintmax_t = u64; } pub mod posix88 { + use types::os::arch::c95::c_long; + pub type off_t = i64; pub type dev_t = i32; pub type ino_t = u64; @@ -2239,7 +2243,7 @@ pub mod types { pub type gid_t = u32; pub type useconds_t = u32; pub type mode_t = u16; - pub type ssize_t = i64; + pub type ssize_t = c_long; } pub mod posix01 { use types::common::c99::{int32_t, int64_t}; @@ -2249,8 +2253,8 @@ pub mod types { use types::os::arch::posix88::{mode_t, off_t, uid_t}; pub type nlink_t = u16; - pub type blksize_t = i64; - pub type blkcnt_t = i32; + pub type blksize_t = i32; + pub type blkcnt_t = i64; #[repr(C)] #[derive(Copy)] pub struct stat { diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 08db053d3f4ac..d09e4bd975924 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -26,7 +26,7 @@ //! a `pub fn new()`. use self::MethodContext::*; -use metadata::csearch; +use metadata::{csearch, decoder}; use middle::def::*; use middle::subst::Substs; use middle::ty::{self, Ty}; @@ -1964,6 +1964,48 @@ impl LintPass for UnconditionalRecursion { } } +declare_lint! { + PLUGIN_AS_LIBRARY, + Warn, + "compiler plugin used as ordinary library in non-plugin crate" +} + +#[derive(Copy)] +pub struct PluginAsLibrary; + +impl LintPass for PluginAsLibrary { + fn get_lints(&self) -> LintArray { + lint_array![PLUGIN_AS_LIBRARY] + } + + fn check_item(&mut self, cx: &Context, it: &ast::Item) { + if cx.sess().plugin_registrar_fn.get().is_some() { + // We're compiling a plugin; it's fine to link other plugins. + return; + } + + match it.node { + ast::ItemExternCrate(..) => (), + _ => return, + }; + + let md = match cx.sess().cstore.find_extern_mod_stmt_cnum(it.id) { + Some(cnum) => cx.sess().cstore.get_crate_data(cnum), + None => { + // Probably means we aren't linking the crate for some reason. + // + // Not sure if / when this could happen. + return; + } + }; + + if decoder::get_plugin_registrar_fn(md.data()).is_some() { + cx.span_lint(PLUGIN_AS_LIBRARY, it.span, + "compiler plugin used as an ordinary library"); + } + } +} + declare_lint! { pub UNUSED_IMPORTS, Warn, diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 616af79326d9a..42a6861f452a6 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -214,6 +214,7 @@ impl LintStore { Stability, UnconditionalRecursion, InvalidNoMangleItems, + PluginAsLibrary, ); add_builtin_with_new!(sess, diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 30d7ec8be639b..0871c36d892c6 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -121,12 +121,10 @@ fn register_native_lib(sess: &Session, sess.cstore.add_used_library(name, kind); } -pub struct PluginMetadata<'a> { - sess: &'a Session, +// Extra info about a crate loaded for plugins or exported macros. +struct ExtensionCrate { metadata: PMDSource, dylib: Option, - info: CrateInfo, - vi_span: Span, target_only: bool, } @@ -451,21 +449,7 @@ impl<'a> CrateReader<'a> { }).collect() } - pub fn read_plugin_metadata<'b>(&'b mut self, - krate: CrateOrString<'b>) -> PluginMetadata<'b> { - let (info, span) = match krate { - CrateOrString::Krate(c) => { - (self.extract_crate_info(c).unwrap(), c.span) - } - CrateOrString::Str(sp, s) => { - (CrateInfo { - name: s.to_string(), - ident: s.to_string(), - id: ast::DUMMY_NODE_ID, - should_link: false, - }, sp) - } - }; + fn read_extension_crate(&mut self, span: Span, info: &CrateInfo) -> ExtensionCrate { let target_triple = &self.sess.opts.target_triple[]; let is_cross = target_triple != config::host_triple(); let mut should_link = info.should_link && !is_cross; @@ -517,30 +501,21 @@ impl<'a> CrateReader<'a> { PMDSource::Owned(library.metadata) }; - PluginMetadata { - sess: self.sess, + ExtensionCrate { metadata: metadata, dylib: dylib.map(|p| p.0), - info: info, - vi_span: span, target_only: target_only, } } -} -#[derive(Copy)] -pub enum CrateOrString<'a> { - Krate(&'a ast::Item), - Str(Span, &'a str) -} + /// Read exported macros. + pub fn read_exported_macros(&mut self, krate: &ast::Item) -> Vec { + let ci = self.extract_crate_info(krate).unwrap(); + let ekrate = self.read_extension_crate(krate.span, &ci); -impl<'a> PluginMetadata<'a> { - /// Read exported macros - pub fn exported_macros(&self) -> Vec { - let imported_from = Some(token::intern(&self.info.ident[]).ident()); - let source_name = format!("<{} macros>", &self.info.ident[]); + let source_name = format!("<{} macros>", krate.ident); let mut macros = vec![]; - decoder::each_exported_macro(self.metadata.as_slice(), + decoder::each_exported_macro(ekrate.metadata.as_slice(), &*self.sess.cstore.intr, |name, attrs, body| { // NB: Don't use parse::parse_tts_from_source_str because it parses with @@ -558,7 +533,7 @@ impl<'a> PluginMetadata<'a> { attrs: attrs, id: ast::DUMMY_NODE_ID, span: span, - imported_from: imported_from, + imported_from: Some(krate.ident), // overridden in plugin/load.rs export: false, use_locally: false, @@ -572,28 +547,35 @@ impl<'a> PluginMetadata<'a> { } /// Look for a plugin registrar. Returns library path and symbol name. - pub fn plugin_registrar(&self) -> Option<(Path, String)> { - if self.target_only { + pub fn find_plugin_registrar(&mut self, span: Span, name: &str) -> Option<(Path, String)> { + let ekrate = self.read_extension_crate(span, &CrateInfo { + name: name.to_string(), + ident: name.to_string(), + id: ast::DUMMY_NODE_ID, + should_link: false, + }); + + if ekrate.target_only { // Need to abort before syntax expansion. - let message = format!("plugin crate `{}` is not available for triple `{}` \ + let message = format!("plugin `{}` is not available for triple `{}` \ (only found {})", - self.info.ident, + name, config::host_triple(), self.sess.opts.target_triple); - self.sess.span_err(self.vi_span, &message[]); + self.sess.span_err(span, &message[]); self.sess.abort_if_errors(); } - let registrar = decoder::get_plugin_registrar_fn(self.metadata.as_slice()) - .map(|id| decoder::get_symbol(self.metadata.as_slice(), id)); + let registrar = decoder::get_plugin_registrar_fn(ekrate.metadata.as_slice()) + .map(|id| decoder::get_symbol(ekrate.metadata.as_slice(), id)); - match (self.dylib.as_ref(), registrar) { + match (ekrate.dylib.as_ref(), registrar) { (Some(dylib), Some(reg)) => Some((dylib.clone(), reg)), (None, Some(_)) => { - let message = format!("plugin crate `{}` only found in rlib format, \ + let message = format!("plugin `{}` only found in rlib format, \ but must be available in dylib format", - self.info.ident); - self.sess.span_err(self.vi_span, &message[]); + name); + self.sess.span_err(span, &message[]); // No need to abort because the loading code will just ignore this // empty dylib. None diff --git a/src/librustc/metadata/macro_import.rs b/src/librustc/metadata/macro_import.rs new file mode 100644 index 0000000000000..28c98d455f046 --- /dev/null +++ b/src/librustc/metadata/macro_import.rs @@ -0,0 +1,186 @@ +// 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. + +//! Used by `rustc` when loading a crate with exported macros. + +use session::Session; +use metadata::creader::CrateReader; + +use std::collections::{HashSet, HashMap}; +use syntax::ast; +use syntax::attr; +use syntax::codemap::Span; +use syntax::parse::token; +use syntax::visit; +use syntax::visit::Visitor; +use syntax::attr::AttrMetaMethods; + +struct MacroLoader<'a> { + sess: &'a Session, + span_whitelist: HashSet, + reader: CrateReader<'a>, + macros: Vec, +} + +impl<'a> MacroLoader<'a> { + fn new(sess: &'a Session) -> MacroLoader<'a> { + MacroLoader { + sess: sess, + span_whitelist: HashSet::new(), + reader: CrateReader::new(sess), + macros: vec![], + } + } +} + +/// Read exported macros. +pub fn read_macro_defs(sess: &Session, krate: &ast::Crate) -> Vec { + let mut loader = MacroLoader::new(sess); + + // We need to error on `#[macro_use] extern crate` when it isn't at the + // crate root, because `$crate` won't work properly. Identify these by + // spans, because the crate map isn't set up yet. + for item in &krate.module.items { + if let ast::ItemExternCrate(_) = item.node { + loader.span_whitelist.insert(item.span); + } + } + + visit::walk_crate(&mut loader, krate); + + loader.macros +} + +pub type MacroSelection = HashMap; + +// note that macros aren't expanded yet, and therefore macros can't add macro imports. +impl<'a, 'v> Visitor<'v> for MacroLoader<'a> { + fn visit_item(&mut self, item: &ast::Item) { + // We're only interested in `extern crate`. + match item.node { + ast::ItemExternCrate(_) => {} + _ => { + visit::walk_item(self, item); + return; + } + } + + // Parse the attributes relating to macros. + let mut import = Some(HashMap::new()); // None => load all + let mut reexport = HashMap::new(); + + for attr in &item.attrs { + let mut used = true; + match &attr.name()[] { + "phase" => { + self.sess.span_err(attr.span, "#[phase] is deprecated"); + } + "plugin" => { + self.sess.span_err(attr.span, "#[plugin] on `extern crate` is deprecated"); + self.sess.span_help(attr.span, &format!("use a crate attribute instead, \ + i.e. #![plugin({})]", + item.ident.as_str())[]); + } + "macro_use" => { + let names = attr.meta_item_list(); + if names.is_none() { + // no names => load all + import = None; + } + if let (Some(sel), Some(names)) = (import.as_mut(), names) { + for attr in names { + if let ast::MetaWord(ref name) = attr.node { + sel.insert(name.clone(), attr.span); + } else { + self.sess.span_err(attr.span, "bad macro import"); + } + } + } + } + "macro_reexport" => { + let names = match attr.meta_item_list() { + Some(names) => names, + None => { + self.sess.span_err(attr.span, "bad macro reexport"); + continue; + } + }; + + for attr in names { + if let ast::MetaWord(ref name) = attr.node { + reexport.insert(name.clone(), attr.span); + } else { + self.sess.span_err(attr.span, "bad macro reexport"); + } + } + } + _ => used = false, + } + if used { + attr::mark_used(attr); + } + } + + self.load_macros(item, import, reexport) + } + + fn visit_mac(&mut self, _: &ast::Mac) { + // bummer... can't see macro imports inside macros. + // do nothing. + } +} + +impl<'a> MacroLoader<'a> { + fn load_macros<'b>(&mut self, + vi: &ast::Item, + import: Option, + reexport: MacroSelection) { + if let Some(sel) = import.as_ref() { + if sel.is_empty() && reexport.is_empty() { + return; + } + } + + if !self.span_whitelist.contains(&vi.span) { + self.sess.span_err(vi.span, "an `extern crate` loading macros must be at \ + the crate root"); + return; + } + + let macros = self.reader.read_exported_macros(vi); + let mut seen = HashSet::new(); + + for mut def in macros { + let name = token::get_ident(def.ident); + seen.insert(name.clone()); + + def.use_locally = match import.as_ref() { + None => true, + Some(sel) => sel.contains_key(&name), + }; + def.export = reexport.contains_key(&name); + self.macros.push(def); + } + + if let Some(sel) = import.as_ref() { + for (name, span) in sel.iter() { + if !seen.contains(name) { + self.sess.span_err(*span, "imported macro not found"); + } + } + } + + for (name, span) in reexport.iter() { + if !seen.contains(name) { + self.sess.span_err(*span, "reexported macro not found"); + } + } + } +} diff --git a/src/librustc/metadata/mod.rs b/src/librustc/metadata/mod.rs index 24007380feec1..0bf1e6d198fa2 100644 --- a/src/librustc/metadata/mod.rs +++ b/src/librustc/metadata/mod.rs @@ -18,3 +18,4 @@ pub mod cstore; pub mod csearch; pub mod loader; pub mod filesearch; +pub mod macro_import; diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index e20968a9ac997..e27e7a8024685 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -530,6 +530,8 @@ impl<'a,T> Iterator for EnumeratedItems<'a,T> { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for VecPerParamSpace { type IntoIter = IntoIter; @@ -538,7 +540,29 @@ impl IntoIterator for VecPerParamSpace { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for VecPerParamSpace { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_vec().into_iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl<'a,T> IntoIterator for &'a VecPerParamSpace { + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.as_slice().into_iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a,T> IntoIterator for &'a VecPerParamSpace { + type Item = &'a T; type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs index b46454bfdd04e..1895cbcb5421e 100644 --- a/src/librustc/plugin/load.rs +++ b/src/librustc/plugin/load.rs @@ -8,24 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Used by `rustc` when loading a plugin, or a crate with exported macros. +//! Used by `rustc` when loading a plugin. use session::Session; -use metadata::creader::{CrateOrString, CrateReader}; +use metadata::creader::CrateReader; use plugin::registry::Registry; use std::mem; use std::env; use std::dynamic_lib::DynamicLibrary; -use std::collections::{HashSet, HashMap}; use std::borrow::ToOwned; use syntax::ast; -use syntax::attr; use syntax::codemap::{Span, COMMAND_LINE_SP}; -use syntax::parse::token; use syntax::ptr::P; -use syntax::visit; -use syntax::visit::Visitor; use syntax::attr::AttrMetaMethods; /// Pointer to a registrar function. @@ -37,51 +32,17 @@ pub struct PluginRegistrar { pub args: Vec>, } -/// Information about loaded plugins. -pub struct Plugins { - /// Imported macros. - pub macros: Vec, - /// Registrars, as function pointers. - pub registrars: Vec, -} - -pub struct PluginLoader<'a> { +struct PluginLoader<'a> { sess: &'a Session, - span_whitelist: HashSet, reader: CrateReader<'a>, - pub plugins: Plugins, -} - -impl<'a> PluginLoader<'a> { - fn new(sess: &'a Session) -> PluginLoader<'a> { - PluginLoader { - sess: sess, - reader: CrateReader::new(sess), - span_whitelist: HashSet::new(), - plugins: Plugins { - macros: vec!(), - registrars: vec!(), - }, - } - } + plugins: Vec, } /// Read plugin metadata and dynamically load registrar functions. pub fn load_plugins(sess: &Session, krate: &ast::Crate, - addl_plugins: Option>) -> Plugins { + addl_plugins: Option>) -> Vec { let mut loader = PluginLoader::new(sess); - // We need to error on `#[macro_use] extern crate` when it isn't at the - // crate root, because `$crate` won't work properly. Identify these by - // spans, because the crate map isn't set up yet. - for item in &krate.module.items { - if let ast::ItemExternCrate(_) = item.node { - loader.span_whitelist.insert(item.span); - } - } - - visit::walk_crate(&mut loader, krate); - for attr in &krate.attrs { if !attr.check_name("plugin") { continue; @@ -102,156 +63,34 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate, } let args = plugin.meta_item_list().map(ToOwned::to_owned).unwrap_or_default(); - loader.load_plugin(CrateOrString::Str(plugin.span, &*plugin.name()), - args); + loader.load_plugin(plugin.span, &*plugin.name(), args); } } if let Some(plugins) = addl_plugins { for plugin in plugins { - loader.load_plugin(CrateOrString::Str(COMMAND_LINE_SP, &plugin), vec![]); - } - } - - return loader.plugins; -} - -pub type MacroSelection = HashMap; - -// note that macros aren't expanded yet, and therefore macros can't add plugins. -impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { - fn visit_item(&mut self, item: &ast::Item) { - // We're only interested in `extern crate`. - match item.node { - ast::ItemExternCrate(_) => {} - _ => { - visit::walk_item(self, item); - return; - } - } - - // Parse the attributes relating to macro loading. - let mut import = Some(HashMap::new()); // None => load all - let mut reexport = HashMap::new(); - for attr in &item.attrs { - let mut used = true; - match &attr.name()[] { - "phase" => { - self.sess.span_err(attr.span, "#[phase] is deprecated"); - } - "plugin" => { - self.sess.span_err(attr.span, "#[plugin] on `extern crate` is deprecated"); - self.sess.span_help(attr.span, &format!("use a crate attribute instead, \ - i.e. #![plugin({})]", - item.ident.as_str())[]); - } - "macro_use" => { - let names = attr.meta_item_list(); - if names.is_none() { - // no names => load all - import = None; - } - if let (Some(sel), Some(names)) = (import.as_mut(), names) { - for attr in names { - if let ast::MetaWord(ref name) = attr.node { - sel.insert(name.clone(), attr.span); - } else { - self.sess.span_err(attr.span, "bad macro import"); - } - } - } - } - "macro_reexport" => { - let names = match attr.meta_item_list() { - Some(names) => names, - None => { - self.sess.span_err(attr.span, "bad macro reexport"); - continue; - } - }; - - for attr in names { - if let ast::MetaWord(ref name) = attr.node { - reexport.insert(name.clone(), attr.span); - } else { - self.sess.span_err(attr.span, "bad macro reexport"); - } - } - } - _ => used = false, - } - if used { - attr::mark_used(attr); - } + loader.load_plugin(COMMAND_LINE_SP, &plugin, vec![]); } - - self.load_macros(item, import, reexport) } - fn visit_mac(&mut self, _: &ast::Mac) { - // bummer... can't see plugins inside macros. - // do nothing. - } + loader.plugins } impl<'a> PluginLoader<'a> { - pub fn load_macros<'b>(&mut self, - vi: &ast::Item, - import: Option, - reexport: MacroSelection) { - if let Some(sel) = import.as_ref() { - if sel.is_empty() && reexport.is_empty() { - return; - } - } - - if !self.span_whitelist.contains(&vi.span) { - self.sess.span_err(vi.span, "an `extern crate` loading macros must be at \ - the crate root"); - return; - } - - let pmd = self.reader.read_plugin_metadata(CrateOrString::Krate(vi)); - - let mut seen = HashSet::new(); - for mut def in pmd.exported_macros() { - let name = token::get_ident(def.ident); - seen.insert(name.clone()); - - def.use_locally = match import.as_ref() { - None => true, - Some(sel) => sel.contains_key(&name), - }; - def.export = reexport.contains_key(&name); - self.plugins.macros.push(def); - } - - if let Some(sel) = import.as_ref() { - for (name, span) in sel.iter() { - if !seen.contains(name) { - self.sess.span_err(*span, "imported macro not found"); - } - } - } - - for (name, span) in reexport.iter() { - if !seen.contains(name) { - self.sess.span_err(*span, "reexported macro not found"); - } + fn new(sess: &'a Session) -> PluginLoader<'a> { + PluginLoader { + sess: sess, + reader: CrateReader::new(sess), + plugins: vec![], } } - pub fn load_plugin<'b>(&mut self, - c: CrateOrString<'b>, - args: Vec>) { - let registrar = { - let pmd = self.reader.read_plugin_metadata(c); - pmd.plugin_registrar() - }; + fn load_plugin(&mut self, span: Span, name: &str, args: Vec>) { + let registrar = self.reader.find_plugin_registrar(span, name); if let Some((lib, symbol)) = registrar { - let fun = self.dylink_registrar(c, lib, symbol); - self.plugins.registrars.push(PluginRegistrar { + let fun = self.dylink_registrar(span, lib, symbol); + self.plugins.push(PluginRegistrar { fun: fun, args: args, }); @@ -259,8 +98,8 @@ impl<'a> PluginLoader<'a> { } // Dynamically link a registrar function into the compiler process. - fn dylink_registrar<'b>(&mut self, - c: CrateOrString<'b>, + fn dylink_registrar(&mut self, + span: Span, path: Path, symbol: String) -> PluginRegistrarFun { // Make sure the path contains a / or the linker will search for it. @@ -272,11 +111,7 @@ impl<'a> PluginLoader<'a> { // inside this crate, so continue would spew "macro undefined" // errors Err(err) => { - if let CrateOrString::Krate(cr) = c { - self.sess.span_fatal(cr.span, &err[]) - } else { - self.sess.fatal(&err[]) - } + self.sess.span_fatal(span, &err[]) } }; @@ -288,11 +123,7 @@ impl<'a> PluginLoader<'a> { } // again fatal if we can't register macros Err(err) => { - if let CrateOrString::Krate(cr) = c { - self.sess.span_fatal(cr.span, &err[]) - } else { - self.sess.fatal(&err[]) - } + self.sess.span_fatal(span, &err[]) } }; diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index c3e205e050fb7..eb1dba7159cf8 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -12,11 +12,11 @@ use rustc::session::Session; use rustc::session::config::{self, Input, OutputFilenames}; use rustc::session::search_paths::PathKind; use rustc::lint; +use rustc::metadata; use rustc::metadata::creader::CrateReader; use rustc::middle::{stability, ty, reachable}; use rustc::middle::dependency_format; use rustc::middle; -use rustc::plugin::load::Plugins; use rustc::plugin::registry::Registry; use rustc::plugin; use rustc::util::common::time; @@ -409,10 +409,12 @@ pub fn phase_2_configure_and_expand(sess: &Session, syntax::std_inject::maybe_inject_crates_ref(krate, sess.opts.alt_std_name.clone())); + let macros = time(time_passes, "macro loading", (), |_| + metadata::macro_import::read_macro_defs(sess, &krate)); + let mut addl_plugins = Some(addl_plugins); - let Plugins { macros, registrars } - = time(time_passes, "plugin loading", (), |_| - plugin::load::load_plugins(sess, &krate, addl_plugins.take().unwrap())); + let registrars = time(time_passes, "plugin loading", (), |_| + plugin::load::load_plugins(sess, &krate, addl_plugins.take().unwrap())); let mut registry = Registry::new(sess, &krate); diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index e73b626e6efdc..213e356536246 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -436,50 +436,73 @@ pub enum DiagnosticKind { } // Opaque pointer types +#[allow(missing_copy_implementations)] pub enum Module_opaque {} pub type ModuleRef = *mut Module_opaque; +#[allow(missing_copy_implementations)] pub enum Context_opaque {} pub type ContextRef = *mut Context_opaque; +#[allow(missing_copy_implementations)] pub enum Type_opaque {} pub type TypeRef = *mut Type_opaque; +#[allow(missing_copy_implementations)] pub enum Value_opaque {} pub type ValueRef = *mut Value_opaque; +#[allow(missing_copy_implementations)] pub enum Metadata_opaque {} pub type MetadataRef = *mut Metadata_opaque; +#[allow(missing_copy_implementations)] pub enum BasicBlock_opaque {} pub type BasicBlockRef = *mut BasicBlock_opaque; +#[allow(missing_copy_implementations)] pub enum Builder_opaque {} pub type BuilderRef = *mut Builder_opaque; +#[allow(missing_copy_implementations)] pub enum ExecutionEngine_opaque {} pub type ExecutionEngineRef = *mut ExecutionEngine_opaque; +#[allow(missing_copy_implementations)] pub enum RustJITMemoryManager_opaque {} pub type RustJITMemoryManagerRef = *mut RustJITMemoryManager_opaque; +#[allow(missing_copy_implementations)] pub enum MemoryBuffer_opaque {} pub type MemoryBufferRef = *mut MemoryBuffer_opaque; +#[allow(missing_copy_implementations)] pub enum PassManager_opaque {} pub type PassManagerRef = *mut PassManager_opaque; +#[allow(missing_copy_implementations)] pub enum PassManagerBuilder_opaque {} pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque; +#[allow(missing_copy_implementations)] pub enum Use_opaque {} pub type UseRef = *mut Use_opaque; +#[allow(missing_copy_implementations)] pub enum TargetData_opaque {} pub type TargetDataRef = *mut TargetData_opaque; +#[allow(missing_copy_implementations)] pub enum ObjectFile_opaque {} pub type ObjectFileRef = *mut ObjectFile_opaque; +#[allow(missing_copy_implementations)] pub enum SectionIterator_opaque {} pub type SectionIteratorRef = *mut SectionIterator_opaque; +#[allow(missing_copy_implementations)] pub enum Pass_opaque {} pub type PassRef = *mut Pass_opaque; +#[allow(missing_copy_implementations)] pub enum TargetMachine_opaque {} pub type TargetMachineRef = *mut TargetMachine_opaque; +#[allow(missing_copy_implementations)] pub enum Archive_opaque {} pub type ArchiveRef = *mut Archive_opaque; +#[allow(missing_copy_implementations)] pub enum Twine_opaque {} pub type TwineRef = *mut Twine_opaque; +#[allow(missing_copy_implementations)] pub enum DiagnosticInfo_opaque {} pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque; +#[allow(missing_copy_implementations)] pub enum DebugLoc_opaque {} pub type DebugLocRef = *mut DebugLoc_opaque; +#[allow(missing_copy_implementations)] pub enum SMDiagnostic_opaque {} pub type SMDiagnosticRef = *mut SMDiagnostic_opaque; @@ -490,6 +513,7 @@ pub mod debuginfo { pub use self::DIDescriptorFlags::*; use super::{MetadataRef}; + #[allow(missing_copy_implementations)] pub enum DIBuilder_opaque {} pub type DIBuilderRef = *mut DIBuilder_opaque; @@ -2192,6 +2216,7 @@ pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef { } } +#[allow(missing_copy_implementations)] pub enum RustString_opaque {} pub type RustStringRef = *mut RustString_opaque; type RustStringRepr = *mut RefCell>; diff --git a/src/librustc_trans/trans/controlflow.rs b/src/librustc_trans/trans/controlflow.rs index ea5eef48257d3..e6cd44676cefb 100644 --- a/src/librustc_trans/trans/controlflow.rs +++ b/src/librustc_trans/trans/controlflow.rs @@ -339,7 +339,7 @@ pub fn trans_ret<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let mut bcx = bcx; let dest = match (fcx.llretslotptr.get(), retval_expr) { (Some(_), Some(retval_expr)) => { - let ret_ty = expr_ty(bcx, &*retval_expr); + let ret_ty = expr_ty_adjusted(bcx, &*retval_expr); expr::SaveIn(fcx.get_ret_slot(bcx, ty::FnConverging(ret_ty), "ret_slot")) } _ => expr::Ignore, diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index a571b2793df17..f43469363cd81 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -88,15 +88,10 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> { Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => { if !ty::has_attr(self.tcx, trait_def_id, "old_orphan_check") { span_err!(self.tcx.sess, item.span, E0210, - "type parameter `{}` is not constrained by any local type; \ - only traits defined in the current crate can be implemented \ - for a type parameter", + "type parameter `{}` must be used as the type parameter for \ + some local type (e.g. `MyStruct`); only traits defined in \ + the current crate can be implemented for a type parameter", param_ty.user_string(self.tcx)); - self.tcx.sess.span_note( - item.span, - &format!("for a limited time, you can add \ - `#![feature(old_orphan_check)]` to your crate \ - to disable this rule")); } } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index f26041dbbe1eb..44e850a073800 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -2022,10 +2022,6 @@ fn enforce_impl_ty_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>, "the type parameter `{}` is not constrained by the \ impl trait, self type, or predicates", param_ty.user_string(tcx)); - tcx.sess.span_help( - ty_param.span, - &format!("you can temporarily opt out of this rule by placing \ - the `#[old_impl_check]` attribute on the impl")); } } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6c3d2d8fa19d1..7ef48378af183 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2490,6 +2490,7 @@ pub struct Stability { pub level: attr::StabilityLevel, pub feature: String, pub since: String, + pub deprecated_since: String, pub reason: String } @@ -2500,6 +2501,8 @@ impl Clean for attr::Stability { feature: self.feature.to_string(), since: self.since.as_ref().map_or("".to_string(), |interned| interned.to_string()), + deprecated_since: self.deprecated_since.as_ref().map_or("".to_string(), + |istr| istr.to_string()), reason: self.reason.as_ref().map_or("".to_string(), |interned| interned.to_string()), } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index e916b63eb8dc7..ed7f051408c45 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -711,7 +711,11 @@ impl<'a> fmt::Display for Stability<'a> { match *stab { Some(ref stability) => { write!(f, "{lvl}", - lvl = stability.level, + lvl = if stability.deprecated_since.is_empty() { + format!("{}", stability.level) + } else { + "Deprecated".to_string() + }, reason = stability.reason) } None => Ok(()) @@ -725,7 +729,11 @@ impl<'a> fmt::Display for ConciseStability<'a> { match *stab { Some(ref stability) => { write!(f, "", - lvl = stability.level, + lvl = if stability.deprecated_since.is_empty() { + format!("{}", stability.level) + } else { + "Deprecated".to_string() + }, colon = if stability.reason.len() > 0 { ": " } else { "" }, reason = stability.reason) } @@ -763,6 +771,9 @@ impl fmt::Display for ModuleSummary { try!(write!(f, " ", (100 * cnt.unstable) as f64/tot as f64)); + try!(write!(f, " ", + (100 * cnt.deprecated) as f64/tot as f64)); try!(write!(f, " ", (100 * cnt.unmarked) as f64/tot as f64)); @@ -778,11 +789,12 @@ impl fmt::Display for ModuleSummary { let mut context = Vec::new(); let tot = self.counts.total(); - let (stable, unstable, unmarked) = if tot == 0 { - (0, 0, 0) + let (stable, unstable, deprecated, unmarked) = if tot == 0 { + (0, 0, 0, 0) } else { ((100 * self.counts.stable)/tot, (100 * self.counts.unstable)/tot, + (100 * self.counts.deprecated)/tot, (100 * self.counts.unmarked)/tot) }; @@ -794,11 +806,12 @@ its children (percentages total for {name}):
stable ({}%),
unstable ({}%),
+ deprecated ({}%),
unmarked ({}%)
The counts do not include methods or trait implementations that are visible only through a re-exported type.", -stable, unstable, unmarked, +stable, unstable, deprecated, unmarked, name=self.name)); try!(write!(f, "")); try!(fmt_inner(f, &mut context, self)); diff --git a/src/librustdoc/html/static/main.css b/src/librustdoc/html/static/main.css index 7267f95b31f2f..a4263badb0136 100644 --- a/src/librustdoc/html/static/main.css +++ b/src/librustdoc/html/static/main.css @@ -292,6 +292,27 @@ nav.sub { .content td p:first-child { margin-top: 0; } .content td h1, .content td h2 { margin-left: 0; font-size: 1.1em; } +.docblock table { + border: 1px solid #ddd; + margin: .5em 0; + border-collapse: collapse; + width: 100%; +} + +.docblock table td { + padding: .5em; + border-top: 1px dashed #ddd; + border-bottom: 1px dashed #ddd; + +} + +.docblock table th { + padding: .5em; + text-align: left; + border-top: 1px solid #ddd; + border-bottom: 1px solid #ddd; +} + .content .item-list { list-style-type: none; padding: 0; diff --git a/src/librustdoc/stability_summary.rs b/src/librustdoc/stability_summary.rs index f1d9aef7f7ce8..47918ba78a270 100644 --- a/src/librustdoc/stability_summary.rs +++ b/src/librustdoc/stability_summary.rs @@ -29,11 +29,12 @@ use html::render::cache; /// The counts for each stability level. #[derive(Copy)] pub struct Counts { - pub unstable: uint, - pub stable: uint, + pub deprecated: u64, + pub unstable: u64, + pub stable: u64, /// No stability level, inherited or otherwise. - pub unmarked: uint, + pub unmarked: u64, } impl Add for Counts { @@ -41,6 +42,7 @@ impl Add for Counts { fn add(self, other: Counts) -> Counts { Counts { + deprecated: self.deprecated + other.deprecated, unstable: self.unstable + other.unstable, stable: self.stable + other.stable, unmarked: self.unmarked + other.unmarked, @@ -51,14 +53,15 @@ impl Add for Counts { impl Counts { fn zero() -> Counts { Counts { + deprecated: 0, unstable: 0, stable: 0, unmarked: 0, } } - pub fn total(&self) -> uint { - self.unstable + self.stable + self.unmarked + pub fn total(&self) -> u64 { + self.deprecated + self.unstable + self.stable + self.unmarked } } @@ -94,9 +97,14 @@ fn visible(item: &Item) -> bool { fn count_stability(stab: Option<&Stability>) -> Counts { match stab { None => Counts { unmarked: 1, .. Counts::zero() }, - Some(ref stab) => match stab.level { - Unstable => Counts { unstable: 1, .. Counts::zero() }, - Stable => Counts { stable: 1, .. Counts::zero() }, + Some(ref stab) => { + if !stab.deprecated_since.is_empty() { + return Counts { deprecated: 1, .. Counts::zero() }; + } + match stab.level { + Unstable => Counts { unstable: 1, .. Counts::zero() }, + Stable => Counts { stable: 1, .. Counts::zero() }, + } } } } diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 18dd122891dae..241e409910f36 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1372,6 +1372,8 @@ enum VacantEntryState { NoElem(EmptyBucket), } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V, S, H> IntoIterator for &'a HashMap where K: Eq + Hash, S: HashState, @@ -1384,6 +1386,22 @@ impl<'a, K, V, S, H> IntoIterator for &'a HashMap } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V, S, H> IntoIterator for &'a HashMap + where K: Eq + Hash, + S: HashState, + H: hash::Hasher +{ + type Item = (&'a K, &'a V); + type IntoIter = Iter<'a, K, V>; + + fn into_iter(self) -> Iter<'a, K, V> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap where K: Eq + Hash, S: HashState, @@ -1396,6 +1414,22 @@ impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap + where K: Eq + Hash, + S: HashState, + H: hash::Hasher +{ + type Item = (&'a K, &'a mut V); + type IntoIter = IterMut<'a, K, V>; + + fn into_iter(mut self) -> IterMut<'a, K, V> { + self.iter_mut() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IntoIterator for HashMap where K: Eq + Hash, S: HashState, @@ -1408,6 +1442,20 @@ impl IntoIterator for HashMap } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IntoIterator for HashMap + where K: Eq + Hash, + S: HashState, + H: hash::Hasher +{ + type Item = (K, V); + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> Iterator for Iter<'a, K, V> { type Item = (&'a K, &'a V); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 96af556dbccb7..300e208931765 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -835,6 +835,8 @@ pub struct Union<'a, T: 'a, S: 'a> { iter: Chain, Difference<'a, T, S>> } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl<'a, T, S, H> IntoIterator for &'a HashSet where T: Eq + Hash, S: HashState, @@ -847,11 +849,41 @@ impl<'a, T, S, H> IntoIterator for &'a HashSet } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl<'a, T, S, H> IntoIterator for &'a HashSet + where T: Eq + Hash, + S: HashState, + H: hash::Hasher +{ + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] +impl IntoIterator for HashSet + where T: Eq + Hash, + S: HashState, + H: hash::Hasher +{ + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + self.into_iter() + } +} + +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl IntoIterator for HashSet where T: Eq + Hash, S: HashState, H: hash::Hasher { + type Item = T; type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 45de67865a633..5f91d173ed2ac 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -112,10 +112,10 @@ impl File { OpenOptions::new().read(true).open(path) } - /// Creates a open a file in write-only mode. + /// Open a file in write-only mode. /// - /// This method will attempt to open a new file, truncating it if it already - /// exists. + /// This function will create a file it it does not exist, + /// and will truncate it if it does. /// /// See the `OpenOptions::open` function for more details. pub fn create(path: &P) -> io::Result { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 2a0206d9ff08e..5369bf3bda0b1 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -132,7 +132,7 @@ pub fn env() -> Vec<(String,String)> { /// Returns a vector of (variable, value) byte-vector pairs for all the /// environment variables of the current process. -#[deprecated(since = "1.0.0", reason = "use env::vars instead")] +#[deprecated(since = "1.0.0", reason = "use env::vars_os instead")] #[unstable(feature = "os")] pub fn env_as_bytes() -> Vec<(Vec, Vec)> { env::vars_os().map(|(k, v)| (byteify(k), byteify(v))).collect() @@ -159,7 +159,7 @@ pub fn env_as_bytes() -> Vec<(Vec, Vec)> { /// None => println!("{} is not defined in the environment.", key) /// } /// ``` -#[deprecated(since = "1.0.0", reason = "use env::var or env::var_os instead")] +#[deprecated(since = "1.0.0", reason = "use env::var instead")] #[unstable(feature = "os")] pub fn getenv(n: &str) -> Option { env::var(n).ok() @@ -171,7 +171,7 @@ pub fn getenv(n: &str) -> Option { /// # Panics /// /// Panics if `n` has any interior NULs. -#[deprecated(since = "1.0.0", reason = "use env::var instead")] +#[deprecated(since = "1.0.0", reason = "use env::var_os instead")] #[unstable(feature = "os")] pub fn getenv_as_bytes(n: &str) -> Option> { env::var_os(n).map(byteify) @@ -732,7 +732,7 @@ pub fn args() -> Vec { /// Returns the arguments which this program was started with (normally passed /// via the command line) as byte vectors. -#[deprecated(since = "1.0.0", reason = "use env::args_raw instead")] +#[deprecated(since = "1.0.0", reason = "use env::args_os instead")] #[unstable(feature = "os")] pub fn args_as_bytes() -> Vec> { real_args_as_bytes() diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 464adadde6215..b45878584e02d 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -292,7 +292,6 @@ pub mod eabi { #[lang="eh_personality"] #[no_mangle] // referenced from rust_try.ll - #[allow(private_no_mangle_fns)] pub extern "C" fn rust_eh_personality( version: c_int, actions: uw::_Unwind_Action, diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 66ae018cb36af..0ee2b5b68090e 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -364,7 +364,10 @@ mod tests { use os; use prelude::v1::*; - #[cfg_attr(target_os = "freebsd", ignore)] // hmm, maybe pipes have a tiny buffer + #[cfg_attr(any(target_os = "freebsd", + target_os = "openbsd"), + ignore)] + // under some system, pipe(2) will return a bidrectionnal pipe #[test] fn test_file_desc() { // Run this test with some pipes so we don't have to mess around with diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs index b29538ad62078..a8466465f871b 100644 --- a/src/rustbook/main.rs +++ b/src/rustbook/main.rs @@ -50,7 +50,7 @@ fn main() { let mut term = Term::new(); let cmd = os::args(); - if cmd.len() < 1 { + if cmd.len() <= 1 { help::usage() } else { match subcommand::parse_name(&cmd[1][]) { diff --git a/src/test/auxiliary/orphan_check_diagnostics.rs b/src/test/auxiliary/orphan_check_diagnostics.rs new file mode 100644 index 0000000000000..7647f159401a7 --- /dev/null +++ b/src/test/auxiliary/orphan_check_diagnostics.rs @@ -0,0 +1,11 @@ +// 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. + +pub trait RemoteTrait {} diff --git a/src/test/auxiliary/plugin_with_plugin_lib.rs b/src/test/auxiliary/plugin_with_plugin_lib.rs new file mode 100644 index 0000000000000..cfc8c015324d9 --- /dev/null +++ b/src/test/auxiliary/plugin_with_plugin_lib.rs @@ -0,0 +1,22 @@ +// 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. + +// force-host + +#![feature(plugin_registrar)] +#![deny(plugin_as_library)] // should have no effect in a plugin crate + +extern crate macro_crate_test; +extern crate rustc; + +use rustc::plugin::Registry; + +#[plugin_registrar] +pub fn plugin_registrar(_: &mut Registry) { } diff --git a/src/test/compile-fail-fulldeps/macro-crate-rlib.rs b/src/test/compile-fail-fulldeps/macro-crate-rlib.rs index 7d38d4352b0de..7a362994b8db6 100644 --- a/src/test/compile-fail-fulldeps/macro-crate-rlib.rs +++ b/src/test/compile-fail-fulldeps/macro-crate-rlib.rs @@ -16,6 +16,6 @@ #![feature(plugin)] #![plugin(rlib_crate_test)] -//~^ ERROR: plugin crate `rlib_crate_test` only found in rlib format, but must be available in dylib format +//~^ ERROR: plugin `rlib_crate_test` only found in rlib format, but must be available in dylib format fn main() {} diff --git a/src/test/compile-fail-fulldeps/plugin-as-extern-crate.rs b/src/test/compile-fail-fulldeps/plugin-as-extern-crate.rs new file mode 100644 index 0000000000000..c5169b61a2bf9 --- /dev/null +++ b/src/test/compile-fail-fulldeps/plugin-as-extern-crate.rs @@ -0,0 +1,22 @@ +// Copyright 2013-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. + +// aux-build:macro_crate_test.rs +// ignore-stage1 +// ignore-cross-compile +// +// macro_crate_test will not compile on a cross-compiled target because +// libsyntax is not compiled for it. + +#![deny(plugin_as_library)] + +extern crate macro_crate_test; //~ ERROR compiler plugin used as an ordinary library + +fn main() { } diff --git a/src/test/compile-fail-fulldeps/plugin-plus-extern-crate.rs b/src/test/compile-fail-fulldeps/plugin-plus-extern-crate.rs new file mode 100644 index 0000000000000..3dfd8838ebec4 --- /dev/null +++ b/src/test/compile-fail-fulldeps/plugin-plus-extern-crate.rs @@ -0,0 +1,27 @@ +// Copyright 2013-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. + +// aux-build:macro_crate_test.rs +// ignore-stage1 +// ignore-cross-compile +// +// macro_crate_test will not compile on a cross-compiled target because +// libsyntax is not compiled for it. + +#![deny(plugin_as_library)] +#![feature(plugin)] +#![plugin(macro_crate_test)] + +extern crate macro_crate_test; //~ ERROR compiler plugin used as an ordinary library + +fn main() { + assert_eq!(1, make_a_1!()); + macro_crate_test::foo(); +} diff --git a/src/test/compile-fail/coherence-bigint-param.rs b/src/test/compile-fail/coherence-bigint-param.rs index b8e48436a4143..b7ca499be7366 100644 --- a/src/test/compile-fail/coherence-bigint-param.rs +++ b/src/test/compile-fail/coherence-bigint-param.rs @@ -16,6 +16,6 @@ use lib::Remote1; pub struct BigInt; impl Remote1 for T { } -//~^ ERROR type parameter `T` is not constrained +//~^ ERROR type parameter `T` must be used as the type parameter for some local type fn main() { } diff --git a/src/test/compile-fail/coherence-cow-no-cover.rs b/src/test/compile-fail/coherence-cow-no-cover.rs index 8d14eb96c6170..1bec97de53386 100644 --- a/src/test/compile-fail/coherence-cow-no-cover.rs +++ b/src/test/compile-fail/coherence-cow-no-cover.rs @@ -18,6 +18,6 @@ use lib::{Remote,Pair}; pub struct Cover(T); impl Remote for Pair,U> { } -//~^ ERROR type parameter `U` is not constrained by any local type +//~^ ERROR type parameter `U` must be used as the type parameter for some local type fn main() { } diff --git a/src/test/compile-fail/coherence-cross-crate-conflict.rs b/src/test/compile-fail/coherence-cross-crate-conflict.rs index 8bdd5c58f3199..a020b518d8273 100644 --- a/src/test/compile-fail/coherence-cross-crate-conflict.rs +++ b/src/test/compile-fail/coherence-cross-crate-conflict.rs @@ -16,7 +16,7 @@ extern crate trait_impl_conflict; use trait_impl_conflict::Foo; impl Foo for A { - //~^ ERROR type parameter `A` is not constrained + //~^ ERROR type parameter `A` must be used as the type parameter for some local type //~^^ ERROR E0119 } diff --git a/src/test/compile-fail/coherence-lone-type-parameter.rs b/src/test/compile-fail/coherence-lone-type-parameter.rs index 917438722de4e..9f7481f12f2f7 100644 --- a/src/test/compile-fail/coherence-lone-type-parameter.rs +++ b/src/test/compile-fail/coherence-lone-type-parameter.rs @@ -13,6 +13,7 @@ extern crate "coherence-lib" as lib; use lib::Remote; -impl Remote for T { } //~ ERROR type parameter `T` is not constrained +impl Remote for T { } +//~^ ERROR type parameter `T` must be used as the type parameter for some local type fn main() { } diff --git a/src/test/compile-fail/coherence-overlapping-pairs.rs b/src/test/compile-fail/coherence-overlapping-pairs.rs index 9354e66af0d81..9878bdec2c36f 100644 --- a/src/test/compile-fail/coherence-overlapping-pairs.rs +++ b/src/test/compile-fail/coherence-overlapping-pairs.rs @@ -16,6 +16,6 @@ use lib::Remote; struct Foo; impl Remote for lib::Pair { } -//~^ ERROR type parameter `T` is not constrained +//~^ ERROR type parameter `T` must be used as the type parameter for some local type fn main() { } diff --git a/src/test/compile-fail/coherence-pair-covered-uncovered-1.rs b/src/test/compile-fail/coherence-pair-covered-uncovered-1.rs index 3655bca6f1d8d..2bdcc346f70d3 100644 --- a/src/test/compile-fail/coherence-pair-covered-uncovered-1.rs +++ b/src/test/compile-fail/coherence-pair-covered-uncovered-1.rs @@ -18,7 +18,7 @@ use lib::{Remote1, Pair}; pub struct Local(T); -impl Remote1>> for i32 { } -//~^ ERROR type parameter `T` is not constrained +impl Remote1>> for i32 { } +//~^ ERROR type parameter `T` must be used as the type parameter for some local type fn main() { } diff --git a/src/test/compile-fail/coherence-pair-covered-uncovered.rs b/src/test/compile-fail/coherence-pair-covered-uncovered.rs index 92a07b3585292..881494f009f15 100644 --- a/src/test/compile-fail/coherence-pair-covered-uncovered.rs +++ b/src/test/compile-fail/coherence-pair-covered-uncovered.rs @@ -16,6 +16,6 @@ use lib::{Remote, Pair}; struct Local(T); impl Remote for Pair> { } -//~^ ERROR type parameter `T` is not constrained +//~^ ERROR type parameter `T` must be used as the type parameter for some local type fn main() { } diff --git a/src/test/compile-fail/orphan-check-diagnostics.rs b/src/test/compile-fail/orphan-check-diagnostics.rs new file mode 100644 index 0000000000000..ff5c101b9178f --- /dev/null +++ b/src/test/compile-fail/orphan-check-diagnostics.rs @@ -0,0 +1,23 @@ +// 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. + +// aux-build:orphan_check_diagnostics.rs +// see #22388 + +extern crate orphan_check_diagnostics; + +use orphan_check_diagnostics::RemoteTrait; + +trait LocalTrait {} + +impl RemoteTrait for T where T: LocalTrait {} +//~^ ERROR type parameter `T` must be used as the type parameter for some local type + +fn main() {} diff --git a/src/test/debuginfo/gdb-pretty-struct-and-enums-pre-gdb-7-7.rs b/src/test/debuginfo/gdb-pretty-struct-and-enums-pre-gdb-7-7.rs index 092cd9edc7065..aa902a9b2d4ad 100644 --- a/src/test/debuginfo/gdb-pretty-struct-and-enums-pre-gdb-7-7.rs +++ b/src/test/debuginfo/gdb-pretty-struct-and-enums-pre-gdb-7-7.rs @@ -13,6 +13,7 @@ // gdb-pretty-struct-and-enums.rs // ignore-windows failing on win32 bot +// ignore-freebsd: gdb package too new // ignore-tidy-linelength // ignore-lldb // ignore-android: FIXME(#10381) diff --git a/src/test/debuginfo/gdb-pretty-struct-and-enums.rs b/src/test/debuginfo/gdb-pretty-struct-and-enums.rs index 4b2628b2a1f73..d9a7e7406eb73 100644 --- a/src/test/debuginfo/gdb-pretty-struct-and-enums.rs +++ b/src/test/debuginfo/gdb-pretty-struct-and-enums.rs @@ -9,6 +9,7 @@ // except according to those terms. // ignore-windows failing on win32 bot +// ignore-freebsd: output doesn't match // ignore-tidy-linelength // ignore-lldb // ignore-android: FIXME(#10381) diff --git a/src/test/run-make/use-extern-for-plugins/Makefile b/src/test/run-make/use-extern-for-plugins/Makefile index bdce7b7810aaf..f8abc5019b4fd 100644 --- a/src/test/run-make/use-extern-for-plugins/Makefile +++ b/src/test/run-make/use-extern-for-plugins/Makefile @@ -1,6 +1,6 @@ -include ../tools.mk -ifneq ($(UNAME),OpenBSD) +ifneq ($(findstring BSD,$(UNAME)),BSD) HOST := $(shell $(RUSTC) -vV | grep 'host:' | sed 's/host: //') ifeq ($(findstring i686,$(HOST)),i686) TARGET := $(subst i686,x86_64,$(HOST)) @@ -13,6 +13,6 @@ all: $(RUSTC) bar.rs -C extra-filename=-targ --target $(TARGET) $(RUSTC) baz.rs --extern a=$(TMPDIR)/liba-targ.rlib --target $(TARGET) else -# OpenBSD support only x86_64 architecture for now +# FreeBSD & OpenBSD support only x86_64 architecture for now all: endif diff --git a/src/test/run-pass-fulldeps/plugin-lib-ok-in-plugin.rs b/src/test/run-pass-fulldeps/plugin-lib-ok-in-plugin.rs new file mode 100644 index 0000000000000..c612ee75651ba --- /dev/null +++ b/src/test/run-pass-fulldeps/plugin-lib-ok-in-plugin.rs @@ -0,0 +1,26 @@ +// Copyright 2013-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. + +// aux-build:macro_crate_test.rs +// aux-build:plugin_with_plugin_lib.rs +// ignore-stage1 +// ignore-cross-compile +// +// macro_crate_test will not compile on a cross-compiled target because +// libsyntax is not compiled for it. + +#![deny(plugin_as_library)] +#![feature(plugin)] +#![plugin(macro_crate_test)] +#![plugin(plugin_with_plugin_lib)] + +fn main() { + assert_eq!(1, make_a_1!()); +} diff --git a/src/test/run-pass-fulldeps/plugin-plus-extern-crate.rs b/src/test/run-pass-fulldeps/plugin-plus-extern-crate.rs index 0c27dba9c627f..d1ce83f267788 100644 --- a/src/test/run-pass-fulldeps/plugin-plus-extern-crate.rs +++ b/src/test/run-pass-fulldeps/plugin-plus-extern-crate.rs @@ -15,6 +15,7 @@ // macro_crate_test will not compile on a cross-compiled target because // libsyntax is not compiled for it. +#![allow(plugin_as_library)] #![feature(plugin)] #![plugin(macro_crate_test)] diff --git a/src/test/run-pass/issue22346.rs b/src/test/run-pass/issue22346.rs new file mode 100644 index 0000000000000..3193e5c5fc247 --- /dev/null +++ b/src/test/run-pass/issue22346.rs @@ -0,0 +1,17 @@ +// 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. + +// This used to cause an ICE because the retslot for the "return" had the wrong type +fn testcase<'a>() -> Box + 'a> { + return Box::new(range(0, 3).map(|i| { return i; })); +} + +fn main() { +}