Skip to content

Commit

Permalink
lint: warn about #[no_mangle] fns that aren't exported
Browse files Browse the repository at this point in the history
The usecase is that functions made visible to systems outside of the
rust ecosystem require the symbol to be visible.
  • Loading branch information
richo committed Jan 30, 2015
1 parent 52c74e6 commit 44ff721
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/librustc/lint/builtin.rs
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lint/context.rs
Expand Up @@ -213,6 +213,7 @@ impl LintStore {
UnstableFeatures,
Stability,
UnconditionalRecursion,
PrivateNoMangleFns,
);

add_builtin_with_new!(sess,
Expand Down

0 comments on commit 44ff721

Please sign in to comment.