]>
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 extern crate rustc_serialize
;
14 extern crate rls_span
as span
;
16 #[cfg(feature = "serialize-serde")]
18 #[cfg(feature = "serialize-serde")]
20 extern crate serde_derive
;
24 use std
::path
::PathBuf
;
29 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
32 /// The Config used to generate this analysis data.
34 pub prelude
: Option
<CratePreludeData
>,
35 pub imports
: Vec
<Import
>,
39 pub macro_refs
: Vec
<MacroRef
>,
40 pub relations
: Vec
<Relation
>,
41 #[cfg(feature = "borrows")]
42 pub per_fn_borrows
: Vec
<BorrowData
>,
46 #[cfg(not(feature = "borrows"))]
47 pub fn new(config
: Config
) -> Analysis
{
60 #[cfg(feature = "borrows")]
61 pub fn new(config
: Config
) -> Analysis
{
71 per_fn_borrows
: vec
![],
76 // DefId::index is a newtype and so the JSON serialisation is ugly. Therefore
77 // we use our own Id which is the same, but without the newtype.
78 #[derive(Clone, Copy, Debug, RustcDecodable, RustcEncodable, PartialEq, Eq, Hash)]
84 /// Crate name, along with its disambiguator (128-bit hash) represents a globally
85 /// unique crate identifier, which should allow for differentiation between
86 /// different crate targets or versions and should point to the same crate when
87 /// pulled by different other, dependent crates.
88 #[derive(Debug, Clone, RustcDecodable, RustcEncodable, PartialEq, Eq, Hash)]
89 pub struct GlobalCrateId
{
91 pub disambiguator
: (u64, u64),
94 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
96 pub file_name
: PathBuf
,
99 pub line_start
: span
::Row
<span
::OneIndexed
>,
100 pub line_end
: span
::Row
<span
::OneIndexed
>,
102 pub column_start
: span
::Column
<span
::OneIndexed
>,
103 pub column_end
: span
::Column
<span
::OneIndexed
>,
106 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
107 pub struct CratePreludeData
{
108 pub crate_id
: GlobalCrateId
,
109 pub crate_root
: String
,
110 pub external_crates
: Vec
<ExternalCrateData
>,
114 /// Data for external crates in the prelude of a crate.
115 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
116 pub struct ExternalCrateData
{
117 /// Source file where the external crate is declared.
118 pub file_name
: String
,
119 /// A crate-local crate index of an external crate. Local crate index is
120 /// always 0, so these should start from 1 and range should be contiguous,
121 /// e.g. from 1 to n for n external crates.
123 pub id
: GlobalCrateId
,
126 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
128 pub kind
: ImportKind
,
129 pub ref_id
: Option
<Id
>,
133 pub parent
: Option
<Id
>,
136 #[derive(Debug, RustcDecodable, RustcEncodable, Clone, Copy, PartialEq, Eq)]
137 pub enum ImportKind
{
143 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
149 pub qualname
: String
,
151 pub parent
: Option
<Id
>,
152 pub children
: Vec
<Id
>,
153 pub decl_id
: Option
<Id
>,
155 pub sig
: Option
<Signature
>,
156 pub attributes
: Vec
<Attribute
>,
159 #[derive(Debug, RustcDecodable, RustcEncodable, Clone, Copy, PartialEq, Eq)]
161 // value = variant names
163 // value = enum name + variant name + types
165 // value = enum name + name + fields
167 // value = variant name + types
169 // value = name + fields
174 // value = type + generics
176 // value = type + generics
182 // value = aliased type
184 // value = type and init expression (for all variable kinds).
193 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
199 pub parent
: Option
<Id
>,
200 pub children
: Vec
<Id
>,
202 pub sig
: Option
<Signature
>,
203 pub attributes
: Vec
<Attribute
>,
206 #[derive(Debug, RustcDecodable, RustcEncodable, Clone, PartialEq, Eq)]
210 // impl Bar for Foo { ... }
212 // impl Bar for &Foo { ... }
214 // impl<T: Baz> Bar for T { ... }
217 // impl Bar for Baz { ... } or impl Baz { ... }, etc.
218 // where Foo: Deref<Target = Baz>
219 // Args are name and id of Baz
223 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
224 pub struct Attribute
{
229 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
236 #[derive(Debug, RustcDecodable, RustcEncodable, Clone, Copy, PartialEq, Eq)]
244 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
245 pub struct MacroRef
{
247 pub qualname
: String
,
248 pub callee_span
: SpanData
,
251 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
252 pub struct Relation
{
254 pub kind
: RelationKind
,
259 #[derive(Debug, RustcDecodable, RustcEncodable, Clone, Copy, PartialEq, Eq)]
260 pub enum RelationKind
{
267 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
268 pub struct Signature
{
270 pub defs
: Vec
<SigElement
>,
271 pub refs
: Vec
<SigElement
>,
274 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
275 pub struct SigElement
{
281 // Each `BorrowData` represents all of the scopes, loans and moves
282 // within an fn or closure referred to by `ref_id`.
283 #[cfg(feature = "borrows")]
284 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
285 pub struct BorrowData
{
287 pub scopes
: Vec
<Scope
>,
288 pub loans
: Vec
<Loan
>,
289 pub moves
: Vec
<Move
>,
290 pub span
: Option
<SpanData
>,
293 #[cfg(feature = "borrows")]
294 #[derive(Debug, RustcDecodable, RustcEncodable, Clone, Copy)]
295 pub enum BorrowKind
{
300 // Each `Loan` is either temporary or assigned to a variable.
301 // The `ref_id` refers to the value that is being loaned/borrowed.
302 // Not all loans will be valid. Invalid loans can be used to help explain
304 #[cfg(feature = "borrows")]
305 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
308 pub kind
: BorrowKind
,
312 // Each `Move` represents an attempt to move the value referred to by `ref_id`.
313 // Not all `Move`s will be valid but can be used to help explain improper usage.
314 #[cfg(feature = "borrows")]
315 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]
321 // Each `Scope` refers to "scope" of a variable (we don't track all values here).
322 // Its ref_id refers to the variable, and the span refers to the scope/region where
323 // the variable is "live".
324 #[cfg(feature = "borrows")]
325 #[derive(Debug, Clone, RustcDecodable, RustcEncodable)]