diff options
| author | Caio <c410.f3r@gmail.com> | 2023-01-12 08:41:21 -0300 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2023-01-12 08:41:21 -0300 |
| commit | 7dd45bafb448ac7e24e751e51cdd2f65c9b7db3d (patch) | |
| tree | f4d375d54482ede7ec65ae499a89e5405cab76ce /compiler/rustc_passes | |
| parent | b22c152958eade17a71d899b29a2d39bcc77aa48 (diff) | |
| download | rust-7dd45bafb448ac7e24e751e51cdd2f65c9b7db3d.tar.gz rust-7dd45bafb448ac7e24e751e51cdd2f65c9b7db3d.zip | |
[RFC 2397] Deny incorrect locations
Diffstat (limited to 'compiler/rustc_passes')
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 7 |
2 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index c59c06ac31e..f9f9799d3e4 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -82,6 +82,7 @@ impl CheckAttrVisitor<'_> { let attrs = self.tcx.hir().attrs(hir_id); for attr in attrs { let attr_is_valid = match attr.name_or_empty() { + sym::do_not_recommend => self.check_do_not_recommend(attr.span, target), sym::inline => self.check_inline(hir_id, attr, span, target), sym::no_coverage => self.check_no_coverage(hir_id, attr, span, target), sym::non_exhaustive => self.check_non_exhaustive(hir_id, attr, span, target), @@ -241,6 +242,16 @@ impl CheckAttrVisitor<'_> { ); } + /// Checks if `#[do_not_recommend]` is applied on a trait impl. + fn check_do_not_recommend(&self, attr_span: Span, target: Target) -> bool { + if let Target::Impl = target { + true + } else { + self.tcx.sess.emit_err(errors::IncorrectDoNotRecommendLocation { span: attr_span }); + false + } + } + /// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid. fn check_inline(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool { match target { diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index c6cd69add28..9c6519ea4bb 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -14,6 +14,13 @@ use rustc_span::{Span, Symbol, DUMMY_SP}; use crate::lang_items::Duplicate; +#[derive(Diagnostic)] +#[diag(passes_incorrect_do_not_recommend_location)] +pub struct IncorrectDoNotRecommendLocation { + #[primary_span] + pub span: Span, +} + #[derive(LintDiagnostic)] #[diag(passes_outer_crate_level_attr)] pub struct OuterCrateLevelAttr; |
