diff options
| author | Caleb Zulawski <caleb.zulawski@gmail.com> | 2020-09-05 22:12:24 -0400 |
|---|---|---|
| committer | Caleb Zulawski <caleb.zulawski@gmail.com> | 2020-09-05 22:12:24 -0400 |
| commit | 8f69266f799c2fc33a871c41f72a1d79eef4126e (patch) | |
| tree | ac6bc06d04fa27cd723047ebb9136b5a7585e055 /compiler/rustc_passes/src | |
| parent | acd68b503d033e0fc94fb5e68cb06ce369b6bd63 (diff) | |
| download | rust-8f69266f799c2fc33a871c41f72a1d79eef4126e.tar.gz rust-8f69266f799c2fc33a871c41f72a1d79eef4126e.zip | |
Emit warnings on misplaced #[no_mangle]
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 5fb59012fb7..efe947daa28 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -83,6 +83,8 @@ impl CheckAttrVisitor<'tcx> { self.check_link_name(hir_id, attr, span, target); } else if self.tcx.sess.check_name(attr, sym::link_section) { self.check_link_section(hir_id, attr, span, target); + } else if self.tcx.sess.check_name(attr, sym::no_mangle) { + self.check_no_mangle(hir_id, attr, span, target); } true }; @@ -419,6 +421,27 @@ impl CheckAttrVisitor<'tcx> { } } + /// Checks if `#[no_mangle]` is applied to a function or static. + fn check_no_mangle(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) { + match target { + Target::Static | Target::Fn | Target::Method(..) => {} + _ => { + // FIXME: #[no_mangle] was previously allowed on non-functions/statics and some + // crates used this, so only emit a warning. + self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| { + lint.build("attribute should be applied to a function or static") + .warn( + "this was previously accepted by the compiler but is \ + being phased out; it will become a hard error in \ + a future release!", + ) + .span_label(*span, "not a function or static") + .emit(); + }); + } + } + } + /// Checks if the `#[repr]` attributes on `item` are valid. fn check_repr( &self, |
