]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_def/src/item_tree/pretty.rs
internal: remove accidental code re-use
[rust.git] / crates / hir_def / src / item_tree / pretty.rs
index cc9944a22f8eb0619009fa3f37a522833c499002..3e33b0c46c2963126e3340322e15d6fd20cf9204 100644 (file)
@@ -2,10 +2,13 @@
 
 use std::fmt::{self, Write};
 
+use itertools::Itertools;
+
 use crate::{
     attr::RawAttrs,
     generics::{WherePredicate, WherePredicateTypeTarget},
     path::GenericArg,
+    type_ref::TraitBoundModifier,
     visibility::RawVisibility,
 };
 
@@ -30,16 +33,16 @@ pub(super) fn print_item_tree(tree: &ItemTree) -> String {
 
 macro_rules! w {
     ($dst:expr, $($arg:tt)*) => {
-        drop(write!($dst, $($arg)*))
+        { let _ = write!($dst, $($arg)*); }
     };
 }
 
 macro_rules! wln {
     ($dst:expr) => {
-        drop(writeln!($dst))
+        { let _ = writeln!($dst); }
     };
     ($dst:expr, $($arg:tt)*) => {
-        drop(writeln!($dst, $($arg)*))
+        { let _ = writeln!($dst, $($arg)*); }
     };
 }
 
@@ -63,7 +66,7 @@ fn indented(&mut self, f: impl FnOnce(&mut Self)) {
     fn blank(&mut self) {
         let mut iter = self.buf.chars().rev().fuse();
         match (iter.next(), iter.next()) {
-            (Some('\n'), Some('\n')) | (Some('\n'), None) | (None, None) => {}
+            (Some('\n'), Some('\n') | None) | (None, None) => {}
             (Some('\n'), Some(_)) => {
                 self.buf.push('\n');
             }
@@ -77,7 +80,7 @@ fn blank(&mut self) {
 
     fn whitespace(&mut self) {
         match self.buf.chars().next_back() {
-            None | Some('\n') | Some(' ') => {}
+            None | Some('\n' | ' ') => {}
             _ => self.buf.push(' '),
         }
     }
@@ -426,7 +429,7 @@ fn print_mod_item(&mut self, item: ModItem) {
                         w!(self, " {{");
                         self.indented(|this| {
                             for item in &**items {
-                                this.print_mod_item((*item).into());
+                                this.print_mod_item(*item);
                             }
                         });
                         wln!(self, "}}");
@@ -437,7 +440,7 @@ fn print_mod_item(&mut self, item: ModItem) {
                 }
             }
             ModItem::MacroCall(it) => {
-                let MacroCall { path, ast_id: _, fragment: _ } = &self.tree[it];
+                let MacroCall { path, ast_id: _, expand_to: _ } = &self.tree[it];
                 wln!(self, "{}!(...);", path);
             }
             ModItem::MacroRules(it) => {
@@ -541,7 +544,17 @@ fn print_type_bounds(&mut self, bounds: &[Interned<TypeBound>]) {
             }
 
             match bound.as_ref() {
-                TypeBound::Path(path) => self.print_path(path),
+                TypeBound::Path(path, modifier) => {
+                    match modifier {
+                        TraitBoundModifier::None => (),
+                        TraitBoundModifier::Maybe => w!(self, "?"),
+                    }
+                    self.print_path(path)
+                }
+                TypeBound::ForLifetime(lifetimes, path) => {
+                    w!(self, "for<{}> ", lifetimes.iter().format(", "));
+                    self.print_path(path);
+                }
                 TypeBound::Lifetime(lt) => w!(self, "{}", lt.name),
                 TypeBound::Error => w!(self, "{{unknown}}"),
             }