]>
git.proxmox.com Git - rustc.git/blob - src/vendor/rls-data/src/lib.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // at http://rust-lang.org/COPYRIGHT.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![cfg_attr(rustbuild, feature(staged_api, rustc_private))]
11 #![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))]
13 #[cfg(feature = "serialize-rustc")]
14 extern crate rustc_serialize
;
15 extern crate rls_span
as span
;
17 #[cfg(feature = "serialize-serde")]
19 #[cfg(feature = "serialize-serde")]
21 extern crate serde_derive
;
25 use std
::path
::PathBuf
;
30 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
31 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
32 #[derive(Debug, Clone)]
35 /// The Config used to generate this analysis data.
37 pub version
: Option
<String
>,
38 pub prelude
: Option
<CratePreludeData
>,
39 pub imports
: Vec
<Import
>,
43 pub macro_refs
: Vec
<MacroRef
>,
44 pub relations
: Vec
<Relation
>,
45 #[cfg(feature = "borrows")]
46 pub per_fn_borrows
: Vec
<BorrowData
>,
50 #[cfg(not(feature = "borrows"))]
51 pub fn new(config
: Config
) -> Analysis
{
54 version
: option_env
!("CARGO_PKG_VERSION").map(|s
| s
.to_string()),
65 #[cfg(feature = "borrows")]
66 pub fn new(config
: Config
) -> Analysis
{
69 version
: option_env
!("CARGO_PKG_VERSION").map(|s
| s
.to_string()),
77 per_fn_borrows
: vec
![],
82 // DefId::index is a newtype and so the JSON serialisation is ugly. Therefore
83 // we use our own Id which is the same, but without the newtype.
84 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
85 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
86 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
92 /// Crate name, along with its disambiguator (128-bit hash) represents a globally
93 /// unique crate identifier, which should allow for differentiation between
94 /// different crate targets or versions and should point to the same crate when
95 /// pulled by different other, dependent crates.
96 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
97 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
98 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
99 pub struct GlobalCrateId
{
101 pub disambiguator
: (u64, u64),
104 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
105 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
106 #[derive(Debug, Clone)]
107 pub struct SpanData
{
108 pub file_name
: PathBuf
,
111 pub line_start
: span
::Row
<span
::OneIndexed
>,
112 pub line_end
: span
::Row
<span
::OneIndexed
>,
114 pub column_start
: span
::Column
<span
::OneIndexed
>,
115 pub column_end
: span
::Column
<span
::OneIndexed
>,
118 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
119 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
120 #[derive(Debug, Clone)]
121 pub struct CratePreludeData
{
122 pub crate_id
: GlobalCrateId
,
123 pub crate_root
: String
,
124 pub external_crates
: Vec
<ExternalCrateData
>,
128 /// Data for external crates in the prelude of a crate.
129 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
130 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
131 #[derive(Debug, Clone)]
132 pub struct ExternalCrateData
{
133 /// Source file where the external crate is declared.
134 pub file_name
: String
,
135 /// A crate-local crate index of an external crate. Local crate index is
136 /// always 0, so these should start from 1 and range should be contiguous,
137 /// e.g. from 1 to n for n external crates.
139 pub id
: GlobalCrateId
,
142 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
143 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
144 #[derive(Debug, Clone)]
146 pub kind
: ImportKind
,
147 pub ref_id
: Option
<Id
>,
149 pub alias_span
: Option
<SpanData
>,
152 pub parent
: Option
<Id
>,
155 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
156 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
157 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
158 pub enum ImportKind
{
164 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
165 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
166 #[derive(Debug, Clone)]
172 pub qualname
: String
,
174 pub parent
: Option
<Id
>,
175 pub children
: Vec
<Id
>,
176 pub decl_id
: Option
<Id
>,
178 pub sig
: Option
<Signature
>,
179 pub attributes
: Vec
<Attribute
>,
182 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
183 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
184 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
186 // value = variant names
188 // value = enum name + variant name + types
190 // value = enum name + name + fields
192 // value = variant name + types
194 // value = name + fields
199 // value = type + generics
202 // value = type + generics
208 // value = aliased type
210 // value = type and init expression (for all variable kinds).
220 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
221 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
222 #[derive(Debug, Clone)]
228 pub parent
: Option
<Id
>,
229 pub children
: Vec
<Id
>,
231 pub sig
: Option
<Signature
>,
232 pub attributes
: Vec
<Attribute
>,
235 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
236 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
237 #[derive(Debug, Clone, PartialEq, Eq)]
241 // impl Bar for Foo { ... }
243 // impl Bar for &Foo { ... }
245 // impl<T: Baz> Bar for T { ... }
248 // impl Bar for Baz { ... } or impl Baz { ... }, etc.
249 // where Foo: Deref<Target = Baz>
250 // Args are name and id of Baz
254 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
255 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
256 #[derive(Debug, Clone)]
257 pub struct Attribute
{
262 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
263 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
264 #[derive(Debug, Clone)]
271 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
272 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
273 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
281 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
282 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
283 #[derive(Debug, Clone)]
284 pub struct MacroRef
{
286 pub qualname
: String
,
287 pub callee_span
: SpanData
,
290 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
291 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
292 #[derive(Debug, Clone)]
293 pub struct Relation
{
295 pub kind
: RelationKind
,
300 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
301 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
302 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
303 pub enum RelationKind
{
310 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
311 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
312 #[derive(Debug, Clone)]
313 pub struct Signature
{
315 pub defs
: Vec
<SigElement
>,
316 pub refs
: Vec
<SigElement
>,
319 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
320 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
321 #[derive(Debug, Clone)]
322 pub struct SigElement
{
328 // Each `BorrowData` represents all of the scopes, loans and moves
329 // within an fn or closure referred to by `ref_id`.
330 #[cfg(feature = "borrows")]
331 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
332 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
333 #[derive(Debug, Clone)]
334 pub struct BorrowData
{
336 pub scopes
: Vec
<Scope
>,
337 pub loans
: Vec
<Loan
>,
338 pub moves
: Vec
<Move
>,
339 pub span
: Option
<SpanData
>,
342 #[cfg(feature = "borrows")]
343 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
344 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
345 #[derive(Debug, Clone, Copy)]
346 pub enum BorrowKind
{
351 // Each `Loan` is either temporary or assigned to a variable.
352 // The `ref_id` refers to the value that is being loaned/borrowed.
353 // Not all loans will be valid. Invalid loans can be used to help explain
355 #[cfg(feature = "borrows")]
356 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
357 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
358 #[derive(Debug, Clone)]
361 pub kind
: BorrowKind
,
365 // Each `Move` represents an attempt to move the value referred to by `ref_id`.
366 // Not all `Move`s will be valid but can be used to help explain improper usage.
367 #[cfg(feature = "borrows")]
368 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
369 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
370 #[derive(Debug, Clone)]
376 // Each `Scope` refers to "scope" of a variable (we don't track all values here).
377 // Its ref_id refers to the variable, and the span refers to the scope/region where
378 // the variable is "live".
379 #[cfg(feature = "borrows")]
380 #[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
381 #[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
382 #[derive(Debug, Clone)]