mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
field signatures
This commit is contained in:
@@ -387,6 +387,7 @@ pub struct VariableData {
|
||||
pub type_value: String,
|
||||
pub visibility: Visibility,
|
||||
pub docs: String,
|
||||
pub sig: Option<Signature>,
|
||||
}
|
||||
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
|
||||
@@ -372,6 +372,7 @@ fn process_formals(&mut self, formals: &'l [ast::Arg], qualname: &str) {
|
||||
parent: None,
|
||||
visibility: Visibility::Inherited,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
}.lower(self.tcx));
|
||||
}
|
||||
}
|
||||
@@ -587,6 +588,7 @@ fn process_assoc_const(&mut self,
|
||||
parent: Some(parent_id),
|
||||
visibility: vis,
|
||||
docs: docs_for_attrs(attrs),
|
||||
sig: None,
|
||||
}.lower(self.tcx));
|
||||
}
|
||||
|
||||
@@ -1072,6 +1074,7 @@ fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) {
|
||||
parent: None,
|
||||
visibility: Visibility::Inherited,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
}.lower(self.tcx));
|
||||
}
|
||||
}
|
||||
@@ -1521,6 +1524,7 @@ fn visit_arm(&mut self, arm: &'l ast::Arm) {
|
||||
parent: None,
|
||||
visibility: Visibility::Inherited,
|
||||
docs: String::new(),
|
||||
sig: None,
|
||||
}.lower(self.tcx));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,6 +658,7 @@ pub struct VariableData {
|
||||
pub parent: Option<DefId>,
|
||||
pub visibility: Visibility,
|
||||
pub docs: String,
|
||||
pub sig: Option<Signature>,
|
||||
}
|
||||
|
||||
impl Lower for data::VariableData {
|
||||
@@ -676,6 +677,7 @@ fn lower(self, tcx: TyCtxt) -> VariableData {
|
||||
parent: self.parent,
|
||||
visibility: self.visibility,
|
||||
docs: self.docs,
|
||||
sig: self.sig.map(|s| s.lower(tcx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ fn from(data: VariableData) -> Option<Def> {
|
||||
parent: data.parent.map(|id| From::from(id)),
|
||||
decl_id: None,
|
||||
docs: data.docs,
|
||||
sig: None,
|
||||
sig: data.sig,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ fn from(data: MacroData) -> Def {
|
||||
children: vec![],
|
||||
decl_id: None,
|
||||
docs: data.docs,
|
||||
sig: None,
|
||||
sig: data.sig,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
type_value: ty_to_string(&typ),
|
||||
visibility: From::from(&item.vis),
|
||||
docs: docs_for_attrs(&item.attrs),
|
||||
sig: None,
|
||||
}))
|
||||
}
|
||||
ast::ItemKind::Const(ref typ, ref expr) => {
|
||||
@@ -197,6 +198,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
type_value: ty_to_string(&typ),
|
||||
visibility: From::from(&item.vis),
|
||||
docs: docs_for_attrs(&item.attrs),
|
||||
sig: None,
|
||||
}))
|
||||
}
|
||||
ast::ItemKind::Mod(ref m) => {
|
||||
@@ -287,18 +289,39 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_field_data(&self, field: &ast::StructField,
|
||||
scope: NodeId) -> Option<VariableData> {
|
||||
pub fn get_field_data(&self,
|
||||
field: &ast::StructField,
|
||||
scope: NodeId)
|
||||
-> Option<VariableData> {
|
||||
if let Some(ident) = field.ident {
|
||||
let name = ident.to_string();
|
||||
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
|
||||
let def_id = self.tcx.map.local_def_id(field.id);
|
||||
let typ = self.tcx.item_type(def_id).to_string();
|
||||
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
|
||||
filter!(self.span_utils, sub_span, field.span, None);
|
||||
let def_id = self.tcx.map.local_def_id(field.id);
|
||||
let typ = self.tcx.item_type(def_id).to_string();
|
||||
|
||||
let span = field.span;
|
||||
let text = self.span_utils.snippet(field.span);
|
||||
let ident_start = text.find(&name).unwrap();
|
||||
let ident_end = ident_start + name.len();
|
||||
// TODO refs
|
||||
let sig = Signature {
|
||||
span: span,
|
||||
text: text,
|
||||
ident_start: ident_start,
|
||||
ident_end: ident_end,
|
||||
defs: vec![SigElement {
|
||||
id: def_id,
|
||||
start: ident_start,
|
||||
end: ident_end,
|
||||
}],
|
||||
refs: vec![],
|
||||
};
|
||||
Some(VariableData {
|
||||
id: field.id,
|
||||
kind: VariableKind::Field,
|
||||
name: ident.to_string(),
|
||||
name: name,
|
||||
qualname: qualname,
|
||||
span: sub_span.unwrap(),
|
||||
scope: scope,
|
||||
@@ -307,6 +330,7 @@ pub fn get_field_data(&self, field: &ast::StructField,
|
||||
type_value: typ,
|
||||
visibility: From::from(&field.vis),
|
||||
docs: docs_for_attrs(&field.attrs),
|
||||
sig: Some(sig),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user