diff options
| author | varkor <github@varkor.com> | 2018-05-26 19:16:21 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-06-20 12:21:08 +0100 |
| commit | 2c6ff2469a94e37b9605a43bc861de66830a94d4 (patch) | |
| tree | 36c1ad6aed0cceb2980e97878c48436fe2d9d757 /src/librustc_save_analysis | |
| parent | fba1fe21084bf248334ad46b0b0a8c40a6d5ee7b (diff) | |
| download | rust-2c6ff2469a94e37b9605a43bc861de66830a94d4.tar.gz rust-2c6ff2469a94e37b9605a43bc861de66830a94d4.zip | |
Refactor ast::GenericParam as a struct
Diffstat (limited to 'src/librustc_save_analysis')
| -rw-r--r-- | src/librustc_save_analysis/dump_visitor.rs | 76 | ||||
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 6 | ||||
| -rw-r--r-- | src/librustc_save_analysis/sig.rs | 53 |
3 files changed, 65 insertions, 70 deletions
diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 303406dac76..94552e08a8c 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -370,35 +370,38 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { id: NodeId, ) { for param in &generics.params { - if let ast::GenericParamAST::Type(ref ty_param) = *param { - let param_ss = ty_param.ident.span; - let name = escape(self.span.snippet(param_ss)); - // Append $id to name to make sure each one is unique - let qualname = format!("{}::{}${}", prefix, name, id); - if !self.span.filter_generated(Some(param_ss), full_span) { - let id = ::id_from_node_id(ty_param.id, &self.save_ctxt); - let span = self.span_from_span(param_ss); + match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => {} + ast::GenericParamKindAST::Type { .. } => { + let param_ss = param.ident.span; + let name = escape(self.span.snippet(param_ss)); + // Append $id to name to make sure each one is unique. + let qualname = format!("{}::{}${}", prefix, name, id); + if !self.span.filter_generated(Some(param_ss), full_span) { + let id = ::id_from_node_id(param.id, &self.save_ctxt); + let span = self.span_from_span(param_ss); - self.dumper.dump_def( - &Access { - public: false, - reachable: false, - }, - Def { - kind: DefKind::Type, - id, - span, - name, - qualname, - value: String::new(), - parent: None, - children: vec![], - decl_id: None, - docs: String::new(), - sig: None, - attributes: vec![], - }, - ); + self.dumper.dump_def( + &Access { + public: false, + reachable: false, + }, + Def { + kind: DefKind::Type, + id, + span, + name, + qualname, + value: String::new(), + parent: None, + children: vec![], + decl_id: None, + docs: String::new(), + sig: None, + attributes: vec![], + }, + ); + } } } } @@ -1479,14 +1482,17 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc fn visit_generics(&mut self, generics: &'l ast::Generics) { for param in &generics.params { - if let ast::GenericParamAST::Type(ref ty_param) = *param { - for bound in ty_param.bounds.iter() { - if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { - self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) + match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => {} + ast::GenericParamKindAST::Type { ref bounds, ref default, .. } => { + for bound in bounds { + if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { + self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path) + } + } + if let Some(ref ty) = default { + self.visit_ty(&ty); } - } - if let Some(ref ty) = ty_param.default { - self.visit_ty(&ty); } } } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index a634e979363..f656b013c0a 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -934,9 +934,9 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String { sig.push_str(&generics .params .iter() - .map(|param| match *param { - ast::GenericParamAST::Lifetime(ref l) => l.lifetime.ident.name.to_string(), - ast::GenericParamAST::Type(ref t) => t.ident.to_string(), + .map(|param| match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => param.ident.name.to_string(), + ast::GenericParamKindAST::Type { .. } => param.ident.to_string(), }) .collect::<Vec<_>>() .join(", ")); diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index f5384683506..8e8e0dfa182 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -223,9 +223,9 @@ impl Sig for ast::Ty { text.push_str("for<"); text.push_str(&f.generic_params .iter() - .filter_map(|p| match *p { - ast::GenericParamAST::Lifetime(ref l) => { - Some(l.lifetime.ident.to_string()) + .filter_map(|param| match param.kind { + ast::GenericParamKindAST::Lifetime { .. } => { + Some(param.ident.to_string()) } _ => None, }) @@ -617,45 +617,34 @@ impl Sig for ast::Generics { let mut defs = vec![]; for param in &self.params { - match *param { - ast::GenericParamAST::Lifetime(ref l) => { - let mut l_text = l.lifetime.ident.to_string(); - defs.push(SigElement { - id: id_from_node_id(l.lifetime.id, scx), - start: offset + text.len(), - end: offset + text.len() + l_text.len(), - }); - - if !l.bounds.is_empty() { - l_text.push_str(": "); - let bounds = l.bounds - .iter() + let mut param_text = param.ident.to_string(); + defs.push(SigElement { + id: id_from_node_id(param.id, scx), + start: offset + text.len(), + end: offset + text.len() + param_text.len(), + }); + match param.kind { + ast::GenericParamKindAST::Lifetime { ref bounds, .. } => { + if !bounds.is_empty() { + param_text.push_str(": "); + let bounds = bounds.iter() .map(|l| l.ident.to_string()) .collect::<Vec<_>>() .join(" + "); - l_text.push_str(&bounds); + param_text.push_str(&bounds); // FIXME add lifetime bounds refs. } - text.push_str(&l_text); - text.push(','); } - ast::GenericParamAST::Type(ref t) => { - let mut t_text = t.ident.to_string(); - defs.push(SigElement { - id: id_from_node_id(t.id, scx), - start: offset + text.len(), - end: offset + text.len() + t_text.len(), - }); - - if !t.bounds.is_empty() { - t_text.push_str(": "); - t_text.push_str(&pprust::bounds_to_string(&t.bounds)); + ast::GenericParamKindAST::Type { ref bounds, .. } => { + if !bounds.is_empty() { + param_text.push_str(": "); + param_text.push_str(&pprust::bounds_to_string(bounds)); // FIXME descend properly into bounds. } - text.push_str(&t_text); - text.push(','); } } + text.push_str(¶m_text); + text.push(','); } text.push('>'); |
