Skip to content

Commit

Permalink
Fix even more possible namespacing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Sep 25, 2022
1 parent c05eaa7 commit 254bb31
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! [`std::concat!`][core::concat!] with support for `const` variables and expressions.
//! [`std::concat!`][core::concat!] with support for `const` variables and
//! expressions.
//!
//! # Examples
//!
Expand All @@ -9,10 +10,18 @@
//! const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
//! const fn tada() -> &'static str { "🎉" }
//! const VERSION: &str = concat!(CRATE_NAME, " ", CRATE_VERSION, tada());
//!
//! # assert_eq!(
//! # VERSION,
//! # std::concat!(env!("CARGO_PKG_NAME"), " ", env!("CARGO_PKG_VERSION"), "🎉"),
//! # );
//! ```
#![no_std]

#[doc(hidden)]
pub use core;

/// Concatenate [`&str`][str] `const` expressions and literals into a static
/// string slice.
///
Expand Down Expand Up @@ -55,21 +64,21 @@ macro_rules! _concat {
off += $s.len();
)*
if off != LEN {
::core::panic!("invalid length written");
$crate::core::panic!("invalid length written");
}
arr
};
// SAFETY: The original constants were asserted to be &str's
// so the resultant bytes are valid UTF-8.
unsafe { ::core::str::from_utf8_unchecked(&ARR) }
unsafe { $crate::core::str::from_utf8_unchecked(&ARR) }
}};
}

#[doc(hidden)]
#[macro_export]
macro_rules! _maybe_std_concat {
($e:literal) => {
::core::concat!($e)
$crate::core::concat!($e)
};
($e:expr) => {
$e
Expand Down

0 comments on commit 254bb31

Please sign in to comment.