X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=compiler%2Frustc_passes%2Fsrc%2Fcheck_attr.rs;h=8a8d88d7bf4adc65b1331a912413676d752be00f;hb=e614bbcd301eb4c3dbb65a4aa3147dc0b6ff197c;hp=f3ccbbb56792dc3493c88a2487fec396a6ecb669;hpb=ff693dc7b8119a1761edf0d08156bb670708824a;p=rust.git diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index f3ccbbb5679..8a8d88d7bf4 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -121,6 +121,10 @@ fn check_attributes( sym::rustc_lint_diagnostics => { self.check_rustc_lint_diagnostics(&attr, span, target) } + sym::rustc_lint_opt_ty => self.check_rustc_lint_opt_ty(&attr, span, target), + sym::rustc_lint_opt_deny_field_access => { + self.check_rustc_lint_opt_deny_field_access(&attr, span, target) + } sym::rustc_clean | sym::rustc_dirty | sym::rustc_if_this_changed @@ -142,6 +146,7 @@ fn check_attributes( | sym::stable | sym::rustc_allowed_through_unstable_modules | sym::rustc_promotable => self.check_stability_promotable(&attr, span, target), + sym::link_ordinal => self.check_link_ordinal(&attr, span, target), _ => true, }; is_valid &= attr_is_valid; @@ -1382,6 +1387,35 @@ fn check_rustc_lint_diagnostics(&self, attr: &Attribute, span: Span, target: Tar self.check_applied_to_fn_or_method(attr, span, target) } + /// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct. + fn check_rustc_lint_opt_ty(&self, attr: &Attribute, span: Span, target: Target) -> bool { + match target { + Target::Struct => true, + _ => { + self.tcx.sess.emit_err(errors::RustcLintOptTy { attr_span: attr.span, span }); + false + } + } + } + + /// Checks that the `#[rustc_lint_opt_deny_field_access]` attribute is only applied to a field. + fn check_rustc_lint_opt_deny_field_access( + &self, + attr: &Attribute, + span: Span, + target: Target, + ) -> bool { + match target { + Target::Field => true, + _ => { + self.tcx + .sess + .emit_err(errors::RustcLintOptDenyFieldAccess { attr_span: attr.span, span }); + false + } + } + } + /// Checks that the dep-graph debugging attributes are only present when the query-dep-graph /// option is passed to the compiler. fn check_rustc_dirty_clean(&self, attr: &Attribute) -> bool { @@ -1828,6 +1862,16 @@ fn check_stability_promotable(&self, attr: &Attribute, _span: Span, target: Targ } } + fn check_link_ordinal(&self, attr: &Attribute, _span: Span, target: Target) -> bool { + match target { + Target::ForeignFn | Target::ForeignStatic => true, + _ => { + self.tcx.sess.emit_err(errors::LinkOrdinal { attr_span: attr.span }); + false + } + } + } + fn check_deprecated(&self, hir_id: HirId, attr: &Attribute, _span: Span, target: Target) { match target { Target::Closure | Target::Expression | Target::Statement | Target::Arm => {