]> git.lizzy.rs Git - rust.git/blob - crates/ide-completion/src/render.rs
Auto merge of #11983 - jhpratt:remove-rustc_deprecated, r=lnicola
[rust.git] / crates / ide-completion / src / render.rs
1 //! `render` module provides utilities for rendering completion suggestions
2 //! into code pieces that will be presented to user.
3
4 pub(crate) mod macro_;
5 pub(crate) mod function;
6 pub(crate) mod const_;
7 pub(crate) mod pattern;
8 pub(crate) mod type_alias;
9 pub(crate) mod variant;
10 pub(crate) mod union_literal;
11 pub(crate) mod literal;
12
13 use hir::{AsAssocItem, HasAttrs, HirDisplay, ScopeDef};
14 use ide_db::{
15     helpers::item_name, imports::import_assets::LocatedImport, RootDatabase, SnippetCap, SymbolKind,
16 };
17 use syntax::{SmolStr, SyntaxKind, TextRange};
18
19 use crate::{
20     context::{PathCompletionCtx, PathKind},
21     item::{Builder, CompletionRelevanceTypeMatch},
22     render::{function::render_fn, literal::render_variant_lit, macro_::render_macro},
23     CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance,
24 };
25 /// Interface for data and methods required for items rendering.
26 #[derive(Debug, Clone)]
27 pub(crate) struct RenderContext<'a> {
28     completion: &'a CompletionContext<'a>,
29     is_private_editable: bool,
30     import_to_add: Option<LocatedImport>,
31 }
32
33 impl<'a> RenderContext<'a> {
34     pub(crate) fn new(completion: &'a CompletionContext<'a>) -> RenderContext<'a> {
35         RenderContext { completion, is_private_editable: false, import_to_add: None }
36     }
37
38     pub(crate) fn private_editable(mut self, private_editable: bool) -> Self {
39         self.is_private_editable = private_editable;
40         self
41     }
42
43     pub(crate) fn import_to_add(mut self, import_to_add: Option<LocatedImport>) -> Self {
44         self.import_to_add = import_to_add;
45         self
46     }
47
48     fn snippet_cap(&self) -> Option<SnippetCap> {
49         self.completion.config.snippet_cap
50     }
51
52     fn db(&self) -> &'a RootDatabase {
53         self.completion.db
54     }
55
56     fn source_range(&self) -> TextRange {
57         self.completion.source_range()
58     }
59
60     fn completion_relevance(&self) -> CompletionRelevance {
61         CompletionRelevance {
62             is_private_editable: self.is_private_editable,
63             requires_import: self.import_to_add.is_some(),
64             ..Default::default()
65         }
66     }
67
68     fn is_deprecated(&self, def: impl HasAttrs) -> bool {
69         let attrs = def.attrs(self.db());
70         attrs.by_key("deprecated").exists()
71     }
72
73     fn is_deprecated_assoc_item(&self, as_assoc_item: impl AsAssocItem) -> bool {
74         let db = self.db();
75         let assoc = match as_assoc_item.as_assoc_item(db) {
76             Some(assoc) => assoc,
77             None => return false,
78         };
79
80         let is_assoc_deprecated = match assoc {
81             hir::AssocItem::Function(it) => self.is_deprecated(it),
82             hir::AssocItem::Const(it) => self.is_deprecated(it),
83             hir::AssocItem::TypeAlias(it) => self.is_deprecated(it),
84         };
85         is_assoc_deprecated
86             || assoc
87                 .containing_trait_or_trait_impl(db)
88                 .map(|trait_| self.is_deprecated(trait_))
89                 .unwrap_or(false)
90     }
91
92     // FIXME: remove this
93     fn docs(&self, def: impl HasAttrs) -> Option<hir::Documentation> {
94         def.docs(self.db())
95     }
96 }
97
98 pub(crate) fn render_field(
99     ctx: RenderContext<'_>,
100     receiver: Option<hir::Name>,
101     field: hir::Field,
102     ty: &hir::Type,
103 ) -> CompletionItem {
104     let is_deprecated = ctx.is_deprecated(field);
105     let name = field.name(ctx.db()).to_smol_str();
106     let mut item = CompletionItem::new(
107         SymbolKind::Field,
108         ctx.source_range(),
109         receiver.map_or_else(|| name.clone(), |receiver| format!("{}.{}", receiver, name).into()),
110     );
111     item.set_relevance(CompletionRelevance {
112         type_match: compute_type_match(ctx.completion, ty),
113         exact_name_match: compute_exact_name_match(ctx.completion, name.as_str()),
114         ..CompletionRelevance::default()
115     });
116     item.detail(ty.display(ctx.db()).to_string())
117         .set_documentation(field.docs(ctx.db()))
118         .set_deprecated(is_deprecated)
119         .lookup_by(name.clone());
120     let is_keyword = SyntaxKind::from_keyword(name.as_str()).is_some();
121     if is_keyword && !matches!(name.as_str(), "self" | "crate" | "super" | "Self") {
122         item.insert_text(format!("r#{}", name));
123     }
124     if let Some(_ref_match) = compute_ref_match(ctx.completion, ty) {
125         // FIXME
126         // For now we don't properly calculate the edits for ref match
127         // completions on struct fields, so we've disabled them. See #8058.
128     }
129     item.build()
130 }
131
132 pub(crate) fn render_tuple_field(
133     ctx: RenderContext<'_>,
134     receiver: Option<hir::Name>,
135     field: usize,
136     ty: &hir::Type,
137 ) -> CompletionItem {
138     let mut item = CompletionItem::new(
139         SymbolKind::Field,
140         ctx.source_range(),
141         receiver.map_or_else(|| field.to_string(), |receiver| format!("{}.{}", receiver, field)),
142     );
143     item.detail(ty.display(ctx.db()).to_string()).lookup_by(field.to_string());
144     item.build()
145 }
146
147 pub(crate) fn render_resolution(
148     ctx: RenderContext<'_>,
149     local_name: hir::Name,
150     resolution: ScopeDef,
151 ) -> Builder {
152     render_resolution_(ctx, local_name, None, resolution)
153 }
154
155 pub(crate) fn render_resolution_simple(
156     ctx: RenderContext<'_>,
157     local_name: hir::Name,
158     resolution: ScopeDef,
159 ) -> Builder {
160     render_resolution_simple_(ctx, local_name, None, resolution)
161 }
162
163 pub(crate) fn render_resolution_with_import(
164     ctx: RenderContext<'_>,
165     import_edit: LocatedImport,
166 ) -> Option<Builder> {
167     let resolution = ScopeDef::from(import_edit.original_item);
168     let local_name = match resolution {
169         ScopeDef::ModuleDef(hir::ModuleDef::Function(f)) => f.name(ctx.completion.db),
170         ScopeDef::ModuleDef(hir::ModuleDef::Const(c)) => c.name(ctx.completion.db)?,
171         ScopeDef::ModuleDef(hir::ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db),
172         _ => item_name(ctx.db(), import_edit.original_item)?,
173     };
174     Some(render_resolution_(ctx, local_name, Some(import_edit), resolution))
175 }
176
177 pub(crate) fn render_type_inference(ty_string: String, ctx: &CompletionContext) -> CompletionItem {
178     let mut builder =
179         CompletionItem::new(CompletionItemKind::InferredType, ctx.source_range(), ty_string);
180     builder.set_relevance(CompletionRelevance { is_definite: true, ..Default::default() });
181     builder.build()
182 }
183
184 fn render_resolution_(
185     ctx: RenderContext<'_>,
186     local_name: hir::Name,
187     import_to_add: Option<LocatedImport>,
188     resolution: ScopeDef,
189 ) -> Builder {
190     let _p = profile::span("render_resolution");
191     use hir::ModuleDef::*;
192
193     match resolution {
194         ScopeDef::ModuleDef(Macro(mac)) => {
195             let ctx = ctx.import_to_add(import_to_add);
196             return render_macro(ctx, local_name, mac);
197         }
198         ScopeDef::ModuleDef(Function(func)) => {
199             let ctx = ctx.import_to_add(import_to_add);
200             return render_fn(ctx, Some(local_name), func);
201         }
202         ScopeDef::ModuleDef(Variant(var)) if ctx.completion.pattern_ctx.is_none() => {
203             let ctx = ctx.clone().import_to_add(import_to_add.clone());
204             if let Some(item) = render_variant_lit(ctx, Some(local_name.clone()), var, None) {
205                 return item;
206             }
207         }
208         _ => (),
209     }
210     render_resolution_simple_(ctx, local_name, import_to_add, resolution)
211 }
212
213 fn render_resolution_simple_(
214     ctx: RenderContext<'_>,
215     local_name: hir::Name,
216     import_to_add: Option<LocatedImport>,
217     resolution: ScopeDef,
218 ) -> Builder {
219     let _p = profile::span("render_resolution");
220     use hir::ModuleDef::*;
221
222     let db = ctx.db();
223     let ctx = ctx.import_to_add(import_to_add);
224     let kind = match resolution {
225         ScopeDef::Unknown => CompletionItemKind::UnresolvedReference,
226         ScopeDef::ModuleDef(Function(_)) => CompletionItemKind::SymbolKind(SymbolKind::Function),
227         ScopeDef::ModuleDef(Variant(_)) => CompletionItemKind::SymbolKind(SymbolKind::Variant),
228         ScopeDef::ModuleDef(Macro(_)) => CompletionItemKind::SymbolKind(SymbolKind::Macro),
229         ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::SymbolKind(SymbolKind::Module),
230         ScopeDef::ModuleDef(Adt(adt)) => CompletionItemKind::SymbolKind(match adt {
231             hir::Adt::Struct(_) => SymbolKind::Struct,
232             hir::Adt::Union(_) => SymbolKind::Union,
233             hir::Adt::Enum(_) => SymbolKind::Enum,
234         }),
235         ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const),
236         ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::SymbolKind(SymbolKind::Static),
237         ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::SymbolKind(SymbolKind::Trait),
238         ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::SymbolKind(SymbolKind::TypeAlias),
239         ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
240         ScopeDef::GenericParam(param) => CompletionItemKind::SymbolKind(match param {
241             hir::GenericParam::TypeParam(_) => SymbolKind::TypeParam,
242             hir::GenericParam::ConstParam(_) => SymbolKind::ConstParam,
243             hir::GenericParam::LifetimeParam(_) => SymbolKind::LifetimeParam,
244         }),
245         ScopeDef::Local(..) => CompletionItemKind::SymbolKind(SymbolKind::Local),
246         ScopeDef::Label(..) => CompletionItemKind::SymbolKind(SymbolKind::Label),
247         ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => {
248             CompletionItemKind::SymbolKind(SymbolKind::SelfParam)
249         }
250     };
251
252     let local_name = local_name.to_smol_str();
253     let mut item = CompletionItem::new(kind, ctx.source_range(), local_name.clone());
254     item.set_relevance(ctx.completion_relevance());
255     if let ScopeDef::Local(local) = resolution {
256         let ty = local.ty(db);
257         if !ty.is_unknown() {
258             item.detail(ty.display(db).to_string());
259         }
260
261         item.set_relevance(CompletionRelevance {
262             type_match: compute_type_match(ctx.completion, &ty),
263             exact_name_match: compute_exact_name_match(ctx.completion, &local_name),
264             is_local: true,
265             ..CompletionRelevance::default()
266         });
267
268         if let Some(ref_match) = compute_ref_match(ctx.completion, &ty) {
269             item.ref_match(ref_match);
270         }
271     };
272
273     // Add `<>` for generic types
274     let type_path_no_ty_args = matches!(
275         ctx.completion.path_context(),
276         Some(PathCompletionCtx { kind: PathKind::Type, has_type_args: false, .. })
277     ) && ctx.completion.config.add_call_parenthesis;
278     if type_path_no_ty_args {
279         if let Some(cap) = ctx.snippet_cap() {
280             let has_non_default_type_params = match resolution {
281                 ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(db),
282                 ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(db),
283                 _ => false,
284             };
285             if has_non_default_type_params {
286                 cov_mark::hit!(inserts_angle_brackets_for_generics);
287                 item.lookup_by(local_name.clone())
288                     .label(SmolStr::from_iter([&local_name, "<…>"]))
289                     .trigger_call_info()
290                     .insert_snippet(cap, format!("{}<$0>", local_name));
291             }
292         }
293     }
294     item.set_documentation(scope_def_docs(db, resolution))
295         .set_deprecated(scope_def_is_deprecated(&ctx, resolution));
296
297     if let Some(import_to_add) = ctx.import_to_add {
298         item.add_import(import_to_add);
299     }
300     item
301 }
302
303 fn scope_def_docs(db: &RootDatabase, resolution: ScopeDef) -> Option<hir::Documentation> {
304     use hir::ModuleDef::*;
305     match resolution {
306         ScopeDef::ModuleDef(Module(it)) => it.docs(db),
307         ScopeDef::ModuleDef(Adt(it)) => it.docs(db),
308         ScopeDef::ModuleDef(Variant(it)) => it.docs(db),
309         ScopeDef::ModuleDef(Const(it)) => it.docs(db),
310         ScopeDef::ModuleDef(Static(it)) => it.docs(db),
311         ScopeDef::ModuleDef(Trait(it)) => it.docs(db),
312         ScopeDef::ModuleDef(TypeAlias(it)) => it.docs(db),
313         _ => None,
314     }
315 }
316
317 fn scope_def_is_deprecated(ctx: &RenderContext<'_>, resolution: ScopeDef) -> bool {
318     match resolution {
319         ScopeDef::ModuleDef(it) => ctx.is_deprecated_assoc_item(it),
320         ScopeDef::GenericParam(it) => ctx.is_deprecated(it),
321         ScopeDef::AdtSelfType(it) => ctx.is_deprecated(it),
322         _ => false,
323     }
324 }
325
326 fn compute_type_match(
327     ctx: &CompletionContext,
328     completion_ty: &hir::Type,
329 ) -> Option<CompletionRelevanceTypeMatch> {
330     let expected_type = ctx.expected_type.as_ref()?;
331
332     // We don't ever consider unit type to be an exact type match, since
333     // nearly always this is not meaningful to the user.
334     if expected_type.is_unit() {
335         return None;
336     }
337
338     if completion_ty == expected_type {
339         Some(CompletionRelevanceTypeMatch::Exact)
340     } else if expected_type.could_unify_with(ctx.db, completion_ty) {
341         Some(CompletionRelevanceTypeMatch::CouldUnify)
342     } else {
343         None
344     }
345 }
346
347 fn compute_exact_name_match(ctx: &CompletionContext, completion_name: &str) -> bool {
348     ctx.expected_name.as_ref().map_or(false, |name| name.text() == completion_name)
349 }
350
351 fn compute_ref_match(
352     ctx: &CompletionContext,
353     completion_ty: &hir::Type,
354 ) -> Option<hir::Mutability> {
355     let expected_type = ctx.expected_type.as_ref()?;
356     if completion_ty != expected_type {
357         let expected_type_without_ref = expected_type.remove_ref()?;
358         if completion_ty.autoderef(ctx.db).any(|deref_ty| deref_ty == expected_type_without_ref) {
359             cov_mark::hit!(suggest_ref);
360             let mutability = if expected_type.is_mutable_reference() {
361                 hir::Mutability::Mut
362             } else {
363                 hir::Mutability::Shared
364             };
365             return Some(mutability);
366         };
367     }
368     None
369 }
370
371 #[cfg(test)]
372 mod tests {
373     use std::cmp;
374
375     use expect_test::{expect, Expect};
376     use ide_db::SymbolKind;
377     use itertools::Itertools;
378
379     use crate::{
380         item::CompletionRelevanceTypeMatch,
381         tests::{check_edit, do_completion, get_all_items, TEST_CONFIG},
382         CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevancePostfixMatch,
383     };
384
385     #[track_caller]
386     fn check(ra_fixture: &str, kind: impl Into<CompletionItemKind>, expect: Expect) {
387         let actual = do_completion(ra_fixture, kind.into());
388         expect.assert_debug_eq(&actual);
389     }
390
391     #[track_caller]
392     fn check_kinds(ra_fixture: &str, kinds: &[CompletionItemKind], expect: Expect) {
393         let actual: Vec<_> =
394             kinds.iter().flat_map(|&kind| do_completion(ra_fixture, kind)).collect();
395         expect.assert_debug_eq(&actual);
396     }
397
398     #[track_caller]
399     fn check_relevance_for_kinds(ra_fixture: &str, kinds: &[CompletionItemKind], expect: Expect) {
400         let mut actual = get_all_items(TEST_CONFIG, ra_fixture);
401         actual.retain(|it| kinds.contains(&it.kind()));
402         actual.sort_by_key(|it| cmp::Reverse(it.relevance().score()));
403         check_relevance_(actual, expect);
404     }
405
406     #[track_caller]
407     fn check_relevance(ra_fixture: &str, expect: Expect) {
408         let mut actual = get_all_items(TEST_CONFIG, ra_fixture);
409         actual.retain(|it| it.kind() != CompletionItemKind::Snippet);
410         actual.retain(|it| it.kind() != CompletionItemKind::Keyword);
411         actual.retain(|it| it.kind() != CompletionItemKind::BuiltinType);
412         actual.sort_by_key(|it| cmp::Reverse(it.relevance().score()));
413         check_relevance_(actual, expect);
414     }
415
416     #[track_caller]
417     fn check_relevance_(actual: Vec<CompletionItem>, expect: Expect) {
418         let actual = actual
419             .into_iter()
420             .flat_map(|it| {
421                 let mut items = vec![];
422
423                 let tag = it.kind().tag();
424                 let relevance = display_relevance(it.relevance());
425                 items.push(format!("{} {} {}\n", tag, it.label(), relevance));
426
427                 if let Some((mutability, relevance)) = it.ref_match() {
428                     let label = format!("&{}{}", mutability.as_keyword_for_ref(), it.label());
429                     let relevance = display_relevance(relevance);
430
431                     items.push(format!("{} {} {}\n", tag, label, relevance));
432                 }
433
434                 items
435             })
436             .collect::<String>();
437
438         expect.assert_eq(&actual);
439
440         fn display_relevance(relevance: CompletionRelevance) -> String {
441             let relevance_factors = vec![
442                 (relevance.type_match == Some(CompletionRelevanceTypeMatch::Exact), "type"),
443                 (
444                     relevance.type_match == Some(CompletionRelevanceTypeMatch::CouldUnify),
445                     "type_could_unify",
446                 ),
447                 (relevance.exact_name_match, "name"),
448                 (relevance.is_local, "local"),
449                 (
450                     relevance.postfix_match == Some(CompletionRelevancePostfixMatch::Exact),
451                     "snippet",
452                 ),
453                 (relevance.is_op_method, "op_method"),
454                 (relevance.requires_import, "requires_import"),
455             ]
456             .into_iter()
457             .filter_map(|(cond, desc)| if cond { Some(desc) } else { None })
458             .join("+");
459
460             format!("[{}]", relevance_factors)
461         }
462     }
463
464     #[test]
465     fn enum_detail_includes_record_fields() {
466         check(
467             r#"
468 enum Foo { Foo { x: i32, y: i32 } }
469
470 fn main() { Foo::Fo$0 }
471 "#,
472             SymbolKind::Variant,
473             expect![[r#"
474                 [
475                     CompletionItem {
476                         label: "Foo {…}",
477                         source_range: 54..56,
478                         delete: 54..56,
479                         insert: "Foo { x: ${1:()}, y: ${2:()} }$0",
480                         kind: SymbolKind(
481                             Variant,
482                         ),
483                         detail: "Foo { x: i32, y: i32 }",
484                     },
485                 ]
486             "#]],
487         );
488     }
489
490     #[test]
491     fn enum_detail_includes_tuple_fields() {
492         check(
493             r#"
494 enum Foo { Foo (i32, i32) }
495
496 fn main() { Foo::Fo$0 }
497 "#,
498             SymbolKind::Variant,
499             expect![[r#"
500                 [
501                     CompletionItem {
502                         label: "Foo(…)",
503                         source_range: 46..48,
504                         delete: 46..48,
505                         insert: "Foo(${1:()}, ${2:()})$0",
506                         kind: SymbolKind(
507                             Variant,
508                         ),
509                         detail: "Foo(i32, i32)",
510                     },
511                 ]
512             "#]],
513         );
514     }
515
516     #[test]
517     fn fn_detail_includes_args_and_return_type() {
518         check(
519             r#"
520 fn foo<T>(a: u32, b: u32, t: T) -> (u32, T) { (a, t) }
521
522 fn main() { fo$0 }
523 "#,
524             SymbolKind::Function,
525             expect![[r#"
526                 [
527                     CompletionItem {
528                         label: "foo(…)",
529                         source_range: 68..70,
530                         delete: 68..70,
531                         insert: "foo(${1:a}, ${2:b}, ${3:t})$0",
532                         kind: SymbolKind(
533                             Function,
534                         ),
535                         lookup: "foo",
536                         detail: "fn(u32, u32, T) -> (u32, T)",
537                         trigger_call_info: true,
538                     },
539                     CompletionItem {
540                         label: "main()",
541                         source_range: 68..70,
542                         delete: 68..70,
543                         insert: "main()$0",
544                         kind: SymbolKind(
545                             Function,
546                         ),
547                         lookup: "main",
548                         detail: "fn()",
549                     },
550                 ]
551             "#]],
552         );
553     }
554
555     #[test]
556     fn enum_detail_just_name_for_unit() {
557         check(
558             r#"
559 enum Foo { Foo }
560
561 fn main() { Foo::Fo$0 }
562 "#,
563             SymbolKind::Variant,
564             expect![[r#"
565                 [
566                     CompletionItem {
567                         label: "Foo",
568                         source_range: 35..37,
569                         delete: 35..37,
570                         insert: "Foo$0",
571                         kind: SymbolKind(
572                             Variant,
573                         ),
574                         detail: "Foo",
575                     },
576                 ]
577             "#]],
578         );
579     }
580
581     #[test]
582     fn lookup_enums_by_two_qualifiers() {
583         check_kinds(
584             r#"
585 mod m {
586     pub enum Spam { Foo, Bar(i32) }
587 }
588 fn main() { let _: m::Spam = S$0 }
589 "#,
590             &[
591                 CompletionItemKind::SymbolKind(SymbolKind::Function),
592                 CompletionItemKind::SymbolKind(SymbolKind::Module),
593                 CompletionItemKind::SymbolKind(SymbolKind::Variant),
594             ],
595             expect![[r#"
596                 [
597                     CompletionItem {
598                         label: "main()",
599                         source_range: 75..76,
600                         delete: 75..76,
601                         insert: "main()$0",
602                         kind: SymbolKind(
603                             Function,
604                         ),
605                         lookup: "main",
606                         detail: "fn()",
607                     },
608                     CompletionItem {
609                         label: "m",
610                         source_range: 75..76,
611                         delete: 75..76,
612                         insert: "m",
613                         kind: SymbolKind(
614                             Module,
615                         ),
616                     },
617                     CompletionItem {
618                         label: "m::Spam::Bar(…)",
619                         source_range: 75..76,
620                         delete: 75..76,
621                         insert: "m::Spam::Bar(${1:()})$0",
622                         kind: SymbolKind(
623                             Variant,
624                         ),
625                         lookup: "Spam::Bar(…)",
626                         detail: "m::Spam::Bar(i32)",
627                         relevance: CompletionRelevance {
628                             exact_name_match: false,
629                             type_match: Some(
630                                 Exact,
631                             ),
632                             is_local: false,
633                             is_item_from_trait: false,
634                             is_name_already_imported: false,
635                             requires_import: false,
636                             is_op_method: false,
637                             is_private_editable: false,
638                             postfix_match: None,
639                             is_definite: false,
640                         },
641                     },
642                     CompletionItem {
643                         label: "m::Spam::Foo",
644                         source_range: 75..76,
645                         delete: 75..76,
646                         insert: "m::Spam::Foo$0",
647                         kind: SymbolKind(
648                             Variant,
649                         ),
650                         lookup: "Spam::Foo",
651                         detail: "m::Spam::Foo",
652                         relevance: CompletionRelevance {
653                             exact_name_match: false,
654                             type_match: Some(
655                                 Exact,
656                             ),
657                             is_local: false,
658                             is_item_from_trait: false,
659                             is_name_already_imported: false,
660                             requires_import: false,
661                             is_op_method: false,
662                             is_private_editable: false,
663                             postfix_match: None,
664                             is_definite: false,
665                         },
666                     },
667                 ]
668             "#]],
669         )
670     }
671
672     #[test]
673     fn sets_deprecated_flag_in_items() {
674         check(
675             r#"
676 #[deprecated]
677 fn something_deprecated() {}
678
679 fn main() { som$0 }
680 "#,
681             SymbolKind::Function,
682             expect![[r#"
683                 [
684                     CompletionItem {
685                         label: "main()",
686                         source_range: 56..59,
687                         delete: 56..59,
688                         insert: "main()$0",
689                         kind: SymbolKind(
690                             Function,
691                         ),
692                         lookup: "main",
693                         detail: "fn()",
694                     },
695                     CompletionItem {
696                         label: "something_deprecated()",
697                         source_range: 56..59,
698                         delete: 56..59,
699                         insert: "something_deprecated()$0",
700                         kind: SymbolKind(
701                             Function,
702                         ),
703                         lookup: "something_deprecated",
704                         detail: "fn()",
705                         deprecated: true,
706                     },
707                 ]
708             "#]],
709         );
710
711         check(
712             r#"
713 struct A { #[deprecated] the_field: u32 }
714 fn foo() { A { the$0 } }
715 "#,
716             SymbolKind::Field,
717             expect![[r#"
718                 [
719                     CompletionItem {
720                         label: "the_field",
721                         source_range: 57..60,
722                         delete: 57..60,
723                         insert: "the_field",
724                         kind: SymbolKind(
725                             Field,
726                         ),
727                         detail: "u32",
728                         deprecated: true,
729                         relevance: CompletionRelevance {
730                             exact_name_match: false,
731                             type_match: Some(
732                                 CouldUnify,
733                             ),
734                             is_local: false,
735                             is_item_from_trait: false,
736                             is_name_already_imported: false,
737                             requires_import: false,
738                             is_op_method: false,
739                             is_private_editable: false,
740                             postfix_match: None,
741                             is_definite: false,
742                         },
743                     },
744                 ]
745             "#]],
746         );
747     }
748
749     #[test]
750     fn renders_docs() {
751         check_kinds(
752             r#"
753 struct S {
754     /// Field docs
755     foo:
756 }
757 impl S {
758     /// Method docs
759     fn bar(self) { self.$0 }
760 }"#,
761             &[CompletionItemKind::Method, CompletionItemKind::SymbolKind(SymbolKind::Field)],
762             expect![[r#"
763                 [
764                     CompletionItem {
765                         label: "bar()",
766                         source_range: 94..94,
767                         delete: 94..94,
768                         insert: "bar()$0",
769                         kind: Method,
770                         lookup: "bar",
771                         detail: "fn(self)",
772                         documentation: Documentation(
773                             "Method docs",
774                         ),
775                     },
776                     CompletionItem {
777                         label: "foo",
778                         source_range: 94..94,
779                         delete: 94..94,
780                         insert: "foo",
781                         kind: SymbolKind(
782                             Field,
783                         ),
784                         detail: "{unknown}",
785                         documentation: Documentation(
786                             "Field docs",
787                         ),
788                     },
789                 ]
790             "#]],
791         );
792
793         check_kinds(
794             r#"
795 use self::my$0;
796
797 /// mod docs
798 mod my { }
799
800 /// enum docs
801 enum E {
802     /// variant docs
803     V
804 }
805 use self::E::*;
806 "#,
807             &[
808                 CompletionItemKind::SymbolKind(SymbolKind::Module),
809                 CompletionItemKind::SymbolKind(SymbolKind::Variant),
810                 CompletionItemKind::SymbolKind(SymbolKind::Enum),
811             ],
812             expect![[r#"
813                 [
814                     CompletionItem {
815                         label: "my",
816                         source_range: 10..12,
817                         delete: 10..12,
818                         insert: "my",
819                         kind: SymbolKind(
820                             Module,
821                         ),
822                         documentation: Documentation(
823                             "mod docs",
824                         ),
825                     },
826                     CompletionItem {
827                         label: "V",
828                         source_range: 10..12,
829                         delete: 10..12,
830                         insert: "V$0",
831                         kind: SymbolKind(
832                             Variant,
833                         ),
834                         detail: "V",
835                         documentation: Documentation(
836                             "variant docs",
837                         ),
838                     },
839                     CompletionItem {
840                         label: "E",
841                         source_range: 10..12,
842                         delete: 10..12,
843                         insert: "E",
844                         kind: SymbolKind(
845                             Enum,
846                         ),
847                         documentation: Documentation(
848                             "enum docs",
849                         ),
850                     },
851                 ]
852             "#]],
853         )
854     }
855
856     #[test]
857     fn dont_render_attrs() {
858         check(
859             r#"
860 struct S;
861 impl S {
862     #[inline]
863     fn the_method(&self) { }
864 }
865 fn foo(s: S) { s.$0 }
866 "#,
867             CompletionItemKind::Method,
868             expect![[r#"
869                 [
870                     CompletionItem {
871                         label: "the_method()",
872                         source_range: 81..81,
873                         delete: 81..81,
874                         insert: "the_method()$0",
875                         kind: Method,
876                         lookup: "the_method",
877                         detail: "fn(&self)",
878                     },
879                 ]
880             "#]],
881         )
882     }
883
884     #[test]
885     fn no_call_parens_if_fn_ptr_needed() {
886         cov_mark::check!(no_call_parens_if_fn_ptr_needed);
887         check_edit(
888             "foo",
889             r#"
890 fn foo(foo: u8, bar: u8) {}
891 struct ManualVtable { f: fn(u8, u8) }
892
893 fn main() -> ManualVtable {
894     ManualVtable { f: f$0 }
895 }
896 "#,
897             r#"
898 fn foo(foo: u8, bar: u8) {}
899 struct ManualVtable { f: fn(u8, u8) }
900
901 fn main() -> ManualVtable {
902     ManualVtable { f: foo }
903 }
904 "#,
905         );
906         check_edit(
907             "type",
908             r#"
909 struct RawIdentTable { r#type: u32 }
910
911 fn main() -> RawIdentTable {
912     RawIdentTable { t$0: 42 }
913 }
914 "#,
915             r#"
916 struct RawIdentTable { r#type: u32 }
917
918 fn main() -> RawIdentTable {
919     RawIdentTable { r#type: 42 }
920 }
921 "#,
922         );
923     }
924
925     #[test]
926     fn no_parens_in_use_item() {
927         cov_mark::check!(no_parens_in_use_item);
928         check_edit(
929             "foo",
930             r#"
931 mod m { pub fn foo() {} }
932 use crate::m::f$0;
933 "#,
934             r#"
935 mod m { pub fn foo() {} }
936 use crate::m::foo;
937 "#,
938         );
939     }
940
941     #[test]
942     fn no_parens_in_call() {
943         check_edit(
944             "foo",
945             r#"
946 fn foo(x: i32) {}
947 fn main() { f$0(); }
948 "#,
949             r#"
950 fn foo(x: i32) {}
951 fn main() { foo(); }
952 "#,
953         );
954         check_edit(
955             "foo",
956             r#"
957 struct Foo;
958 impl Foo { fn foo(&self){} }
959 fn f(foo: &Foo) { foo.f$0(); }
960 "#,
961             r#"
962 struct Foo;
963 impl Foo { fn foo(&self){} }
964 fn f(foo: &Foo) { foo.foo(); }
965 "#,
966         );
967     }
968
969     #[test]
970     fn inserts_angle_brackets_for_generics() {
971         cov_mark::check!(inserts_angle_brackets_for_generics);
972         check_edit(
973             "Vec",
974             r#"
975 struct Vec<T> {}
976 fn foo(xs: Ve$0)
977 "#,
978             r#"
979 struct Vec<T> {}
980 fn foo(xs: Vec<$0>)
981 "#,
982         );
983         check_edit(
984             "Vec",
985             r#"
986 type Vec<T> = (T,);
987 fn foo(xs: Ve$0)
988 "#,
989             r#"
990 type Vec<T> = (T,);
991 fn foo(xs: Vec<$0>)
992 "#,
993         );
994         check_edit(
995             "Vec",
996             r#"
997 struct Vec<T = i128> {}
998 fn foo(xs: Ve$0)
999 "#,
1000             r#"
1001 struct Vec<T = i128> {}
1002 fn foo(xs: Vec)
1003 "#,
1004         );
1005         check_edit(
1006             "Vec",
1007             r#"
1008 struct Vec<T> {}
1009 fn foo(xs: Ve$0<i128>)
1010 "#,
1011             r#"
1012 struct Vec<T> {}
1013 fn foo(xs: Vec<i128>)
1014 "#,
1015         );
1016     }
1017
1018     #[test]
1019     fn active_param_relevance() {
1020         check_relevance(
1021             r#"
1022 struct S { foo: i64, bar: u32, baz: u32 }
1023 fn test(bar: u32) { }
1024 fn foo(s: S) { test(s.$0) }
1025 "#,
1026             expect![[r#"
1027                 fd bar [type+name]
1028                 fd baz [type]
1029                 fd foo []
1030             "#]],
1031         );
1032     }
1033
1034     #[test]
1035     fn record_field_relevances() {
1036         check_relevance(
1037             r#"
1038 struct A { foo: i64, bar: u32, baz: u32 }
1039 struct B { x: (), y: f32, bar: u32 }
1040 fn foo(a: A) { B { bar: a.$0 }; }
1041 "#,
1042             expect![[r#"
1043                 fd bar [type+name]
1044                 fd baz [type]
1045                 fd foo []
1046             "#]],
1047         )
1048     }
1049
1050     #[test]
1051     fn record_field_and_call_relevances() {
1052         check_relevance(
1053             r#"
1054 struct A { foo: i64, bar: u32, baz: u32 }
1055 struct B { x: (), y: f32, bar: u32 }
1056 fn f(foo: i64) {  }
1057 fn foo(a: A) { B { bar: f(a.$0) }; }
1058 "#,
1059             expect![[r#"
1060                 fd foo [type+name]
1061                 fd bar []
1062                 fd baz []
1063             "#]],
1064         );
1065         check_relevance(
1066             r#"
1067 struct A { foo: i64, bar: u32, baz: u32 }
1068 struct B { x: (), y: f32, bar: u32 }
1069 fn f(foo: i64) {  }
1070 fn foo(a: A) { f(B { bar: a.$0 }); }
1071 "#,
1072             expect![[r#"
1073                 fd bar [type+name]
1074                 fd baz [type]
1075                 fd foo []
1076             "#]],
1077         );
1078     }
1079
1080     #[test]
1081     fn prioritize_exact_ref_match() {
1082         check_relevance(
1083             r#"
1084 struct WorldSnapshot { _f: () };
1085 fn go(world: &WorldSnapshot) { go(w$0) }
1086 "#,
1087             expect![[r#"
1088                 lc world [type+name+local]
1089                 st WorldSnapshot []
1090                 fn go(…) []
1091             "#]],
1092         );
1093     }
1094
1095     #[test]
1096     fn too_many_arguments() {
1097         cov_mark::check!(too_many_arguments);
1098         check_relevance(
1099             r#"
1100 struct Foo;
1101 fn f(foo: &Foo) { f(foo, w$0) }
1102 "#,
1103             expect![[r#"
1104                 lc foo [local]
1105                 st Foo []
1106                 fn f(…) []
1107             "#]],
1108         );
1109     }
1110
1111     #[test]
1112     fn score_fn_type_and_name_match() {
1113         check_relevance(
1114             r#"
1115 struct A { bar: u8 }
1116 fn baz() -> u8 { 0 }
1117 fn bar() -> u8 { 0 }
1118 fn f() { A { bar: b$0 }; }
1119 "#,
1120             expect![[r#"
1121                 fn bar() [type+name]
1122                 fn baz() [type]
1123                 st A []
1124                 fn f() []
1125             "#]],
1126         );
1127     }
1128
1129     #[test]
1130     fn score_method_type_and_name_match() {
1131         check_relevance(
1132             r#"
1133 fn baz(aaa: u32){}
1134 struct Foo;
1135 impl Foo {
1136 fn aaa(&self) -> u32 { 0 }
1137 fn bbb(&self) -> u32 { 0 }
1138 fn ccc(&self) -> u64 { 0 }
1139 }
1140 fn f() {
1141     baz(Foo.$0
1142 }
1143 "#,
1144             expect![[r#"
1145                 me aaa() [type+name]
1146                 me bbb() [type]
1147                 me ccc() []
1148             "#]],
1149         );
1150     }
1151
1152     #[test]
1153     fn score_method_name_match_only() {
1154         check_relevance(
1155             r#"
1156 fn baz(aaa: u32){}
1157 struct Foo;
1158 impl Foo {
1159 fn aaa(&self) -> u64 { 0 }
1160 }
1161 fn f() {
1162     baz(Foo.$0
1163 }
1164 "#,
1165             expect![[r#"
1166                 me aaa() [name]
1167             "#]],
1168         );
1169     }
1170
1171     #[test]
1172     fn suggest_ref_mut() {
1173         cov_mark::check!(suggest_ref);
1174         check_relevance(
1175             r#"
1176 struct S;
1177 fn foo(s: &mut S) {}
1178 fn main() {
1179     let mut s = S;
1180     foo($0);
1181 }
1182             "#,
1183             expect![[r#"
1184                 lc s [name+local]
1185                 lc &mut s [type+name+local]
1186                 st S []
1187                 fn main() []
1188                 fn foo(…) []
1189             "#]],
1190         );
1191         check_relevance(
1192             r#"
1193 struct S;
1194 fn foo(s: &mut S) {}
1195 fn main() {
1196     let mut s = S;
1197     foo(&mut $0);
1198 }
1199             "#,
1200             expect![[r#"
1201                 lc s [type+name+local]
1202                 st S [type]
1203                 st S []
1204                 fn main() []
1205                 fn foo(…) []
1206             "#]],
1207         );
1208         check_relevance(
1209             r#"
1210 struct S;
1211 fn foo(s: &mut S) {}
1212 fn main() {
1213     let mut ssss = S;
1214     foo(&mut s$0);
1215 }
1216             "#,
1217             expect![[r#"
1218                 lc ssss [type+local]
1219                 st S [type]
1220                 st S []
1221                 fn main() []
1222                 fn foo(…) []
1223             "#]],
1224         );
1225     }
1226
1227     #[test]
1228     fn suggest_deref() {
1229         check_relevance(
1230             r#"
1231 //- minicore: deref
1232 struct S;
1233 struct T(S);
1234
1235 impl core::ops::Deref for T {
1236     type Target = S;
1237
1238     fn deref(&self) -> &Self::Target {
1239         &self.0
1240     }
1241 }
1242
1243 fn foo(s: &S) {}
1244
1245 fn main() {
1246     let t = T(S);
1247     let m = 123;
1248
1249     foo($0);
1250 }
1251             "#,
1252             expect![[r#"
1253                 lc m [local]
1254                 lc t [local]
1255                 lc &t [type+local]
1256                 st T []
1257                 st S []
1258                 fn main() []
1259                 fn foo(…) []
1260                 md core []
1261                 tt Sized []
1262             "#]],
1263         )
1264     }
1265
1266     #[test]
1267     fn suggest_deref_mut() {
1268         check_relevance(
1269             r#"
1270 //- minicore: deref_mut
1271 struct S;
1272 struct T(S);
1273
1274 impl core::ops::Deref for T {
1275     type Target = S;
1276
1277     fn deref(&self) -> &Self::Target {
1278         &self.0
1279     }
1280 }
1281
1282 impl core::ops::DerefMut for T {
1283     fn deref_mut(&mut self) -> &mut Self::Target {
1284         &mut self.0
1285     }
1286 }
1287
1288 fn foo(s: &mut S) {}
1289
1290 fn main() {
1291     let t = T(S);
1292     let m = 123;
1293
1294     foo($0);
1295 }
1296             "#,
1297             expect![[r#"
1298                 lc m [local]
1299                 lc t [local]
1300                 lc &mut t [type+local]
1301                 st T []
1302                 st S []
1303                 fn main() []
1304                 fn foo(…) []
1305                 md core []
1306                 tt Sized []
1307             "#]],
1308         )
1309     }
1310
1311     #[test]
1312     fn locals() {
1313         check_relevance(
1314             r#"
1315 fn foo(bar: u32) {
1316     let baz = 0;
1317
1318     f$0
1319 }
1320 "#,
1321             expect![[r#"
1322                 lc baz [local]
1323                 lc bar [local]
1324                 fn foo(…) []
1325             "#]],
1326         );
1327     }
1328
1329     #[test]
1330     fn enum_owned() {
1331         check_relevance(
1332             r#"
1333 enum Foo { A, B }
1334 fn foo() {
1335     bar($0);
1336 }
1337 fn bar(t: Foo) {}
1338 "#,
1339             expect![[r#"
1340                 ev Foo::A [type]
1341                 ev Foo::B [type]
1342                 en Foo []
1343                 fn bar(…) []
1344                 fn foo() []
1345             "#]],
1346         );
1347     }
1348
1349     #[test]
1350     fn enum_ref() {
1351         check_relevance(
1352             r#"
1353 enum Foo { A, B }
1354 fn foo() {
1355     bar($0);
1356 }
1357 fn bar(t: &Foo) {}
1358 "#,
1359             expect![[r#"
1360                 ev Foo::A []
1361                 ev &Foo::A [type]
1362                 ev Foo::B []
1363                 ev &Foo::B [type]
1364                 en Foo []
1365                 fn bar(…) []
1366                 fn foo() []
1367             "#]],
1368         );
1369     }
1370
1371     #[test]
1372     fn suggest_deref_fn_ret() {
1373         check_relevance(
1374             r#"
1375 //- minicore: deref
1376 struct S;
1377 struct T(S);
1378
1379 impl core::ops::Deref for T {
1380     type Target = S;
1381
1382     fn deref(&self) -> &Self::Target {
1383         &self.0
1384     }
1385 }
1386
1387 fn foo(s: &S) {}
1388 fn bar() -> T {}
1389
1390 fn main() {
1391     foo($0);
1392 }
1393 "#,
1394             expect![[r#"
1395                 st T []
1396                 st S []
1397                 fn main() []
1398                 fn bar() []
1399                 fn &bar() [type]
1400                 fn foo(…) []
1401                 md core []
1402                 tt Sized []
1403             "#]],
1404         )
1405     }
1406
1407     #[test]
1408     fn op_function_relevances() {
1409         check_relevance(
1410             r#"
1411 #[lang = "sub"]
1412 trait Sub {
1413     fn sub(self, other: Self) -> Self { self }
1414 }
1415 impl Sub for u32 {}
1416 fn foo(a: u32) { a.$0 }
1417 "#,
1418             expect![[r#"
1419                 me sub(…) (as Sub) [op_method]
1420             "#]],
1421         );
1422         check_relevance(
1423             r#"
1424 struct Foo;
1425 impl Foo {
1426     fn new() -> Self {}
1427 }
1428 #[lang = "eq"]
1429 pub trait PartialEq<Rhs: ?Sized = Self> {
1430     fn eq(&self, other: &Rhs) -> bool;
1431     fn ne(&self, other: &Rhs) -> bool;
1432 }
1433
1434 impl PartialEq for Foo {}
1435 fn main() {
1436     Foo::$0
1437 }
1438 "#,
1439             expect![[r#"
1440                 fn new() []
1441                 me eq(…) (as PartialEq) [op_method]
1442                 me ne(…) (as PartialEq) [op_method]
1443             "#]],
1444         );
1445     }
1446
1447     #[test]
1448     fn struct_field_method_ref() {
1449         check_kinds(
1450             r#"
1451 struct Foo { bar: u32 }
1452 impl Foo { fn baz(&self) -> u32 { 0 } }
1453
1454 fn foo(f: Foo) { let _: &u32 = f.b$0 }
1455 "#,
1456             &[CompletionItemKind::Method, CompletionItemKind::SymbolKind(SymbolKind::Field)],
1457             // FIXME
1458             // Ideally we'd also suggest &f.bar and &f.baz() as exact
1459             // type matches. See #8058.
1460             expect![[r#"
1461                 [
1462                     CompletionItem {
1463                         label: "baz()",
1464                         source_range: 98..99,
1465                         delete: 98..99,
1466                         insert: "baz()$0",
1467                         kind: Method,
1468                         lookup: "baz",
1469                         detail: "fn(&self) -> u32",
1470                     },
1471                     CompletionItem {
1472                         label: "bar",
1473                         source_range: 98..99,
1474                         delete: 98..99,
1475                         insert: "bar",
1476                         kind: SymbolKind(
1477                             Field,
1478                         ),
1479                         detail: "u32",
1480                     },
1481                 ]
1482             "#]],
1483         );
1484     }
1485
1486     #[test]
1487     fn qualified_path_ref() {
1488         // disabled right now because it doesn't render correctly, #8058
1489         check_kinds(
1490             r#"
1491 struct S;
1492
1493 struct T;
1494 impl T {
1495     fn foo() -> S {}
1496 }
1497
1498 fn bar(s: &S) {}
1499
1500 fn main() {
1501     bar(T::$0);
1502 }
1503 "#,
1504             &[CompletionItemKind::SymbolKind(SymbolKind::Function)],
1505             expect![[r#"
1506                 [
1507                     CompletionItem {
1508                         label: "foo()",
1509                         source_range: 95..95,
1510                         delete: 95..95,
1511                         insert: "foo()$0",
1512                         kind: SymbolKind(
1513                             Function,
1514                         ),
1515                         lookup: "foo",
1516                         detail: "fn() -> S",
1517                     },
1518                 ]
1519             "#]],
1520         );
1521     }
1522
1523     #[test]
1524     fn generic_enum() {
1525         check_relevance(
1526             r#"
1527 enum Foo<T> { A(T), B }
1528 // bar() should not be an exact type match
1529 // because the generic parameters are different
1530 fn bar() -> Foo<u8> { Foo::B }
1531 // FIXME baz() should be an exact type match
1532 // because the types could unify, but it currently
1533 // is not. This is due to the T here being
1534 // TyKind::Placeholder rather than TyKind::Missing.
1535 fn baz<T>() -> Foo<T> { Foo::B }
1536 fn foo() {
1537     let foo: Foo<u32> = Foo::B;
1538     let _: Foo<u32> = f$0;
1539 }
1540 "#,
1541             expect![[r#"
1542                 lc foo [type+local]
1543                 ev Foo::A(…) [type_could_unify]
1544                 ev Foo::B [type_could_unify]
1545                 fn foo() []
1546                 en Foo []
1547                 fn baz() []
1548                 fn bar() []
1549             "#]],
1550         );
1551     }
1552
1553     #[test]
1554     fn postfix_exact_match_is_high_priority() {
1555         cov_mark::check!(postfix_exact_match_is_high_priority);
1556         check_relevance_for_kinds(
1557             r#"
1558 mod ops {
1559     pub trait Not {
1560         type Output;
1561         fn not(self) -> Self::Output;
1562     }
1563
1564     impl Not for bool {
1565         type Output = bool;
1566         fn not(self) -> bool { if self { false } else { true }}
1567     }
1568 }
1569
1570 fn main() {
1571     let _: bool = (9 > 2).not$0;
1572 }
1573     "#,
1574             &[CompletionItemKind::Snippet, CompletionItemKind::Method],
1575             expect![[r#"
1576                 sn not [snippet]
1577                 me not() (use ops::Not) [type_could_unify+requires_import]
1578                 sn if []
1579                 sn while []
1580                 sn ref []
1581                 sn refm []
1582                 sn match []
1583                 sn box []
1584                 sn dbg []
1585                 sn dbgr []
1586                 sn call []
1587             "#]],
1588         );
1589     }
1590
1591     #[test]
1592     fn postfix_inexact_match_is_low_priority() {
1593         cov_mark::check!(postfix_inexact_match_is_low_priority);
1594         check_relevance_for_kinds(
1595             r#"
1596 struct S;
1597 impl S {
1598     fn f(&self) {}
1599 }
1600 fn main() {
1601     S.$0
1602 }
1603     "#,
1604             &[CompletionItemKind::Snippet, CompletionItemKind::Method],
1605             expect![[r#"
1606                 me f() []
1607                 sn ref []
1608                 sn refm []
1609                 sn match []
1610                 sn box []
1611                 sn dbg []
1612                 sn dbgr []
1613                 sn call []
1614                 sn let []
1615                 sn letm []
1616             "#]],
1617         );
1618     }
1619
1620     #[test]
1621     fn flyimport_reduced_relevance() {
1622         check_relevance(
1623             r#"
1624 mod std {
1625     pub mod io {
1626         pub trait BufRead {}
1627         pub struct BufReader;
1628         pub struct BufWriter;
1629     }
1630 }
1631 struct Buffer;
1632
1633 fn f() {
1634     Buf$0
1635 }
1636 "#,
1637             expect![[r#"
1638                 md std []
1639                 st Buffer []
1640                 fn f() []
1641                 tt BufRead (use std::io::BufRead) [requires_import]
1642                 st BufReader (use std::io::BufReader) [requires_import]
1643                 st BufWriter (use std::io::BufWriter) [requires_import]
1644             "#]],
1645         );
1646     }
1647 }