Start using new diagnostic logic on all existing single parsers

This commit is contained in:
Jonathan Dönszelmann
2025-02-06 17:36:34 +01:00
committed by Jana Dönszelmann
parent 28bf61b9b3
commit 4e1b6d13a2
4 changed files with 14 additions and 43 deletions

View File

@@ -84,28 +84,8 @@ pub(crate) trait AttributeParser: Default + 'static {
pub(crate) trait SingleAttributeParser: 'static {
const PATH: &'static [Symbol];
<<<<<<< Conflict 1 of 1
+++++++ Contents of side #1
/// Called when a duplicate attribute is found.
%%%%%%% Changes from base to side #2
+ const ON_DUPLICATE_STRATEGY: AttributeDuplicates;
+
/// Caled when a duplicate attribute is found.
>>>>>>> Conflict 1 of 1 ends
///
/// - `unused` is the span of the attribute that was unused or bad because of some
/// duplicate reason (see [`AttributeDuplicates`])
/// - `used` is the span of the attribute that was used in favor of the unused attribute
// FIXME(jdonszelmann): default error
fn on_duplicate(cx: &AcceptContext<'_>, used: Span, unused: Span) {
cx.emit_err(UnusedMultiple {
this: used,
other: unused,
name: Symbol::intern(
&Self::PATH.into_iter().map(|i| i.to_string()).collect::<Vec<_>>().join(".."),
),
});
}
const ON_DUPLICATE_STRATEGY: AttributeDuplicates;
const ON_DUPLICATE: OnDuplicate;
/// Converts a single syntactical attribute to a single semantic attribute, or [`AttributeKind`]
fn convert(cx: &AcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind>;
@@ -126,7 +106,7 @@ impl<T: SingleAttributeParser> AttributeParser for Single<T> {
// keep the first and error
AttributeDuplicates::ErrorFollowing => {
if let Some((_, unused)) = group.1 {
T::on_duplicate(cx, cx.attr_span, unused);
T::ON_DUPLICATE.exec::<T>(cx, cx.attr_span, unused);
return;
}
}
@@ -134,7 +114,7 @@ impl<T: SingleAttributeParser> AttributeParser for Single<T> {
// then replace
AttributeDuplicates::FutureWarnPreceding => {
if let Some((_, used)) = group.1 {
T::on_duplicate(cx, used, cx.attr_span);
T::ON_DUPLICATE.exec::<T>(cx, used, cx.attr_span);
}
}
}