coverage: Tighten validation of #[coverage(off)]
and #[coverage(on)]
This commit is contained in:
parent
b5dfeba0e1
commit
a000fa8b54
5 changed files with 28 additions and 29 deletions
|
@ -105,6 +105,9 @@ pub struct AttributeTemplate {
|
|||
pub word: bool,
|
||||
/// If `Some`, the attribute is allowed to take a list of items like `#[allow(..)]`.
|
||||
pub list: Option<&'static str>,
|
||||
/// If non-empty, the attribute is allowed to take a list containing exactly
|
||||
/// one of the listed words, like `#[coverage(off)]`.
|
||||
pub one_of: &'static [Symbol],
|
||||
/// If `Some`, the attribute is allowed to be a name/value pair where the
|
||||
/// value is a string, like `#[must_use = "reason"]`.
|
||||
pub name_value_str: Option<&'static str>,
|
||||
|
@ -165,19 +168,20 @@ pub enum AttributeDuplicates {
|
|||
/// E.g., `template!(Word, List: "description")` means that the attribute
|
||||
/// supports forms `#[attr]` and `#[attr(description)]`.
|
||||
macro_rules! template {
|
||||
(Word) => { template!(@ true, None, None) };
|
||||
(List: $descr: expr) => { template!(@ false, Some($descr), None) };
|
||||
(NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) };
|
||||
(Word, List: $descr: expr) => { template!(@ true, Some($descr), None) };
|
||||
(Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) };
|
||||
(Word) => { template!(@ true, None, &[], None) };
|
||||
(List: $descr: expr) => { template!(@ false, Some($descr), &[], None) };
|
||||
(OneOf: $one_of: expr) => { template!(@ false, None, $one_of, None) };
|
||||
(NameValueStr: $descr: expr) => { template!(@ false, None, &[], Some($descr)) };
|
||||
(Word, List: $descr: expr) => { template!(@ true, Some($descr), &[], None) };
|
||||
(Word, NameValueStr: $descr: expr) => { template!(@ true, None, &[], Some($descr)) };
|
||||
(List: $descr1: expr, NameValueStr: $descr2: expr) => {
|
||||
template!(@ false, Some($descr1), Some($descr2))
|
||||
template!(@ false, Some($descr1), &[], Some($descr2))
|
||||
};
|
||||
(Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
|
||||
template!(@ true, Some($descr1), Some($descr2))
|
||||
template!(@ true, Some($descr1), &[], Some($descr2))
|
||||
};
|
||||
(@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate {
|
||||
word: $word, list: $list, name_value_str: $name_value_str
|
||||
(@ $word: expr, $list: expr, $one_of: expr, $name_value_str: expr) => { AttributeTemplate {
|
||||
word: $word, list: $list, one_of: $one_of, name_value_str: $name_value_str
|
||||
} };
|
||||
}
|
||||
|
||||
|
@ -478,7 +482,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
|||
EncodeCrossCrate::No, experimental!(no_sanitize)
|
||||
),
|
||||
gated!(
|
||||
coverage, Normal, template!(Word, List: "on|off"),
|
||||
coverage, Normal, template!(OneOf: &[sym::off, sym::on]),
|
||||
ErrorPreceding, EncodeCrossCrate::No,
|
||||
coverage_attribute, experimental!(coverage)
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue