diff --git a/Cargo.lock b/Cargo.lock index 3436121..030b228 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "rls-data" -version = "0.5.0" +version = "0.6.0" dependencies = [ "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 7535133..fbef6e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,6 @@ categories = ["development-tools"] [dependencies] rls-span = { version = "0.4", features = ["serialize-rustc"] } rustc-serialize = "0.3" + +[features] +borrows=[] diff --git a/src/lib.rs b/src/lib.rs index 4f9e634..4fdf7e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,9 +42,12 @@ pub struct Analysis { pub refs: Vec, pub macro_refs: Vec, pub relations: Vec, + #[cfg(feature = "borrows")] + pub per_fn_borrows: Vec, } impl Analysis { + #[cfg(not(feature = "borrows"))] pub fn new() -> Analysis { Analysis { kind: Format::Json, @@ -57,6 +60,21 @@ impl Analysis { relations: vec![], } } + + #[cfg(feature = "borrows")] + pub fn new() -> Analysis { + Analysis { + kind: Format::Json, + prelude: None, + imports: vec![], + defs: vec![], + impls: vec![], + refs: vec![], + macro_refs: vec![], + relations: vec![], + per_fn_borrows: vec![], + } + } } // DefId::index is a newtype and so the JSON serialisation is ugly. Therefore @@ -240,3 +258,52 @@ pub struct SigElement { pub start: usize, pub end: usize, } + +// Each `BorrowData` represents all of the scopes, loans and moves +// within an fn or closure referred to by `ref_id`. +#[cfg(feature = "borrows")] +#[derive(Debug, Clone, RustcDecodable, RustcEncodable)] +pub struct BorrowData { + pub ref_id: Id, + pub scopes: Vec, + pub loans: Vec, + pub moves: Vec, +} + +#[cfg(feature = "borrows")] +#[derive(Debug, RustcDecodable, RustcEncodable, Clone, Copy)] +pub enum BorrowKind { + ImmBorrow, + MutBorrow, +} + +// Each `Loan` is either temporary or assigned to a variable. +// The `ref_id` refers to the value that is being loaned/borrowed. +// Not all loans will be valid. Invalid loans can be used to help explain +// improper usage. +#[cfg(feature = "borrows")] +#[derive(Debug, Clone, RustcDecodable, RustcEncodable)] +pub struct Loan { + pub ref_id: Id, + pub kind: BorrowKind, + pub span: SpanData, +} + +// Each `Move` represents an attempt to move the value referred to by `ref_id`. +// Not all `Move`s will be valid but can be used to help explain improper usage. +#[cfg(feature = "borrows")] +#[derive(Debug, Clone, RustcDecodable, RustcEncodable)] +pub struct Move { + pub ref_id: Id, + pub span: SpanData, +} + +// Each `Scope` refers to "scope" of a variable (we don't track all values here). +// Its ref_id refers to the variable, and the span refers to the scope/region where +// the variable is "live". +#[cfg(feature = "borrows")] +#[derive(Debug, Clone, RustcDecodable, RustcEncodable)] +pub struct Scope { + pub ref_id: Id, + pub span: SpanData, +}