This repository was archived by the owner on Oct 6, 2024. It is now read-only.
This repository was archived by the owner on Oct 6, 2024. It is now read-only.
Cannot use stringify! within paste::item! in a #[doc] attribute #29
Closed
Description
This may be an odd edge case, but I want to have this bit of code within a macro:
paste::item! {
/// The error type returned when a checked
#[doc = $name_str]
/// type conversion fails.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum [< TryFrom $name Error >] {
/// The error type returned when a checked integral type conversion fails.
TryFromIntError(TryFromIntError),
/// The error type returned when a floating point value is outside the range
/// of the integer type it needs to be converted to.
FloatToInt,
}
impl From<TryFromIntError> for [< TryFrom $name Error >] {
fn from(e: TryFromIntError) -> Self {
Self::TryFromIntError(e)
}
}
}
It gives this compiler error:
error: unexpected token: `stringify`
--> src\base\def_macro.rs:714:9
|
714 | / paste::item! {
715 | | /// The error type returned when a checked
716 | | #[doc = $name_str]
717 | | /// type conversion fails.
... |
730 | | }
731 | | }
| |_________^
|
::: src\base.rs:40:1
The $name_str
is passed into this invocation as stringify!($name)
. This works just fine if done outside of a paste::item!
, so there must be something going on in the interaction between paste::item!
, stringify!
and/or #[doc]
.
It does not work with #[doc = stringify!($name)]
either (same exact error), but #[doc = "a regular string"]
works just fine.
Metadata
Metadata
Assignees
Labels
No labels