Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #121998

Merged
merged 28 commits into from
Mar 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d0873c7
constify a couple thread_local statics
matthiaskrgr Feb 12, 2024
e478111
Improve assert_matches! documentation
Voultapher Feb 28, 2024
d2495fa
Drop link to matches macro and link matches macro to assert_matches.
Voultapher Feb 29, 2024
d6438f5
Apply review comments
Voultapher Mar 2, 2024
fb2b918
Small enhancement to description of From trait
jonaspleyer Mar 3, 2024
c45f0a9
Apply suggestions from code review
Voultapher Mar 3, 2024
aa38c26
Tweak `parse_asm_args`.
nnethercote Dec 20, 2023
3996447
Remove `file_path_mapping` param from `ParseSess::new`.
nnethercote Mar 4, 2024
0d4ebe1
Move `sess` function and use it more.
nnethercote Mar 4, 2024
4260f7e
Rename a misnamed `Session` parameter.
nnethercote Mar 4, 2024
4146136
Extract an arguments struct for `Builder::then_else_break`
Zalathar Feb 27, 2024
9eb927e
Don't run test_get_os_named_thread on win7
roblabla Mar 4, 2024
e463060
include feedback from workingjubilee
jonaspleyer Mar 4, 2024
ede25ad
Fix LVI tests after making frame pointers easily enableable
raoulstrackx Feb 27, 2024
05e68fa
Fix comment in Atomic{Ptr,Bool}::as_ptr.
Lee-Janggun Mar 4, 2024
1eedca8
Allow a way to add constructors for rustc_type_ir types
compiler-errors Feb 27, 2024
748da32
Update platform-support.md with supported musl version
wesleywiser Mar 4, 2024
80d2bdb
Rename all `ParseSess` variables/fields/lifetimes as `psess`.
nnethercote Mar 4, 2024
706fe0b
Rollup merge of #120976 - matthiaskrgr:constify_TL_statics, r=lcnr
matthiaskrgr Mar 4, 2024
8886c31
Rollup merge of #121683 - fortanix:raoul/lvi_fixes, r=cuviper
matthiaskrgr Mar 4, 2024
e7bb224
Rollup merge of #121703 - compiler-errors:new, r=lcnr
matthiaskrgr Mar 4, 2024
008ab33
Rollup merge of #121732 - Voultapher:improve-assert_matches-documenta…
matthiaskrgr Mar 4, 2024
58a0f64
Rollup merge of #121928 - Zalathar:then-else-args, r=Nadrieril
matthiaskrgr Mar 4, 2024
9d81d4e
Rollup merge of #121939 - jonaspleyer:patch-typo-core-From-descr, r=w…
matthiaskrgr Mar 4, 2024
4944ab4
Rollup merge of #121968 - roblabla:fix-win7, r=jhpratt
matthiaskrgr Mar 4, 2024
13b9712
Rollup merge of #121969 - nnethercote:ParseSess-cleanups, r=wesleywiser
matthiaskrgr Mar 4, 2024
c83ca5b
Rollup merge of #121977 - Lee-Janggun:master, r=WaffleLapkin
matthiaskrgr Mar 4, 2024
5e13bc4
Rollup merge of #121994 - wesleywiser:update_musl_version_docs, r=ehuss
matthiaskrgr Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve assert_matches! documentation
This new documentation tries to avoid to limit the impact of the
conceptual pitfall, that the if guard relaxes the constraint, when
really it tightens it. This is achieved by changing the text and
examples. The previous documentation also chose a rather weird and
non-representative example for the if guard, that made it needlessly
complicated to understand.
  • Loading branch information
Voultapher committed Feb 28, 2024
commit e4781115f2a5e50d60673d5c64d49182fc190247
79 changes: 50 additions & 29 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@ macro_rules! assert_ne {
};
}

/// Asserts that an expression matches any of the given patterns.
/// Asserts that an expression matches the provided pattern.
///
/// Like in a `match` expression, the pattern can be optionally followed by `if`
/// and a guard expression that has access to names bound by the pattern.
/// This macro is generally preferable to `assert!(matches!(value, pattern))`, because it can print
/// the debug representation, of the actual value shape that did not meet expectation. In contrast
/// using [`assert!`] will only print that the expectation was not met, but not why.
///
/// On panic, this macro will print the value of the expression with its
/// debug representation.
/// The pattern syntax is exactly the same as found in a match arm and the [`matches!`] macro. The
/// optional if guard can be used to add additional checks that must be true for the matched value,
/// otherwise this macro will panic.
///
/// Like [`assert!`], this macro has a second form, where a custom
/// panic message can be provided.
/// On panic, this macro will print the value of the expression with its debug representation.
///
/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
///
/// # Examples
///
Expand All @@ -130,13 +133,20 @@ macro_rules! assert_ne {
///
/// use std::assert_matches::assert_matches;
///
/// let a = 1u32.checked_add(2);
/// let b = 1u32.checked_sub(2);
/// let a = Some(345);
/// let b = Some(56);
/// assert_matches!(a, Some(_));
/// assert_matches!(b, None);
/// assert_matches!(b, Some(_));
///
/// assert_matches!(a, Some(345));
/// assert_matches!(a, Some(345) | None);
///
/// // assert_matches!(a, None); // panics
/// // assert_matches!(b, Some(345)); // panics
/// // assert_matches!(b, Some(345) | None); // panics
///
/// let c = Ok("abc".to_string());
/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
/// assert_matches!(a, Some(x) if x > 100);
/// // assert_matches!(a, Some(x) if x < 100); // panics
/// ```
#[unstable(feature = "assert_matches", issue = "82775")]
#[allow_internal_unstable(panic_internals)]
Expand Down Expand Up @@ -369,21 +379,25 @@ macro_rules! debug_assert_ne {
};
}

/// Asserts that an expression matches any of the given patterns.
/// Asserts that an expression matches the provided pattern.
///
/// Like in a `match` expression, the pattern can be optionally followed by `if`
/// and a guard expression that has access to names bound by the pattern.
/// This macro is generally preferable to `debug_assert!(matches!(value, pattern))`, because it can
/// print the debug representation, of the actual value shape that did not meet expectation. In
/// contrast using [`debug_assert!`] will only print that the expectation was not met, but not why.
///
/// The pattern syntax is exactly the same as found in a match arm and the [`matches!`] macro. The
/// optional if guard can be used to add additional checks that must be true for the matched value,
/// otherwise this macro will panic.
///
/// On panic, this macro will print the value of the expression with its
/// debug representation.
/// On panic, this macro will print the value of the expression with its debug representation.
///
/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only
/// enabled in non optimized builds by default. An optimized build will not
/// execute `debug_assert_matches!` statements unless `-C debug-assertions` is
/// passed to the compiler. This makes `debug_assert_matches!` useful for
/// checks that are too expensive to be present in a release build but may be
/// helpful during development. The result of expanding `debug_assert_matches!`
/// is always type checked.
/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
///
/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only enabled in non optimized
/// builds by default. An optimized build will not execute `debug_assert_matches!` statements unless
/// `-C debug-assertions` is passed to the compiler. This makes `debug_assert_matches!` useful for
/// checks that are too expensive to be present in a release build but may be helpful during
/// development. The result of expanding `debug_assert_matches!` is always type checked.
///
/// # Examples
///
Expand All @@ -392,13 +406,20 @@ macro_rules! debug_assert_ne {
///
/// use std::assert_matches::debug_assert_matches;
///
/// let a = 1u32.checked_add(2);
/// let b = 1u32.checked_sub(2);
/// let a = Some(345);
/// let b = Some(56);
/// debug_assert_matches!(a, Some(_));
/// debug_assert_matches!(b, None);
/// debug_assert_matches!(b, Some(_));
///
/// debug_assert_matches!(a, Some(345));
/// debug_assert_matches!(a, Some(345) | None);
///
/// // debug_assert_matches!(a, None); // panics
/// // debug_assert_matches!(b, Some(345)); // panics
/// // debug_assert_matches!(b, Some(345) | None); // panics
///
/// let c = Ok("abc".to_string());
/// debug_assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
/// debug_assert_matches!(a, Some(x) if x > 100);
/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
/// ```
#[unstable(feature = "assert_matches", issue = "82775")]
#[allow_internal_unstable(assert_matches)]
Expand Down
Loading