mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-04 03:45:10 +00:00
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:
parent
52c74e63da
commit
44ff72195e
@ -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;
|
||||
|
@ -213,6 +213,7 @@ impl LintStore {
|
||||
UnstableFeatures,
|
||||
Stability,
|
||||
UnconditionalRecursion,
|
||||
PrivateNoMangleFns,
|
||||
);
|
||||
|
||||
add_builtin_with_new!(sess,
|
||||
|
Loading…
Reference in New Issue
Block a user