From 41f76924d06ad4b267c0c1e5c83acf666c07f34e Mon Sep 17 00:00:00 2001 From: pierwill Date: Fri, 29 Oct 2021 12:14:17 -0500 Subject: [PATCH 01/10] Document all public items in `rustc_incremental` Also: - Review and edit current docs - Enforce documentation for crate Co-authored-by: r00ster Co-authored-by: Camille Gillot --- .../rustc_incremental/src/assert_dep_graph.rs | 2 ++ .../src/assert_module_sources.rs | 1 + compiler/rustc_incremental/src/lib.rs | 1 + compiler/rustc_incremental/src/persist/fs.rs | 34 ++++++++++++++----- .../rustc_incremental/src/persist/load.rs | 17 ++++++++-- .../rustc_incremental/src/persist/save.rs | 15 ++++++-- .../src/persist/work_product.rs | 6 +++- 7 files changed, 63 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index 571337a8dcbc6..7b5b015d5a509 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -52,6 +52,7 @@ use std::env; use std::fs::{self, File}; use std::io::{BufWriter, Write}; +#[allow(missing_docs)] pub fn assert_dep_graph(tcx: TyCtxt<'_>) { tcx.dep_graph.with_ignore(|| { if tcx.sess.opts.debugging_opts.dump_dep_graph { @@ -262,6 +263,7 @@ fn dump_graph(query: &DepGraphQuery) { } } +#[allow(missing_docs)] pub struct GraphvizDepGraph<'q>(FxHashSet<&'q DepNode>, Vec<(&'q DepNode, &'q DepNode)>); impl<'a, 'q> dot::GraphWalk<'a> for GraphvizDepGraph<'q> { diff --git a/compiler/rustc_incremental/src/assert_module_sources.rs b/compiler/rustc_incremental/src/assert_module_sources.rs index a5f3e4553ce56..2cf8f9b08e190 100644 --- a/compiler/rustc_incremental/src/assert_module_sources.rs +++ b/compiler/rustc_incremental/src/assert_module_sources.rs @@ -29,6 +29,7 @@ use rustc_session::cgu_reuse_tracker::*; use rustc_span::symbol::{sym, Symbol}; use std::collections::BTreeSet; +#[allow(missing_docs)] pub fn assert_module_sources(tcx: TyCtxt<'_>) { tcx.dep_graph.with_ignore(|| { if tcx.sess.opts.incremental.is_none() { diff --git a/compiler/rustc_incremental/src/lib.rs b/compiler/rustc_incremental/src/lib.rs index dd3f8c937f81a..07e9f8b00ca1b 100644 --- a/compiler/rustc_incremental/src/lib.rs +++ b/compiler/rustc_incremental/src/lib.rs @@ -1,5 +1,6 @@ //! Support for serializing the dep-graph and reloading it. +#![deny(missing_docs)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(in_band_lifetimes)] #![feature(let_else)] diff --git a/compiler/rustc_incremental/src/persist/fs.rs b/compiler/rustc_incremental/src/persist/fs.rs index c0137fc7a5ac8..a49a1554d5bfe 100644 --- a/compiler/rustc_incremental/src/persist/fs.rs +++ b/compiler/rustc_incremental/src/persist/fs.rs @@ -133,21 +133,26 @@ const QUERY_CACHE_FILENAME: &str = "query-cache.bin"; // case-sensitive (as opposed to base64, for example). const INT_ENCODE_BASE: usize = base_n::CASE_INSENSITIVE; +/// Returns the path to a session's dependency graph. pub fn dep_graph_path(sess: &Session) -> PathBuf { in_incr_comp_dir_sess(sess, DEP_GRAPH_FILENAME) } +/// Returns the path to a session's staging dependency graph. +/// +/// On the difference between dep-graph and staging dep-graph, +/// see `build_dep_graph`. pub fn staging_dep_graph_path(sess: &Session) -> PathBuf { in_incr_comp_dir_sess(sess, STAGING_DEP_GRAPH_FILENAME) } - pub fn work_products_path(sess: &Session) -> PathBuf { in_incr_comp_dir_sess(sess, WORK_PRODUCTS_FILENAME) } - +/// Returns the path to a session's query cache. pub fn query_cache_path(sess: &Session) -> PathBuf { in_incr_comp_dir_sess(sess, QUERY_CACHE_FILENAME) } +/// Locks a given session directory. pub fn lock_file_path(session_dir: &Path) -> PathBuf { let crate_dir = session_dir.parent().unwrap(); @@ -166,23 +171,35 @@ pub fn lock_file_path(session_dir: &Path) -> PathBuf { crate_dir.join(&directory_name[0..dash_indices[2]]).with_extension(&LOCK_FILE_EXT[1..]) } +/// Returns the path for a given filename within the incremental compilation directory +/// in the current session. pub fn in_incr_comp_dir_sess(sess: &Session, file_name: &str) -> PathBuf { in_incr_comp_dir(&sess.incr_comp_session_dir(), file_name) } +/// Returns the path for a given filename within the incremental compilation directory, +/// not necessarily from the current session. +/// +/// To ensure the file is part of the current session, use [`in_incr_comp_dir_sess`]. pub fn in_incr_comp_dir(incr_comp_session_dir: &Path, file_name: &str) -> PathBuf { incr_comp_session_dir.join(file_name) } -/// Allocates the private session directory. The boolean in the Ok() result -/// indicates whether we should try loading a dep graph from the successfully -/// initialized directory, or not. -/// The post-condition of this fn is that we have a valid incremental -/// compilation session directory, if the result is `Ok`. A valid session +/// Allocates the private session directory. +/// +/// If the result of this function is `Ok`, we have a valid incremental +/// compilation session directory. A valid session /// directory is one that contains a locked lock file. It may or may not contain /// a dep-graph and work products from a previous session. -/// If the call fails, the fn may leave behind an invalid session directory. +/// +/// This always attempts to load a dep-graph from the directory. +/// If loading fails for some reason, we fallback to a disabled `DepGraph`. +/// See [`rustc_interface::queries::dep_graph`]. +/// +/// If this function returns an error, it may leave behind an invalid session directory. /// The garbage collection will take care of it. +/// +/// [`rustc_interface::queries::dep_graph`]: ../../rustc_interface/struct.Queries.html#structfield.dep_graph pub fn prepare_session_directory( sess: &Session, crate_name: &str, @@ -661,6 +678,7 @@ fn is_old_enough_to_be_collected(timestamp: SystemTime) -> bool { timestamp < SystemTime::now() - Duration::from_secs(10) } +/// Runs garbage collection for the current session. pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> { debug!("garbage_collect_session_directories() - begin"); diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs index 9c6e2aeb50a76..9cae4e9181899 100644 --- a/compiler/rustc_incremental/src/persist/load.rs +++ b/compiler/rustc_incremental/src/persist/load.rs @@ -18,13 +18,24 @@ use super::work_product; type WorkProductMap = FxHashMap; #[derive(Debug)] +/// Represents the result of an attempt to load incremental compilation data. pub enum LoadResult { - Ok { data: T }, + /// Loading was successful. + Ok { + #[allow(missing_docs)] + data: T, + }, + /// The file either didn't exist or was produced by an incompatible compiler version. DataOutOfDate, - Error { message: String }, + /// An error occured. + Error { + #[allow(missing_docs)] + message: String, + }, } impl LoadResult { + /// Accesses the data returned in [`LoadResult::Ok`]. pub fn open(self, sess: &Session) -> T { // Check for errors when using `-Zassert-incremental-state` match (sess.opts.assert_incr_state, &self) { @@ -99,6 +110,7 @@ pub enum MaybeAsync { } impl MaybeAsync> { + /// Accesses the data returned in [`LoadResult::Ok`] in an asynchronous way if possible. pub fn open(self) -> LoadResult { match self { MaybeAsync::Sync(result) => result, @@ -109,6 +121,7 @@ impl MaybeAsync> { } } +/// An asynchronous type for computing the dependency graph. pub type DepGraphFuture = MaybeAsync>; /// Launch a thread and load the dependency graph in the background. diff --git a/compiler/rustc_incremental/src/persist/save.rs b/compiler/rustc_incremental/src/persist/save.rs index 6c683058b12d6..9601a49267f08 100644 --- a/compiler/rustc_incremental/src/persist/save.rs +++ b/compiler/rustc_incremental/src/persist/save.rs @@ -13,9 +13,13 @@ use super::file_format; use super::fs::*; use super::work_product; -/// Save and dump the DepGraph. +/// Saves and writes the [`DepGraph`] to the file system. /// -/// No query must be invoked after this function. +/// This function saves both the dep-graph and the query result cache, +/// and drops the result cache. +/// +/// This function should only run after all queries have completed. +/// Trying to execute a query afterwards would attempt to read the result cache we just dropped. pub fn save_dep_graph(tcx: TyCtxt<'_>) { debug!("save_dep_graph()"); tcx.dep_graph.with_ignore(|| { @@ -75,6 +79,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) { }) } +/// Saves the work product index. pub fn save_work_product_index( sess: &Session, dep_graph: &DepGraph, @@ -139,6 +144,12 @@ fn encode_query_cache(tcx: TyCtxt<'_>, encoder: &mut FileEncoder) -> FileEncodeR tcx.sess.time("incr_comp_serialize_result_cache", || tcx.serialize_query_result_cache(encoder)) } +/// Builds the dependency graph. +/// +/// This function breates the *staging dep-graph*. When the dep-graph is modified by a query +/// execution, the new dependency information is not kept in memory but directly +/// output to this file. `save_dep_graph` then finalizes the staging dep-graph +/// and moves it to the permanent dep-graph path pub fn build_dep_graph( sess: &Session, prev_graph: SerializedDepGraph, diff --git a/compiler/rustc_incremental/src/persist/work_product.rs b/compiler/rustc_incremental/src/persist/work_product.rs index 19d64bda56d6d..85b44ed753192 100644 --- a/compiler/rustc_incremental/src/persist/work_product.rs +++ b/compiler/rustc_incremental/src/persist/work_product.rs @@ -1,4 +1,6 @@ -//! This module contains files for saving intermediate work-products. +//! Functions for saving and removing intermediate [work products]. +//! +//! [work products]: WorkProduct use crate::persist::fs::*; use rustc_fs_util::link_or_copy; @@ -7,6 +9,7 @@ use rustc_session::Session; use std::fs as std_fs; use std::path::PathBuf; +/// Copies a CGU work product to the incremental compilation directory, so next compilation can find and reuse it. pub fn copy_cgu_workproduct_to_incr_comp_cache_dir( sess: &Session, cgu_name: &str, @@ -40,6 +43,7 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir( Some((work_product_id, work_product)) } +/// Removes files for a given work product. pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) { if let Some(ref file_name) = work_product.saved_file { let path = in_incr_comp_dir_sess(sess, file_name); From c025a5d9623154e194ac55f90e1d4e42658c59d7 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Wed, 8 Dec 2021 17:54:05 -0500 Subject: [PATCH 02/10] move core/stream/stream/mod.rs to core/stream/stream.rs --- library/core/src/stream/{stream/mod.rs => stream.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename library/core/src/stream/{stream/mod.rs => stream.rs} (100%) diff --git a/library/core/src/stream/stream/mod.rs b/library/core/src/stream/stream.rs similarity index 100% rename from library/core/src/stream/stream/mod.rs rename to library/core/src/stream/stream.rs From 9f6da95abd13ff22b04a2f9b5c3822e9a9d1beeb Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Thu, 9 Dec 2021 02:23:11 +0300 Subject: [PATCH 03/10] fix typo in `intrinsics::raw_eq` docs --- library/core/src/intrinsics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index edbc250eb0d0c..2eb2bb6c5d404 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1919,7 +1919,7 @@ extern "rust-intrinsic" { /// Determines whether the raw bytes of the two values are equal. /// - /// The is particularly handy for arrays, since it allows things like just + /// This is particularly handy for arrays, since it allows things like just /// comparing `i96`s instead of forcing `alloca`s for `[6 x i16]`. /// /// Above some backend-decided threshold this will emit calls to `memcmp`, From 4b0a9c9bc3e30215366cb1106645e5ddcfa93b92 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 8 Dec 2021 22:54:51 -0800 Subject: [PATCH 04/10] Delete Utf8Lossy::from_str --- library/core/src/str/lossy.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/library/core/src/str/lossy.rs b/library/core/src/str/lossy.rs index 32bd22846e7dd..6ec1c93908fc7 100644 --- a/library/core/src/str/lossy.rs +++ b/library/core/src/str/lossy.rs @@ -12,11 +12,6 @@ pub struct Utf8Lossy { } impl Utf8Lossy { - #[must_use] - pub fn from_str(s: &str) -> &Utf8Lossy { - Utf8Lossy::from_bytes(s.as_bytes()) - } - #[must_use] pub fn from_bytes(bytes: &[u8]) -> &Utf8Lossy { // SAFETY: Both use the same memory layout, and UTF-8 correctness isn't required. From cebd9494bdee15e45303bf9ecf7c77b60a6c15b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAnior=20Bassani?= Date: Thu, 9 Dec 2021 11:56:19 -0300 Subject: [PATCH 05/10] Replace iterator-based set construction by *Set::From<[T; N]> --- library/alloc/src/collections/btree/set.rs | 37 ++++++----- library/std/src/collections/hash/set.rs | 75 +++++++++++----------- 2 files changed, 55 insertions(+), 57 deletions(-) diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index 4a83cdb917c85..dfdf3c9384288 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -491,7 +491,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let set = BTreeSet::from([1, 2, 3]); /// assert_eq!(set.contains(&1), true); /// assert_eq!(set.contains(&4), false); /// ``` @@ -515,7 +515,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let set = BTreeSet::from([1, 2, 3]); /// assert_eq!(set.get(&2), Some(&2)); /// assert_eq!(set.get(&4), None); /// ``` @@ -536,7 +536,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let a = BTreeSet::from([1, 2, 3]); /// let mut b = BTreeSet::new(); /// /// assert_eq!(a.is_disjoint(&b), true); @@ -562,7 +562,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let sup: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let sup = BTreeSet::from([1, 2, 3]); /// let mut set = BTreeSet::new(); /// /// assert_eq!(set.is_subset(&sup), true); @@ -639,7 +639,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let sub: BTreeSet<_> = [1, 2].iter().cloned().collect(); + /// let sub = BTreeSet::from([1, 2]); /// let mut set = BTreeSet::new(); /// /// assert_eq!(set.is_superset(&sub), false); @@ -853,7 +853,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let mut set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let mut set = BTreeSet::from([1, 2, 3]); /// assert_eq!(set.take(&2), Some(2)); /// assert_eq!(set.take(&2), None); /// ``` @@ -876,8 +876,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let xs = [1, 2, 3, 4, 5, 6]; - /// let mut set: BTreeSet = xs.iter().cloned().collect(); + /// let mut set = BTreeSet::from([1, 2, 3, 4, 5, 6]); /// // Keep only the even numbers. /// set.retain(|&k| k % 2 == 0); /// assert!(set.iter().eq([2, 4, 6].iter())); @@ -1009,7 +1008,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet = [1, 2, 3].iter().cloned().collect(); + /// let set = BTreeSet::from([1, 2, 3]); /// let mut set_iter = set.iter(); /// assert_eq!(set_iter.next(), Some(&1)); /// assert_eq!(set_iter.next(), Some(&2)); @@ -1022,7 +1021,7 @@ impl BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet = [3, 1, 2].iter().cloned().collect(); + /// let set = BTreeSet::from([3, 1, 2]); /// let mut set_iter = set.iter(); /// assert_eq!(set_iter.next(), Some(&1)); /// assert_eq!(set_iter.next(), Some(&2)); @@ -1124,7 +1123,7 @@ impl IntoIterator for BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet = [1, 2, 3, 4].iter().cloned().collect(); + /// let set = BTreeSet::from([1, 2, 3, 4]); /// /// let v: Vec<_> = set.into_iter().collect(); /// assert_eq!(v, [1, 2, 3, 4]); @@ -1243,8 +1242,8 @@ impl Sub<&BTreeSet> for &BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); - /// let b: BTreeSet<_> = vec![3, 4, 5].into_iter().collect(); + /// let a = BTreeSet::from([1, 2, 3]); + /// let b = BTreeSet::from([3, 4, 5]); /// /// let result = &a - &b; /// let result_vec: Vec<_> = result.into_iter().collect(); @@ -1266,8 +1265,8 @@ impl BitXor<&BTreeSet> for &BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); - /// let b: BTreeSet<_> = vec![2, 3, 4].into_iter().collect(); + /// let a = BTreeSet::from([1, 2, 3]); + /// let b = BTreeSet::from([2, 3, 4]); /// /// let result = &a ^ &b; /// let result_vec: Vec<_> = result.into_iter().collect(); @@ -1289,8 +1288,8 @@ impl BitAnd<&BTreeSet> for &BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); - /// let b: BTreeSet<_> = vec![2, 3, 4].into_iter().collect(); + /// let a = BTreeSet::from([1, 2, 3]); + /// let b = BTreeSet::from([2, 3, 4]); /// /// let result = &a & &b; /// let result_vec: Vec<_> = result.into_iter().collect(); @@ -1312,8 +1311,8 @@ impl BitOr<&BTreeSet> for &BTreeSet { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); - /// let b: BTreeSet<_> = vec![3, 4, 5].into_iter().collect(); + /// let a = BTreeSet::from([1, 2, 3]); + /// let b = BTreeSet::from([3, 4, 5]); /// /// let result = &a | &b; /// let result_vec: Vec<_> = result.into_iter().collect(); diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 3f264ee6732f7..a1e28c0b0a695 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -233,7 +233,7 @@ impl HashSet { /// ``` /// use std::collections::HashSet; /// - /// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let mut set = HashSet::from([1, 2, 3]); /// assert!(!set.is_empty()); /// /// // print 1, 2, 3 in an arbitrary order @@ -489,8 +489,8 @@ where /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); - /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); + /// let a = HashSet::from([1, 2, 3]); + /// let b = HashSet::from([4, 2, 3, 4]); /// /// // Can be seen as `a - b`. /// for x in a.difference(&b) { @@ -518,8 +518,8 @@ where /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); - /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); + /// let a = HashSet::from([1, 2, 3]); + /// let b = HashSet::from([4, 2, 3, 4]); /// /// // Print 1, 4 in arbitrary order. /// for x in a.symmetric_difference(&b) { @@ -548,8 +548,8 @@ where /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); - /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); + /// let a = HashSet::from([1, 2, 3]); + /// let b = HashSet::from([4, 2, 3, 4]); /// /// // Print 2, 3 in arbitrary order. /// for x in a.intersection(&b) { @@ -576,8 +576,8 @@ where /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); - /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); + /// let a = HashSet::from([1, 2, 3]); + /// let b = HashSet::from([4, 2, 3, 4]); /// /// // Print 1, 2, 3, 4 in arbitrary order. /// for x in a.union(&b) { @@ -608,7 +608,7 @@ where /// ``` /// use std::collections::HashSet; /// - /// let set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let set = HashSet::from([1, 2, 3]); /// assert_eq!(set.contains(&1), true); /// assert_eq!(set.contains(&4), false); /// ``` @@ -633,7 +633,7 @@ where /// ``` /// use std::collections::HashSet; /// - /// let set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let set = HashSet::from([1, 2, 3]); /// assert_eq!(set.get(&2), Some(&2)); /// assert_eq!(set.get(&4), None); /// ``` @@ -657,7 +657,7 @@ where /// /// use std::collections::HashSet; /// - /// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let mut set = HashSet::from([1, 2, 3]); /// assert_eq!(set.len(), 3); /// assert_eq!(set.get_or_insert(2), &2); /// assert_eq!(set.get_or_insert(100), &100); @@ -744,7 +744,7 @@ where /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let a = HashSet::from([1, 2, 3]); /// let mut b = HashSet::new(); /// /// assert_eq!(a.is_disjoint(&b), true); @@ -770,7 +770,7 @@ where /// ``` /// use std::collections::HashSet; /// - /// let sup: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let sup = HashSet::from([1, 2, 3]); /// let mut set = HashSet::new(); /// /// assert_eq!(set.is_subset(&sup), true); @@ -792,7 +792,7 @@ where /// ``` /// use std::collections::HashSet; /// - /// let sub: HashSet<_> = [1, 2].iter().cloned().collect(); + /// let sub = HashSet::from([1, 2]); /// let mut set = HashSet::new(); /// /// assert_eq!(set.is_superset(&sub), false); @@ -893,7 +893,7 @@ where /// ``` /// use std::collections::HashSet; /// - /// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); + /// let mut set = HashSet::from([1, 2, 3]); /// assert_eq!(set.take(&2), Some(2)); /// assert_eq!(set.take(&2), None); /// ``` @@ -917,8 +917,7 @@ where /// ``` /// use std::collections::HashSet; /// - /// let xs = [1, 2, 3, 4, 5, 6]; - /// let mut set: HashSet = xs.iter().cloned().collect(); + /// let mut set = HashSet::from([1, 2, 3, 4, 5, 6]); /// set.retain(|&k| k % 2 == 0); /// assert_eq!(set.len(), 3); /// ``` @@ -1097,8 +1096,8 @@ where /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); - /// let b: HashSet<_> = vec![3, 4, 5].into_iter().collect(); + /// let a = HashSet::from([1, 2, 3]); + /// let b = HashSet::from([3, 4, 5]); /// /// let set = &a | &b; /// @@ -1130,8 +1129,8 @@ where /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); - /// let b: HashSet<_> = vec![2, 3, 4].into_iter().collect(); + /// let a = HashSet::from([1, 2, 3]); + /// let b = HashSet::from([2, 3, 4]); /// /// let set = &a & &b; /// @@ -1163,8 +1162,8 @@ where /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); - /// let b: HashSet<_> = vec![3, 4, 5].into_iter().collect(); + /// let a = HashSet::from([1, 2, 3]); + /// let b = HashSet::from([3, 4, 5]); /// /// let set = &a ^ &b; /// @@ -1196,8 +1195,8 @@ where /// ``` /// use std::collections::HashSet; /// - /// let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); - /// let b: HashSet<_> = vec![3, 4, 5].into_iter().collect(); + /// let a = HashSet::from([1, 2, 3]); + /// let b = HashSet::from([3, 4, 5]); /// /// let set = &a - &b; /// @@ -1226,7 +1225,7 @@ where /// ``` /// use std::collections::HashSet; /// -/// let a: HashSet = vec![1, 2, 3].into_iter().collect(); +/// let a = HashSet::from([1, 2, 3]); /// /// let mut iter = a.iter(); /// ``` @@ -1248,7 +1247,7 @@ pub struct Iter<'a, K: 'a> { /// ``` /// use std::collections::HashSet; /// -/// let a: HashSet = vec![1, 2, 3].into_iter().collect(); +/// let a = HashSet::from([1, 2, 3]); /// /// let mut iter = a.into_iter(); /// ``` @@ -1269,7 +1268,7 @@ pub struct IntoIter { /// ``` /// use std::collections::HashSet; /// -/// let mut a: HashSet = vec![1, 2, 3].into_iter().collect(); +/// let mut a = HashSet::from([1, 2, 3]); /// /// let mut drain = a.drain(); /// ``` @@ -1291,7 +1290,7 @@ pub struct Drain<'a, K: 'a> { /// /// use std::collections::HashSet; /// -/// let mut a: HashSet = vec![1, 2, 3].into_iter().collect(); +/// let mut a = HashSet::from([1, 2, 3]); /// /// let mut drain_filtered = a.drain_filter(|v| v % 2 == 0); /// ``` @@ -1315,8 +1314,8 @@ where /// ``` /// use std::collections::HashSet; /// -/// let a: HashSet = vec![1, 2, 3].into_iter().collect(); -/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); +/// let a = HashSet::from([1, 2, 3]); +/// let b = HashSet::from([4, 2, 3, 4]); /// /// let mut intersection = a.intersection(&b); /// ``` @@ -1342,8 +1341,8 @@ pub struct Intersection<'a, T: 'a, S: 'a> { /// ``` /// use std::collections::HashSet; /// -/// let a: HashSet = vec![1, 2, 3].into_iter().collect(); -/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); +/// let a = HashSet::from([1, 2, 3]); +/// let b = HashSet::from([4, 2, 3, 4]); /// /// let mut difference = a.difference(&b); /// ``` @@ -1369,8 +1368,8 @@ pub struct Difference<'a, T: 'a, S: 'a> { /// ``` /// use std::collections::HashSet; /// -/// let a: HashSet = vec![1, 2, 3].into_iter().collect(); -/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); +/// let a = HashSet::from([1, 2, 3]); +/// let b = HashSet::from([4, 2, 3, 4]); /// /// let mut intersection = a.symmetric_difference(&b); /// ``` @@ -1393,8 +1392,8 @@ pub struct SymmetricDifference<'a, T: 'a, S: 'a> { /// ``` /// use std::collections::HashSet; /// -/// let a: HashSet = vec![1, 2, 3].into_iter().collect(); -/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); +/// let a = HashSet::from([1, 2, 3]); +/// let b = HashSet::from([4, 2, 3, 4]); /// /// let mut union_iter = a.union(&b); /// ``` From 99bd24e9a3a812fcbaa82c3465f28dbe7a60667c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 5 Dec 2021 15:55:41 -0800 Subject: [PATCH 06/10] Fix span calculation on secondary_label as well --- compiler/rustc_builtin_macros/src/format.rs | 5 +++-- src/test/ui/fmt/issue-91556.rs | 8 ++++++++ src/test/ui/fmt/issue-91556.stderr | 11 +++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/fmt/issue-91556.rs create mode 100644 src/test/ui/fmt/issue-91556.stderr diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 62a55c0e49ed0..8c343b6ea0817 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -995,8 +995,9 @@ pub fn expand_preparsed_format_args( e.note(¬e); } if let Some((label, span)) = err.secondary_label { - let sp = fmt_span.from_inner(span); - e.span_label(sp, label); + if efmt_kind_is_lit { + e.span_label(fmt_span.from_inner(span), label); + } } e.emit(); return DummyResult::raw_expr(sp, true); diff --git a/src/test/ui/fmt/issue-91556.rs b/src/test/ui/fmt/issue-91556.rs new file mode 100644 index 0000000000000..e782e6f907631 --- /dev/null +++ b/src/test/ui/fmt/issue-91556.rs @@ -0,0 +1,8 @@ +fn main() { + let _ = format!(concat!("{0}π–³π–Ύπ—Œπ—{"), i); + //~^ ERROR: invalid format string: expected `'}'` but string was terminated + //~| NOTE: if you intended to print `{`, you can escape it using `{{` + //~| NOTE: in this expansion of concat! + //~| NOTE: in this expansion of concat! + //~| NOTE: expected `'}'` in format string +} diff --git a/src/test/ui/fmt/issue-91556.stderr b/src/test/ui/fmt/issue-91556.stderr new file mode 100644 index 0000000000000..dbd5aef458b8e --- /dev/null +++ b/src/test/ui/fmt/issue-91556.stderr @@ -0,0 +1,11 @@ +error: invalid format string: expected `'}'` but string was terminated + --> $DIR/issue-91556.rs:2:19 + | +LL | let _ = format!(concat!("{0}π–³π–Ύπ—Œπ—{"), i); + | ^^^^^^^^^^^^^^^^^^^ expected `'}'` in format string + | + = note: if you intended to print `{`, you can escape it using `{{` + = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + From 258fd8974e66ae4e5bb243954bcf856ddd9204d4 Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Thu, 9 Dec 2021 23:05:08 +0530 Subject: [PATCH 07/10] Add deprecation warning for --passes --- src/librustdoc/config.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 04bcade156a9d..2c917e0f49687 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -327,6 +327,19 @@ impl Options { return Err(0); } + let color = config::parse_color(matches); + let config::JsonConfig { json_rendered, json_unused_externs, .. } = + config::parse_json(matches); + let error_format = config::parse_error_format(matches, color, json_rendered); + + let codegen_options = CodegenOptions::build(matches, error_format); + let debugging_opts = DebuggingOptions::build(matches, error_format); + + let diag = new_handler(error_format, None, &debugging_opts); + + // check for deprecated options + check_deprecated_options(matches, &diag); + if matches.opt_strs("passes") == ["list"] { println!("Available passes for running rustdoc:"); for pass in passes::PASSES { @@ -359,19 +372,6 @@ impl Options { return Err(0); } - let color = config::parse_color(matches); - let config::JsonConfig { json_rendered, json_unused_externs, .. } = - config::parse_json(matches); - let error_format = config::parse_error_format(matches, color, json_rendered); - - let codegen_options = CodegenOptions::build(matches, error_format); - let debugging_opts = DebuggingOptions::build(matches, error_format); - - let diag = new_handler(error_format, None, &debugging_opts); - - // check for deprecated options - check_deprecated_options(matches, &diag); - let mut emit = Vec::new(); for list in matches.opt_strs("emit") { for kind in list.split(',') { From e472fea0789f202c0a1019e08b7fa041d36c355b Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Thu, 9 Dec 2021 23:46:13 +0530 Subject: [PATCH 08/10] Add test for deprecation warning for --passes --- src/test/rustdoc-ui/issue-91713.rs | 2 ++ src/test/rustdoc-ui/issue-91713.stderr | 4 ++++ src/test/rustdoc-ui/issue-91713.stdout | 31 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/test/rustdoc-ui/issue-91713.rs create mode 100644 src/test/rustdoc-ui/issue-91713.stderr create mode 100644 src/test/rustdoc-ui/issue-91713.stdout diff --git a/src/test/rustdoc-ui/issue-91713.rs b/src/test/rustdoc-ui/issue-91713.rs new file mode 100644 index 0000000000000..a7f8270e4be88 --- /dev/null +++ b/src/test/rustdoc-ui/issue-91713.rs @@ -0,0 +1,2 @@ +// check-pass +// compile-flags: --passes list diff --git a/src/test/rustdoc-ui/issue-91713.stderr b/src/test/rustdoc-ui/issue-91713.stderr new file mode 100644 index 0000000000000..70c22b3c01e9e --- /dev/null +++ b/src/test/rustdoc-ui/issue-91713.stderr @@ -0,0 +1,4 @@ +warning: the `passes` flag is deprecated + | + = note: see issue #44136 for more information + diff --git a/src/test/rustdoc-ui/issue-91713.stdout b/src/test/rustdoc-ui/issue-91713.stdout new file mode 100644 index 0000000000000..d0372d4945f3a --- /dev/null +++ b/src/test/rustdoc-ui/issue-91713.stdout @@ -0,0 +1,31 @@ +Available passes for running rustdoc: +check_doc_test_visibility - run various visibility-related lints on doctests + strip-hidden - strips all `#[doc(hidden)]` items from the output + unindent-comments - removes excess indentation on comments in order for markdown to like it + strip-private - strips all private items from a crate which cannot be seen externally, implies strip-priv-imports + strip-priv-imports - strips all private import statements (`use`, `extern crate`) from a crate + propagate-doc-cfg - propagates `#[doc(cfg(...))]` to child items +collect-intra-doc-links - resolves intra-doc links +check-code-block-syntax - validates syntax inside Rust code blocks + collect-trait-impls - retrieves trait impls for items in the crate +calculate-doc-coverage - counts the number of items with and without documentation +check-invalid-html-tags - detects invalid HTML tags in doc comments + check-bare-urls - detects URLs that are not hyperlinks + +Default passes for rustdoc: + collect-trait-impls + unindent-comments +check_doc_test_visibility + strip-hidden (when not --document-hidden-items) + strip-private (when not --document-private-items) + strip-priv-imports (when --document-private-items) +collect-intra-doc-links +check-code-block-syntax +check-invalid-html-tags + propagate-doc-cfg + check-bare-urls + +Passes run with `--show-coverage`: + strip-hidden (when not --document-hidden-items) + strip-private (when not --document-private-items) +calculate-doc-coverage From 2b6987d91fda4d47415914acc54afc26be837ac2 Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj <57791542+inashivb@users.noreply.github.com> Date: Fri, 10 Dec 2021 00:08:24 +0530 Subject: [PATCH 09/10] Update src/test/rustdoc-ui/issue-91713.rs Co-authored-by: Joshua Nelson --- src/test/rustdoc-ui/issue-91713.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/rustdoc-ui/issue-91713.rs b/src/test/rustdoc-ui/issue-91713.rs index a7f8270e4be88..b7057d868c275 100644 --- a/src/test/rustdoc-ui/issue-91713.rs +++ b/src/test/rustdoc-ui/issue-91713.rs @@ -1,2 +1,3 @@ // check-pass // compile-flags: --passes list +// error-pattern: the `passes` flag is deprecated From faf407d5dccacdcaa0ee40bfee18847226c570f7 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 9 Dec 2021 12:21:00 -0600 Subject: [PATCH 10/10] Don't copy llvm tools to sysroot when using download-ci-llvm Fixes #91710 --- src/bootstrap/compile.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 186b5e92d33e3..6a734ab517715 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1173,7 +1173,12 @@ impl Step for Assemble { // (e.g. the `bootimage` crate). for tool in LLVM_TOOLS { let tool_exe = exe(tool, target_compiler.host); - builder.copy(&llvm_bin_dir.join(&tool_exe), &libdir_bin.join(&tool_exe)); + let src_path = llvm_bin_dir.join(&tool_exe); + // When using `donwload-ci-llvm`, some of the tools + // may not exist, so skip trying to copy them. + if src_path.exists() { + builder.copy(&src_path, &libdir_bin.join(&tool_exe)); + } } } }