Giter Site home page Giter Site logo

rust-tenacious's Introduction

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:

#![plugin(tenacious)]
#![feature(custom_attribute, plugin)]

#[no_move]
#[derive(Debug)]
struct Foo;

fn main() {
    let x = Foo;
    let y = x; // warning
    bar(Some(y)); // warning   
}

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

}

struct MoreFoo {
    foos: Vec<Foo> // warning
}

#[no_move]
struct 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()``

Adding the #[allow(moved_no_move)] annotation to a struct will suppress warnings that the struct contains a #[no_move] type but is not marked as #[no_move]. The #[allow_movable_interior] attribute does the above and additionally permits moveable types in type parameters. See tests/run-pass/allow-move.rs for examples.

Be aware that if you depend on a crate using #[no_move], you must have #![plugin(tenacious)] in your own crate to see the warnings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.