lint: Deny #[no_mangle] const items

This renames the PrivateNoMangleFns lint to allow both to happen in a
single pass, since they do roughly the same work.
This commit is contained in:
Richo Healey 2015-02-02 19:33:50 -08:00
parent eaf4c5c784
commit 51ed1ecefd
3 changed files with 26 additions and 6 deletions

View File

@ -2065,12 +2065,19 @@ declare_lint! {
"functions marked #[no_mangle] should be exported" "functions marked #[no_mangle] should be exported"
} }
#[derive(Copy)] declare_lint! {
pub struct PrivateNoMangleFns; NO_MANGLE_CONST_ITEMS,
Deny,
"const items will not have their symbols exported"
}
impl LintPass for PrivateNoMangleFns { #[derive(Copy)]
pub struct InvalidNoMangleItems;
impl LintPass for InvalidNoMangleItems {
fn get_lints(&self) -> LintArray { fn get_lints(&self) -> LintArray {
lint_array!(PRIVATE_NO_MANGLE_FNS) lint_array!(PRIVATE_NO_MANGLE_FNS,
NO_MANGLE_CONST_ITEMS)
} }
fn check_item(&mut self, cx: &Context, it: &ast::Item) { fn check_item(&mut self, cx: &Context, it: &ast::Item) {
@ -2083,6 +2090,12 @@ impl LintPass for PrivateNoMangleFns {
cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg.as_slice()); cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg.as_slice());
} }
}, },
ast::ItemConst(..) => {
if attr::contains_name(it.attrs.as_slice(), "no_mangle") {
let msg = "const items should never be #[no_mangle]";
cx.span_lint(NO_MANGLE_CONST_ITEMS, it.span, msg);
}
}
_ => {}, _ => {},
} }
} }

View File

@ -213,7 +213,7 @@ impl LintStore {
UnstableFeatures, UnstableFeatures,
Stability, Stability,
UnconditionalRecursion, UnconditionalRecursion,
PrivateNoMangleFns, InvalidNoMangleItems,
); );
add_builtin_with_new!(sess, add_builtin_with_new!(sess,

View File

@ -8,13 +8,20 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// compile-flags:-F private_no_mangle_fns // compile-flags:-F private_no_mangle_fns -F no_mangle_const_items
// FIXME(#19495) no_mangle'ing main ICE's. // FIXME(#19495) no_mangle'ing main ICE's.
#[no_mangle] #[no_mangle]
fn foo() { //~ ERROR function foo is marked #[no_mangle], but not exported fn foo() { //~ ERROR function foo is marked #[no_mangle], but not exported
} }
#[allow(dead_code)]
#[no_mangle]
const FOO: u64 = 1; //~ ERROR const items should never be #[no_mangle]
#[no_mangle]
pub const PUB_FOO: u64 = 1; //~ ERROR const items should never be #[no_mangle]
#[no_mangle] #[no_mangle]
pub fn bar() { pub fn bar() {
} }