Return the original snippet if the attribute contains invalid syntax
This allows us to keep formatting the macro def with attributes that become invalid syntax when the `$` is replaced with `z`, e.g. `#[doc = $expr]`.
This commit is contained in:
parent
be79f5e433
commit
b4c85d1bcb
@ -813,9 +813,11 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
}
|
||||
// 1 = `[`
|
||||
let shape = shape.offset_left(prefix.len() + 1)?;
|
||||
self.meta()?
|
||||
.rewrite(context, shape)
|
||||
.map(|rw| format!("{}[{}]", prefix, rw))
|
||||
Some(
|
||||
self.meta()
|
||||
.and_then(|meta| meta.rewrite(context, shape))
|
||||
.map_or_else(|| snippet.to_owned(), |rw| format!("{}[{}]", prefix, rw)),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,3 +77,11 @@ macro_rules! m (
|
||||
macro_rules! m [
|
||||
() => ()
|
||||
];
|
||||
|
||||
// #2470
|
||||
macro foo($type_name: ident, $docs: expr) {
|
||||
#[allow(non_camel_case_types)]
|
||||
#[doc=$docs]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct $type_name;
|
||||
}
|
||||
|
@ -68,3 +68,11 @@ macro_rules! m (
|
||||
macro_rules! m [
|
||||
() => ()
|
||||
];
|
||||
|
||||
// #2470
|
||||
macro foo($type_name: ident, $docs: expr) {
|
||||
#[allow(non_camel_case_types)]
|
||||
#[doc=$docs]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct $type_name;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user