mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
parent
7a64588efa
commit
e28e73c81f
3 changed files with 15 additions and 1 deletions
|
@ -35,6 +35,7 @@ use std::ptr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
#[allow_unrooted_in_rc]
|
||||||
pub struct Promise {
|
pub struct Promise {
|
||||||
reflector: Reflector,
|
reflector: Reflector,
|
||||||
/// Since Promise values are natively reference counted without the knowledge of
|
/// Since Promise values are natively reference counted without the knowledge of
|
||||||
|
|
|
@ -41,5 +41,6 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
||||||
reg.register_late_lint_pass(Box::new(unrooted_must_root::UnrootedPass::new()));
|
reg.register_late_lint_pass(Box::new(unrooted_must_root::UnrootedPass::new()));
|
||||||
|
|
||||||
reg.register_attribute("allow_unrooted_interior".to_string(), Whitelisted);
|
reg.register_attribute("allow_unrooted_interior".to_string(), Whitelisted);
|
||||||
|
reg.register_attribute("allow_unrooted_in_rc".to_string(), Whitelisted);
|
||||||
reg.register_attribute("must_root".to_string(), Whitelisted);
|
reg.register_attribute("must_root".to_string(), Whitelisted);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,24 @@ fn is_unrooted_ty(cx: &LateContext, ty: &ty::TyS, in_new_function: bool) -> bool
|
||||||
let mut ret = false;
|
let mut ret = false;
|
||||||
ty.maybe_walk(|t| {
|
ty.maybe_walk(|t| {
|
||||||
match t.sty {
|
match t.sty {
|
||||||
ty::Adt(did, _) => {
|
ty::Adt(did, substs) => {
|
||||||
if cx.tcx.has_attr(did.did, "must_root") {
|
if cx.tcx.has_attr(did.did, "must_root") {
|
||||||
ret = true;
|
ret = true;
|
||||||
false
|
false
|
||||||
} else if cx.tcx.has_attr(did.did, "allow_unrooted_interior") {
|
} else if cx.tcx.has_attr(did.did, "allow_unrooted_interior") {
|
||||||
false
|
false
|
||||||
|
} else if match_def_path(cx, did.did, &["alloc", "rc", "Rc"]) {
|
||||||
|
// Rc<Promise> is okay
|
||||||
|
let inner = substs.type_at(0);
|
||||||
|
if let ty::Adt(did, _) = inner.sty {
|
||||||
|
if cx.tcx.has_attr(did.did, "allow_unrooted_in_rc") {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
} else if match_def_path(cx, did.did, &["core", "cell", "Ref"]) ||
|
} else if match_def_path(cx, did.did, &["core", "cell", "Ref"]) ||
|
||||||
match_def_path(cx, did.did, &["core", "cell", "RefMut"]) ||
|
match_def_path(cx, did.did, &["core", "cell", "RefMut"]) ||
|
||||||
match_def_path(cx, did.did, &["core", "slice", "Iter"]) ||
|
match_def_path(cx, did.did, &["core", "slice", "Iter"]) ||
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue