Skip to content

Commit ff4ca50

Browse files
committed
Auto merge of #87374 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backports Backports: * Move assert_matches to an inner module #86947 * rename assert_matches module #87195 * Fix rust-analyzer install when not available. #87007
2 parents 3a5d335 + c8b3431 commit ff4ca50

File tree

10 files changed

+58
-24
lines changed

10 files changed

+58
-24
lines changed

compiler/rustc_middle/src/ich/impls_syntax.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::ich::StableHashingContext;
66
use rustc_ast as ast;
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
88
use rustc_span::{BytePos, NormalizedPos, SourceFile};
9+
use std::assert_matches::assert_matches;
910

1011
use smallvec::SmallVec;
1112

compiler/rustc_mir/src/interpret/memory.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! integer. It is crucial that these operations call `check_align` *before*
77
//! short-circuiting the empty case!
88
9+
use std::assert_matches::assert_matches;
910
use std::borrow::Cow;
1011
use std::collections::VecDeque;
1112
use std::convert::{TryFrom, TryInto};

library/core/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ use prelude::v1::*;
182182
#[macro_use]
183183
mod macros;
184184

185+
// We don't export this through #[macro_export] for now, to avoid breakage.
186+
// See https://github.com/rust-lang/rust/issues/82913
187+
#[cfg(not(test))]
188+
#[unstable(feature = "assert_matches", issue = "82775")]
189+
/// Unstable module containing the unstable `assert_matches` macro.
190+
pub mod assert_matches {
191+
#[unstable(feature = "assert_matches", issue = "82775")]
192+
pub use crate::macros::{assert_matches, debug_assert_matches};
193+
}
194+
185195
#[macro_use]
186196
mod internal_macros;
187197

library/core/src/macros/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ macro_rules! assert_ne {
126126
/// ```
127127
/// #![feature(assert_matches)]
128128
///
129+
/// use std::assert_matches::assert_matches;
130+
///
129131
/// let a = 1u32.checked_add(2);
130132
/// let b = 1u32.checked_sub(2);
131133
/// assert_matches!(a, Some(_));
@@ -134,10 +136,10 @@ macro_rules! assert_ne {
134136
/// let c = Ok("abc".to_string());
135137
/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
136138
/// ```
137-
#[macro_export]
138139
#[unstable(feature = "assert_matches", issue = "82775")]
139140
#[allow_internal_unstable(core_panic)]
140-
macro_rules! assert_matches {
141+
#[rustc_macro_transparency = "semitransparent"]
142+
pub macro assert_matches {
141143
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({
142144
match $left {
143145
$( $pattern )|+ $( if $guard )? => {}
@@ -149,7 +151,7 @@ macro_rules! assert_matches {
149151
);
150152
}
151153
}
152-
});
154+
}),
153155
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
154156
match $left {
155157
$( $pattern )|+ $( if $guard )? => {}
@@ -161,7 +163,7 @@ macro_rules! assert_matches {
161163
);
162164
}
163165
}
164-
});
166+
}),
165167
}
166168

167169
/// Asserts that a boolean expression is `true` at runtime.
@@ -283,6 +285,8 @@ macro_rules! debug_assert_ne {
283285
/// ```
284286
/// #![feature(assert_matches)]
285287
///
288+
/// use std::assert_matches::debug_assert_matches;
289+
///
286290
/// let a = 1u32.checked_add(2);
287291
/// let b = 1u32.checked_sub(2);
288292
/// debug_assert_matches!(a, Some(_));
@@ -294,8 +298,9 @@ macro_rules! debug_assert_ne {
294298
#[macro_export]
295299
#[unstable(feature = "assert_matches", issue = "82775")]
296300
#[allow_internal_unstable(assert_matches)]
297-
macro_rules! debug_assert_matches {
298-
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); })
301+
#[rustc_macro_transparency = "semitransparent"]
302+
pub macro debug_assert_matches($($arg:tt)*) {
303+
if $crate::cfg!(debug_assertions) { $crate::assert_matches::assert_matches!($($arg)*); }
299304
}
300305

301306
/// Returns whether the given expression matches any of the given patterns.

library/std/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -552,17 +552,17 @@ pub use std_detect::{
552552
#[stable(feature = "rust1", since = "1.0.0")]
553553
#[allow(deprecated, deprecated_in_future)]
554554
pub use core::{
555-
assert_eq, assert_matches, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches,
556-
debug_assert_ne, matches, r#try, todo, unimplemented, unreachable, write, writeln,
555+
assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo,
556+
unimplemented, unreachable, write, writeln,
557557
};
558558

559559
// Re-export built-in macros defined through libcore.
560560
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
561561
#[allow(deprecated)]
562562
pub use core::{
563-
asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
564-
format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax,
565-
module_path, option_env, stringify, trace_macros,
563+
asm, assert, assert_matches, cfg, column, compile_error, concat, concat_idents, env, file,
564+
format_args, format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm,
565+
log_syntax, module_path, option_env, stringify, trace_macros,
566566
};
567567

568568
#[stable(feature = "core_primitive", since = "1.43.0")]

src/bootstrap/install.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,17 @@ macro_rules! install {
139139

140140
install!((self, builder, _config),
141141
Docs, "src/doc", _config.docs, only_hosts: false, {
142-
let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs");
143-
install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball);
142+
if let Some(tarball) = builder.ensure(dist::Docs { host: self.target }) {
143+
install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball);
144+
} else {
145+
panic!("docs are not available to install, \
146+
check that `build.docs` is true in `config.toml`");
147+
}
144148
};
145149
Std, "library/std", true, only_hosts: false, {
146150
for target in &builder.targets {
151+
// `expect` should be safe, only None when host != build, but this
152+
// only runs when host == build
147153
let tarball = builder.ensure(dist::Std {
148154
compiler: self.compiler,
149155
target: *target
@@ -165,10 +171,15 @@ install!((self, builder, _config),
165171
}
166172
};
167173
RustAnalyzer, "rust-analyzer", Self::should_build(_config), only_hosts: true, {
168-
let tarball = builder
169-
.ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target })
170-
.expect("missing rust-analyzer");
171-
install_sh(builder, "rust-analyzer", self.compiler.stage, Some(self.target), &tarball);
174+
if let Some(tarball) =
175+
builder.ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target })
176+
{
177+
install_sh(builder, "rust-analyzer", self.compiler.stage, Some(self.target), &tarball);
178+
} else {
179+
builder.info(
180+
&format!("skipping Install rust-analyzer stage{} ({})", self.compiler.stage, self.target),
181+
);
182+
}
172183
};
173184
Clippy, "clippy", Self::should_build(_config), only_hosts: true, {
174185
let tarball = builder.ensure(dist::Clippy { compiler: self.compiler, target: self.target });
@@ -212,6 +223,8 @@ install!((self, builder, _config),
212223
}
213224
};
214225
Analysis, "analysis", Self::should_build(_config), only_hosts: false, {
226+
// `expect` should be safe, only None with host != build, but this
227+
// only uses the `build` compiler
215228
let tarball = builder.ensure(dist::Analysis {
216229
// Find the actual compiler (handling the full bootstrap option) which
217230
// produced the save-analysis data because that data isn't copied

src/test/ui/macros/assert-matches-macro-msg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#![feature(assert_matches)]
88

9+
use std::assert_matches::assert_matches;
10+
911
fn main() {
1012
assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3");
1113
}

src/test/ui/matches2021.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#![feature(assert_matches)]
88

9+
use std::assert_matches::assert_matches;
10+
911
fn main() {
1012
assert!(matches!((), ()));
1113
assert_matches!((), ());
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
2-
assert(true);
3-
//~^ ERROR expected function, found macro `assert`
2+
assert_eq(1, 1);
3+
//~^ ERROR expected function, found macro `assert_eq`
44
}

src/test/ui/resolve/resolve-hint-macro.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0423]: expected function, found macro `assert`
1+
error[E0423]: expected function, found macro `assert_eq`
22
--> $DIR/resolve-hint-macro.rs:2:5
33
|
4-
LL | assert(true);
5-
| ^^^^^^ not a function
4+
LL | assert_eq(1, 1);
5+
| ^^^^^^^^^ not a function
66
|
77
help: use `!` to invoke the macro
88
|
9-
LL | assert!(true);
10-
| ^
9+
LL | assert_eq!(1, 1);
10+
| ^
1111

1212
error: aborting due to previous error
1313

0 commit comments

Comments
 (0)