Auto merge of #8073 - eefriedman:root-lint, r=Manishearth

Make unrooted_must_root a bit more aggressive.

Basically, instead of trying to check for specific kinds of statements,
just check the types of all local variables.

Also included are some commented-out proposals for some slightly more
aggressive lints which might be useful (but trigger a little too
frequently at the moment).

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-24 20:20:04 -05:00
commit bb88832c07
7 changed files with 101 additions and 95 deletions

View file

@ -310,11 +310,13 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
/// Retrieve a copy of the inner optional `JS<T>` as `LayoutJS<T>`.
/// For use by layout, which can't use safe types like Temporary.
#[allow(unrooted_must_root)]
pub unsafe fn get_inner_as_layout(&self) -> Option<LayoutJS<T>> {
ptr::read(self.ptr.get()).map(|js| js.to_layout())
}
/// Get a rooted value out of this object
#[allow(unrooted_must_root)]
pub fn get(&self) -> Option<Root<T>> {
unsafe {
ptr::read(self.ptr.get()).map(|o| o.root())

View file

@ -431,6 +431,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::SaveContext)).unwrap();
}
#[allow(unrooted_must_root)]
// https://html.spec.whatwg.org/multipage/#dom-context-2d-restore
fn Restore(&self) {
let mut saved_states = self.saved_states.borrow_mut();

View file

@ -18,6 +18,7 @@ pub struct FileList {
}
impl FileList {
#[allow(unrooted_must_root)]
fn new_inherited(files: Vec<JS<File>>) -> FileList {
FileList {
reflector_: Reflector::new(),
@ -25,6 +26,7 @@ impl FileList {
}
}
#[allow(unrooted_must_root)]
pub fn new(window: &Window, files: Vec<JS<File>>) -> Root<FileList> {
reflect_dom_object(box FileList::new_inherited(files), GlobalRef::Window(window), FileListBinding::Wrap)
}

View file

@ -32,6 +32,7 @@ pub struct HTMLCollection {
}
impl HTMLCollection {
#[allow(unrooted_must_root)]
fn new_inherited(collection: Collection) -> HTMLCollection {
HTMLCollection {
reflector_: Reflector::new(),
@ -39,6 +40,7 @@ impl HTMLCollection {
}
}
#[allow(unrooted_must_root)]
pub fn new(window: &Window, collection: Collection) -> Root<HTMLCollection> {
reflect_dom_object(box HTMLCollection::new_inherited(collection),
GlobalRef::Window(window), HTMLCollectionBinding::Wrap)

View file

@ -27,6 +27,7 @@ pub struct NodeList {
}
impl NodeList {
#[allow(unrooted_must_root)]
fn new_inherited(list_type: NodeListType) -> NodeList {
NodeList {
reflector_: Reflector::new(),
@ -34,6 +35,7 @@ impl NodeList {
}
}
#[allow(unrooted_must_root)]
pub fn new(window: &Window,
list_type: NodeListType) -> Root<NodeList> {
reflect_dom_object(box NodeList::new_inherited(list_type),

View file

@ -109,6 +109,7 @@ impl WebGLRenderingContext {
})
}
#[allow(unrooted_must_root)]
pub fn new(global: GlobalRef, canvas: &HTMLCanvasElement, size: Size2D<i32>, attrs: GLContextAttributes)
-> Option<Root<WebGLRenderingContext>> {
match WebGLRenderingContext::new_inherited(global, canvas, size, attrs) {