提交 44ff7219 编写于 作者: R Richo Healey

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.
上级 52c74e63
......@@ -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;
......
......@@ -213,6 +213,7 @@ pub fn register_builtin(&mut self, sess: Option<&Session>) {
UnstableFeatures,
Stability,
UnconditionalRecursion,
PrivateNoMangleFns,
);
add_builtin_with_new!(sess,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册