|
| 1 | +use rustc_feature::{AttributeTemplate, template}; |
| 2 | +use rustc_hir::attrs::AttributeKind; |
| 3 | +use rustc_hir::lints::AttributeLintKind; |
| 4 | +use rustc_session::lint::builtin::MALFORMED_DIAGNOSTIC_ATTRIBUTES; |
| 5 | +use rustc_span::{Symbol, sym}; |
| 6 | + |
| 7 | +use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser}; |
| 8 | +use crate::context::{AcceptContext, Stage}; |
| 9 | +use crate::parser::ArgParser; |
| 10 | +use crate::target_checking::{ALL_TARGETS, AllowedTargets}; |
| 11 | + |
| 12 | +pub(crate) struct DoNotRecommendParser; |
| 13 | +impl<S: Stage> SingleAttributeParser<S> for DoNotRecommendParser { |
| 14 | + const PATH: &[Symbol] = &[sym::diagnostic, sym::do_not_recommend]; |
| 15 | + const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; |
| 16 | + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn; |
| 17 | + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); // Checked in check_attr. |
| 18 | + const TEMPLATE: AttributeTemplate = template!(Word /*doesn't matter */); |
| 19 | + |
| 20 | + fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> { |
| 21 | + let attr_span = cx.attr_span; |
| 22 | + if !matches!(args, ArgParser::NoArgs) { |
| 23 | + cx.emit_lint( |
| 24 | + MALFORMED_DIAGNOSTIC_ATTRIBUTES, |
| 25 | + AttributeLintKind::DoNotRecommendDoesNotExpectArgs, |
| 26 | + attr_span, |
| 27 | + ); |
| 28 | + } |
| 29 | + Some(AttributeKind::DoNotRecommend { attr_span }) |
| 30 | + } |
| 31 | +} |
0 commit comments