Skip to content

Commit eb27b51

Browse files
committed
field signatures
1 parent c53fa9a commit eb27b51

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

src/librustc_save_analysis/data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ pub struct VariableData {
387387
pub type_value: String,
388388
pub visibility: Visibility,
389389
pub docs: String,
390+
pub sig: Option<Signature>,
390391
}
391392

392393
#[derive(Debug, RustcEncodable)]

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
372372
parent: None,
373373
visibility: Visibility::Inherited,
374374
docs: String::new(),
375+
sig: None,
375376
}.lower(self.tcx));
376377
}
377378
}
@@ -587,6 +588,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
587588
parent: Some(parent_id),
588589
visibility: vis,
589590
docs: docs_for_attrs(attrs),
591+
sig: None,
590592
}.lower(self.tcx));
591593
}
592594

@@ -1072,6 +1074,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
10721074
parent: None,
10731075
visibility: Visibility::Inherited,
10741076
docs: String::new(),
1077+
sig: None,
10751078
}.lower(self.tcx));
10761079
}
10771080
}
@@ -1521,6 +1524,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll,
15211524
parent: None,
15221525
visibility: Visibility::Inherited,
15231526
docs: String::new(),
1527+
sig: None,
15241528
}.lower(self.tcx));
15251529
}
15261530
}

src/librustc_save_analysis/external_data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ pub struct VariableData {
658658
pub parent: Option<DefId>,
659659
pub visibility: Visibility,
660660
pub docs: String,
661+
pub sig: Option<Signature>,
661662
}
662663

663664
impl Lower for data::VariableData {
@@ -676,6 +677,7 @@ impl Lower for data::VariableData {
676677
parent: self.parent,
677678
visibility: self.visibility,
678679
docs: self.docs,
680+
sig: self.sig.map(|s| s.lower(tcx)),
679681
}
680682
}
681683
}

src/librustc_save_analysis/json_api_dumper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl From<VariableData> for Option<Def> {
419419
parent: data.parent.map(|id| From::from(id)),
420420
decl_id: None,
421421
docs: data.docs,
422-
sig: None,
422+
sig: data.sig,
423423
}),
424424
_ => None,
425425
}

src/librustc_save_analysis/json_dumper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl From<MacroData> for Def {
379379
children: vec![],
380380
decl_id: None,
381381
docs: data.docs,
382-
sig: None,
382+
sig: data.sig,
383383
}
384384
}
385385
}

src/librustc_save_analysis/lib.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
179179
type_value: ty_to_string(&typ),
180180
visibility: From::from(&item.vis),
181181
docs: docs_for_attrs(&item.attrs),
182+
sig: None,
182183
}))
183184
}
184185
ast::ItemKind::Const(ref typ, ref expr) => {
@@ -197,6 +198,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
197198
type_value: ty_to_string(&typ),
198199
visibility: From::from(&item.vis),
199200
docs: docs_for_attrs(&item.attrs),
201+
sig: None,
200202
}))
201203
}
202204
ast::ItemKind::Mod(ref m) => {
@@ -287,18 +289,39 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
287289
}
288290
}
289291

290-
pub fn get_field_data(&self, field: &ast::StructField,
291-
scope: NodeId) -> Option<VariableData> {
292+
pub fn get_field_data(&self,
293+
field: &ast::StructField,
294+
scope: NodeId)
295+
-> Option<VariableData> {
292296
if let Some(ident) = field.ident {
297+
let name = ident.to_string();
293298
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
294-
let def_id = self.tcx.map.local_def_id(field.id);
295-
let typ = self.tcx.item_type(def_id).to_string();
296299
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
297300
filter!(self.span_utils, sub_span, field.span, None);
301+
let def_id = self.tcx.map.local_def_id(field.id);
302+
let typ = self.tcx.item_type(def_id).to_string();
303+
304+
let span = field.span;
305+
let text = self.span_utils.snippet(field.span);
306+
let ident_start = text.find(&name).unwrap();
307+
let ident_end = ident_start + name.len();
308+
// TODO refs
309+
let sig = Signature {
310+
span: span,
311+
text: text,
312+
ident_start: ident_start,
313+
ident_end: ident_end,
314+
defs: vec![SigElement {
315+
id: def_id,
316+
start: ident_start,
317+
end: ident_end,
318+
}],
319+
refs: vec![],
320+
};
298321
Some(VariableData {
299322
id: field.id,
300323
kind: VariableKind::Field,
301-
name: ident.to_string(),
324+
name: name,
302325
qualname: qualname,
303326
span: sub_span.unwrap(),
304327
scope: scope,
@@ -307,6 +330,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
307330
type_value: typ,
308331
visibility: From::from(&field.vis),
309332
docs: docs_for_attrs(&field.attrs),
333+
sig: Some(sig),
310334
})
311335
} else {
312336
None

0 commit comments

Comments
 (0)