From 7b9d50d14d0982b33a9288343792327e4e1d33cd Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Tue, 15 Oct 2019 10:34:53 +0200 Subject: [PATCH 01/17] rename Error::iter_chain() and remove Error::iter_sources() Rename * Error::iter_chain() -> Error::chain() * ErrorIter -> Chain Removed * Error::iter_sources() according to https://github.com/rust-lang/rust/issues/58520 Rationale: 1. Such iterators are helpful. They should better be stabilized sooner than later. 2. self should be included. It is easy to .skip(1) it. Not including self is harmful because it is harder to add self to the iterator than to remove it. 3. The chosen name should be telling and reflect the fact that self is included. `.chain()` was chosen because the iterator iterates over the chain of errors that is somehow included in self. 4. The resulting iterator is named `Chain` because the `error::Chain` is what we want to have. --- src/libstd/error.rs | 92 ++++++--------------------------------------- 1 file changed, 12 insertions(+), 80 deletions(-) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 6b9a35fccc4dc..df24b6635f411 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -725,6 +725,9 @@ impl dyn Error { /// Returns an iterator starting with the current error and continuing with /// recursively calling [`source`]. /// + /// If you want to omit the current error and only use its sources, + /// use `skip(1)`. + /// /// # Examples /// /// ``` @@ -763,7 +766,7 @@ impl dyn Error { /// // let err : Box = b.into(); // or /// let err = &b as &(dyn Error); /// - /// let mut iter = err.iter_chain(); + /// let mut iter = err.chain(); /// /// assert_eq!("B".to_string(), iter.next().unwrap().to_string()); /// assert_eq!("A".to_string(), iter.next().unwrap().to_string()); @@ -774,98 +777,27 @@ impl dyn Error { /// [`source`]: trait.Error.html#method.source #[unstable(feature = "error_iter", issue = "58520")] #[inline] - pub fn iter_chain(&self) -> ErrorIter<'_> { - ErrorIter { + pub fn chain(&self) -> Chain<'_> { + Chain { current: Some(self), } } - - /// Returns an iterator starting with the [`source`] of this error - /// and continuing with recursively calling [`source`]. - /// - /// # Examples - /// - /// ``` - /// #![feature(error_iter)] - /// use std::error::Error; - /// use std::fmt; - /// - /// #[derive(Debug)] - /// struct A; - /// - /// #[derive(Debug)] - /// struct B(Option>); - /// - /// #[derive(Debug)] - /// struct C(Option>); - /// - /// impl fmt::Display for A { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "A") - /// } - /// } - /// - /// impl fmt::Display for B { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "B") - /// } - /// } - /// - /// impl fmt::Display for C { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "C") - /// } - /// } - /// - /// impl Error for A {} - /// - /// impl Error for B { - /// fn source(&self) -> Option<&(dyn Error + 'static)> { - /// self.0.as_ref().map(|e| e.as_ref()) - /// } - /// } - /// - /// impl Error for C { - /// fn source(&self) -> Option<&(dyn Error + 'static)> { - /// self.0.as_ref().map(|e| e.as_ref()) - /// } - /// } - /// - /// let b = B(Some(Box::new(A))); - /// let c = C(Some(Box::new(b))); - /// - /// // let err : Box = c.into(); // or - /// let err = &c as &(dyn Error); - /// - /// let mut iter = err.iter_sources(); - /// - /// assert_eq!("B".to_string(), iter.next().unwrap().to_string()); - /// assert_eq!("A".to_string(), iter.next().unwrap().to_string()); - /// assert!(iter.next().is_none()); - /// assert!(iter.next().is_none()); - /// ``` - /// - /// [`source`]: trait.Error.html#method.source - #[inline] - #[unstable(feature = "error_iter", issue = "58520")] - pub fn iter_sources(&self) -> ErrorIter<'_> { - ErrorIter { - current: self.source(), - } - } } -/// An iterator over [`Error`] +/// An iterator over an [`Error`] and its sources. +/// +/// If you want to omit the initial error and only process +/// its sources, use `skip(1)`. /// /// [`Error`]: trait.Error.html #[unstable(feature = "error_iter", issue = "58520")] #[derive(Copy, Clone, Debug)] -pub struct ErrorIter<'a> { +pub struct Chain<'a> { current: Option<&'a (dyn Error + 'static)>, } #[unstable(feature = "error_iter", issue = "58520")] -impl<'a> Iterator for ErrorIter<'a> { +impl<'a> Iterator for Chain<'a> { type Item = &'a (dyn Error + 'static); fn next(&mut self) -> Option { From 1aceaaa969d85195966e453590cbfc68771bf904 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 1 Nov 2019 08:52:14 +1100 Subject: [PATCH 02/17] Avoid hashing the key twice in `get_query()`. For a single-threaded parallel compiler, this reduces instruction counts across several benchmarks, by up to 2.8%. The commit also adds documentation about `Sharded`'s use of `FxHasher`. --- src/librustc/lib.rs | 1 + src/librustc/ty/query/plumbing.rs | 16 +++++++++++++--- src/librustc_data_structures/sharded.rs | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 996f5b1241263..3c4845e6346cf 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -61,6 +61,7 @@ #![feature(log_syntax)] #![feature(associated_type_bounds)] #![feature(rustc_attrs)] +#![feature(hash_raw_entry)] #![recursion_limit="512"] diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 538154b035ac6..323c8eb18b0c1 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -14,12 +14,13 @@ use errors::Level; use errors::Diagnostic; use errors::FatalError; use errors::Handler; -use rustc_data_structures::fx::{FxHashMap}; +use rustc_data_structures::fx::{FxHasher, FxHashMap}; use rustc_data_structures::sync::{Lrc, Lock}; use rustc_data_structures::sharded::Sharded; use rustc_data_structures::thin_vec::ThinVec; #[cfg(not(parallel_compiler))] use rustc_data_structures::cold_path; +use std::hash::{Hash, Hasher}; use std::mem; use std::ptr; use std::collections::hash_map::Entry; @@ -80,8 +81,17 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> { pub(super) fn try_get(tcx: TyCtxt<'tcx>, span: Span, key: &Q::Key) -> TryGetJob<'a, 'tcx, Q> { let cache = Q::query_cache(tcx); loop { - let mut lock = cache.get_shard_by_value(key).lock(); - if let Some(value) = lock.results.get(key) { + // We compute the key's hash once and then use it for both the + // shard lookup and the hashmap lookup. This relies on the fact + // that both of them use `FxHasher`. + let mut state = FxHasher::default(); + key.hash(&mut state); + let key_hash = state.finish(); + + let mut lock = cache.get_shard_by_hash(key_hash).lock(); + if let Some((_, value)) = + lock.results.raw_entry().from_key_hashed_nocheck(key_hash, key) + { tcx.prof.query_cache_hit(Q::NAME); let result = (value.value.clone(), value.index); #[cfg(debug_assertions)] diff --git a/src/librustc_data_structures/sharded.rs b/src/librustc_data_structures/sharded.rs index 2f972eeccdcbd..a28a5e0f0415a 100644 --- a/src/librustc_data_structures/sharded.rs +++ b/src/librustc_data_structures/sharded.rs @@ -60,6 +60,7 @@ impl Sharded { } } + /// The shard is selected by hashing `val` with `FxHasher`. #[inline] pub fn get_shard_by_value(&self, val: &K) -> &Lock { if SHARDS == 1 { @@ -69,6 +70,11 @@ impl Sharded { } } + /// Get a shard with a pre-computed hash value. If `get_shard_by_value` is + /// ever used in combination with `get_shard_by_hash` on a single `Sharded` + /// instance, then `hash` must be computed with `FxHasher`. Otherwise, + /// `hash` can be computed with any hasher, so long as that hasher is used + /// consistently for each `Sharded` instance. #[inline] pub fn get_shard_by_hash(&self, hash: u64) -> &Lock { let hash_len = mem::size_of::(); From b941034f2f4ffe42e9b7eb19c9a726f9fdc6d35f Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 11 Nov 2019 19:11:24 +0100 Subject: [PATCH 03/17] qualify-const remove cannot mutate statics in initializer of another static error --- src/librustc_mir/transform/qualify_consts.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 5ad5363768d34..15d771ac685f3 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -782,19 +782,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { // Only allow statics (not consts) to refer to other statics. if self.mode == Mode::Static || self.mode == Mode::StaticMut { - if self.mode == Mode::Static - && context.is_mutating_use() - && !self.suppress_errors - { - // this is not strictly necessary as miri will also bail out - // For interior mutability we can't really catch this statically as that - // goes through raw pointers and intermediate temporaries, so miri has - // to catch this anyway - self.tcx.sess.span_err( - self.span, - "cannot mutate statics in the initializer of another static", - ); - } return; } unleash_miri!(self); From 695e91a1d585dbf462f4cb6c41eeb54cc34286d6 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 12 Nov 2019 13:20:44 +0100 Subject: [PATCH 04/17] check-consts remove cannot mutate statics in initializer of another static error --- .../transform/check_consts/validation.rs | 12 +----------- .../assign-to-static-within-other-static.rs | 3 ++- .../assign-to-static-within-other-static.stderr | 5 +++-- src/test/ui/error-codes/E0017.rs | 1 - src/test/ui/error-codes/E0017.stderr | 10 ++-------- src/test/ui/error-codes/E0388.rs | 1 - src/test/ui/error-codes/E0388.stderr | 10 ++-------- 7 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 244d434a51eab..93ce108cc8041 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -326,17 +326,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { let is_thread_local = self.tcx.has_attr(*def_id, sym::thread_local); if is_thread_local { self.check_op(ops::ThreadLocalAccess); - } else if self.const_kind() == ConstKind::Static && context.is_mutating_use() { - // this is not strictly necessary as miri will also bail out - // For interior mutability we can't really catch this statically as that - // goes through raw pointers and intermediate temporaries, so miri has - // to catch this anyway - - self.tcx.sess.span_err( - self.span, - "cannot mutate statics in the initializer of another static", - ); - } else { + } else if self.const_kind() != ConstKind::Static || !context.is_mutating_use() { self.check_op(ops::StaticAccess); } } diff --git a/src/test/ui/consts/const-eval/assign-to-static-within-other-static.rs b/src/test/ui/consts/const-eval/assign-to-static-within-other-static.rs index b4c416b1c55f0..648caae30b427 100644 --- a/src/test/ui/consts/const-eval/assign-to-static-within-other-static.rs +++ b/src/test/ui/consts/const-eval/assign-to-static-within-other-static.rs @@ -7,7 +7,8 @@ use std::cell::UnsafeCell; static mut FOO: u32 = 42; static BOO: () = unsafe { - FOO = 5; //~ ERROR cannot mutate statics in the initializer of another static + FOO = 5; + //~^ could not evaluate static initializer [E0080] }; fn main() {} diff --git a/src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr b/src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr index 02b72765b377e..cb4d35b9a1809 100644 --- a/src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr +++ b/src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr @@ -1,8 +1,9 @@ -error: cannot mutate statics in the initializer of another static +error[E0080]: could not evaluate static initializer --> $DIR/assign-to-static-within-other-static.rs:10:5 | LL | FOO = 5; - | ^^^^^^^ + | ^^^^^^^ tried to modify a static's initial value from another static's initializer error: aborting due to previous error +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/error-codes/E0017.rs b/src/test/ui/error-codes/E0017.rs index 71250eb4621f8..94b6587eb815a 100644 --- a/src/test/ui/error-codes/E0017.rs +++ b/src/test/ui/error-codes/E0017.rs @@ -4,6 +4,5 @@ const C: i32 = 2; const CR: &'static mut i32 = &mut C; //~ ERROR E0017 static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017 //~| ERROR cannot borrow - //~| ERROR cannot mutate statics static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017 fn main() {} diff --git a/src/test/ui/error-codes/E0017.stderr b/src/test/ui/error-codes/E0017.stderr index 67ff7da611bb1..47863f0221405 100644 --- a/src/test/ui/error-codes/E0017.stderr +++ b/src/test/ui/error-codes/E0017.stderr @@ -10,12 +10,6 @@ error[E0017]: references in statics may only refer to immutable values LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ statics require immutable values -error: cannot mutate statics in the initializer of another static - --> $DIR/E0017.rs:5:39 - | -LL | static STATIC_REF: &'static mut i32 = &mut X; - | ^^^^^^ - error[E0596]: cannot borrow immutable static item `X` as mutable --> $DIR/E0017.rs:5:39 | @@ -23,12 +17,12 @@ LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ cannot borrow as mutable error[E0017]: references in statics may only refer to immutable values - --> $DIR/E0017.rs:8:38 + --> $DIR/E0017.rs:7:38 | LL | static CONST_REF: &'static mut i32 = &mut C; | ^^^^^^ statics require immutable values -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0017, E0596. For more information about an error, try `rustc --explain E0017`. diff --git a/src/test/ui/error-codes/E0388.rs b/src/test/ui/error-codes/E0388.rs index 817f2554adef0..3aa4ac9655cc9 100644 --- a/src/test/ui/error-codes/E0388.rs +++ b/src/test/ui/error-codes/E0388.rs @@ -4,7 +4,6 @@ const C: i32 = 2; const CR: &'static mut i32 = &mut C; //~ ERROR E0017 static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017 //~| ERROR cannot borrow - //~| ERROR cannot mutate statics static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017 fn main() {} diff --git a/src/test/ui/error-codes/E0388.stderr b/src/test/ui/error-codes/E0388.stderr index e0ca431673240..b52d5260b13c8 100644 --- a/src/test/ui/error-codes/E0388.stderr +++ b/src/test/ui/error-codes/E0388.stderr @@ -10,12 +10,6 @@ error[E0017]: references in statics may only refer to immutable values LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ statics require immutable values -error: cannot mutate statics in the initializer of another static - --> $DIR/E0388.rs:5:39 - | -LL | static STATIC_REF: &'static mut i32 = &mut X; - | ^^^^^^ - error[E0596]: cannot borrow immutable static item `X` as mutable --> $DIR/E0388.rs:5:39 | @@ -23,12 +17,12 @@ LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ cannot borrow as mutable error[E0017]: references in statics may only refer to immutable values - --> $DIR/E0388.rs:8:38 + --> $DIR/E0388.rs:7:38 | LL | static CONST_REF: &'static mut i32 = &mut C; | ^^^^^^ statics require immutable values -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0017, E0596. For more information about an error, try `rustc --explain E0017`. From 139477df640516fc15d884bc895ae9f6823aff9a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 12 Nov 2019 10:14:48 -0800 Subject: [PATCH 05/17] Update mdbook. --- Cargo.lock | 347 ++++++++++++++++----------------- src/tools/rustbook/Cargo.toml | 7 +- src/tools/rustbook/src/main.rs | 34 +--- 3 files changed, 182 insertions(+), 206 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f770f3eadbea..ca78a4a7f1e65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,7 +54,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -104,7 +104,7 @@ checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" dependencies = [ "libc", "termion", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -212,12 +212,6 @@ dependencies = [ "toml", ] -[[package]] -name = "build_const" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" - [[package]] name = "build_helper" version = "0.1.0" @@ -311,7 +305,7 @@ dependencies = [ "num_cpus", "opener", "openssl", - "percent-encoding 2.0.0", + "percent-encoding 2.1.0", "pretty_env_logger", "remove_dir_all", "rustc-workspace-hack", @@ -330,7 +324,7 @@ dependencies = [ "unicode-width", "url 2.1.0", "walkdir", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -482,7 +476,7 @@ dependencies = [ "itertools 0.8.0", "lazy_static 1.3.0", "matches", - "pulldown-cmark 0.6.0", + "pulldown-cmark 0.6.1", "quine-mc_cluskey", "regex-syntax", "semver", @@ -511,6 +505,26 @@ dependencies = [ "cc", ] +[[package]] +name = "codespan" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de67bdcd653002a6dba3eb53850ce3a485547225d81cb6c2bbdbc5a0cba5d15d" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "codespan-reporting" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd1d915d9e2b2ad696b2cd73215a84823ef3f0e3084d90304204415921b62c6" +dependencies = [ + "codespan", + "termcolor", + "unicode-width", +] + [[package]] name = "colored" version = "1.6.0" @@ -564,7 +578,7 @@ dependencies = [ "serde", "serde_json", "walkdir", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -585,7 +599,7 @@ dependencies = [ "serde_derive", "serde_json", "tempfile", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -594,6 +608,34 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +[[package]] +name = "cookie" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" +dependencies = [ + "time", + "url 1.7.2", +] + +[[package]] +name = "cookie_store" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" +dependencies = [ + "cookie", + "failure", + "idna 0.1.5", + "log", + "publicsuffix", + "serde", + "serde_json", + "time", + "try_from", + "url 1.7.2", +] + [[package]] name = "core" version = "0.0.0" @@ -623,22 +665,13 @@ version = "0.29.0" dependencies = [ "curl", "failure", - "percent-encoding 2.0.0", + "percent-encoding 2.1.0", "serde", "serde_derive", "serde_json", "url 2.1.0", ] -[[package]] -name = "crc" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" -dependencies = [ - "build_const", -] - [[package]] name = "crc32fast" version = "1.1.2" @@ -754,7 +787,7 @@ dependencies = [ "commoncrypto", "hex 0.3.2", "openssl", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -769,7 +802,7 @@ dependencies = [ "openssl-sys", "schannel", "socket2", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -785,7 +818,7 @@ dependencies = [ "openssl-sys", "pkg-config", "vcpkg", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -901,7 +934,7 @@ dependencies = [ "cfg-if", "libc", "redox_users", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -921,6 +954,12 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" +[[package]] +name = "dunce" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0ad6bf6a88548d1126045c413548df1453d9be094a8ab9fd59bf1fdd338da4f" + [[package]] name = "either" version = "1.5.0" @@ -1050,15 +1089,15 @@ checksum = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" [[package]] name = "flate2" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2291c165c8e703ee54ef3055ad6188e3d51108e2ded18e9f2476e774fc5ad3d4" +checksum = "ad3c5233c9a940c8719031b423d7e6c16af66e031cb0420b0896f5245bf181d3" dependencies = [ + "cfg-if", "crc32fast", "libc", "libz-sys", - "miniz-sys", - "miniz_oxide_c_api", + "miniz_oxide", ] [[package]] @@ -1107,7 +1146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" dependencies = [ "libc", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -1359,7 +1398,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3753954f7bd71f0e671afb8b5a992d1724cf43b7f95a563cd4a0bde94659ca8" dependencies = [ "scopeguard 1.0.0", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -1378,9 +1417,9 @@ dependencies = [ [[package]] name = "http" -version = "0.1.16" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe67e3678f2827030e89cc4b9e7ecd16d52f132c0b940ab5005f88e821500f6a" +checksum = "d7e06e336150b178206af098a055e3621e8336027e2b4d126bda0bc64824baaf" dependencies = [ "bytes", "fnv", @@ -1539,7 +1578,7 @@ dependencies = [ "remove_dir_all", "tar", "walkdir", - "winapi 0.3.6", + "winapi 0.3.8", "xz2", ] @@ -1704,7 +1743,7 @@ dependencies = [ "num_cpus", "tokio", "tokio-codec", - "unicase 2.5.1", + "unicase", ] [[package]] @@ -1744,19 +1783,6 @@ dependencies = [ "rustc-std-workspace-core", ] -[[package]] -name = "libflate" -version = "0.1.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90c6f86f4b0caa347206f916f8b687b51d77c6ef8ff18d52dd007491fd580529" -dependencies = [ - "adler32", - "byteorder", - "crc32fast", - "rle-decode-fast", - "take_mut", -] - [[package]] name = "libgit2-sys" version = "0.9.0" @@ -1926,9 +1952,9 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "mdbook" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a070268274c566082efb6b2ace7743e43ba91a70d5c6982981e96d3c05ac81c" +checksum = "031bdd9d4893c983e2f69ebc4b59070feee8276a584c4aabdcb351235ea28016" dependencies = [ "ammonia", "chrono", @@ -1942,7 +1968,7 @@ dependencies = [ "log", "memchr", "open", - "pulldown-cmark 0.5.3", + "pulldown-cmark 0.6.1", "regex", "serde", "serde_derive", @@ -1955,16 +1981,21 @@ dependencies = [ [[package]] name = "mdbook-linkcheck" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77d1f0ba4d1e6b86fa18e8853d026d7d76a97eb7eb5eb052ed80901e43b7fc10" +checksum = "c0a04db564ca37c47771f8455c825dc941ea851ff0deffcf55a04c512406b409" dependencies = [ - "env_logger 0.6.2", + "codespan", + "codespan-reporting", + "dunce", + "either", + "env_logger 0.7.1", "failure", + "http", "log", "mdbook", - "memchr", - "pulldown-cmark 0.5.3", + "percent-encoding 2.1.0", + "pulldown-cmark 0.6.1", "rayon", "regex", "reqwest", @@ -1972,8 +2003,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "structopt 0.2.18", - "url 1.7.2", + "structopt", ] [[package]] @@ -2000,7 +2030,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" dependencies = [ "libc", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2024,19 +2054,17 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425" dependencies = [ - "unicase 2.5.1", + "unicase", ] [[package]] name = "mime_guess" -version = "2.0.0-alpha.6" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed" +checksum = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599" dependencies = [ "mime", - "phf", - "phf_codegen", - "unicase 1.4.2", + "unicase", ] [[package]] @@ -2048,37 +2076,15 @@ dependencies = [ "macro-utils", ] -[[package]] -name = "miniz-sys" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "miniz_oxide" -version = "0.2.0" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c" +checksum = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625" dependencies = [ "adler32", ] -[[package]] -name = "miniz_oxide_c_api" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e" -dependencies = [ - "cc", - "crc", - "libc", - "miniz_oxide", -] - [[package]] name = "mio" version = "0.6.16" @@ -2107,7 +2113,7 @@ dependencies = [ "log", "mio", "miow 0.3.3", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2140,7 +2146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" dependencies = [ "socket2", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2190,7 +2196,7 @@ checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" dependencies = [ "cfg-if", "libc", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2247,7 +2253,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "998c59e83d9474c01127a96e023b7a04bb061dd286bf8bb939d31dc8d31a7448" dependencies = [ - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2359,7 +2365,7 @@ dependencies = [ "tokio", "tokio-named-pipes", "tokio-uds", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2393,7 +2399,7 @@ dependencies = [ "rand 0.6.1", "rustc_version", "smallvec 0.6.10", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2408,7 +2414,7 @@ dependencies = [ "redox_syscall", "rustc_version", "smallvec 0.6.10", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2419,9 +2425,9 @@ checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" [[package]] name = "percent-encoding" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f28a6faf4ffea762ba8f4baef48c61a6db348647c73095034041fc79dd954" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pest" @@ -2512,7 +2518,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" dependencies = [ "siphasher", - "unicase 1.4.2", ] [[package]] @@ -2619,6 +2624,19 @@ dependencies = [ "core", ] +[[package]] +name = "publicsuffix" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bf259a81de2b2eb9850ec990ec78e6a25319715584fd7652b9b26f96fcb1510" +dependencies = [ + "error-chain", + "idna 0.2.0", + "lazy_static 1.3.0", + "regex", + "url 2.1.0", +] + [[package]] name = "pulldown-cmark" version = "0.5.3" @@ -2626,21 +2644,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77043da1282374688ee212dc44b3f37ff929431de9c9adc3053bd3cee5630357" dependencies = [ "bitflags", - "getopts", "memchr", - "unicase 2.5.1", + "unicase", ] [[package]] name = "pulldown-cmark" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b0ad0d4c1702965ee6bb5b4ff5e71f83850b497d497e9444302987bf9e26a4" +checksum = "1c205cc82214f3594e2d50686730314f817c67ffa80fe800cf0db78c3c2b9d9e" dependencies = [ "bitflags", "getopts", "memchr", - "unicase 2.5.1", + "unicase", ] [[package]] @@ -2712,7 +2729,7 @@ dependencies = [ "rand_pcg", "rand_xorshift 0.1.0", "rustc_version", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2807,7 +2824,7 @@ dependencies = [ "libc", "rand_core 0.4.0", "rdrand", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -2934,23 +2951,25 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" dependencies = [ - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] name = "reqwest" -version = "0.9.11" +version = "0.9.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e542d9f077c126af32536b6aacc75bb7325400eab8cd0743543be5d91660780d" +checksum = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650" dependencies = [ "base64", "bytes", + "cookie", + "cookie_store", "encoding_rs", + "flate2", "futures", "http", "hyper", "hyper-tls", - "libflate", "log", "mime", "mime_guess", @@ -2958,6 +2977,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "time", "tokio", "tokio-executor", "tokio-io", @@ -2965,14 +2985,9 @@ dependencies = [ "tokio-timer", "url 1.7.2", "uuid", + "winreg", ] -[[package]] -name = "rle-decode-fast" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac" - [[package]] name = "rls" version = "1.40.0" @@ -3100,6 +3115,7 @@ name = "rustbook" version = "0.1.0" dependencies = [ "clap", + "codespan-reporting", "failure", "mdbook", "mdbook-linkcheck", @@ -3396,7 +3412,7 @@ dependencies = [ "smallvec 0.6.10", "syn 0.15.35", "url 2.1.0", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -3907,7 +3923,7 @@ dependencies = [ "rustfmt-config_proc_macro", "serde", "serde_json", - "structopt 0.3.1", + "structopt", "term 0.6.0", "toml", "unicode-segmentation", @@ -3937,7 +3953,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e1a231dc10abf6749cfa5d7767f25888d484201accbd919b66ab5413c502d56" dependencies = [ "lazy_static 1.3.0", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -4148,7 +4164,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -4241,16 +4257,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -[[package]] -name = "structopt" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16c2cdbf9cc375f15d1b4141bc48aeef444806655cd0e904207edc8d68d86ed7" -dependencies = [ - "clap", - "structopt-derive 0.2.18", -] - [[package]] name = "structopt" version = "0.3.1" @@ -4258,19 +4264,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ac9d6e93dd792b217bf89cda5c14566e3043960c6f9da890c2ba5d09d07804c" dependencies = [ "clap", - "structopt-derive 0.3.1", -] - -[[package]] -name = "structopt-derive" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53010261a84b37689f9ed7d395165029f9cc7abb9f56bbfe86bee2597ed25107" -dependencies = [ - "heck", - "proc-macro2 0.4.30", - "quote 0.6.12", - "syn 0.15.35", + "structopt-derive", ] [[package]] @@ -4414,12 +4408,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" - [[package]] name = "tar" version = "0.4.20" @@ -4443,7 +4431,7 @@ dependencies = [ "rand 0.7.0", "redox_syscall", "remove_dir_all", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -4473,7 +4461,7 @@ checksum = "0dd90505d5006a4422d3520b30c781d480b3f36768c2fa2187c3e950bc110464" dependencies = [ "byteorder", "dirs", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -4552,13 +4540,13 @@ dependencies = [ [[package]] name = "time" -version = "0.1.40" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" +checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" dependencies = [ "libc", "redox_syscall", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -4674,7 +4662,7 @@ dependencies = [ "tokio-io", "tokio-reactor", "tokio-signal", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -4718,7 +4706,7 @@ dependencies = [ "tokio-executor", "tokio-io", "tokio-reactor", - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -4837,6 +4825,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" +[[package]] +name = "try_from" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" +dependencies = [ + "cfg-if", +] + [[package]] name = "typenum" version = "1.10.0" @@ -4855,15 +4852,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" -[[package]] -name = "unicase" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" -dependencies = [ - "version_check", -] - [[package]] name = "unicase" version = "2.5.1" @@ -4890,9 +4878,9 @@ checksum = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" [[package]] name = "unicode-segmentation" -version = "1.2.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" +checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" [[package]] name = "unicode-width" @@ -4961,7 +4949,7 @@ checksum = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" dependencies = [ "idna 0.2.0", "matches", - "percent-encoding 2.0.0", + "percent-encoding 2.1.0", "serde", ] @@ -5037,7 +5025,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" dependencies = [ "same-file", - "winapi 0.3.6", + "winapi 0.3.8", "winapi-util", ] @@ -5071,9 +5059,9 @@ checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", @@ -5097,7 +5085,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" dependencies = [ - "winapi 0.3.6", + "winapi 0.3.8", ] [[package]] @@ -5112,10 +5100,19 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" dependencies = [ - "winapi 0.3.6", + "winapi 0.3.8", "winapi-util", ] +[[package]] +name = "winreg" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" +dependencies = [ + "winapi 0.3.8", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/src/tools/rustbook/Cargo.toml b/src/tools/rustbook/Cargo.toml index 89bbde4d5a9e3..327de29037cc3 100644 --- a/src/tools/rustbook/Cargo.toml +++ b/src/tools/rustbook/Cargo.toml @@ -6,12 +6,15 @@ license = "MIT OR Apache-2.0" edition = "2018" [features] -linkcheck = ["mdbook-linkcheck"] +linkcheck = ["mdbook-linkcheck", "codespan-reporting"] [dependencies] clap = "2.25.0" failure = "0.1" -mdbook-linkcheck = { version = "0.3.0", optional = true } +mdbook-linkcheck = { version = "0.5.0", optional = true } +# Keep in sync with mdbook-linkcheck. +codespan-reporting = { version = "0.5", optional = true } + # A noop dependency that changes in the Rust repository, it's a bit of a hack. # See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` diff --git a/src/tools/rustbook/src/main.rs b/src/tools/rustbook/src/main.rs index d5dc9a79b5acb..fc28315669376 100644 --- a/src/tools/rustbook/src/main.rs +++ b/src/tools/rustbook/src/main.rs @@ -12,8 +12,6 @@ use mdbook::MDBook; use failure::Error; #[cfg(feature = "linkcheck")] use mdbook::renderer::RenderContext; -#[cfg(feature = "linkcheck")] -use mdbook_linkcheck::{self, errors::BrokenLinks}; fn main() { let d_message = "-d, --dest-dir=[dest-dir] @@ -57,26 +55,7 @@ fn main() { { if let Err(err) = linkcheck(sub_matches) { eprintln!("Error: {}", err); - - // HACK: ignore timeouts - let actually_broken = err - .downcast::() - .map(|broken_links| { - broken_links - .links() - .iter() - .inspect(|cause| eprintln!("\tCaused By: {}", cause)) - .fold(false, |already_broken, cause| { - already_broken || !format!("{}", cause).contains("timed out") - }) - }) - .unwrap_or(false); - - if actually_broken { - std::process::exit(101); - } else { - std::process::exit(0); - } + std::process::exit(101); } } @@ -99,8 +78,9 @@ pub fn linkcheck(args: &ArgMatches<'_>) -> Result<(), Error> { let book = MDBook::load(&book_dir).unwrap(); let cfg = book.config; let render_ctx = RenderContext::new(&book_dir, book.book, cfg, &book_dir); - - mdbook_linkcheck::check_links(&render_ctx) + let cache_file = render_ctx.destination.join("cache.json"); + let color = codespan_reporting::term::termcolor::ColorChoice::Auto; + mdbook_linkcheck::run(&cache_file, color, &render_ctx) } // Build command implementation @@ -124,11 +104,7 @@ fn get_book_dir(args: &ArgMatches<'_>) -> PathBuf { if let Some(dir) = args.value_of("dir") { // Check if path is relative from current dir, or absolute... let p = Path::new(dir); - if p.is_relative() { - env::current_dir().unwrap().join(dir) - } else { - p.to_path_buf() - } + if p.is_relative() { env::current_dir().unwrap().join(dir) } else { p.to_path_buf() } } else { env::current_dir().unwrap() } From 32d1f47a06238a7e76829b75184e895352728319 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 12 Nov 2019 10:45:33 -0800 Subject: [PATCH 06/17] Fix mdbook-linkcheck license checks. --- src/tools/tidy/src/deps.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index e6ea1c75e2899..e65f7a62cacb7 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -55,6 +55,9 @@ const EXCEPTIONS: &[&str] = &[ "sized-chunks", // MPL-2.0+, cargo via im-rc // FIXME: this dependency violates the documentation comment above: "fortanix-sgx-abi", // MPL-2.0+, libstd but only for `sgx` target + "dunce", // CC0-1.0 mdbook-linkcheck + "codespan-reporting", // Apache-2.0 mdbook-linkcheck + "codespan", // Apache-2.0 mdbook-linkcheck ]; /// Which crates to check against the whitelist? From bc1bd95e5a63643cfbbe1d84b2560117644bf8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 13 Nov 2019 14:28:15 -0800 Subject: [PATCH 07/17] Do not ICE on recovery from unmet associated type bound obligation --- src/librustc_typeck/check/mod.rs | 11 ++++++++--- src/test/ui/issues/issue-66353.rs | 15 +++++++++++++++ src/test/ui/issues/issue-66353.stderr | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/issues/issue-66353.rs create mode 100644 src/test/ui/issues/issue-66353.stderr diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 72b5018589cf8..be56157287c57 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -705,9 +705,14 @@ impl Inherited<'a, 'tcx> { span_bug!(obligation.cause.span, "escaping bound vars in predicate {:?}", obligation); } - self.fulfillment_cx - .borrow_mut() - .register_predicate_obligation(self, obligation); + let _ = self.fulfillment_cx + .try_borrow_mut() + .map_err(|e| self.tcx.sess.delay_span_bug(obligation.cause.span, &format!( + "fullfillment context already borrowed: {:?} - {:?}", + e, + obligation, + ))) + .map(|mut cx| cx.register_predicate_obligation(self, obligation)); } fn register_predicates(&self, obligations: I) diff --git a/src/test/ui/issues/issue-66353.rs b/src/test/ui/issues/issue-66353.rs new file mode 100644 index 0000000000000..d8abdd5206ef4 --- /dev/null +++ b/src/test/ui/issues/issue-66353.rs @@ -0,0 +1,15 @@ +// #66353: ICE when trying to recover from incorrect associated type + +trait _Func { + fn func(_: Self); +} + +trait _A { + type AssocT; +} + +fn main() { + _Func::< <() as _A>::AssocT >::func(()); + //~^ ERROR the trait bound `(): _A` is not satisfied + //~| ERROR the trait bound `(): _Func<_>` is not satisfied +} diff --git a/src/test/ui/issues/issue-66353.stderr b/src/test/ui/issues/issue-66353.stderr new file mode 100644 index 0000000000000..8fd50300ca63e --- /dev/null +++ b/src/test/ui/issues/issue-66353.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `(): _A` is not satisfied + --> $DIR/issue-66353.rs:12:14 + | +LL | _Func::< <() as _A>::AssocT >::func(()); + | ^^^^^^^^^^^^^^^^^^ the trait `_A` is not implemented for `()` + +error[E0277]: the trait bound `(): _Func<_>` is not satisfied + --> $DIR/issue-66353.rs:12:41 + | +LL | fn func(_: Self); + | ----------------- required by `_Func::func` +... +LL | _Func::< <() as _A>::AssocT >::func(()); + | ^^ the trait `_Func<_>` is not implemented for `()` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. From 41372631ff7a9dc352c4765b08847757a5f7d590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 13 Nov 2019 14:45:52 -0800 Subject: [PATCH 08/17] Fix ICE when trying to suggest `Type<>` instead of `Type()` --- src/librustc/hir/lowering.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 2c8e14f2addff..15039cc3cdff2 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1860,15 +1860,16 @@ impl<'a> LoweringContext<'a> { if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) { // Do not suggest going from `Trait()` to `Trait<>` if data.inputs.len() > 0 { - let split = snippet.find('(').unwrap(); - let trait_name = &snippet[0..split]; - let args = &snippet[split + 1 .. snippet.len() - 1]; - err.span_suggestion( - data.span, - "use angle brackets instead", - format!("{}<{}>", trait_name, args), - Applicability::MaybeIncorrect, - ); + if let Some(split) = snippet.find('(') { + let trait_name = &snippet[0..split]; + let args = &snippet[split + 1 .. snippet.len() - 1]; + err.span_suggestion( + data.span, + "use angle brackets instead", + format!("{}<{}>", trait_name, args), + Applicability::MaybeIncorrect, + ); + } } }; err.emit(); From 7d61484b469aeb9db9c4d7a69c3bf1f24882d183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 13 Nov 2019 15:22:45 -0800 Subject: [PATCH 09/17] Do not ICE in `if` without `else` in `async fn` --- src/librustc_typeck/check/generator_interior.rs | 10 ++++++++-- .../async-await/issue-66387-if-without-else.rs | 8 ++++++++ .../issue-66387-if-without-else.stderr | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/async-await/issue-66387-if-without-else.rs create mode 100644 src/test/ui/async-await/issue-66387-if-without-else.stderr diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index ff9c945eec452..6e254122c0100 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -244,7 +244,13 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { // can be reborrowed without needing to spill to a temporary. // If this were not the case, then we could conceivably have // to create intermediate temporaries.) - let ty = self.fcx.tables.borrow().expr_ty(expr); - self.record(ty, scope, Some(expr), expr.span); + // + // The type table might not have invormation for this expression + // if it is in a malformed scope. (#66387) + if let Some(ty) = self.fcx.tables.borrow().expr_ty_opt(expr) { + self.record(ty, scope, Some(expr), expr.span); + } else { + self.fcx.tcx.sess.delay_span_bug(expr.span, "no type for node"); + } } } diff --git a/src/test/ui/async-await/issue-66387-if-without-else.rs b/src/test/ui/async-await/issue-66387-if-without-else.rs new file mode 100644 index 0000000000000..3602b09c0ece7 --- /dev/null +++ b/src/test/ui/async-await/issue-66387-if-without-else.rs @@ -0,0 +1,8 @@ +// edition:2018 +async fn f() -> i32 { + if true { //~ ERROR if may be missing an else clause + return 0; + } +} + +fn main() {} diff --git a/src/test/ui/async-await/issue-66387-if-without-else.stderr b/src/test/ui/async-await/issue-66387-if-without-else.stderr new file mode 100644 index 0000000000000..32952059525a0 --- /dev/null +++ b/src/test/ui/async-await/issue-66387-if-without-else.stderr @@ -0,0 +1,16 @@ +error[E0317]: if may be missing an else clause + --> $DIR/issue-66387-if-without-else.rs:3:5 + | +LL | / if true { +LL | | return 0; +LL | | } + | |_____^ expected (), found i32 + | + = note: expected type `()` + found type `i32` + = note: `if` expressions without `else` evaluate to `()` + = help: consider adding an `else` block that evaluates to the expected type + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0317`. From 3fe7cfc32656518d5e6262e580f0a16cd2412dd7 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Wed, 13 Nov 2019 17:14:50 -0800 Subject: [PATCH 10/17] Remove some stack frames from `.async` calls The `Context` argument is currently smuggled through TLS for async-generated futures. The current infrastructure is closure-based, and results in an extra 6 stack frames when .awaiting an async-generated future! ``` 12: foo::async_b::{{closure}} at src/main.rs:10 13: as core::future::future::Future>::poll::{{closure}} at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/future.rs:43 14: std::future::set_task_context at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/future.rs:79 15: as core::future::future::Future>::poll at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/future.rs:43 16: std::future::poll_with_tls_context::{{closure}} at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/future.rs:121 17: std::future::get_task_context at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/future.rs:111 18: std::future::poll_with_tls_context at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/future.rs:121 19: foo::async_a::{{closure}} at src/main.rs:6 ``` While the long (medium?) term solution is to remove the use of TLS entirely, we can improve things a bit in the meantime. In particular, this commit does 2 things: 1. `get_task_context` has been inlined into `poll_with_tls_context`, removing 2 frames (16 and 17 above). 2. `set_task_context` now returns a guard type that resets the TLS rather than taking a closure, removing 2 frames (13 and 14 above). We can also remove frame 18 by removing `poll_with_tls_context` in favor of a `get_task_context` function which returns a guard, but that requires adjusting the code generated for .await, so I've left that off for now. --- src/libstd/future.rs | 45 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/src/libstd/future.rs b/src/libstd/future.rs index c65f71fb1a4e2..6de3f1d545b57 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -40,10 +40,11 @@ impl> Future for GenFuture { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { // Safe because we're !Unpin + !Drop mapping to a ?Unpin value let gen = unsafe { Pin::map_unchecked_mut(self, |s| &mut s.0) }; - set_task_context(cx, || match gen.resume() { + let _guard = unsafe { set_task_context(cx) }; + match gen.resume() { GeneratorState::Yielded(()) => Poll::Pending, GeneratorState::Complete(x) => Poll::Ready(x), - }) + } } } @@ -61,35 +62,23 @@ impl Drop for SetOnDrop { } } -#[doc(hidden)] -#[unstable(feature = "gen_future", issue = "50547")] -/// Sets the thread-local task context used by async/await futures. -pub fn set_task_context(cx: &mut Context<'_>, f: F) -> R -where - F: FnOnce() -> R -{ +// Safety: the returned guard must drop before `cx` is dropped and before +// any previous guard is dropped. +unsafe fn set_task_context(cx: &mut Context<'_>) -> SetOnDrop { // transmute the context's lifetime to 'static so we can store it. - let cx = unsafe { - core::mem::transmute::<&mut Context<'_>, &mut Context<'static>>(cx) - }; + let cx = core::mem::transmute::<&mut Context<'_>, &mut Context<'static>>(cx); let old_cx = TLS_CX.with(|tls_cx| { tls_cx.replace(Some(NonNull::from(cx))) }); - let _reset = SetOnDrop(old_cx); - f() + SetOnDrop(old_cx) } #[doc(hidden)] #[unstable(feature = "gen_future", issue = "50547")] -/// Retrieves the thread-local task context used by async/await futures. -/// -/// This function acquires exclusive access to the task context. -/// -/// Panics if no context has been set or if the context has already been -/// retrieved by a surrounding call to get_task_context. -pub fn get_task_context(f: F) -> R +/// Polls a future in the current thread-local task waker. +pub fn poll_with_tls_context(f: Pin<&mut F>) -> Poll where - F: FnOnce(&mut Context<'_>) -> R + F: Future { let cx_ptr = TLS_CX.with(|tls_cx| { // Clear the entry so that nested `get_task_waker` calls @@ -108,15 +97,5 @@ where // // The pointer that was inserted came from an `&mut Context<'_>`, // so it is safe to treat as mutable. - unsafe { f(cx_ptr.as_mut()) } -} - -#[doc(hidden)] -#[unstable(feature = "gen_future", issue = "50547")] -/// Polls a future in the current thread-local task waker. -pub fn poll_with_tls_context(f: Pin<&mut F>) -> Poll -where - F: Future -{ - get_task_context(|cx| F::poll(f, cx)) + unsafe { F::poll(f, cx_ptr.as_mut()) } } From 6c9ba97d23254045b182edbb8a4448a8c25c7a76 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 14 Nov 2019 10:38:15 +0100 Subject: [PATCH 11/17] miri: helper methods for max values of machine's usize/isize --- src/librustc/mir/interpret/pointer.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index 1bb4d9ea4d6d9..7c77b2c0711b9 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -1,4 +1,5 @@ use std::fmt::{self, Display}; +use std::convert::TryFrom; use crate::mir; use crate::ty::layout::{self, HasDataLayout, Size}; @@ -40,6 +41,18 @@ pub trait PointerArithmetic: layout::HasDataLayout { self.data_layout().pointer_size } + #[inline] + fn usize_max(&self) -> u64 { + let max_usize_plus_1 = 1u128 << self.pointer_size().bits(); + u64::try_from(max_usize_plus_1-1).unwrap() + } + + #[inline] + fn isize_max(&self) -> i64 { + let max_isize_plus_1 = 1u128 << (self.pointer_size().bits()-1); + i64::try_from(max_isize_plus_1-1).unwrap() + } + /// Helper function: truncate given value-"overflowed flag" pair to pointer size and /// update "overflowed flag" if there was an overflow. /// This should be called by all the other methods before returning! From 336e332fd6f6ce1433ab29b58f6845f7662e60cf Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 14 Nov 2019 09:42:01 -0800 Subject: [PATCH 12/17] Link to tracking issue in HIR const-check error --- src/librustc_error_codes/error_codes/E0744.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustc_error_codes/error_codes/E0744.md b/src/librustc_error_codes/error_codes/E0744.md index 254223f3565f9..b299102fd6934 100644 --- a/src/librustc_error_codes/error_codes/E0744.md +++ b/src/librustc_error_codes/error_codes/E0744.md @@ -15,3 +15,10 @@ const _: i32 = { x }; ``` + +This will be allowed at some point in the future, but the implementation is not +yet complete. See the tracking issue for [conditionals] or [loops] in a const +context for the current status. + +[conditionals]: https://github.com/rust-lang/rust/issues/49146 +[loops]: https://github.com/rust-lang/rust/issues/52000 From 43492283b4952a0d6d55fbadfe53d48264f2f2b4 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 15 Nov 2019 03:05:03 +0900 Subject: [PATCH 13/17] Don't warn labels beginning with `_` --- src/librustc_resolve/late.rs | 4 +++- src/test/ui/label/label-beginning-with-underscore.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/label/label-beginning-with-underscore.rs diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 24d6331bbd37d..6b0683879740a 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -1767,7 +1767,9 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { fn with_resolved_label(&mut self, label: Option