Merge pull request #2471 from topecongiro/issue-2470

Return the original snippet if the attribute contains invalid syntax
This commit is contained in:
Nick Cameron 2018-02-21 11:53:23 +13:00 committed by GitHub
commit b060f6473e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -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)),
)
}
}
}

View File

@ -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;
}

View File

@ -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;
}