servo/rust-tenacious

Name: rust-tenacious

Owner: Servo

Description: Lint to disallow the moving of marked types in Rust

Created: 2015-07-03 19:34:30.0

Updated: 2018-01-22 18:46:09.0

Pushed: 2015-08-13 18:09:58.0

Homepage:

Size: 105

Language: Rust

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

rust-tenacious

Build Status

This plugin warns when types marked #[no_move] are being moved.

This is quite useful for ensuring that things don't get moved around when data is shared via an FFI. Servo uses this for safely sharing rooted values with the spidermonkey GC.

Note that #[no_move] is transitive, any struct or enum containing a #[no_move] type must be annotated as well. Similarly, any type with #[no_move] substitutions in its type parameters (E.g. Vec<Foo> where Foo is no_move) will be treated as immovable.

Example:

lugin(tenacious)]
eature(custom_attribute, plugin)]

_move]
rive(Debug)]
ct Foo;

ain() {
let x = Foo;
let y = x; // warning
bar(Some(y)); // warning   


ar(t: Option<Foo>) {
match t {
    Some(foo) => { // warning
        println!("{:?}", foo)
    },
    _ => ()
}



ct MoreFoo {
foos: Vec<Foo> // warning


_move]
ct MoreFoo2 {
foos: Vec<Foo> // no warning

Note that this will not lint on the moving of temporaries (though it's easy to tweak it to do so). For example, if foo() returns a move-protected value, bar(foo()) will not error even though let x = foo(); bar(x) will, since the value returned by foo() is a temporary (rvalue) and doesn't actualy get moved in memory.

It also will not catch moves within generic functions like mem::swap() and mem::replace()`


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.