Skip to content

Commit

Permalink
Added compiler lint ban on DOMRefCell
Browse files Browse the repository at this point in the history
  • Loading branch information
yoava333 committed Mar 9, 2016
1 parent 25c6c29 commit 444eddb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/plugins/lints/ban.rs
Expand Up @@ -37,5 +37,11 @@ impl EarlyLintPass for BanPass {
.is_some() {
cx.span_lint(BANNED_TYPE, ty.span, "Banned type Cell<JSVal> detected. Use MutHeap<JSVal> instead")
}
if match_ty_unwrap(ty, &["dom", "bindings", "cell", "DOMRefCell"])
.and_then(|t| t.get(0))
.and_then(|t| match_ty_unwrap(&**t, &["dom", "bindings", "js", "JS"]))
.is_some() {
cx.span_lint(BANNED_TYPE, ty.span, "Banned type DOMRefCell<JS<T>> detected. Use MutHeap<JS<T>> instead")
}
}
}
1 change: 1 addition & 0 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/compiletest/plugin/Cargo.toml
Expand Up @@ -13,3 +13,6 @@ path = "../helper"

[dependencies.plugins]
path = "../../../components/plugins"

[dependencies.script]
path = "../../../components/script"
19 changes: 19 additions & 0 deletions tests/compiletest/plugin/compile-fail/ban-domrefcell.rs
@@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#![feature(plugin)]
#![plugin(plugins)]

extern crate script;

use script::dom::bindings::cell::DOMRefCell;
use script::dom::bindings::js::JS;
use script::dom::node::Node;

struct Foo {
bar: DOMRefCell<JS<Node>>
//~^ ERROR Banned type DOMRefCell<JS<T>> detected. Use MutHeap<JS<T>> instead,
}

fn main() {}

0 comments on commit 444eddb

Please sign in to comment.