From 18b24b718d2f3d5788a1a0406ae5d0b652f176fd Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 16 Sep 2019 15:43:46 +0100 Subject: [PATCH 1/7] Make some adjustments to the documentation for `std::convert::identity` Fixes some extra blank lines and makes some minor tweaks to the wording. --- src/libcore/convert.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 402a7b2c95a46..06f2b7bab12eb 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -42,11 +42,11 @@ use crate::fmt; -/// An identity function. +/// The identity function. /// /// Two things are important to note about this function: /// -/// - It is not always equivalent to a closure like `|x| x` since the +/// - It is not always equivalent to a closure like `|x| x`, since the /// closure may coerce `x` into a different type. /// /// - It moves the input `x` passed to the function. @@ -56,31 +56,32 @@ use crate::fmt; /// /// # Examples /// -/// Using `identity` to do nothing among other interesting functions: +/// Using `identity` to do nothing in a sequence of other, interesting, +/// functions: /// /// ```rust /// use std::convert::identity; /// /// fn manipulation(x: u32) -> u32 { -/// // Let's assume that this function does something interesting. +/// // Let's pretend that adding one is an interesting function. /// x + 1 /// } /// /// let _arr = &[identity, manipulation]; /// ``` /// -/// Using `identity` to get a function that changes nothing in a conditional: +/// Using `identity` as a "do nothing" base case in a conditional: /// /// ```rust /// use std::convert::identity; /// /// # let condition = true; -/// +/// # /// # fn manipulation(x: u32) -> u32 { x + 1 } -/// +/// # /// let do_stuff = if condition { manipulation } else { identity }; /// -/// // do more interesting stuff.. +/// // Do more interesting stuff... /// /// let _results = do_stuff(42); /// ``` From 2fd4e584a8a994e3fc8e19113db58e62561fb7e9 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 10 Sep 2019 18:59:14 +0200 Subject: [PATCH 2/7] `AdtDef` is an algebraic data type, not abstract data type. --- src/librustc/ty/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 17eb4a8957fd5..5ca819e12f232 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1938,9 +1938,15 @@ pub struct FieldDef { pub vis: Visibility, } -/// The definition of an abstract data type -- a struct or enum. +/// The definition of a user-defined type, e.g., a `struct`, `enum`, or `union`. /// /// These are all interned (by `intern_adt_def`) into the `adt_defs` table. +/// +/// The initialism *"Adt"* stands for an [*algebraic data type (ADT)*][adt]. +/// This is slightly wrong because `union`s are not ADTs. +/// Moreover, Rust only allows recursive data types through indirection. +/// +/// [adt]: https://en.wikipedia.org/wiki/Algebraic_data_type pub struct AdtDef { /// `DefId` of the struct, enum or union item. pub did: DefId, From 4b175339b88f033561f2ffee55bf33d47741bd20 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 15 Sep 2019 13:53:04 +0200 Subject: [PATCH 3/7] update miri --- Cargo.lock | 6 +++--- src/tools/miri | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc3c2ae2a58c5..5fcea25b89a1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -232,9 +232,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.2.7" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" +checksum = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" [[package]] name = "bytes" @@ -2065,7 +2065,7 @@ dependencies = [ "hex", "log", "num-traits", - "rand 0.6.1", + "rand 0.7.0", "rustc-workspace-hack", "rustc_version", "shell-escape", diff --git a/src/tools/miri b/src/tools/miri index dd94c7c5a32be..508fdb860b2b7 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit dd94c7c5a32be2ee0adeeaf9d46f26f14925797c +Subproject commit 508fdb860b2b7c9f0f31b51b83c8808d76f72291 From f90a81c23873b751b4d414d57a339e198b105ceb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 15 Sep 2019 13:54:04 +0200 Subject: [PATCH 4/7] with byteorder 1.3, the i128 feature is a NOP --- Cargo.lock | 1 - src/librustc/Cargo.toml | 2 +- src/librustc_mir/Cargo.toml | 2 +- src/tools/rustc-workspace-hack/Cargo.toml | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fcea25b89a1d..0772dc60c8109 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3253,7 +3253,6 @@ dependencies = [ name = "rustc-workspace-hack" version = "1.0.0" dependencies = [ - "byteorder", "crossbeam-utils 0.6.5", "serde", "serde_json", diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index d569573a5e94c..0834faf132424 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -31,7 +31,7 @@ syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } backtrace = "0.3.3" parking_lot = "0.9" -byteorder = { version = "1.1", features = ["i128"]} +byteorder = { version = "1.3" } chalk-engine = { version = "0.9.0", default-features=false } rustc_fs_util = { path = "../librustc_fs_util" } smallvec = { version = "0.6.7", features = ["union", "may_dangle"] } diff --git a/src/librustc_mir/Cargo.toml b/src/librustc_mir/Cargo.toml index e02736078b571..0691390bead4b 100644 --- a/src/librustc_mir/Cargo.toml +++ b/src/librustc_mir/Cargo.toml @@ -24,6 +24,6 @@ rustc_lexer = { path = "../librustc_lexer" } rustc_serialize = { path = "../libserialize", package = "serialize" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } -byteorder = { version = "1.1", features = ["i128"] } +byteorder = { version = "1.3" } rustc_apfloat = { path = "../librustc_apfloat" } smallvec = { version = "0.6.7", features = ["union", "may_dangle"] } diff --git a/src/tools/rustc-workspace-hack/Cargo.toml b/src/tools/rustc-workspace-hack/Cargo.toml index d068e1cf307b8..930279c0ca27b 100644 --- a/src/tools/rustc-workspace-hack/Cargo.toml +++ b/src/tools/rustc-workspace-hack/Cargo.toml @@ -62,7 +62,6 @@ crossbeam-utils = { version = "0.6.5", features = ["nightly"] } serde = { version = "1.0.82", features = ['derive'] } serde_json = { version = "1.0.31", features = ["raw_value"] } smallvec = { version = "0.6", features = ['union', 'may_dangle'] } -byteorder = { version = "1.2.7", features = ["i128"] } [target.'cfg(not(windows))'.dependencies] From b7ebbc291a6304488eac6b13d5656d6981728551 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 16 Sep 2019 10:06:11 +0200 Subject: [PATCH 5/7] update miri for latest breakage --- src/tools/miri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri b/src/tools/miri index 508fdb860b2b7..d88138723780d 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit 508fdb860b2b7c9f0f31b51b83c8808d76f72291 +Subproject commit d88138723780d11ca2c09560111223dc20b9d5f3 From 8a8a57e8cf00b6b14e33e4443fe095b6dbffe81b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 16 Sep 2019 20:37:00 +0200 Subject: [PATCH 6/7] update Nomicon and Reference --- src/doc/nomicon | 2 +- src/doc/reference | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/nomicon b/src/doc/nomicon index 38b9a76bc8b59..3600533888b17 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 38b9a76bc8b59ac862663807fc51c9b757337fd6 +Subproject commit 3600533888b17cc8f9ead74ad78d76ee07275743 diff --git a/src/doc/reference b/src/doc/reference index 1944efed35989..fa5dfb832ef8a 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 1944efed35989ba57fa397c0724c4921310311fc +Subproject commit fa5dfb832ef8a7568e17dabf612f486d641ff4ac From d1f763f60d47c6777934039f86529e189c1b92a9 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 16 Sep 2019 15:53:08 -0300 Subject: [PATCH 7/7] Use while let slice_pattern instead of carrying an index around --- src/librustc_mir/borrow_check/conflict_errors.rs | 10 ++++++---- src/librustc_mir/borrow_check/mod.rs | 8 ++++---- src/librustc_mir/borrow_check/nll/type_check/mod.rs | 7 +++++-- src/librustc_mir/build/matches/mod.rs | 5 +++-- src/librustc_mir/transform/check_unsafety.rs | 5 +++-- src/librustc_mir/util/alignment.rs | 5 +++-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs index 4b4516d6bf290..81359c6a46e99 100644 --- a/src/librustc_mir/borrow_check/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/conflict_errors.rs @@ -614,8 +614,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { projection, } = first_borrowed_place; - for (i, elem) in projection.iter().enumerate().rev() { - let proj_base = &projection[..i]; + let mut cursor = &**projection; + while let [proj_base @ .., elem] = cursor { + cursor = proj_base; match elem { ProjectionElem::Field(field, _) if union_ty(base, proj_base).is_some() => { @@ -637,8 +638,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { projection, } = second_borrowed_place; - for (i, elem) in projection.iter().enumerate().rev() { - let proj_base = &projection[..i]; + let mut cursor = &**projection; + while let [proj_base @ .., elem] = cursor { + cursor = proj_base; if let ProjectionElem::Field(field, _) = elem { if let Some(union_ty) = union_ty(base, proj_base) { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 5ef70461296c7..1d3576244c4af 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1758,7 +1758,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { debug!("check_if_assigned_path_is_moved place: {:?}", place); // None case => assigning to `x` does not require `x` be initialized. - for (i, elem) in place.projection.iter().enumerate().rev() { + let mut cursor = &*place.projection; + while let [proj_base @ .., elem] = cursor { + cursor = proj_base; + match elem { ProjectionElem::Index(_/*operand*/) | ProjectionElem::ConstantIndex { .. } | @@ -1771,8 +1774,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // assigning to (*P) requires P to be initialized ProjectionElem::Deref => { - let proj_base = &place.projection[..i]; - self.check_if_full_path_is_moved( location, InitializationRequiringAction::Use, (PlaceRef { @@ -1790,7 +1791,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } ProjectionElem::Field(..) => { - let proj_base = &place.projection[..i]; // if type of `P` has a dtor, then // assigning to `P.f` requires `P` itself // be already initialized diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 1d17bae559c59..62bff3421a078 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -2417,9 +2417,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { "add_reborrow_constraint({:?}, {:?}, {:?})", location, borrow_region, borrowed_place ); - for (i, elem) in borrowed_place.projection.iter().enumerate().rev() { + + let mut cursor = &*borrowed_place.projection; + while let [proj_base @ .., elem] = cursor { + cursor = proj_base; + debug!("add_reborrow_constraint - iteration {:?}", elem); - let proj_base = &borrowed_place.projection[..i]; match elem { ProjectionElem::Deref => { diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index aa261f8eb6fb2..2b0237c7c08b9 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -1296,8 +1296,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Insert a Shallow borrow of the prefixes of any fake borrows. for place in fake_borrows { - for (i, elem) in place.projection.iter().enumerate().rev() { - let proj_base = &place.projection[..i]; + let mut cursor = &*place.projection; + while let [proj_base @ .., elem] = cursor { + cursor = proj_base; if let ProjectionElem::Deref = elem { // Insert a shallow borrow after a deref. For other diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index f8af9b9fcbee0..39aa5c717acc1 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -407,8 +407,9 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { place: &Place<'tcx>, is_mut_use: bool, ) { - for (i, elem) in place.projection.iter().enumerate().rev() { - let proj_base = &place.projection[..i]; + let mut cursor = &*place.projection; + while let [proj_base @ .., elem] = cursor { + cursor = proj_base; match elem { ProjectionElem::Field(..) => { diff --git a/src/librustc_mir/util/alignment.rs b/src/librustc_mir/util/alignment.rs index b4c97f9191732..a75c1af04f047 100644 --- a/src/librustc_mir/util/alignment.rs +++ b/src/librustc_mir/util/alignment.rs @@ -38,8 +38,9 @@ fn is_within_packed<'tcx, L>(tcx: TyCtxt<'tcx>, local_decls: &L, place: &Place<' where L: HasLocalDecls<'tcx>, { - for (i, elem) in place.projection.iter().enumerate().rev() { - let proj_base = &place.projection[..i]; + let mut cursor = &*place.projection; + while let [proj_base @ .., elem] = cursor { + cursor = proj_base; match elem { // encountered a Deref, which is ABI-aligned