From 5a6ca7a38dbb34f89c8a0381db5ab23b56f44737 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 21 Nov 2016 07:07:40 +1300 Subject: [PATCH 1/7] save-analysis: add `Signature` info to structs --- src/librustc_save_analysis/data.rs | 26 +++++++++++ src/librustc_save_analysis/dump_visitor.rs | 18 +++++++- src/librustc_save_analysis/external_data.rs | 31 ++++++++++++- src/librustc_save_analysis/json_api_dumper.rs | 12 +++++ src/librustc_save_analysis/json_dumper.rs | 13 +++++- src/librustc_save_analysis/span_utils.rs | 45 ++++++++++++++++++- 6 files changed, 139 insertions(+), 6 deletions(-) diff --git a/src/librustc_save_analysis/data.rs b/src/librustc_save_analysis/data.rs index fc235aaf927..42fdb6a4dd7 100644 --- a/src/librustc_save_analysis/data.rs +++ b/src/librustc_save_analysis/data.rs @@ -290,6 +290,7 @@ pub struct StructData { pub fields: Vec, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } #[derive(Debug, RustcEncodable)] @@ -405,3 +406,28 @@ pub struct VariableRefData { pub scope: NodeId, pub ref_id: DefId, } + + +/// Encodes information about the signature of a definition. This should have +/// enough information to create a nice display about a definition without +/// access to the source code. +#[derive(Debug, RustcEncodable)] +pub struct Signature { + pub span: Span, + pub text: String, + // These identify the main identifier for the defintion as byte offsets into + // `text`. E.g., of `foo` in `pub fn foo(...)` + pub ident_start: usize, + pub ident_end: usize, + pub defs: Vec, + pub refs: Vec, +} + +/// An element of a signature. `start` and `end` are byte offsets into the `text` +/// of the parent `Signature`. +#[derive(Debug, RustcEncodable)] +pub struct SigElement { + pub id: DefId, + pub start: usize, + pub end: usize, +} diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index afa78a05a63..a77527cf8bb 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -619,6 +619,9 @@ fn process_struct(&mut self, }; if !self.span.filter_generated(sub_span, item.span) { + let mut sig = self.sig_base(item); + sig.ident_start = sig.text.find(&name).expect("Name not in struct signature?"); + sig.ident_end = sig.ident_start + name.len(); self.dumper.struct_data(StructData { span: sub_span.expect("No span found for struct"), id: item.id, @@ -630,11 +633,10 @@ fn process_struct(&mut self, fields: fields, visibility: From::from(&item.vis), docs: docs_for_attrs(&item.attrs), + sig: sig, }.lower(self.tcx)); } - - // fields for field in def.fields() { self.process_struct_field_def(field, item.id); self.visit_ty(&field.ty); @@ -643,6 +645,18 @@ fn process_struct(&mut self, self.process_generic_params(ty_params, item.span, &qualname, item.id); } + fn sig_base(&self, item: &ast::Item) -> Signature { + let text = self.span.signature_string_for_span(item.span).expect("Couldn't make signature"); + Signature { + span: mk_sp(item.span.lo, item.span.lo + BytePos(text.len() as u32)), + text: text, + ident_start: 0, + ident_end: 0, + defs: vec![], + refs: vec![], + } + } + fn process_enum(&mut self, item: &'l ast::Item, enum_definition: &'l ast::EnumDef, diff --git a/src/librustc_save_analysis/external_data.rs b/src/librustc_save_analysis/external_data.rs index 58475757423..d35b1bac78f 100644 --- a/src/librustc_save_analysis/external_data.rs +++ b/src/librustc_save_analysis/external_data.rs @@ -15,7 +15,7 @@ use syntax::codemap::CodeMap; use syntax_pos::Span; -use data::{self, Visibility}; +use data::{self, Visibility, SigElement}; // FIXME: this should be pub(crate), but the current snapshot doesn't allow it yet pub trait Lower { @@ -428,6 +428,7 @@ pub struct StructData { pub fields: Vec, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } impl Lower for data::StructData { @@ -445,6 +446,7 @@ fn lower(self, tcx: TyCtxt) -> StructData { fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(), visibility: self.visibility, docs: self.docs, + sig: self.sig.lower(tcx), } } } @@ -700,3 +702,30 @@ fn lower(self, tcx: TyCtxt) -> VariableRefData { } } } + +#[derive(Debug, RustcEncodable)] +pub struct Signature { + pub span: SpanData, + pub text: String, + // These identify the main identifier for the defintion as byte offsets into + // `text`. E.g., of `foo` in `pub fn foo(...)` + pub ident_start: usize, + pub ident_end: usize, + pub defs: Vec, + pub refs: Vec, +} + +impl Lower for data::Signature { + type Target = Signature; + + fn lower(self, tcx: TyCtxt) -> Signature { + Signature { + span: SpanData::from_span(self.span, tcx.sess.codemap()), + text: self.text, + ident_start: self.ident_start, + ident_end: self.ident_end, + defs: self.defs, + refs: self.refs, + } + } +} diff --git a/src/librustc_save_analysis/json_api_dumper.rs b/src/librustc_save_analysis/json_api_dumper.rs index d56aae18a7c..118d2273c13 100644 --- a/src/librustc_save_analysis/json_api_dumper.rs +++ b/src/librustc_save_analysis/json_api_dumper.rs @@ -179,6 +179,7 @@ struct Def { children: Vec, decl_id: Option, docs: String, + sig: Option, } #[derive(Debug, RustcEncodable)] @@ -221,6 +222,7 @@ fn from(data: EnumData) -> Option { children: data.variants.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, + sig: None, }), _ => None, } @@ -240,6 +242,7 @@ fn from(data: TupleVariantData) -> Option { children: vec![], decl_id: None, docs: data.docs, + sig: None, }) } } @@ -256,6 +259,7 @@ fn from(data: StructVariantData) -> Option { children: vec![], decl_id: None, docs: data.docs, + sig: None, }) } } @@ -273,6 +277,7 @@ fn from(data: StructData) -> Option { children: data.fields.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, + sig: Some(data.sig), }), _ => None, } @@ -292,6 +297,7 @@ fn from(data: TraitData) -> Option { parent: None, decl_id: None, docs: data.docs, + sig: None, }), _ => None, } @@ -311,6 +317,7 @@ fn from(data: FunctionData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: None, docs: data.docs, + sig: None, }), _ => None, } @@ -330,6 +337,7 @@ fn from(data: MethodData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: data.decl_id.map(|id| From::from(id)), docs: data.docs, + sig: None, }), _ => None, } @@ -348,6 +356,7 @@ fn from(data: MacroData) -> Option { parent: None, decl_id: None, docs: data.docs, + sig: None, }) } } @@ -365,6 +374,7 @@ fn from(data:ModData) -> Option { parent: None, decl_id: None, docs: data.docs, + sig: None, }), _ => None, } @@ -384,6 +394,7 @@ fn from(data: TypeDefData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: None, docs: String::new(), + sig: None, }), _ => None, } @@ -408,6 +419,7 @@ fn from(data: VariableData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: None, docs: data.docs, + sig: None, }), _ => None, } diff --git a/src/librustc_save_analysis/json_dumper.rs b/src/librustc_save_analysis/json_dumper.rs index f97272ad544..3abb19d5384 100644 --- a/src/librustc_save_analysis/json_dumper.rs +++ b/src/librustc_save_analysis/json_dumper.rs @@ -86,6 +86,7 @@ fn mod_data(&mut self, data: ModData) { children: data.items.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, + sig: None, }; if def.span.file_name != def.value { // If the module is an out-of-line defintion, then we'll make the @@ -223,6 +224,7 @@ struct Def { children: Vec, decl_id: Option, docs: String, + sig: Option, } #[derive(Debug, RustcEncodable)] @@ -264,6 +266,7 @@ fn from(data: EnumData) -> Def { children: data.variants.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, + sig: None, } } } @@ -280,6 +283,7 @@ fn from(data: TupleVariantData) -> Def { children: vec![], decl_id: None, docs: data.docs, + sig: None, } } } @@ -295,6 +299,7 @@ fn from(data: StructVariantData) -> Def { children: vec![], decl_id: None, docs: data.docs, + sig: None, } } } @@ -310,6 +315,7 @@ fn from(data: StructData) -> Def { children: data.fields.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, + sig: Some(data.sig), } } } @@ -325,6 +331,7 @@ fn from(data: TraitData) -> Def { children: data.items.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, + sig: None, } } } @@ -340,6 +347,7 @@ fn from(data: FunctionData) -> Def { children: vec![], decl_id: None, docs: data.docs, + sig: None, } } } @@ -355,6 +363,7 @@ fn from(data: MethodData) -> Def { children: vec![], decl_id: data.decl_id.map(|id| From::from(id)), docs: data.docs, + sig: None, } } } @@ -370,10 +379,10 @@ fn from(data: MacroData) -> Def { children: vec![], decl_id: None, docs: data.docs, + sig: None, } } } - impl From for Def { fn from(data: TypeDefData) -> Def { Def { @@ -386,6 +395,7 @@ fn from(data: TypeDefData) -> Def { children: vec![], decl_id: None, docs: String::new(), + sig: None, } } } @@ -406,6 +416,7 @@ fn from(data: VariableData) -> Def { children: vec![], decl_id: None, docs: data.docs, + sig: None, } } } diff --git a/src/librustc_save_analysis/span_utils.rs b/src/librustc_save_analysis/span_utils.rs index e06aefd865f..d09f7375500 100644 --- a/src/librustc_save_analysis/span_utils.rs +++ b/src/librustc_save_analysis/span_utils.rs @@ -18,8 +18,7 @@ use syntax::ast; use syntax::parse::lexer::{self, Reader, StringReader}; -use syntax::parse::token::{self, Token}; -use syntax::symbol::keywords; +use syntax::tokenstream::TokenTree; use syntax_pos::*; #[derive(Clone)] @@ -87,6 +86,12 @@ pub fn retokenise_span(&self, span: Span) -> StringReader<'a> { lexer::StringReader::new(s.diagnostic(), filemap) } + fn span_to_tts(&self, span: Span) -> Vec { + let srdr = self.retokenise_span(span); + let mut p = Parser::new(&self.sess.parse_sess, Box::new(srdr)); + p.parse_all_token_trees().expect("Couldn't re-parse span") + } + // Re-parses a path and returns the span for the last identifier in the path pub fn span_for_last_ident(&self, span: Span) -> Option { let mut result = None; @@ -308,6 +313,42 @@ pub fn spans_with_brackets(&self, span: Span, nesting: isize, limit: isize) -> V } } + /// `span` must be the span for an item such as a function or struct. This + /// function returns the program text from the start of the span until the + /// end of the 'signature' part, that is up to, but not including an opening + /// brace or semicolon. + pub fn signature_string_for_span(&self, span: Span) -> Option { + let mut toks = self.span_to_tts(span).into_iter(); + let mut prev = toks.next().unwrap(); + let first_span = prev.get_span(); + let mut angle_count = 0; + for tok in toks { + if let TokenTree::Token(_, ref tok) = prev { + angle_count += match *tok { + token::Eof => { return None; } + token::Lt => 1, + token::Gt => -1, + token::BinOp(token::Shl) => 2, + token::BinOp(token::Shr) => -2, + _ => 0, + }; + } + if angle_count > 0 { + prev = tok; + continue; + } + if let TokenTree::Token(_, token::Semi) = tok { + return Some(self.snippet(mk_sp(first_span.lo, prev.get_span().hi))); + } else if let TokenTree::Delimited(_, ref d) = tok { + if d.delim == token::Brace { + return Some(self.snippet(mk_sp(first_span.lo, prev.get_span().hi))); + } + } + prev = tok; + } + None + } + pub fn sub_span_before_token(&self, span: Span, tok: Token) -> Option { let mut toks = self.retokenise_span(span); let mut prev = toks.real_token(); From c53fa9a8983a0195076f436e70be24f449c37afc Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 21 Nov 2016 18:11:36 +1300 Subject: [PATCH 2/7] save-analysis: fix ICE on partially resolved path Occurs when we produce save-analysis before type checking is complete (due to errors). --- src/librustc_save_analysis/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 862345fd46e..68836d8823e 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -545,7 +545,11 @@ pub fn get_path_def(&self, id: NodeId) -> Def { } pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option { +<<<<<<< HEAD let def = self.get_path_def(id); +======= + let def = option_try!(self.tcx.expect_resolution(id).maybe_full_def()); +>>>>>>> save-analysis: fix ICE on partially resolved path let sub_span = self.span_utils.span_for_last_ident(path.span); filter!(self.span_utils, sub_span, path.span, None); match def { From eb27b5166e9e35cd315acda6b6db91fe4c220fcd Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 22 Nov 2016 08:12:02 +1300 Subject: [PATCH 3/7] field signatures --- src/librustc_save_analysis/data.rs | 1 + src/librustc_save_analysis/dump_visitor.rs | 4 +++ src/librustc_save_analysis/external_data.rs | 2 ++ src/librustc_save_analysis/json_api_dumper.rs | 2 +- src/librustc_save_analysis/json_dumper.rs | 2 +- src/librustc_save_analysis/lib.rs | 34 ++++++++++++++++--- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/librustc_save_analysis/data.rs b/src/librustc_save_analysis/data.rs index 42fdb6a4dd7..a9db5a440ef 100644 --- a/src/librustc_save_analysis/data.rs +++ b/src/librustc_save_analysis/data.rs @@ -387,6 +387,7 @@ pub struct VariableData { pub type_value: String, pub visibility: Visibility, pub docs: String, + pub sig: Option, } #[derive(Debug, RustcEncodable)] diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index a77527cf8bb..5f61e888ca4 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -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)); } } diff --git a/src/librustc_save_analysis/external_data.rs b/src/librustc_save_analysis/external_data.rs index d35b1bac78f..81ea681a289 100644 --- a/src/librustc_save_analysis/external_data.rs +++ b/src/librustc_save_analysis/external_data.rs @@ -658,6 +658,7 @@ pub struct VariableData { pub parent: Option, pub visibility: Visibility, pub docs: String, + pub sig: Option, } 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)), } } } diff --git a/src/librustc_save_analysis/json_api_dumper.rs b/src/librustc_save_analysis/json_api_dumper.rs index 118d2273c13..b349d15e62f 100644 --- a/src/librustc_save_analysis/json_api_dumper.rs +++ b/src/librustc_save_analysis/json_api_dumper.rs @@ -419,7 +419,7 @@ fn from(data: VariableData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: None, docs: data.docs, - sig: None, + sig: data.sig, }), _ => None, } diff --git a/src/librustc_save_analysis/json_dumper.rs b/src/librustc_save_analysis/json_dumper.rs index 3abb19d5384..795ba1fe0fb 100644 --- a/src/librustc_save_analysis/json_dumper.rs +++ b/src/librustc_save_analysis/json_dumper.rs @@ -379,7 +379,7 @@ fn from(data: MacroData) -> Def { children: vec![], decl_id: None, docs: data.docs, - sig: None, + sig: data.sig, } } } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 68836d8823e..c2e441e7eba 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -179,6 +179,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option { 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 { 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 { } } - pub fn get_field_data(&self, field: &ast::StructField, - scope: NodeId) -> Option { + pub fn get_field_data(&self, + field: &ast::StructField, + scope: NodeId) + -> Option { 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 From e9ecd8805dadbac76173e5207c18b42374e0aba1 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 22 Nov 2016 10:05:25 +1300 Subject: [PATCH 4/7] further lowering of signature data --- src/librustc_save_analysis/json_api_dumper.rs | 49 +++++++++++++++++-- src/librustc_save_analysis/json_dumper.rs | 48 ++++++++++++++++-- 2 files changed, 89 insertions(+), 8 deletions(-) diff --git a/src/librustc_save_analysis/json_api_dumper.rs b/src/librustc_save_analysis/json_api_dumper.rs index b349d15e62f..777e64fe77f 100644 --- a/src/librustc_save_analysis/json_api_dumper.rs +++ b/src/librustc_save_analysis/json_api_dumper.rs @@ -14,7 +14,7 @@ use rustc_serialize::json::as_json; use external_data::*; -use data::{VariableKind, Visibility}; +use data::{VariableKind, Visibility, SigElement}; use dump::Dump; use super::Format; @@ -179,7 +179,7 @@ struct Def { children: Vec, decl_id: Option, docs: String, - sig: Option, + sig: Option, } #[derive(Debug, RustcEncodable)] @@ -277,7 +277,7 @@ fn from(data: StructData) -> Option { children: data.fields.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, - sig: Some(data.sig), + sig: Some(From::from(data.sig)), }), _ => None, } @@ -400,6 +400,7 @@ fn from(data: TypeDefData) -> Option { } } } + impl From for Option { fn from(data: VariableData) -> Option { match data.visibility { @@ -419,9 +420,49 @@ fn from(data: VariableData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: None, docs: data.docs, - sig: data.sig, + sig: data.sig.map(|s| From::from(s)), }), _ => None, } } } + +#[derive(Debug, RustcEncodable)] +pub struct JsonSignature { + span: SpanData, + text: String, + ident_start: usize, + ident_end: usize, + defs: Vec, + refs: Vec, +} + +impl From for JsonSignature { + fn from(data: Signature) -> JsonSignature { + JsonSignature { + span: data.span, + text: data.text, + ident_start: data.ident_start, + ident_end: data.ident_end, + defs: data.defs.into_iter().map(|s| From::from(s)).collect(), + refs: data.refs.into_iter().map(|s| From::from(s)).collect(), + } + } +} + +#[derive(Debug, RustcEncodable)] +pub struct JsonSigElement { + id: Id, + start: usize, + end: usize, +} + +impl From for JsonSigElement { + fn from(data: SigElement) -> JsonSigElement { + JsonSigElement { + id: From::from(data.id), + start: data.start, + end: data.end, + } + } +} diff --git a/src/librustc_save_analysis/json_dumper.rs b/src/librustc_save_analysis/json_dumper.rs index 795ba1fe0fb..818190ca7d2 100644 --- a/src/librustc_save_analysis/json_dumper.rs +++ b/src/librustc_save_analysis/json_dumper.rs @@ -14,7 +14,7 @@ use rustc_serialize::json::as_json; use external_data::*; -use data::VariableKind; +use data::{VariableKind, SigElement}; use dump::Dump; use super::Format; @@ -224,7 +224,7 @@ struct Def { children: Vec, decl_id: Option, docs: String, - sig: Option, + sig: Option, } #[derive(Debug, RustcEncodable)] @@ -315,7 +315,7 @@ fn from(data: StructData) -> Def { children: data.fields.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, - sig: Some(data.sig), + sig: Some(From::from(data.sig)), } } } @@ -379,7 +379,7 @@ fn from(data: MacroData) -> Def { children: vec![], decl_id: None, docs: data.docs, - sig: data.sig, + sig: data.sig.map(|s| From::from(s)), } } } @@ -507,3 +507,43 @@ fn from(data: MacroUseData) -> MacroRef { } } } + +#[derive(Debug, RustcEncodable)] +pub struct JsonSignature { + span: SpanData, + text: String, + ident_start: usize, + ident_end: usize, + defs: Vec, + refs: Vec, +} + +impl From for JsonSignature { + fn from(data: Signature) -> JsonSignature { + JsonSignature { + span: data.span, + text: data.text, + ident_start: data.ident_start, + ident_end: data.ident_end, + defs: data.defs.into_iter().map(|s| From::from(s)).collect(), + refs: data.refs.into_iter().map(|s| From::from(s)).collect(), + } + } +} + +#[derive(Debug, RustcEncodable)] +pub struct JsonSigElement { + id: Id, + start: usize, + end: usize, +} + +impl From for JsonSigElement { + fn from(data: SigElement) -> JsonSigElement { + JsonSigElement { + id: From::from(data.id), + start: data.start, + end: data.end, + } + } +} From d8492367bf9de1baeeb18498f521be6f180ff89d Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 30 Nov 2016 11:50:08 +1300 Subject: [PATCH 5/7] signature info for other items (mods, fns, methods, etc.) --- src/librustc_save_analysis/data.rs | 12 ++++- src/librustc_save_analysis/dump_visitor.rs | 43 +++++++++-------- src/librustc_save_analysis/external_data.rs | 18 ++++++- src/librustc_save_analysis/json_dumper.rs | 18 +++---- src/librustc_save_analysis/lib.rs | 52 +++++++++++++++------ src/librustc_save_analysis/span_utils.rs | 13 ++++-- 6 files changed, 106 insertions(+), 50 deletions(-) diff --git a/src/librustc_save_analysis/data.rs b/src/librustc_save_analysis/data.rs index a9db5a440ef..0a6281bf8c5 100644 --- a/src/librustc_save_analysis/data.rs +++ b/src/librustc_save_analysis/data.rs @@ -135,6 +135,7 @@ pub struct EnumData { pub variants: Vec, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } /// Data for extern crates. @@ -169,6 +170,7 @@ pub struct FunctionData { pub visibility: Visibility, pub parent: Option, pub docs: String, + pub sig: Signature, } /// Data about a function call. @@ -253,6 +255,7 @@ pub struct MethodData { pub parent: Option, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } /// Data for modules. @@ -267,6 +270,7 @@ pub struct ModData { pub items: Vec, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } /// Data for a reference to a module. @@ -304,6 +308,7 @@ pub struct StructVariantData { pub scope: NodeId, pub parent: Option, pub docs: String, + pub sig: Signature, } #[derive(Debug, RustcEncodable)] @@ -317,6 +322,7 @@ pub struct TraitData { pub items: Vec, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } #[derive(Debug, RustcEncodable)] @@ -330,6 +336,7 @@ pub struct TupleVariantData { pub scope: NodeId, pub parent: Option, pub docs: String, + pub sig: Signature, } /// Data for a typedef. @@ -343,6 +350,7 @@ pub struct TypeDefData { pub visibility: Visibility, pub parent: Option, pub docs: String, + pub sig: Option, } /// Data for a reference to a type or trait. @@ -412,7 +420,7 @@ pub struct VariableRefData { /// Encodes information about the signature of a definition. This should have /// enough information to create a nice display about a definition without /// access to the source code. -#[derive(Debug, RustcEncodable)] +#[derive(Clone, Debug, RustcEncodable)] pub struct Signature { pub span: Span, pub text: String, @@ -426,7 +434,7 @@ pub struct Signature { /// An element of a signature. `start` and `end` are byte offsets into the `text` /// of the parent `Signature`. -#[derive(Debug, RustcEncodable)] +#[derive(Clone, Debug, RustcEncodable)] pub struct SigElement { pub id: DefId, pub start: usize, diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 5f61e888ca4..5bec2654ea1 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -445,6 +445,7 @@ fn process_method(&mut self, parent: trait_id, visibility: vis, docs: docs_for_attrs(attrs), + sig: method_data.sig, }.lower(self.tcx)); } @@ -516,6 +517,7 @@ fn process_generic_params(&mut self, visibility: Visibility::Inherited, parent: None, docs: String::new(), + sig: None, }.lower(self.tcx)); } } @@ -621,9 +623,6 @@ fn process_struct(&mut self, }; if !self.span.filter_generated(sub_span, item.span) { - let mut sig = self.sig_base(item); - sig.ident_start = sig.text.find(&name).expect("Name not in struct signature?"); - sig.ident_end = sig.ident_start + name.len(); self.dumper.struct_data(StructData { span: sub_span.expect("No span found for struct"), id: item.id, @@ -635,7 +634,7 @@ fn process_struct(&mut self, fields: fields, visibility: From::from(&item.vis), docs: docs_for_attrs(&item.attrs), - sig: sig, + sig: self.save_ctxt.sig_base(item), }.lower(self.tcx)); } @@ -647,18 +646,6 @@ fn process_struct(&mut self, self.process_generic_params(ty_params, item.span, &qualname, item.id); } - fn sig_base(&self, item: &ast::Item) -> Signature { - let text = self.span.signature_string_for_span(item.span).expect("Couldn't make signature"); - Signature { - span: mk_sp(item.span.lo, item.span.lo + BytePos(text.len() as u32)), - text: text, - ident_start: 0, - ident_end: 0, - defs: vec![], - refs: vec![], - } - } - fn process_enum(&mut self, item: &'l ast::Item, enum_definition: &'l ast::EnumDef, @@ -679,6 +666,18 @@ fn process_enum(&mut self, qualname.push_str("::"); qualname.push_str(&name); + let text = self.span.signature_string_for_span(variant.span); + let ident_start = text.find(&name).unwrap(); + let ident_end = ident_start + name.len(); + let sig = Signature { + span: variant.span, + text: text, + ident_start: ident_start, + ident_end: ident_end, + defs: vec![], + refs: vec![], + }; + match variant.node.data { ast::VariantData::Struct(ref fields, _) => { let sub_span = self.span.span_for_first_ident(variant.span); @@ -700,6 +699,7 @@ fn process_enum(&mut self, scope: enum_data.scope, parent: Some(make_def_id(item.id, &self.tcx.map)), docs: docs_for_attrs(&variant.node.attrs), + sig: sig, }.lower(self.tcx)); } } @@ -725,6 +725,7 @@ fn process_enum(&mut self, scope: enum_data.scope, parent: Some(make_def_id(item.id, &self.tcx.map)), docs: docs_for_attrs(&variant.node.attrs), + sig: sig, }.lower(self.tcx)); } } @@ -809,6 +810,7 @@ fn process_trait(&mut self, items: methods.iter().map(|i| i.id).collect(), visibility: From::from(&item.vis), docs: docs_for_attrs(&item.attrs), + sig: self.save_ctxt.sig_base(item), }.lower(self.tcx)); } @@ -1289,10 +1291,10 @@ fn visit_item(&mut self, item: &'l ast::Item) { Struct(ref def, ref ty_params) => self.process_struct(item, def, ty_params), Enum(ref def, ref ty_params) => self.process_enum(item, def, ty_params), Impl(.., - ref ty_params, - ref trait_ref, - ref typ, - ref impl_items) => { + ref ty_params, + ref trait_ref, + ref typ, + ref impl_items) => { self.process_impl(item, ty_params, trait_ref, &typ, impl_items) } Trait(_, ref generics, ref trait_refs, ref methods) => @@ -1315,6 +1317,7 @@ fn visit_item(&mut self, item: &'l ast::Item) { visibility: From::from(&item.vis), parent: None, docs: docs_for_attrs(&item.attrs), + sig: Some(self.save_ctxt.sig_base(item)), }.lower(self.tcx)); } diff --git a/src/librustc_save_analysis/external_data.rs b/src/librustc_save_analysis/external_data.rs index 81ea681a289..18ae3a7fa9e 100644 --- a/src/librustc_save_analysis/external_data.rs +++ b/src/librustc_save_analysis/external_data.rs @@ -97,6 +97,7 @@ pub struct EnumData { pub variants: Vec, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } impl Lower for data::EnumData { @@ -113,6 +114,7 @@ fn lower(self, tcx: TyCtxt) -> EnumData { variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(), visibility: self.visibility, docs: self.docs, + sig: self.sig.lower(tcx), } } } @@ -176,6 +178,7 @@ pub struct FunctionData { pub visibility: Visibility, pub parent: Option, pub docs: String, + pub sig: Signature, } impl Lower for data::FunctionData { @@ -193,6 +196,7 @@ fn lower(self, tcx: TyCtxt) -> FunctionData { visibility: self.visibility, parent: self.parent, docs: self.docs, + sig: self.sig.lower(tcx), } } } @@ -341,6 +345,7 @@ pub struct MethodData { pub visibility: Visibility, pub parent: Option, pub docs: String, + pub sig: Signature, } impl Lower for data::MethodData { @@ -358,6 +363,7 @@ fn lower(self, tcx: TyCtxt) -> MethodData { visibility: self.visibility, parent: self.parent, docs: self.docs, + sig: self.sig.lower(tcx), } } } @@ -374,6 +380,7 @@ pub struct ModData { pub items: Vec, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } impl Lower for data::ModData { @@ -390,6 +397,7 @@ fn lower(self, tcx: TyCtxt) -> ModData { items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(), visibility: self.visibility, docs: self.docs, + sig: self.sig.lower(tcx), } } } @@ -462,6 +470,7 @@ pub struct StructVariantData { pub scope: DefId, pub parent: Option, pub docs: String, + pub sig: Signature, } impl Lower for data::StructVariantData { @@ -478,6 +487,7 @@ fn lower(self, tcx: TyCtxt) -> StructVariantData { scope: make_def_id(self.scope, &tcx.map), parent: self.parent, docs: self.docs, + sig: self.sig.lower(tcx), } } } @@ -493,6 +503,7 @@ pub struct TraitData { pub items: Vec, pub visibility: Visibility, pub docs: String, + pub sig: Signature, } impl Lower for data::TraitData { @@ -509,6 +520,7 @@ fn lower(self, tcx: TyCtxt) -> TraitData { items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(), visibility: self.visibility, docs: self.docs, + sig: self.sig.lower(tcx), } } } @@ -524,6 +536,7 @@ pub struct TupleVariantData { pub scope: DefId, pub parent: Option, pub docs: String, + pub sig: Signature, } impl Lower for data::TupleVariantData { @@ -540,6 +553,7 @@ fn lower(self, tcx: TyCtxt) -> TupleVariantData { scope: make_def_id(self.scope, &tcx.map), parent: self.parent, docs: self.docs, + sig: self.sig.lower(tcx), } } } @@ -555,6 +569,7 @@ pub struct TypeDefData { pub visibility: Visibility, pub parent: Option, pub docs: String, + pub sig: Option, } impl Lower for data::TypeDefData { @@ -570,6 +585,7 @@ fn lower(self, tcx: TyCtxt) -> TypeDefData { visibility: self.visibility, parent: self.parent, docs: self.docs, + sig: self.sig.map(|s| s.lower(tcx)), } } } @@ -705,7 +721,7 @@ fn lower(self, tcx: TyCtxt) -> VariableRefData { } } -#[derive(Debug, RustcEncodable)] +#[derive(Clone, Debug, RustcEncodable)] pub struct Signature { pub span: SpanData, pub text: String, diff --git a/src/librustc_save_analysis/json_dumper.rs b/src/librustc_save_analysis/json_dumper.rs index 818190ca7d2..16c06a556df 100644 --- a/src/librustc_save_analysis/json_dumper.rs +++ b/src/librustc_save_analysis/json_dumper.rs @@ -86,7 +86,7 @@ fn mod_data(&mut self, data: ModData) { children: data.items.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), }; if def.span.file_name != def.value { // If the module is an out-of-line defintion, then we'll make the @@ -266,7 +266,7 @@ fn from(data: EnumData) -> Def { children: data.variants.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), } } } @@ -283,7 +283,7 @@ fn from(data: TupleVariantData) -> Def { children: vec![], decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), } } } @@ -299,7 +299,7 @@ fn from(data: StructVariantData) -> Def { children: vec![], decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), } } } @@ -331,7 +331,7 @@ fn from(data: TraitData) -> Def { children: data.items.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), } } } @@ -347,7 +347,7 @@ fn from(data: FunctionData) -> Def { children: vec![], decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), } } } @@ -363,7 +363,7 @@ fn from(data: MethodData) -> Def { children: vec![], decl_id: data.decl_id.map(|id| From::from(id)), docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), } } } @@ -379,7 +379,7 @@ fn from(data: MacroData) -> Def { children: vec![], decl_id: None, docs: data.docs, - sig: data.sig.map(|s| From::from(s)), + sig: None, } } } @@ -395,7 +395,7 @@ fn from(data: TypeDefData) -> Def { children: vec![], decl_id: None, docs: String::new(), - sig: None, + sig: data.sig.map(|s| From::from(s)), } } } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index c2e441e7eba..d854c434d66 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -152,6 +152,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option { visibility: From::from(&item.vis), parent: None, docs: docs_for_attrs(&item.attrs), + sig: self.sig_base(item), })) } ast::ItemKind::Static(ref typ, mt, ref expr) => { @@ -179,7 +180,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option { type_value: ty_to_string(&typ), visibility: From::from(&item.vis), docs: docs_for_attrs(&item.attrs), - sig: None, + sig: Some(self.sig_base(item)), })) } ast::ItemKind::Const(ref typ, ref expr) => { @@ -198,7 +199,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option { type_value: ty_to_string(&typ), visibility: From::from(&item.vis), docs: docs_for_attrs(&item.attrs), - sig: None, + sig: Some(self.sig_base(item)), })) } ast::ItemKind::Mod(ref m) => { @@ -209,6 +210,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option { let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Mod); filter!(self.span_utils, sub_span, item.span, None); + Some(Data::ModData(ModData { id: item.id, name: item.ident.to_string(), @@ -219,6 +221,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option { items: m.items.iter().map(|i| i.id).collect(), visibility: From::from(&item.vis), docs: docs_for_attrs(&item.attrs), + sig: self.sig_base(item), })) } ast::ItemKind::Enum(ref def, _) => { @@ -241,6 +244,7 @@ pub fn get_item_data(&self, item: &ast::Item) -> Option { variants: def.variants.iter().map(|v| v.node.data.id()).collect(), visibility: From::from(&item.vis), docs: docs_for_attrs(&item.attrs), + sig: self.sig_base(item), })) } ast::ItemKind::Impl(.., ref trait_ref, ref typ, _) => { @@ -305,17 +309,12 @@ pub fn get_field_data(&self, 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, - }], + defs: vec![], refs: vec![], }; Some(VariableData { @@ -412,9 +411,24 @@ pub fn get_method_data(&self, id: ast::NodeId, let sub_span = self.span_utils.sub_span_after_keyword(span, keywords::Fn); filter!(self.span_utils, sub_span, span, None); + + let name = name.to_string(); + let text = self.span_utils.signature_string_for_span(span); + println!("text: `{}`, name: `{}`", text, name); + let ident_start = text.find(&name).unwrap(); + let ident_end = ident_start + name.len(); + let sig = Signature { + span: span, + text: text, + ident_start: ident_start, + ident_end: ident_end, + defs: vec![], + refs: vec![], + }; + Some(FunctionData { id: id, - name: name.to_string(), + name: name, qualname: qualname, declaration: decl_id, span: sub_span.unwrap(), @@ -424,6 +438,7 @@ pub fn get_method_data(&self, id: ast::NodeId, visibility: vis, parent: parent_scope, docs: docs, + sig: sig, }) } @@ -569,11 +584,7 @@ pub fn get_path_def(&self, id: NodeId) -> Def { } pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option { -<<<<<<< HEAD let def = self.get_path_def(id); -======= - let def = option_try!(self.tcx.expect_resolution(id).maybe_full_def()); ->>>>>>> save-analysis: fix ICE on partially resolved path let sub_span = self.span_utils.span_for_last_ident(path.span); filter!(self.span_utils, sub_span, path.span, None); match def { @@ -723,6 +734,21 @@ fn lookup_ref_id(&self, ref_id: NodeId) -> Option { } } + fn sig_base(&self, item: &ast::Item) -> Signature { + let text = self.span_utils.signature_string_for_span(item.span); + let name = item.ident.to_string(); + let ident_start = text.find(&name).expect("Name not in signature?"); + let ident_end = ident_start + name.len(); + Signature { + span: mk_sp(item.span.lo, item.span.lo + BytePos(text.len() as u32)), + text: text, + ident_start: ident_start, + ident_end: ident_end, + defs: vec![], + refs: vec![], + } + } + #[inline] pub fn enclosing_scope(&self, id: NodeId) -> NodeId { self.tcx.map.get_enclosing_scope(id).unwrap_or(CRATE_NODE_ID) diff --git a/src/librustc_save_analysis/span_utils.rs b/src/librustc_save_analysis/span_utils.rs index d09f7375500..f749396e7ca 100644 --- a/src/librustc_save_analysis/span_utils.rs +++ b/src/librustc_save_analysis/span_utils.rs @@ -18,6 +18,9 @@ use syntax::ast; use syntax::parse::lexer::{self, Reader, StringReader}; +use syntax::parse::token::{self, Token}; +use syntax::parse::parser::Parser; +use syntax::symbol::keywords; use syntax::tokenstream::TokenTree; use syntax_pos::*; @@ -317,7 +320,7 @@ pub fn spans_with_brackets(&self, span: Span, nesting: isize, limit: isize) -> V /// function returns the program text from the start of the span until the /// end of the 'signature' part, that is up to, but not including an opening /// brace or semicolon. - pub fn signature_string_for_span(&self, span: Span) -> Option { + pub fn signature_string_for_span(&self, span: Span) -> String { let mut toks = self.span_to_tts(span).into_iter(); let mut prev = toks.next().unwrap(); let first_span = prev.get_span(); @@ -325,7 +328,7 @@ pub fn signature_string_for_span(&self, span: Span) -> Option { for tok in toks { if let TokenTree::Token(_, ref tok) = prev { angle_count += match *tok { - token::Eof => { return None; } + token::Eof => { break; } token::Lt => 1, token::Gt => -1, token::BinOp(token::Shl) => 2, @@ -338,15 +341,15 @@ pub fn signature_string_for_span(&self, span: Span) -> Option { continue; } if let TokenTree::Token(_, token::Semi) = tok { - return Some(self.snippet(mk_sp(first_span.lo, prev.get_span().hi))); + return self.snippet(mk_sp(first_span.lo, prev.get_span().hi)); } else if let TokenTree::Delimited(_, ref d) = tok { if d.delim == token::Brace { - return Some(self.snippet(mk_sp(first_span.lo, prev.get_span().hi))); + return self.snippet(mk_sp(first_span.lo, prev.get_span().hi)); } } prev = tok; } - None + self.snippet(span) } pub fn sub_span_before_token(&self, span: Span, tok: Token) -> Option { From 5d971ab5f27e802409c49a3ee5642c433b2cca3b Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Sat, 17 Dec 2016 14:37:40 -1000 Subject: [PATCH 6/7] save-analysis signature stuff for json-api flavour. --- src/librustc_save_analysis/json_api_dumper.rs | 16 ++++++++-------- src/librustc_save_analysis/lib.rs | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/librustc_save_analysis/json_api_dumper.rs b/src/librustc_save_analysis/json_api_dumper.rs index 777e64fe77f..342c33af2f8 100644 --- a/src/librustc_save_analysis/json_api_dumper.rs +++ b/src/librustc_save_analysis/json_api_dumper.rs @@ -222,7 +222,7 @@ fn from(data: EnumData) -> Option { children: data.variants.into_iter().map(|id| From::from(id)).collect(), decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), }), _ => None, } @@ -242,7 +242,7 @@ fn from(data: TupleVariantData) -> Option { children: vec![], decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), }) } } @@ -259,7 +259,7 @@ fn from(data: StructVariantData) -> Option { children: vec![], decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), }) } } @@ -297,7 +297,7 @@ fn from(data: TraitData) -> Option { parent: None, decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), }), _ => None, } @@ -317,7 +317,7 @@ fn from(data: FunctionData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), }), _ => None, } @@ -337,7 +337,7 @@ fn from(data: MethodData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: data.decl_id.map(|id| From::from(id)), docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), }), _ => None, } @@ -374,7 +374,7 @@ fn from(data:ModData) -> Option { parent: None, decl_id: None, docs: data.docs, - sig: None, + sig: Some(From::from(data.sig)), }), _ => None, } @@ -394,7 +394,7 @@ fn from(data: TypeDefData) -> Option { parent: data.parent.map(|id| From::from(id)), decl_id: None, docs: String::new(), - sig: None, + sig: data.sig.map(|s| From::from(s)), }), _ => None, } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index d854c434d66..491521a3239 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -414,7 +414,6 @@ pub fn get_method_data(&self, id: ast::NodeId, let name = name.to_string(); let text = self.span_utils.signature_string_for_span(span); - println!("text: `{}`, name: `{}`", text, name); let ident_start = text.find(&name).unwrap(); let ident_end = ident_start + name.len(); let sig = Signature { From c24b1928ca97f98b72b4413b177a7eb3fe73456f Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 22 Dec 2016 17:01:45 +1300 Subject: [PATCH 7/7] rebasing fix --- src/librustc_save_analysis/span_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_save_analysis/span_utils.rs b/src/librustc_save_analysis/span_utils.rs index f749396e7ca..448bb2e7617 100644 --- a/src/librustc_save_analysis/span_utils.rs +++ b/src/librustc_save_analysis/span_utils.rs @@ -91,7 +91,7 @@ pub fn retokenise_span(&self, span: Span) -> StringReader<'a> { fn span_to_tts(&self, span: Span) -> Vec { let srdr = self.retokenise_span(span); - let mut p = Parser::new(&self.sess.parse_sess, Box::new(srdr)); + let mut p = Parser::new(&self.sess.parse_sess, Box::new(srdr), None, false); p.parse_all_token_trees().expect("Couldn't re-parse span") }