Fix is_from_proc_macro attr
This commit is contained in:
parent
cefa31a524
commit
59ecf4d073
5 changed files with 83 additions and 15 deletions
|
|
@ -63,8 +63,8 @@ fn span_matches_pat(sess: &Session, span: Span, start_pat: Pat, end_pat: Pat) ->
|
|||
Pat::Num => start_str.as_bytes().first().map_or(false, u8::is_ascii_digit),
|
||||
} && match end_pat {
|
||||
Pat::Str(text) => end_str.ends_with(text),
|
||||
Pat::MultiStr(texts) => texts.iter().any(|s| start_str.ends_with(s)),
|
||||
Pat::OwnedMultiStr(texts) => texts.iter().any(|s| start_str.starts_with(s)),
|
||||
Pat::MultiStr(texts) => texts.iter().any(|s| end_str.ends_with(s)),
|
||||
Pat::OwnedMultiStr(texts) => texts.iter().any(|s| end_str.ends_with(s)),
|
||||
Pat::Sym(sym) => end_str.ends_with(sym.as_str()),
|
||||
Pat::Num => end_str.as_bytes().last().map_or(false, u8::is_ascii_hexdigit),
|
||||
})
|
||||
|
|
@ -333,26 +333,32 @@ fn attr_search_pat(attr: &Attribute) -> (Pat, Pat) {
|
|||
match attr.kind {
|
||||
AttrKind::Normal(..) => {
|
||||
if let Some(ident) = attr.ident() {
|
||||
// TODO: I feel like it's likely we can use `Cow` instead but this will require quite a bit of
|
||||
// refactoring
|
||||
// NOTE: This will likely have false positives, like `allow = 1`
|
||||
(
|
||||
Pat::OwnedMultiStr(vec![ident.to_string(), "#".to_owned()]),
|
||||
Pat::Str(""),
|
||||
)
|
||||
let ident_string = ident.to_string();
|
||||
if attr.style == AttrStyle::Outer {
|
||||
(
|
||||
Pat::OwnedMultiStr(vec!["#[".to_owned() + &ident_string, ident_string]),
|
||||
Pat::Str(""),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
Pat::OwnedMultiStr(vec!["#![".to_owned() + &ident_string, ident_string]),
|
||||
Pat::Str(""),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
(Pat::Str("#"), Pat::Str("]"))
|
||||
}
|
||||
},
|
||||
AttrKind::DocComment(_kind @ CommentKind::Line, ..) => {
|
||||
if matches!(attr.style, AttrStyle::Outer) {
|
||||
if attr.style == AttrStyle::Outer {
|
||||
(Pat::Str("///"), Pat::Str(""))
|
||||
} else {
|
||||
(Pat::Str("//!"), Pat::Str(""))
|
||||
}
|
||||
},
|
||||
AttrKind::DocComment(_kind @ CommentKind::Block, ..) => {
|
||||
if matches!(attr.style, AttrStyle::Outer) {
|
||||
if attr.style == AttrStyle::Outer {
|
||||
(Pat::Str("/**"), Pat::Str("*/"))
|
||||
} else {
|
||||
(Pat::Str("/*!"), Pat::Str("*/"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue