Skip to content

Commit

Permalink
Disallow #[no_mangle]
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Aug 8, 2014
1 parent 5804e14 commit f9e452e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions example.rs
Expand Up @@ -2,6 +2,7 @@

extern crate getopts;

#[no_mangle]
fn main() {
unsafe { }
}
25 changes: 24 additions & 1 deletion src/chamber_plugin/lib.rs
Expand Up @@ -41,6 +41,9 @@ pub fn plugin_registrar(reg: &mut Registry) {
fail!("can't get arguments for crate limit");
}
}

// #[no_mangle] can be used to override weak symbols
reg.register_lint_pass(box NoManglePass);
}

local_data_key!(key_params: String)
Expand Down Expand Up @@ -110,7 +113,7 @@ impl CrateLimitPass {
}

declare_lint!(CH_CRATE_LIMIT, Forbid,
"enforces")
"enforces limits on which crates can be linked")

impl LintPass for CrateLimitPass {
fn get_lints(&self) -> LintArray {
Expand Down Expand Up @@ -144,3 +147,23 @@ impl LintPass for CrateLimitPass {
}
}

struct NoManglePass;

declare_lint!(CH_NO_MANGLE, Forbid,
"forbids #[no_mangle]")

impl LintPass for NoManglePass {
fn get_lints(&self) -> LintArray {
lint_array!(CH_NO_MANGLE)
}

fn check_attribute(&mut self, ctx: &Context, attr: &ast::Attribute) {

use syntax::attr;

if attr::contains_name(&[attr.node.value], "no_mangle") {
ctx.span_lint(CH_NO_MANGLE, attr.span, "chamber: no_mangle");
}
}
}

0 comments on commit f9e452e

Please sign in to comment.