diff options
Diffstat (limited to 'crates/hir_def/src/item_tree/pretty.rs')
-rw-r--r-- | crates/hir_def/src/item_tree/pretty.rs | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/crates/hir_def/src/item_tree/pretty.rs b/crates/hir_def/src/item_tree/pretty.rs index 4bc87a0e2..cc9944a22 100644 --- a/crates/hir_def/src/item_tree/pretty.rs +++ b/crates/hir_def/src/item_tree/pretty.rs | |||
@@ -163,21 +163,46 @@ impl<'a> Printer<'a> { | |||
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | fn print_use_tree(&mut self, use_tree: &UseTree) { | ||
167 | match &use_tree.kind { | ||
168 | UseTreeKind::Single { path, alias } => { | ||
169 | w!(self, "{}", path); | ||
170 | if let Some(alias) = alias { | ||
171 | w!(self, " as {}", alias); | ||
172 | } | ||
173 | } | ||
174 | UseTreeKind::Glob { path } => { | ||
175 | if let Some(path) = path { | ||
176 | w!(self, "{}::", path); | ||
177 | } | ||
178 | w!(self, "*"); | ||
179 | } | ||
180 | UseTreeKind::Prefixed { prefix, list } => { | ||
181 | if let Some(prefix) = prefix { | ||
182 | w!(self, "{}::", prefix); | ||
183 | } | ||
184 | w!(self, "{{"); | ||
185 | for (i, tree) in list.iter().enumerate() { | ||
186 | if i != 0 { | ||
187 | w!(self, ", "); | ||
188 | } | ||
189 | self.print_use_tree(tree); | ||
190 | } | ||
191 | w!(self, "}}"); | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | |||
166 | fn print_mod_item(&mut self, item: ModItem) { | 196 | fn print_mod_item(&mut self, item: ModItem) { |
167 | self.print_attrs_of(item); | 197 | self.print_attrs_of(item); |
168 | 198 | ||
169 | match item { | 199 | match item { |
170 | ModItem::Import(it) => { | 200 | ModItem::Import(it) => { |
171 | let Import { visibility, path, is_glob, alias, ast_id: _, index } = &self.tree[it]; | 201 | let Import { visibility, use_tree, ast_id: _ } = &self.tree[it]; |
172 | self.print_visibility(*visibility); | 202 | self.print_visibility(*visibility); |
173 | w!(self, "use {}", path); | 203 | w!(self, "use "); |
174 | if *is_glob { | 204 | self.print_use_tree(use_tree); |
175 | w!(self, "::*"); | 205 | wln!(self, ";"); |
176 | } | ||
177 | if let Some(alias) = alias { | ||
178 | w!(self, " as {}", alias); | ||
179 | } | ||
180 | wln!(self, "; // {}", index); | ||
181 | } | 206 | } |
182 | ModItem::ExternCrate(it) => { | 207 | ModItem::ExternCrate(it) => { |
183 | let ExternCrate { name, alias, visibility, ast_id: _ } = &self.tree[it]; | 208 | let ExternCrate { name, alias, visibility, ast_id: _ } = &self.tree[it]; |
@@ -210,6 +235,7 @@ impl<'a> Printer<'a> { | |||
210 | abi, | 235 | abi, |
211 | params, | 236 | params, |
212 | ret_type, | 237 | ret_type, |
238 | async_ret_type: _, | ||
213 | ast_id: _, | 239 | ast_id: _, |
214 | flags, | 240 | flags, |
215 | } = &self.tree[it]; | 241 | } = &self.tree[it]; |
@@ -320,7 +346,6 @@ impl<'a> Printer<'a> { | |||
320 | visibility, | 346 | visibility, |
321 | is_auto, | 347 | is_auto, |
322 | is_unsafe, | 348 | is_unsafe, |
323 | bounds, | ||
324 | items, | 349 | items, |
325 | generic_params, | 350 | generic_params, |
326 | ast_id: _, | 351 | ast_id: _, |
@@ -334,10 +359,6 @@ impl<'a> Printer<'a> { | |||
334 | } | 359 | } |
335 | w!(self, "trait {}", name); | 360 | w!(self, "trait {}", name); |
336 | self.print_generic_params(generic_params); | 361 | self.print_generic_params(generic_params); |
337 | if !bounds.is_empty() { | ||
338 | w!(self, ": "); | ||
339 | self.print_type_bounds(bounds); | ||
340 | } | ||
341 | self.print_where_clause_and_opening_brace(generic_params); | 362 | self.print_where_clause_and_opening_brace(generic_params); |
342 | self.indented(|this| { | 363 | self.indented(|this| { |
343 | for item in &**items { | 364 | for item in &**items { |
@@ -513,13 +534,13 @@ impl<'a> Printer<'a> { | |||
513 | } | 534 | } |
514 | } | 535 | } |
515 | 536 | ||
516 | fn print_type_bounds(&mut self, bounds: &[TypeBound]) { | 537 | fn print_type_bounds(&mut self, bounds: &[Interned<TypeBound>]) { |
517 | for (i, bound) in bounds.iter().enumerate() { | 538 | for (i, bound) in bounds.iter().enumerate() { |
518 | if i != 0 { | 539 | if i != 0 { |
519 | w!(self, " + "); | 540 | w!(self, " + "); |
520 | } | 541 | } |
521 | 542 | ||
522 | match bound { | 543 | match bound.as_ref() { |
523 | TypeBound::Path(path) => self.print_path(path), | 544 | TypeBound::Path(path) => self.print_path(path), |
524 | TypeBound::Lifetime(lt) => w!(self, "{}", lt.name), | 545 | TypeBound::Lifetime(lt) => w!(self, "{}", lt.name), |
525 | TypeBound::Error => w!(self, "{{unknown}}"), | 546 | TypeBound::Error => w!(self, "{{unknown}}"), |