Skip to content

Commit

Permalink
Fixed assert* macro hygiene.
Browse files Browse the repository at this point in the history
"Fixed" use of function calls in const contexts in case that
rust-lang/rust#80243 gets merged.
  • Loading branch information
rodrimati1992 committed Dec 29, 2020
1 parent 38301f1 commit d26e51f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion const_format/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "const_format"
version = "0.2.7"
version = "0.2.8"
authors = ["rodrimati1992 <rodrimatt1985@gmail.com>"]
edition = "2018"
license = "Zlib"
Expand Down
8 changes: 4 additions & 4 deletions const_format/src/doctests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ pub struct Assert;
/// ```rust
/// #![feature(const_mut_refs)]
///
/// const_format::assertc_eq!(0u8, 0, "foo");
/// const_format::assertc_eq!(0u8, 0u8, "foo");
///
/// ```
///
/// ```compile_fail
/// #![feature(const_mut_refs)]
///
/// const_format::assertc_eq!(0u8, 10, "foo");
/// const_format::assertc_eq!(0u8, 10u8, "foo");
///
/// ```
///
Expand All @@ -179,14 +179,14 @@ pub struct Assert;
/// ```rust
/// #![feature(const_mut_refs)]
///
/// const_format::assertc_ne!(0u8, 10, "foo");
/// const_format::assertc_ne!(0u8, 10u8, "foo");
///
/// ```
///
/// ```compile_fail
/// #![feature(const_mut_refs)]
///
/// const_format::assertc_ne!(0u8, 0, "foo");
/// const_format::assertc_ne!(0u8, 0u8, "foo");
///
/// ```
///
Expand Down
10 changes: 8 additions & 2 deletions const_format/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@
//! writer
//! }
//!
//! const STRING: &str = strwriter_as_str!(&build_string());
//! const STRING: &str = {
//! const STR: &StrWriter<[u8; CAP]> = &build_string();
//! strwriter_as_str!(STR)
//! };
//!
//! // The formatter
//! assert_eq!(
Expand Down Expand Up @@ -224,7 +227,10 @@
//! writer
//! }
//!
//! const STRING: &str = strwriter_as_str!(&build_string());
//! const STRING: &str = {
//! const S: &StrWriter<[u8; CAP]> = &build_string();
//! strwriter_as_str!(S)
//! };
//!
//! assert_eq!(
//! STRING,
Expand Down
7 changes: 4 additions & 3 deletions const_format/src/fmt/str_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ use core::marker::PhantomData;
/// }
///
/// impl<L: Num, R: Num> Mul<L, R> {
/// const STR: &'static str = strwriter_as_str!(&compute_str(L::V, R::V));
/// const __STR: &'static StrWriter<[u8]> = &compute_str(L::V, R::V);
/// const STR: &'static str = strwriter_as_str!(Self::__STR);
/// }
///
/// assert_eq!(Mul::<Two,Three>::STR, "2 * 3 == 6");
Expand Down Expand Up @@ -315,8 +316,8 @@ impl StrWriter {
/// }
///
/// const SLICE: &[u8] = {
/// let promoted: &'static StrWriter = &slice();
/// promoted.as_bytes_alt()
/// const PROM: &'static StrWriter = &slice();
/// PROM.as_bytes_alt()
/// };
///
///
Expand Down
15 changes: 12 additions & 3 deletions const_format/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ macro_rules! try_ {
/// writer
/// }
///
/// const TEXT: &str = strwriter_as_str!(&foo());
/// const TEXT: &str = {
/// const S: &StrWriter = &foo();
/// strwriter_as_str!(S)
/// };
/// assert_eq!(TEXT, "foo bar baz")
///
/// ```
Expand Down Expand Up @@ -187,7 +190,10 @@ macro_rules! unwrap_or_else {
/// writer
/// }
///
/// const TEXT: &str = strwriter_as_str!(&make_strwriter());
/// const TEXT: &str = {
/// const TEXT_: &StrWriter = &make_strwriter();
/// strwriter_as_str!(TEXT_)
/// };
///
/// assert_eq!(TEXT, "[0, 1],[0, 1],100,100,Unit,Unit");
///
Expand Down Expand Up @@ -244,7 +250,10 @@ macro_rules! coerce_to_fmt {
/// writer
/// }
///
/// const STR: &str = strwriter_as_str!(&formatted());
/// const STR: &str = {
/// const S: &StrWriter = &formatted();
/// strwriter_as_str!(S)
/// };
///
/// fn main() {
/// assert_eq!(STR, "[3, 5, 8, D, 15, 22]");
Expand Down
4 changes: 2 additions & 2 deletions const_format/src/macros/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ macro_rules! __assertc_equality_inner {
use __cf_osRcTFl4A::coerce_to_fmt as __cf_coerce_to_fmt;

#[allow(irrefutable_let_patterns)]
if let __cf_respan_to!(($left) [ref __cf_left, ref __cf_right]) =
[$left, $right]
if let __cf_respan_to!(($left) (ref __cf_left, ref __cf_right, __cf_fmt)) =
($left, $right, __cf_fmt)
{__cf_respan_to!{
($left)
let __cf_fmt = &mut __cf_fmt
Expand Down
4 changes: 2 additions & 2 deletions const_format/src/macros/call_debug_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
/// }
///
/// const TEXT: &str = {
/// let promoted = &make();
/// strwriter_as_str!(unwrap!(promoted))
/// const PROM: &StrWriter<[u8]> = &unwrap!(make());
/// strwriter_as_str!(PROM)
/// };
///
/// const EXPECTED: &str = "\
Expand Down

0 comments on commit d26e51f

Please sign in to comment.