]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_save_analysis/dump_visitor.rs
Auto merge of #53783 - RalfJung:ptr-docs, r=alexcrichton
[rust.git] / src / librustc_save_analysis / dump_visitor.rs
index 6f5655b8cec535be80182279598cb27bcad7d9db..d719d257f352c6a9d61cd017a2cab3a665f24183 100644 (file)
@@ -147,9 +147,9 @@ pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
         let crate_root = source_file.map(|source_file| {
             let source_file = Path::new(source_file);
             match source_file.file_name() {
-                Some(_) => source_file.parent().unwrap().display().to_string(),
-                None => source_file.display().to_string(),
-            }
+                Some(_) => source_file.parent().unwrap().display(),
+                None => source_file.display(),
+            }.to_string()
         });
 
         let data = CratePreludeData {
@@ -176,8 +176,8 @@ fn process_path_prefixes(&self, path: &ast::Path) -> Vec<(Span, String)> {
         let segments = &path.segments[if path.is_global() { 1 } else { 0 }..];
 
         let mut result = Vec::with_capacity(segments.len());
+        let mut segs = Vec::with_capacity(segments.len());
 
-        let mut segs = vec![];
         for (i, seg) in segments.iter().enumerate() {
             segs.push(seg.clone());
             let sub_path = ast::Path {
@@ -591,9 +591,7 @@ fn process_enum(
 
         for variant in &enum_definition.variants {
             let name = variant.node.ident.name.to_string();
-            let mut qualname = enum_data.qualname.clone();
-            qualname.push_str("::");
-            qualname.push_str(&name);
+            let qualname = format!("{}::{}", enum_data.qualname, name);
 
             match variant.node.data {
                 ast::VariantData::Struct(ref fields, _) => {
@@ -973,9 +971,9 @@ fn process_var_decl_multi(&mut self, pats: &'l [P<ast::Pat>]) {
             match self.save_ctxt.get_path_def(id) {
                 HirDef::Local(id) => {
                     let mut value = if immut == ast::Mutability::Immutable {
-                        self.span.snippet(ident.span).to_string()
+                        self.span.snippet(ident.span)
                     } else {
-                        "<mutable>".to_string()
+                        "<mutable>".to_owned()
                     };
                     let hir_id = self.tcx.hir.node_to_hir_id(id);
                     let typ = self.save_ctxt
@@ -1103,10 +1101,9 @@ fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) {
     /// mac_uses and mac_defs sets to prevent multiples.
     fn process_macro_use(&mut self, span: Span) {
         let source_span = span.source_callsite();
-        if self.macro_calls.contains(&source_span) {
+        if !self.macro_calls.insert(source_span) {
             return;
         }
-        self.macro_calls.insert(source_span);
 
         let data = match self.save_ctxt.get_macro_use_data(span) {
             None => return,
@@ -1362,6 +1359,14 @@ fn process_use_tree(&mut self,
             }
         }
     }
+
+    fn process_bounds(&mut self, bounds: &'l ast::GenericBounds) {
+        for bound in bounds {
+            if let ast::GenericBound::Trait(ref trait_ref, _) = *bound {
+                self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path)
+            }
+        }
+    }
 }
 
 impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, O> {
@@ -1527,20 +1532,19 @@ fn visit_item(&mut self, item: &'l ast::Item) {
 
     fn visit_generics(&mut self, generics: &'l ast::Generics) {
         for param in &generics.params {
-            match param.kind {
-                ast::GenericParamKind::Lifetime { .. } => {}
-                ast::GenericParamKind::Type { ref default, .. } => {
-                    for bound in &param.bounds {
-                        if let ast::GenericBound::Trait(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 ast::GenericParamKind::Type { ref default, .. } = param.kind {
+                self.process_bounds(&param.bounds);
+                if let Some(ref ty) = default {
+                    self.visit_ty(&ty);
                 }
             }
         }
+        for pred in &generics.where_clause.predicates {
+            if let ast::WherePredicate::BoundPredicate(ref wbp) = *pred {
+                self.process_bounds(&wbp.bounds);
+                self.visit_ty(&wbp.bounded_ty);
+            }
+        }
     }
 
     fn visit_ty(&mut self, t: &'l ast::Ty) {
@@ -1601,8 +1605,7 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
                 }
             }
             ast::ExprKind::Closure(_, _, _, ref decl, ref body, _fn_decl_span) => {
-                let mut id = String::from("$");
-                id.push_str(&ex.id.to_string());
+                let id = format!("${}", ex.id);
 
                 // walk arg and return types
                 for arg in &decl.inputs {
@@ -1663,7 +1666,10 @@ fn visit_pat(&mut self, p: &'l ast::Pat) {
 
     fn visit_arm(&mut self, arm: &'l ast::Arm) {
         self.process_var_decl_multi(&arm.pats);
-        walk_list!(self, visit_expr, &arm.guard);
+        match arm.guard {
+            Some(ast::Guard::If(ref expr)) => self.visit_expr(expr),
+            _ => {}
+        }
         self.visit_expr(&arm.body);
     }