lint: warn about #[no_mangle] fns that aren't exported

The usecase is that functions made visible to systems outside of the
rust ecosystem require the symbol to be visible.
This commit is contained in:
Richo Healey 2015-01-21 12:07:03 -08:00
parent 52c74e63da
commit 44ff72195e
2 changed files with 30 additions and 0 deletions

View File

@ -2036,6 +2036,35 @@ impl LintPass for HardwiredLints {
}
}
declare_lint! {
PRIVATE_NO_MANGLE_FNS,
Warn,
"functions marked #[no_mangle] should be exported"
}
#[derive(Copy)]
pub struct PrivateNoMangleFns;
impl LintPass for PrivateNoMangleFns {
fn get_lints(&self) -> LintArray {
lint_array!(PRIVATE_NO_MANGLE_FNS)
}
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
match it.node {
ast::ItemFn(..) => {
if attr::contains_name(it.attrs.as_slice(), "no_mangle") &&
!cx.exported_items.contains(&it.id) {
let msg = format!("function {} is marked #[no_mangle], but not exported",
it.ident);
cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg.as_slice());
}
},
_ => {},
}
}
}
/// Forbids using the `#[feature(...)]` attribute
#[derive(Copy)]
pub struct UnstableFeatures;

View File

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