diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index f13814527cdfd3a6ddb58b691839c85753a34814..bef9e6be8d96cff7bf1cf4cf80b27927ccd97338 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -2036,6 +2036,35 @@ fn get_lints(&self) -> LintArray { } } +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; diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index f57d7956edfe5846614cb7d3b152456abd52730d..76f874f2428781f23eef4201371c63256558ddd2 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -213,6 +213,7 @@ pub fn register_builtin(&mut self, sess: Option<&Session>) { UnstableFeatures, Stability, UnconditionalRecursion, + PrivateNoMangleFns, ); add_builtin_with_new!(sess,