Skip to content

Commit d26e51f

Browse files
committed
Fixed assert* macro hygiene.
"Fixed" use of function calls in const contexts in case that rust-lang/rust#80243 gets merged.
1 parent 38301f1 commit d26e51f

File tree

7 files changed

+33
-17
lines changed

7 files changed

+33
-17
lines changed

const_format/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "const_format"
3-
version = "0.2.7"
3+
version = "0.2.8"
44
authors = ["rodrimati1992 <[email protected]>"]
55
edition = "2018"
66
license = "Zlib"

const_format/src/doctests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ pub struct Assert;
163163
/// ```rust
164164
/// #![feature(const_mut_refs)]
165165
///
166-
/// const_format::assertc_eq!(0u8, 0, "foo");
166+
/// const_format::assertc_eq!(0u8, 0u8, "foo");
167167
///
168168
/// ```
169169
///
170170
/// ```compile_fail
171171
/// #![feature(const_mut_refs)]
172172
///
173-
/// const_format::assertc_eq!(0u8, 10, "foo");
173+
/// const_format::assertc_eq!(0u8, 10u8, "foo");
174174
///
175175
/// ```
176176
///
@@ -179,14 +179,14 @@ pub struct Assert;
179179
/// ```rust
180180
/// #![feature(const_mut_refs)]
181181
///
182-
/// const_format::assertc_ne!(0u8, 10, "foo");
182+
/// const_format::assertc_ne!(0u8, 10u8, "foo");
183183
///
184184
/// ```
185185
///
186186
/// ```compile_fail
187187
/// #![feature(const_mut_refs)]
188188
///
189-
/// const_format::assertc_ne!(0u8, 0, "foo");
189+
/// const_format::assertc_ne!(0u8, 0u8, "foo");
190190
///
191191
/// ```
192192
///

const_format/src/fmt.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@
147147
//! writer
148148
//! }
149149
//!
150-
//! const STRING: &str = strwriter_as_str!(&build_string());
150+
//! const STRING: &str = {
151+
//! const STR: &StrWriter<[u8; CAP]> = &build_string();
152+
//! strwriter_as_str!(STR)
153+
//! };
151154
//!
152155
//! // The formatter
153156
//! assert_eq!(
@@ -224,7 +227,10 @@
224227
//! writer
225228
//! }
226229
//!
227-
//! const STRING: &str = strwriter_as_str!(&build_string());
230+
//! const STRING: &str = {
231+
//! const S: &StrWriter<[u8; CAP]> = &build_string();
232+
//! strwriter_as_str!(S)
233+
//! };
228234
//!
229235
//! assert_eq!(
230236
//! STRING,

const_format/src/fmt/str_writer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ use core::marker::PhantomData;
8282
/// }
8383
///
8484
/// impl<L: Num, R: Num> Mul<L, R> {
85-
/// const STR: &'static str = strwriter_as_str!(&compute_str(L::V, R::V));
85+
/// const __STR: &'static StrWriter<[u8]> = &compute_str(L::V, R::V);
86+
/// const STR: &'static str = strwriter_as_str!(Self::__STR);
8687
/// }
8788
///
8889
/// assert_eq!(Mul::<Two,Three>::STR, "2 * 3 == 6");
@@ -315,8 +316,8 @@ impl StrWriter {
315316
/// }
316317
///
317318
/// const SLICE: &[u8] = {
318-
/// let promoted: &'static StrWriter = &slice();
319-
/// promoted.as_bytes_alt()
319+
/// const PROM: &'static StrWriter = &slice();
320+
/// PROM.as_bytes_alt()
320321
/// };
321322
///
322323
///

const_format/src/macros.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ macro_rules! try_ {
7171
/// writer
7272
/// }
7373
///
74-
/// const TEXT: &str = strwriter_as_str!(&foo());
74+
/// const TEXT: &str = {
75+
/// const S: &StrWriter = &foo();
76+
/// strwriter_as_str!(S)
77+
/// };
7578
/// assert_eq!(TEXT, "foo bar baz")
7679
///
7780
/// ```
@@ -187,7 +190,10 @@ macro_rules! unwrap_or_else {
187190
/// writer
188191
/// }
189192
///
190-
/// const TEXT: &str = strwriter_as_str!(&make_strwriter());
193+
/// const TEXT: &str = {
194+
/// const TEXT_: &StrWriter = &make_strwriter();
195+
/// strwriter_as_str!(TEXT_)
196+
/// };
191197
///
192198
/// assert_eq!(TEXT, "[0, 1],[0, 1],100,100,Unit,Unit");
193199
///
@@ -244,7 +250,10 @@ macro_rules! coerce_to_fmt {
244250
/// writer
245251
/// }
246252
///
247-
/// const STR: &str = strwriter_as_str!(&formatted());
253+
/// const STR: &str = {
254+
/// const S: &StrWriter = &formatted();
255+
/// strwriter_as_str!(S)
256+
/// };
248257
///
249258
/// fn main() {
250259
/// assert_eq!(STR, "[3, 5, 8, D, 15, 22]");

const_format/src/macros/assertions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ macro_rules! __assertc_equality_inner {
571571
use __cf_osRcTFl4A::coerce_to_fmt as __cf_coerce_to_fmt;
572572

573573
#[allow(irrefutable_let_patterns)]
574-
if let __cf_respan_to!(($left) [ref __cf_left, ref __cf_right]) =
575-
[$left, $right]
574+
if let __cf_respan_to!(($left) (ref __cf_left, ref __cf_right, __cf_fmt)) =
575+
($left, $right, __cf_fmt)
576576
{__cf_respan_to!{
577577
($left)
578578
let __cf_fmt = &mut __cf_fmt

const_format/src/macros/call_debug_fmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
/// }
6363
///
6464
/// const TEXT: &str = {
65-
/// let promoted = &make();
66-
/// strwriter_as_str!(unwrap!(promoted))
65+
/// const PROM: &StrWriter<[u8]> = &unwrap!(make());
66+
/// strwriter_as_str!(PROM)
6767
/// };
6868
///
6969
/// const EXPECTED: &str = "\

0 commit comments

Comments
 (0)