diff options
| author | Jana Dönszelmann <jana@donsz.nl> | 2025-03-04 14:17:06 +0100 |
|---|---|---|
| committer | Jana Dönszelmann <jana@donsz.nl> | 2025-06-17 23:19:31 +0200 |
| commit | ee976bbbcaf85390a00f03dedacd035e7e274e8e (patch) | |
| tree | ac9ac3364e06bc17d8aec7742493ebeff2ab3c92 /compiler/rustc_attr_parsing/src/attributes/confusables.rs | |
| parent | 566f691374bff0461f2992e381e58539b0e5ae8a (diff) | |
| download | rust-ee976bbbcaf85390a00f03dedacd035e7e274e8e.tar.gz rust-ee976bbbcaf85390a00f03dedacd035e7e274e8e.zip | |
fix bugs in inline/force_inline and diagnostics of all attr parsers
Diffstat (limited to 'compiler/rustc_attr_parsing/src/attributes/confusables.rs')
| -rw-r--r-- | compiler/rustc_attr_parsing/src/attributes/confusables.rs | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/compiler/rustc_attr_parsing/src/attributes/confusables.rs b/compiler/rustc_attr_parsing/src/attributes/confusables.rs index afd3c012f05..0be9d690c32 100644 --- a/compiler/rustc_attr_parsing/src/attributes/confusables.rs +++ b/compiler/rustc_attr_parsing/src/attributes/confusables.rs @@ -1,4 +1,5 @@ use rustc_attr_data_structures::AttributeKind; +use rustc_feature::template; use rustc_span::{Span, Symbol, sym}; use thin_vec::ThinVec; @@ -13,37 +14,41 @@ pub(crate) struct ConfusablesParser { } impl<S: Stage> AttributeParser<S> for ConfusablesParser { - const ATTRIBUTES: AcceptMapping<Self, S> = &[(&[sym::rustc_confusables], |this, cx, args| { - let Some(list) = args.list() else { - // FIXME(jdonszelmann): error when not a list? Bring validation code here. - // NOTE: currently subsequent attributes are silently ignored using - // tcx.get_attr(). - return; - }; - - if list.is_empty() { - cx.emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span }); - } - - for param in list.mixed() { - let span = param.span(); - - let Some(lit) = param.lit() else { - cx.emit_err(session_diagnostics::IncorrectMetaItem { - span, - suggestion: Some(session_diagnostics::IncorrectMetaItemSuggestion { - lo: span.shrink_to_lo(), - hi: span.shrink_to_hi(), - }), - }); - continue; + const ATTRIBUTES: AcceptMapping<Self, S> = &[( + &[sym::rustc_confusables], + template!(List: r#""name1", "name2", ..."#), + |this, cx, args| { + let Some(list) = args.list() else { + // FIXME(jdonszelmann): error when not a list? Bring validation code here. + // NOTE: currently subsequent attributes are silently ignored using + // tcx.get_attr(). + return; }; - this.confusables.push(lit.symbol); - } - - this.first_span.get_or_insert(cx.attr_span); - })]; + if list.is_empty() { + cx.emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span }); + } + + for param in list.mixed() { + let span = param.span(); + + let Some(lit) = param.lit() else { + cx.emit_err(session_diagnostics::IncorrectMetaItem { + span, + suggestion: Some(session_diagnostics::IncorrectMetaItemSuggestion { + lo: span.shrink_to_lo(), + hi: span.shrink_to_hi(), + }), + }); + continue; + }; + + this.confusables.push(lit.symbol); + } + + this.first_span.get_or_insert(cx.attr_span); + }, + )]; fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> { if self.confusables.is_empty() { |
