From 5dd09b079046dafc0a07308bab74efa47d1f13b2 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 7 Jul 2021 16:25:46 +0000 Subject: [PATCH 1/8] Move [debug_]assert_matches to mod {core, std}::assert. --- compiler/rustc_middle/src/ich/impls_syntax.rs | 1 + compiler/rustc_mir/src/interpret/memory.rs | 1 + library/core/src/lib.rs | 10 ++++++++++ library/core/src/macros/mod.rs | 17 +++++++++++------ library/std/src/lib.rs | 4 ++-- src/test/ui/macros/assert-matches-macro-msg.rs | 2 ++ src/test/ui/matches2021.rs | 2 ++ src/test/ui/resolve/resolve-hint-macro.rs | 4 ++-- src/test/ui/resolve/resolve-hint-macro.stderr | 10 +++++----- 9 files changed, 36 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_middle/src/ich/impls_syntax.rs b/compiler/rustc_middle/src/ich/impls_syntax.rs index 2d8f661ef59e9..1c66f831b5f4b 100644 --- a/compiler/rustc_middle/src/ich/impls_syntax.rs +++ b/compiler/rustc_middle/src/ich/impls_syntax.rs @@ -6,6 +6,7 @@ use crate::ich::StableHashingContext; use rustc_ast as ast; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_span::{BytePos, NormalizedPos, SourceFile}; +use std::assert::assert_matches; use smallvec::SmallVec; diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index 77de19ac674c2..577a036815a98 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -6,6 +6,7 @@ //! integer. It is crucial that these operations call `check_align` *before* //! short-circuiting the empty case! +use std::assert::assert_matches; use std::borrow::Cow; use std::collections::VecDeque; use std::convert::{TryFrom, TryInto}; diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 949ef27f018e4..65235a0db0359 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -182,6 +182,16 @@ use prelude::v1::*; #[macro_use] mod macros; +// We don't export this through #[macro_export] for now, to avoid breakage. +// See https://github.com/rust-lang/rust/issues/82913 +#[cfg(not(test))] +#[unstable(feature = "assert_matches", issue = "82775")] +/// Unstable module containing the unstable `assert_matches` macro. +pub mod assert { + #[unstable(feature = "assert_matches", issue = "82775")] + pub use crate::macros::{assert_matches, debug_assert_matches}; +} + #[macro_use] mod internal_macros; diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 7eb65483b99e7..5a8e2f543921b 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -126,6 +126,8 @@ macro_rules! assert_ne { /// ``` /// #![feature(assert_matches)] /// +/// use std::assert::assert_matches; +/// /// let a = 1u32.checked_add(2); /// let b = 1u32.checked_sub(2); /// assert_matches!(a, Some(_)); @@ -134,10 +136,10 @@ macro_rules! assert_ne { /// let c = Ok("abc".to_string()); /// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100); /// ``` -#[macro_export] #[unstable(feature = "assert_matches", issue = "82775")] #[allow_internal_unstable(core_panic)] -macro_rules! assert_matches { +#[rustc_macro_transparency = "semitransparent"] +pub macro assert_matches { ($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({ match $left { $( $pattern )|+ $( if $guard )? => {} @@ -149,7 +151,7 @@ macro_rules! assert_matches { ); } } - }); + }), ($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({ match $left { $( $pattern )|+ $( if $guard )? => {} @@ -161,7 +163,7 @@ macro_rules! assert_matches { ); } } - }); + }), } /// Asserts that a boolean expression is `true` at runtime. @@ -283,6 +285,8 @@ macro_rules! debug_assert_ne { /// ``` /// #![feature(assert_matches)] /// +/// use std::assert::debug_assert_matches; +/// /// let a = 1u32.checked_add(2); /// let b = 1u32.checked_sub(2); /// debug_assert_matches!(a, Some(_)); @@ -294,8 +298,9 @@ macro_rules! debug_assert_ne { #[macro_export] #[unstable(feature = "assert_matches", issue = "82775")] #[allow_internal_unstable(assert_matches)] -macro_rules! debug_assert_matches { - ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); }) +#[rustc_macro_transparency = "semitransparent"] +pub macro debug_assert_matches($($arg:tt)*) { + if $crate::cfg!(debug_assertions) { $crate::assert::assert_matches!($($arg)*); } } /// Returns whether the given expression matches any of the given patterns. diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c4f21587457c1..e83a000e38b2d 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -552,8 +552,8 @@ pub use std_detect::{ #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated, deprecated_in_future)] pub use core::{ - assert_eq, assert_matches, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches, - debug_assert_ne, matches, r#try, todo, unimplemented, unreachable, write, writeln, + assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo, + unimplemented, unreachable, write, writeln, }; // Re-export built-in macros defined through libcore. diff --git a/src/test/ui/macros/assert-matches-macro-msg.rs b/src/test/ui/macros/assert-matches-macro-msg.rs index 43be9532f5d1c..714a6561a6d09 100644 --- a/src/test/ui/macros/assert-matches-macro-msg.rs +++ b/src/test/ui/macros/assert-matches-macro-msg.rs @@ -6,6 +6,8 @@ #![feature(assert_matches)] +use std::assert::assert_matches; + fn main() { assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3"); } diff --git a/src/test/ui/matches2021.rs b/src/test/ui/matches2021.rs index 1090b1578ba51..a6fa5128d2f86 100644 --- a/src/test/ui/matches2021.rs +++ b/src/test/ui/matches2021.rs @@ -6,6 +6,8 @@ #![feature(assert_matches)] +use std::assert::assert_matches; + fn main() { assert!(matches!((), ())); assert_matches!((), ()); diff --git a/src/test/ui/resolve/resolve-hint-macro.rs b/src/test/ui/resolve/resolve-hint-macro.rs index 6155ae7bcdfdf..5532c8b90e326 100644 --- a/src/test/ui/resolve/resolve-hint-macro.rs +++ b/src/test/ui/resolve/resolve-hint-macro.rs @@ -1,4 +1,4 @@ fn main() { - assert(true); - //~^ ERROR expected function, found macro `assert` + assert_eq(1, 1); + //~^ ERROR expected function, found macro `assert_eq` } diff --git a/src/test/ui/resolve/resolve-hint-macro.stderr b/src/test/ui/resolve/resolve-hint-macro.stderr index 7d35ce7e65e58..efcfc7198ab51 100644 --- a/src/test/ui/resolve/resolve-hint-macro.stderr +++ b/src/test/ui/resolve/resolve-hint-macro.stderr @@ -1,13 +1,13 @@ -error[E0423]: expected function, found macro `assert` +error[E0423]: expected function, found macro `assert_eq` --> $DIR/resolve-hint-macro.rs:2:5 | -LL | assert(true); - | ^^^^^^ not a function +LL | assert_eq(1, 1); + | ^^^^^^^^^ not a function | help: use `!` to invoke the macro | -LL | assert!(true); - | ^ +LL | assert_eq!(1, 1); + | ^ error: aborting due to previous error From 1b60ea8890d016c905a740037e2a49688bc3507a Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Fri, 16 Jul 2021 09:18:14 -0700 Subject: [PATCH 2/8] rename assert_matches module --- compiler/rustc_middle/src/ich/impls_syntax.rs | 2 +- compiler/rustc_mir/src/interpret/memory.rs | 2 +- library/core/src/lib.rs | 2 +- library/std/src/lib.rs | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/ich/impls_syntax.rs b/compiler/rustc_middle/src/ich/impls_syntax.rs index 1c66f831b5f4b..acf2990b64348 100644 --- a/compiler/rustc_middle/src/ich/impls_syntax.rs +++ b/compiler/rustc_middle/src/ich/impls_syntax.rs @@ -6,7 +6,7 @@ use crate::ich::StableHashingContext; use rustc_ast as ast; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_span::{BytePos, NormalizedPos, SourceFile}; -use std::assert::assert_matches; +use std::assert_matches::assert_matches; use smallvec::SmallVec; diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index 577a036815a98..76073599e22b1 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -6,7 +6,7 @@ //! integer. It is crucial that these operations call `check_align` *before* //! short-circuiting the empty case! -use std::assert::assert_matches; +use std::assert_matches::assert_matches; use std::borrow::Cow; use std::collections::VecDeque; use std::convert::{TryFrom, TryInto}; diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 65235a0db0359..0bb0f8768a0ef 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -187,7 +187,7 @@ mod macros; #[cfg(not(test))] #[unstable(feature = "assert_matches", issue = "82775")] /// Unstable module containing the unstable `assert_matches` macro. -pub mod assert { +pub mod assert_matches { #[unstable(feature = "assert_matches", issue = "82775")] pub use crate::macros::{assert_matches, debug_assert_matches}; } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index e83a000e38b2d..31dcd9546bc8a 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -560,9 +560,9 @@ pub use core::{ #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] #[allow(deprecated)] pub use core::{ - asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, - format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax, - module_path, option_env, stringify, trace_macros, + asm, assert, assert_matches, cfg, column, compile_error, concat, concat_idents, env, file, + format_args, format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, + log_syntax, module_path, option_env, stringify, trace_macros, }; #[stable(feature = "core_primitive", since = "1.43.0")] From 96941c7c121155538a6b8ebdafaedd3a5dc58433 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Fri, 16 Jul 2021 11:26:20 -0700 Subject: [PATCH 3/8] fix ui tests --- src/test/ui/macros/assert-matches-macro-msg.rs | 2 +- src/test/ui/matches2021.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/ui/macros/assert-matches-macro-msg.rs b/src/test/ui/macros/assert-matches-macro-msg.rs index 714a6561a6d09..fd8cd5a1a0566 100644 --- a/src/test/ui/macros/assert-matches-macro-msg.rs +++ b/src/test/ui/macros/assert-matches-macro-msg.rs @@ -6,7 +6,7 @@ #![feature(assert_matches)] -use std::assert::assert_matches; +use std::assert_matches::assert_matches; fn main() { assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3"); diff --git a/src/test/ui/matches2021.rs b/src/test/ui/matches2021.rs index a6fa5128d2f86..f5497c1d16de6 100644 --- a/src/test/ui/matches2021.rs +++ b/src/test/ui/matches2021.rs @@ -6,7 +6,7 @@ #![feature(assert_matches)] -use std::assert::assert_matches; +use std::assert_matches::assert_matches; fn main() { assert!(matches!((), ())); From 5142fa3e3aeb84ab6590cf1b9db01641b19b7b83 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Fri, 16 Jul 2021 12:16:39 -0700 Subject: [PATCH 4/8] pls this time --- library/core/src/macros/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 5a8e2f543921b..a763ae27cd14b 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -126,7 +126,7 @@ macro_rules! assert_ne { /// ``` /// #![feature(assert_matches)] /// -/// use std::assert::assert_matches; +/// use std::assert_matches::assert_matches; /// /// let a = 1u32.checked_add(2); /// let b = 1u32.checked_sub(2); @@ -300,7 +300,7 @@ macro_rules! debug_assert_ne { #[allow_internal_unstable(assert_matches)] #[rustc_macro_transparency = "semitransparent"] pub macro debug_assert_matches($($arg:tt)*) { - if $crate::cfg!(debug_assertions) { $crate::assert::assert_matches!($($arg)*); } + if $crate::cfg!(debug_assertions) { $crate::assert_matches::assert_matches!($($arg)*); } } /// Returns whether the given expression matches any of the given patterns. From 8fde11b20831a9d82079e0e84745ca77713831ed Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Fri, 16 Jul 2021 13:25:11 -0700 Subject: [PATCH 5/8] i sweat to god --- library/core/src/macros/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index a763ae27cd14b..1a3c088e922a0 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -285,7 +285,7 @@ macro_rules! debug_assert_ne { /// ``` /// #![feature(assert_matches)] /// -/// use std::assert::debug_assert_matches; +/// use std::assert_matches::debug_assert_matches; /// /// let a = 1u32.checked_add(2); /// let b = 1u32.checked_sub(2); From ef7502b878720d4f948b3a535f77e03b2fcc4060 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 9 Jul 2021 10:01:23 -0700 Subject: [PATCH 6/8] Fix rust-analyzer install when not available. --- src/bootstrap/install.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 13ee909afd5e4..6f3054538a898 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -165,10 +165,15 @@ install!((self, builder, _config), } }; RustAnalyzer, "rust-analyzer", Self::should_build(_config), only_hosts: true, { - let tarball = builder - .ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target }) - .expect("missing rust-analyzer"); - install_sh(builder, "rust-analyzer", self.compiler.stage, Some(self.target), &tarball); + if let Some(tarball) = + builder.ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target }) + { + install_sh(builder, "rust-analyzer", self.compiler.stage, Some(self.target), &tarball); + } else { + builder.info( + &format!("skipping Install rust-analyzer stage{} ({})", self.compiler.stage, self.target), + ); + } }; Clippy, "clippy", Self::should_build(_config), only_hosts: true, { let tarball = builder.ensure(dist::Clippy { compiler: self.compiler, target: self.target }); From cc9284d21db8a730707cb5a8694aaad25e11c232 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 11 Jul 2021 09:01:31 -0700 Subject: [PATCH 7/8] Add comments why install steps should never fail. --- src/bootstrap/install.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 6f3054538a898..2ac9d3dda206f 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -139,11 +139,15 @@ macro_rules! install { install!((self, builder, _config), Docs, "src/doc", _config.docs, only_hosts: false, { + // `expect` should be safe, only None when config.docs is false, + // which is guarded in `should_run` let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs"); install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball); }; Std, "library/std", true, only_hosts: false, { for target in &builder.targets { + // `expect` should be safe, only None when host != build, but this + // only runs when host == build let tarball = builder.ensure(dist::Std { compiler: self.compiler, target: *target @@ -217,6 +221,8 @@ install!((self, builder, _config), } }; Analysis, "analysis", Self::should_build(_config), only_hosts: false, { + // `expect` should be safe, only None with host != build, but this + // only uses the `build` compiler let tarball = builder.ensure(dist::Analysis { // Find the actual compiler (handling the full bootstrap option) which // produced the save-analysis data because that data isn't copied From c8b3431be195b3b07a687aa08e285b014eaf6077 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 12 Jul 2021 13:29:47 -0700 Subject: [PATCH 8/8] Provide a better error when `x.py install src/doc` doesn't work. --- src/bootstrap/install.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 2ac9d3dda206f..8a1b6df0dafe3 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -139,10 +139,12 @@ macro_rules! install { install!((self, builder, _config), Docs, "src/doc", _config.docs, only_hosts: false, { - // `expect` should be safe, only None when config.docs is false, - // which is guarded in `should_run` - let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs"); - install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball); + if let Some(tarball) = builder.ensure(dist::Docs { host: self.target }) { + install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball); + } else { + panic!("docs are not available to install, \ + check that `build.docs` is true in `config.toml`"); + } }; Std, "library/std", true, only_hosts: false, { for target in &builder.targets {