From bf90d4377f046b7809a50b8fa74be6848d4c1a86 Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Fri, 22 Jun 2018 21:23:17 +0100 Subject: [PATCH 01/13] Updated RELEASES for 1.28.0 --- RELEASES.md | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 068e9e7263e7d..1dee94b76ac31 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,141 @@ +Version 1.28.0 (2018-08-02) +=========================== + +Language +-------- +- [Stabilised the `#[repr(transparent)]` attribute.][51562] This attribute + allows a Rust newtype wrapper (`struct NewType(T);`) to be represented as + the inner type across Foreign Function Interface (FFI) boundaries. +- [The keywords `pure`, `sizeof`, `alignof`, and `offsetof` have been unreserved + and can now be used as identifiers.][51196] +- [Stabilised the `GlobalAlloc` trait and `#[global_allocator]` + attribute.][51241] This will allow users to specify a global allocator for + their program. +- [Unit test functions marked with the `#[test]` attribute can now return + `Result<(), E: Debug>` in addition to `()`.][51298] +- [Stabilised a `lifetime` specifier to `macro_rules!` allowing macros to easily + target lifetimes.][50385] + +Compiler +-------- +- [Stabilised the `s` and `z` optimisation levels.][50265] These optimisations + prioritise making smaller binary sizes. `z` is the same as `s` with the + exception that it does not vectorise loops, which typically results in an even + smaller binary. +- [Stabilised the short error format.][49546] Specified with + `--error-format=short` this option will provide a more compressed output of + rust error messages. +- [Added a lint warning when you have duplicated `macro_export`s.][50143] +- [Reduced the number of allocations in the macro parser.][50855] This can + improve compile times of macro heavy crates on average by 5%. + +Libraries +--------- +- [Implemented `Default` for `&mut str`.][51306] +- [Implemented `From` for all integer and unsigned number types.][50554] +- [Implemented `Extend` for `()`.][50234] +- [The `Debug` implementation of `time::Duration` should now be more easily + human readable.][50364] Previously a `Duration` of one second would printed as + `Duration { secs: 1, nanos: 0 }` will now be printed as `1s`. +- [Implemented `From<&String>` for `Cow`, `From<&Vec>` for `Cow<[T]>`, + `From>` for `CString`, `From, From, From<&CString>` + for `Cow`, `From, From, From<&OsString>` for + `Cow`, `From<&PathBuf>` for `Cow`, and `From>` + for `PathBuf`.][50170] +- [`DirEntry::metadata` now uses `fstatat` instead of `lstat` when + possible.][51050] This can provide up to a 40% speed increase. +- [Improved error messages when using `format!`.][50610] + +Stabilized APIs +--------------- +- [`Iterator::step_by`] +- [`Path::ancestors`] +- [`btree_map::Entry::or_default`] +- [`fmt::Alignment`] +- [`hash_map::Entry::or_default`] +- [`iter::repeat_with`] +- [`num::NonZeroU128`] +- [`num::NonZeroU16`] +- [`num::NonZeroU32`] +- [`num::NonZeroU64`] +- [`num::NonZeroU8`] +- [`ops::RangeBounds`] +- [`slice::SliceIndex`] +- [`slice::from_mut`] +- [`slice::from_ref`] +- [`{Any + Send + Sync}::downcast_mut`] +- [`{Any + Send + Sync}::downcast_ref`] +- [`{Any + Send + Sync}::is`] + +Cargo +----- +- [Cargo will now no longer allow you to publish crates with build scripts that + modify the `src` directory.][5584] The `src` directory in a crate should be + considered to be immutable. + +Misc +---- +- [Stabilised the `suggestion_applicability` field in the json output.][50486] + This will allow dev tools to check whether a code suggestion would apply + to them. + +Compatibility Notes +------------------- +- [Rust will no longer consider trait objects with duplicated constraints to + have implementations.][51276] For example the below code will now fail + to compile. + ```rust + trait Trait {} + + impl Trait + Send { + fn test(&self) { println!("one"); } //~ ERROR duplicate definitions with name `test` + } + + impl Trait + Send + Send { + fn test(&self) { println!("two"); } + } + ``` + +[49546]: https://github.com/rust-lang/rust/pull/49546/ +[50143]: https://github.com/rust-lang/rust/pull/50143/ +[50170]: https://github.com/rust-lang/rust/pull/50170/ +[50234]: https://github.com/rust-lang/rust/pull/50234/ +[50265]: https://github.com/rust-lang/rust/pull/50265/ +[50364]: https://github.com/rust-lang/rust/pull/50364/ +[50385]: https://github.com/rust-lang/rust/pull/50385/ +[50486]: https://github.com/rust-lang/rust/pull/50486/ +[50554]: https://github.com/rust-lang/rust/pull/50554/ +[50610]: https://github.com/rust-lang/rust/pull/50610/ +[50855]: https://github.com/rust-lang/rust/pull/50855/ +[51050]: https://github.com/rust-lang/rust/pull/51050/ +[51196]: https://github.com/rust-lang/rust/pull/51196/ +[51200]: https://github.com/rust-lang/rust/pull/51200/ +[51241]: https://github.com/rust-lang/rust/pull/51241/ +[51276]: https://github.com/rust-lang/rust/pull/51276/ +[51298]: https://github.com/rust-lang/rust/pull/51298/ +[51306]: https://github.com/rust-lang/rust/pull/51306/ +[51562]: https://github.com/rust-lang/rust/pull/51562/ +[5584]: https://github.com/rust-lang/cargo/pull/5584/ +[`Iterator::step_by`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.step_by +[`Path::ancestors`]: https://doc.rust-lang.org/std/path/struct.Path.html#method.ancestors +[`btree_map::Entry::or_default`]: https://doc.rust-lang.org/std/collections/btree_map/enum.Entry.html#method.or_default +[`fmt::Alignment`]: https://doc.rust-lang.org/std/fmt/enum.Alignment.html +[`hash_map::Entry::or_default`]: https://doc.rust-lang.org/std/collections/btree_map/enum.Entry.html#method.or_default +[`iter::repeat_with`]: https://doc.rust-lang.org/std/iter/fn.repeat_with.html +[`num::NonZeroU128`]: https://doc.rust-lang.org/std/num/struct.NonZeroU128.html +[`num::NonZeroU16`]: https://doc.rust-lang.org/std/num/struct.NonZeroU16.html +[`num::NonZeroU32`]: https://doc.rust-lang.org/std/num/struct.NonZeroU32.html +[`num::NonZeroU64`]: https://doc.rust-lang.org/std/num/struct.NonZeroU64.html +[`num::NonZeroU8`]: https://doc.rust-lang.org/std/num/struct.NonZeroU8.html +[`ops::RangeBounds`]: https://doc.rust-lang.org/std/ops/trait.RangeBounds.html +[`slice::SliceIndex`]: https://doc.rust-lang.org/std/slice/trait.SliceIndex.html +[`slice::from_mut`]: https://doc.rust-lang.org/std/slice/fn.from_mut.html +[`slice::from_ref`]: https://doc.rust-lang.org/std/slice/fn.from_ref.html +[`{Any + Send + Sync}::downcast_mut`]: https://doc.rust-lang.org/std/any/trait.Any.html#method.downcast_mut-2 +[`{Any + Send + Sync}::downcast_ref`]: https://doc.rust-lang.org/std/any/trait.Any.html#method.downcast_ref-2 +[`{Any + Send + Sync}::is`]: https://doc.rust-lang.org/std/any/trait.Any.html#method.is-2 + + Version 1.27.0 (2018-06-21) ========================== From b58047681bd9255905feff26a53f0279e3f533e3 Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Fri, 22 Jun 2018 22:36:01 +0100 Subject: [PATCH 02/13] Update RELEASES.md --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 1dee94b76ac31..9118dcd32100f 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -36,7 +36,7 @@ Libraries - [Implemented `Extend` for `()`.][50234] - [The `Debug` implementation of `time::Duration` should now be more easily human readable.][50364] Previously a `Duration` of one second would printed as - `Duration { secs: 1, nanos: 0 }` will now be printed as `1s`. + `Duration { secs: 1, nanos: 0 }` and will now be printed as `1s`. - [Implemented `From<&String>` for `Cow`, `From<&Vec>` for `Cow<[T]>`, `From>` for `CString`, `From, From, From<&CString>` for `Cow`, `From, From, From<&OsString>` for From ffc733fcef4e724524a705c7bc8c9e068fa3ca3a Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Sat, 23 Jun 2018 10:45:46 +0100 Subject: [PATCH 03/13] Update RELEASES.md --- RELEASES.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 9118dcd32100f..fe74e244623f3 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -42,6 +42,8 @@ Libraries for `Cow`, `From, From, From<&OsString>` for `Cow`, `From<&PathBuf>` for `Cow`, and `From>` for `PathBuf`.][50170] +- [Implemented `Shl` and `Shr` for `Wrapping` + and `Wrapping`.][50465] - [`DirEntry::metadata` now uses `fstatat` instead of `lstat` when possible.][51050] This can provide up to a 40% speed increase. - [Improved error messages when using `format!`.][50610] @@ -70,7 +72,7 @@ Stabilized APIs Cargo ----- - [Cargo will now no longer allow you to publish crates with build scripts that - modify the `src` directory.][5584] The `src` directory in a crate should be + modify the `src` directory.][cargo/5584] The `src` directory in a crate should be considered to be immutable. Misc @@ -103,6 +105,7 @@ Compatibility Notes [50265]: https://github.com/rust-lang/rust/pull/50265/ [50364]: https://github.com/rust-lang/rust/pull/50364/ [50385]: https://github.com/rust-lang/rust/pull/50385/ +[50465]: https://github.com/rust-lang/rust/pull/50465/ [50486]: https://github.com/rust-lang/rust/pull/50486/ [50554]: https://github.com/rust-lang/rust/pull/50554/ [50610]: https://github.com/rust-lang/rust/pull/50610/ @@ -115,7 +118,7 @@ Compatibility Notes [51298]: https://github.com/rust-lang/rust/pull/51298/ [51306]: https://github.com/rust-lang/rust/pull/51306/ [51562]: https://github.com/rust-lang/rust/pull/51562/ -[5584]: https://github.com/rust-lang/cargo/pull/5584/ +[cargo/5584]: https://github.com/rust-lang/cargo/pull/5584/ [`Iterator::step_by`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.step_by [`Path::ancestors`]: https://doc.rust-lang.org/std/path/struct.Path.html#method.ancestors [`btree_map::Entry::or_default`]: https://doc.rust-lang.org/std/collections/btree_map/enum.Entry.html#method.or_default From 3f31c389c491e6082ff850ae6873b3a5097d4d7f Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Tue, 26 Jun 2018 13:41:32 +0100 Subject: [PATCH 04/13] Updated RELEASES --- RELEASES.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index fe74e244623f3..4405b593b29bc 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -3,26 +3,26 @@ Version 1.28.0 (2018-08-02) Language -------- -- [Stabilised the `#[repr(transparent)]` attribute.][51562] This attribute +- [The `#[repr(transparent)]` attribute is now stable.][51562] This attribute allows a Rust newtype wrapper (`struct NewType(T);`) to be represented as the inner type across Foreign Function Interface (FFI) boundaries. - [The keywords `pure`, `sizeof`, `alignof`, and `offsetof` have been unreserved and can now be used as identifiers.][51196] -- [Stabilised the `GlobalAlloc` trait and `#[global_allocator]` - attribute.][51241] This will allow users to specify a global allocator for +- [The `GlobalAlloc` trait and `#[global_allocator]` attribute are now + stable.][51241] This will allow users to specify a global allocator for their program. - [Unit test functions marked with the `#[test]` attribute can now return `Result<(), E: Debug>` in addition to `()`.][51298] -- [Stabilised a `lifetime` specifier to `macro_rules!` allowing macros to easily - target lifetimes.][50385] +- [The `lifetime` specifier for `macro_rules!` is now stable.][50385] This + allows macros to easily target lifetimes. Compiler -------- -- [Stabilised the `s` and `z` optimisation levels.][50265] These optimisations +- [The `s` and `z` optimisation levels are now stable.][50265] These optimisations prioritise making smaller binary sizes. `z` is the same as `s` with the exception that it does not vectorise loops, which typically results in an even smaller binary. -- [Stabilised the short error format.][49546] Specified with +- [The short error format is now stable.][49546] Specified with `--error-format=short` this option will provide a more compressed output of rust error messages. - [Added a lint warning when you have duplicated `macro_export`s.][50143] @@ -77,9 +77,9 @@ Cargo Misc ---- -- [Stabilised the `suggestion_applicability` field in the json output.][50486] - This will allow dev tools to check whether a code suggestion would apply - to them. +- [The `suggestion_applicability` field in `rustc`'s json output is now + stable.][50486] This will allow dev tools to check whether a code suggestion + would apply to them. Compatibility Notes ------------------- @@ -328,7 +328,7 @@ Language - [Closures now implement `Copy` and/or `Clone` if all captured variables implement either or both traits.][49299] - [The inclusive range syntax e.g. `for x in 0..=10` is now stable.][47813] -- [Stablise `'_`. The underscore lifetime can be used anywhere where a +- [The `'_` lifetime is now stable. The underscore lifetime can be used anywhere where a lifetime can be elided.][49458] - [`impl Trait` is now stable allowing you to have abstract types in returns or in function parameters.][49255] e.g. `fn foo() -> impl Iterator` or @@ -529,7 +529,7 @@ Version 1.25.0 (2018-03-29) Language -------- -- [Stabilised `#[repr(align(x))]`.][47006] [RFC 1358] +- [The `#[repr(align(x))]` attribute is now stable.][47006] [RFC 1358] - [You can now use nested groups of imports.][47948] e.g. `use std::{fs::File, io::Read, path::{Path, PathBuf}};` - [You can now have `|` at the start of a match arm.][47947] e.g. From dab257f1932718b659564a242ee450016175d12c Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Wed, 4 Jul 2018 15:56:18 +0100 Subject: [PATCH 05/13] Update RELEASES.md --- RELEASES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 4405b593b29bc..e7887f7e5ec74 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -56,6 +56,7 @@ Stabilized APIs - [`fmt::Alignment`] - [`hash_map::Entry::or_default`] - [`iter::repeat_with`] +- [`num::NonZeroUsize`] - [`num::NonZeroU128`] - [`num::NonZeroU16`] - [`num::NonZeroU32`] @@ -125,6 +126,7 @@ Compatibility Notes [`fmt::Alignment`]: https://doc.rust-lang.org/std/fmt/enum.Alignment.html [`hash_map::Entry::or_default`]: https://doc.rust-lang.org/std/collections/btree_map/enum.Entry.html#method.or_default [`iter::repeat_with`]: https://doc.rust-lang.org/std/iter/fn.repeat_with.html +[`num::NonZeroUsize`]: https://doc.rust-lang.org/std/num/struct.NonZeroUsize.html [`num::NonZeroU128`]: https://doc.rust-lang.org/std/num/struct.NonZeroU128.html [`num::NonZeroU16`]: https://doc.rust-lang.org/std/num/struct.NonZeroU16.html [`num::NonZeroU32`]: https://doc.rust-lang.org/std/num/struct.NonZeroU32.html From dc425e2e64863d4e1aa0f2bb41f7bfa3cd14b558 Mon Sep 17 00:00:00 2001 From: Val Markovic Date: Wed, 4 Jul 2018 17:26:45 -0700 Subject: [PATCH 06/13] Clarifying how the alignment of the struct works The docs were not specifying how to compute the alignment of the struct, so I had to spend some time trying to figure out how that works. Found the answer [on this page](http://camlorn.net/posts/April%202017/rust-struct-field-reordering.html): > The total size of this struct is 5, but the most-aligned field is b with alignment 2, so we round up to 6 and give the struct an alignment of 2 bytes. --- src/libcore/mem.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 84173654655eb..8fb4e0d6a02e3 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -229,6 +229,8 @@ pub fn forget(t: T) { /// 2. Round up the current size to the nearest multiple of the next field's [alignment]. /// /// Finally, round the size of the struct to the nearest multiple of its [alignment]. +/// The alignment of the struct is usually the largest alignment of all its +/// fields; this can be changed with the use of `repr(align(N))`. /// /// Unlike `C`, zero sized structs are not rounded up to one byte in size. /// @@ -283,7 +285,8 @@ pub fn forget(t: T) { /// // The size of the second field is 2, so add 2 to the size. Size is 4. /// // The alignment of the third field is 1, so add 0 to the size for padding. Size is 4. /// // The size of the third field is 1, so add 1 to the size. Size is 5. -/// // Finally, the alignment of the struct is 2, so add 1 to the size for padding. Size is 6. +/// // Finally, the alignment of the struct is 2 (because the largest alignment amongst its +/// // fields is 2), so add 1 to the size for padding. Size is 6. /// assert_eq!(6, mem::size_of::()); /// /// #[repr(C)] From e769deca998479c7b78931af45a26c6c822c74f7 Mon Sep 17 00:00:00 2001 From: willmo Date: Sat, 7 Jul 2018 20:09:34 -0700 Subject: [PATCH 07/13] Add #[repr(transparent)] to Atomic* types This allows them to be used in #[repr(C)] structs without warnings. Since rust-lang/rfcs#1649 and rust-lang/rust#35603 they are already documented to have "the same in-memory representation as" their corresponding primitive types. This just makes that explicit. --- src/libcore/sync/atomic.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index e9d1fb8911504..1e2b18bf9b038 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -124,6 +124,7 @@ pub fn spin_loop_hint() { /// [`bool`]: ../../../std/primitive.bool.html #[cfg(target_has_atomic = "8")] #[stable(feature = "rust1", since = "1.0.0")] +#[repr(transparent)] pub struct AtomicBool { v: UnsafeCell, } @@ -147,6 +148,7 @@ unsafe impl Sync for AtomicBool {} /// This type has the same in-memory representation as a `*mut T`. #[cfg(target_has_atomic = "ptr")] #[stable(feature = "rust1", since = "1.0.0")] +#[repr(transparent)] pub struct AtomicPtr { p: UnsafeCell<*mut T>, } @@ -976,6 +978,7 @@ macro_rules! atomic_int { /// /// [module-level documentation]: index.html #[$stable] + #[repr(transparent)] pub struct $atomic_type { v: UnsafeCell<$int_type>, } From c0ec5d5e44a84c75052abc6eed505669487f3285 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 8 Jul 2018 15:07:06 +0200 Subject: [PATCH 08/13] Add setting to prevent doc auto-hide of trait implementations --- src/librustdoc/html/render.rs | 2 ++ src/librustdoc/html/static/main.js | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e4afb9ae54b8a..41c08dbf4ab65 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1669,6 +1669,8 @@ impl<'a> Settings<'a> { settings: vec![ ("item-declarations", "Auto-hide item declarations.", true), ("item-attributes", "Auto-hide item attributes.", true), + ("trait-implementations", "Auto-hide trait implementations documentation", + true), ("go-to-only-result", "Directly go to item in search if there is only one result", false), ], diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index f3c9ce424106d..3bd343c0c0b68 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1938,17 +1938,19 @@ if (collapse) { toggleAllDocs(pageId, true); } - onEach(document.getElementsByClassName("collapse-toggle"), function(e) { - // inherent impl ids are like 'impl' or impl-'. - // they will never be hidden by default. - var n = e.parentNode; - if (n.id.match(/^impl(?:-\d+)?$/) === null) { - // Automatically minimize all non-inherent impls - if (collapse || hasClass(n, 'impl')) { - collapseDocs(e, "hide", pageId); + if (getCurrentValue('rustdoc-trait-implementations') !== "false") { + onEach(document.getElementsByClassName("collapse-toggle"), function(e) { + // inherent impl ids are like 'impl' or impl-'. + // they will never be hidden by default. + var n = e.parentNode; + if (n.id.match(/^impl(?:-\d+)?$/) === null) { + // Automatically minimize all non-inherent impls + if (collapse || hasClass(n, 'impl')) { + collapseDocs(e, "hide", pageId); + } } - } - }); + }); + } } var x = document.getElementById('toggle-all-docs'); From 26615b8f20432c2332a8ca93b18301872870dd01 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 8 Jul 2018 15:07:17 +0200 Subject: [PATCH 09/13] Fix some links --- src/libcore/num/flt2dec/strategy/dragon.rs | 4 ++-- src/libcore/num/flt2dec/strategy/grisu.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/num/flt2dec/strategy/dragon.rs b/src/libcore/num/flt2dec/strategy/dragon.rs index 6aa4f297e75ba..9c9e531c593c6 100644 --- a/src/libcore/num/flt2dec/strategy/dragon.rs +++ b/src/libcore/num/flt2dec/strategy/dragon.rs @@ -9,9 +9,9 @@ // except according to those terms. /*! -Almost direct (but slightly optimized) Rust translation of Figure 3 of [1]. +Almost direct (but slightly optimized) Rust translation of Figure 3 of \[1\]. -[1] Burger, R. G. and Dybvig, R. K. 1996. Printing floating-point numbers +\[1\] Burger, R. G. and Dybvig, R. K. 1996. Printing floating-point numbers quickly and accurately. SIGPLAN Not. 31, 5 (May. 1996), 108-116. */ diff --git a/src/libcore/num/flt2dec/strategy/grisu.rs b/src/libcore/num/flt2dec/strategy/grisu.rs index cf70a1978f5e6..5c023a191db55 100644 --- a/src/libcore/num/flt2dec/strategy/grisu.rs +++ b/src/libcore/num/flt2dec/strategy/grisu.rs @@ -9,10 +9,10 @@ // except according to those terms. /*! -Rust adaptation of Grisu3 algorithm described in [1]. It uses about +Rust adaptation of Grisu3 algorithm described in \[1\]. It uses about 1KB of precomputed table, and in turn, it's very quick for most inputs. -[1] Florian Loitsch. 2010. Printing floating-point numbers quickly and +\[1\] Florian Loitsch. 2010. Printing floating-point numbers quickly and accurately with integers. SIGPLAN Not. 45, 6 (June 2010), 233-243. */ From aac0d914b2d776c43d6c95054815f49e19792e6e Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 9 Jul 2018 09:24:42 +0200 Subject: [PATCH 10/13] Correct some codegen stats counters --- src/librustc_codegen_llvm/builder.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index 7b4998e85881e..c71e49b0d8821 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -277,7 +277,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } pub fn nswsub(&self, lhs: ValueRef, rhs: ValueRef) -> ValueRef { - self.count_insn("nwsub"); + self.count_insn("nswsub"); unsafe { llvm::LLVMBuildNSWSub(self.llbuilder, lhs, rhs, noname()) } @@ -291,14 +291,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } pub fn fsub(&self, lhs: ValueRef, rhs: ValueRef) -> ValueRef { - self.count_insn("sub"); + self.count_insn("fsub"); unsafe { llvm::LLVMBuildFSub(self.llbuilder, lhs, rhs, noname()) } } pub fn fsub_fast(&self, lhs: ValueRef, rhs: ValueRef) -> ValueRef { - self.count_insn("sub"); + self.count_insn("fsub"); unsafe { let instr = llvm::LLVMBuildFSub(self.llbuilder, lhs, rhs, noname()); llvm::LLVMRustSetHasUnsafeAlgebra(instr); @@ -1315,6 +1315,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } pub fn add_incoming_to_phi(&self, phi: ValueRef, val: ValueRef, bb: BasicBlockRef) { + self.count_insn("addincoming"); unsafe { llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint); } From a49b75d2f342f5904d89f34f46dfd621c20da7f7 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 9 Jul 2018 13:16:02 -0700 Subject: [PATCH 11/13] Add test case from issue #51515 --- src/test/ui/suggestions/issue-51515.rs | 18 ++++++++++++++++++ src/test/ui/suggestions/issue-51515.stderr | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/test/ui/suggestions/issue-51515.rs create mode 100644 src/test/ui/suggestions/issue-51515.stderr diff --git a/src/test/ui/suggestions/issue-51515.rs b/src/test/ui/suggestions/issue-51515.rs new file mode 100644 index 0000000000000..b5bbf48ddfac8 --- /dev/null +++ b/src/test/ui/suggestions/issue-51515.rs @@ -0,0 +1,18 @@ +// Copyright 2018 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. + +#![feature(nll)] + +fn main() { + let foo = &16; + *foo = 32; + let bar = foo; + *bar = 64; +} diff --git a/src/test/ui/suggestions/issue-51515.stderr b/src/test/ui/suggestions/issue-51515.stderr new file mode 100644 index 0000000000000..7cdbef1badc76 --- /dev/null +++ b/src/test/ui/suggestions/issue-51515.stderr @@ -0,0 +1,17 @@ +error[E0594]: cannot assign to `*foo` which is behind a `&` reference + --> $DIR/issue-51515.rs:15:5 + | +LL | let foo = &16; + | --- help: consider changing this to be a mutable reference: `&mut 16` +LL | *foo = 32; + | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written + +error[E0594]: cannot assign to `*bar` which is behind a `&` reference + --> $DIR/issue-51515.rs:17:5 + | +LL | *bar = 64; + | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0594`. From dc8ae26c1ee4f95e3baef603506fbaa95cb2ccd1 Mon Sep 17 00:00:00 2001 From: ashtneoi Date: Mon, 9 Jul 2018 13:33:57 -0700 Subject: [PATCH 12/13] Fix issue #51515 and update test --- src/librustc_mir/borrow_check/mod.rs | 6 ++++-- src/test/ui/suggestions/issue-51515.rs | 6 ++++++ src/test/ui/suggestions/issue-51515.stderr | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index a5db0d15d8ab3..1a66a2d2cb902 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1905,8 +1905,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // highlighted text will always be `&` and // thus can transform to `&mut` by slicing off // first ASCII character and prepending "&mut ". - let borrowed_expr = src[1..].to_string(); - return (assignment_rhs_span, format!("&mut {}", borrowed_expr)); + if src.starts_with('&') { + let borrowed_expr = src[1..].to_string(); + return (assignment_rhs_span, format!("&mut {}", borrowed_expr)); + } } } diff --git a/src/test/ui/suggestions/issue-51515.rs b/src/test/ui/suggestions/issue-51515.rs index b5bbf48ddfac8..3e0a3b757a3d6 100644 --- a/src/test/ui/suggestions/issue-51515.rs +++ b/src/test/ui/suggestions/issue-51515.rs @@ -12,7 +12,13 @@ fn main() { let foo = &16; + //~^ HELP consider changing this to be a mutable reference + //~| SUGGESTION &mut 16 *foo = 32; + //~^ ERROR cannot assign to `*foo` which is behind a `&` reference let bar = foo; + //~^ HELP consider changing this to be a mutable reference + //~| SUGGESTION &mut i32 *bar = 64; + //~^ ERROR cannot assign to `*bar` which is behind a `&` reference } diff --git a/src/test/ui/suggestions/issue-51515.stderr b/src/test/ui/suggestions/issue-51515.stderr index 7cdbef1badc76..3e7349b5acabf 100644 --- a/src/test/ui/suggestions/issue-51515.stderr +++ b/src/test/ui/suggestions/issue-51515.stderr @@ -1,14 +1,18 @@ error[E0594]: cannot assign to `*foo` which is behind a `&` reference - --> $DIR/issue-51515.rs:15:5 + --> $DIR/issue-51515.rs:17:5 | LL | let foo = &16; | --- help: consider changing this to be a mutable reference: `&mut 16` +... LL | *foo = 32; | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written error[E0594]: cannot assign to `*bar` which is behind a `&` reference - --> $DIR/issue-51515.rs:17:5 + --> $DIR/issue-51515.rs:22:5 | +LL | let bar = foo; + | --- help: consider changing this to be a mutable reference: `&mut i32` +... LL | *bar = 64; | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written From bc09fcb990a7195db540b3dcb9f0f90e52213be2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Jul 2018 15:26:57 -0700 Subject: [PATCH 13/13] rustc: Avoid /tmp/ in graphviz writing This issue was reported to security@rust-lang.org by Sebastien Marie following our recent [security advisory][1]. Because `/tmp` is typically globally writable it's possible for one user to place symlinks in `/tmp` pointing to files in another user's directories, causing `rustc` to overwrite the contents of innocent files by accident. This patch instead defaults the output path here to the cwd which should avoid this issue. [1]: https://blog.rust-lang.org/2018/07/06/security-advisory-for-rustdoc.html --- src/librustc/infer/lexical_region_resolve/graphviz.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs index d9d08294334db..d76d33b990222 100644 --- a/src/librustc/infer/lexical_region_resolve/graphviz.rs +++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs @@ -39,14 +39,14 @@ use std::sync::atomic::{AtomicBool, Ordering}; fn print_help_message() { println!("\ -Z print-region-graph by default prints a region constraint graph for every \n\ -function body, to the path `/tmp/constraints.nodeXXX.dot`, where the XXX is \n\ +function body, to the path `constraints.nodeXXX.dot`, where the XXX is \n\ replaced with the node id of the function under analysis. \n\ \n\ To select one particular function body, set `RUST_REGION_GRAPH_NODE=XXX`, \n\ where XXX is the node id desired. \n\ \n\ To generate output to some path other than the default \n\ -`/tmp/constraints.nodeXXX.dot`, set `RUST_REGION_GRAPH=/path/desired.dot`; \n\ +`constraints.nodeXXX.dot`, set `RUST_REGION_GRAPH=/path/desired.dot`; \n\ occurrences of the character `%` in the requested path will be replaced with\n\ the node id of the function under analysis. \n\ \n\ @@ -90,7 +90,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>( } Ok(other_path) => other_path, - Err(_) => "/tmp/constraints.node%.dot".to_string(), + Err(_) => "constraints.node%.dot".to_string(), }; if output_template.is_empty() {