Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ impl<'a> FilterAttrs<'a> for &'a [Attribute] {
#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
use crate::ext::IdentExt;
use crate::parse::{Parse, ParseStream, Result};

pub fn parse_inner(input: ParseStream, attrs: &mut Vec<Attribute>) -> Result<()> {
Expand Down Expand Up @@ -540,8 +541,13 @@ pub mod parsing {
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Meta {
fn parse(input: ParseStream) -> Result<Self> {
let path = input.call(Path::parse_mod_style)?;
parse_meta_after_path(path, input)
if cfg!(feature = "full") && input.peek(Token![unsafe]) {
let unsafe_ident = Ident::parse_any(input)?;
parse_meta_list_after_path(Path::from(unsafe_ident), input).map(Meta::List)
} else {
let path = input.call(Path::parse_mod_style)?;
parse_meta_after_path(path, input)
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/test_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@ fn test_negative_lit() {
"###);
}

#[test]
fn test_unsafe() {
let meta = test("#[unsafe(no_mangle)]");

snapshot!(meta, @r###"
Meta::List {
path: Path {
segments: [
PathSegment {
ident: "unsafe",
},
],
},
delimiter: MacroDelimiter::Paren,
tokens: TokenStream(`no_mangle`),
}
"###);
}

fn test(input: &str) -> Meta {
let attrs = Attribute::parse_outer.parse_str(input).unwrap();

Expand Down