Skip to content

Commit d699f39

Browse files
ATantalizedLionemilio
authored andcommitted
Allow must_use if a reason is specified
1 parent 307d1e9 commit d699f39

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/bindgen/ir/annotation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl AnnotationSet {
113113
})
114114
.collect();
115115

116-
let must_use = attrs.has_attr_word("must_use");
116+
let must_use = attrs.has_attr_word("must_use") || attrs.has_attr_namevalue("must_use");
117117
let deprecated = attrs.find_deprecated_note();
118118
let mut annotations = HashMap::new();
119119

src/bindgen/utilities.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ pub trait SynAttributeHelpers {
149149
})
150150
}
151151

152+
/// Searches for attributes like `#[test = "..."]`.
153+
/// Example:
154+
/// - `item.has_attr_namevalue("test")` => `#[test = "..."]`
155+
fn has_attr_namevalue(&self, name: &str) -> bool {
156+
self.attrs().iter().any(|attr| {
157+
if let syn::Meta::NameValue(nv) = &attr.meta {
158+
nv.path.is_ident(name)
159+
} else {
160+
false
161+
}
162+
})
163+
}
164+
152165
/// Searches for attributes like `#[unsafe(test)]`.
153166
/// Example:
154167
/// - `item.has_unsafe_attr_word("test")` => `#[unsafe(test)]`

0 commit comments

Comments
 (0)