1 //! See `CompletionContext` structure.
3 use hir::{Local, ScopeDef, Semantics, SemanticsScope, Type};
4 use ide_db::base_db::{FilePosition, SourceDatabase};
5 use ide_db::{call_info::ActiveParameter, RootDatabase};
7 algo::find_node_at_offset,
8 ast::{self, NameOrNameRef, NameOwner},
9 match_ast, AstNode, NodeOrToken,
11 SyntaxNode, SyntaxToken, TextRange, TextSize,
18 fn_is_prev, for_is_prev2, has_bind_pat_parent, has_block_expr_parent,
19 has_field_list_parent, has_impl_as_prev_sibling, has_impl_parent,
20 has_item_list_or_source_file_parent, has_ref_parent, has_trait_as_prev_sibling,
21 has_trait_parent, if_is_prev, inside_impl_trait_block, is_in_loop_body, is_match_arm,
27 /// `CompletionContext` is created early during completion to figure out, where
28 /// exactly is the cursor, syntax-wise.
30 pub(crate) struct CompletionContext<'a> {
31 pub(super) sema: Semantics<'a, RootDatabase>,
32 pub(super) scope: SemanticsScope<'a>,
33 pub(super) db: &'a RootDatabase,
34 pub(super) config: &'a CompletionConfig,
35 pub(super) position: FilePosition,
36 /// The token before the cursor, in the original file.
37 pub(super) original_token: SyntaxToken,
38 /// The token before the cursor, in the macro-expanded file.
39 pub(super) token: SyntaxToken,
40 pub(super) krate: Option<hir::Crate>,
41 pub(super) expected_name: Option<NameOrNameRef>,
42 pub(super) expected_type: Option<Type>,
43 pub(super) name_ref_syntax: Option<ast::NameRef>,
44 pub(super) lifetime_syntax: Option<ast::Lifetime>,
45 pub(super) lifetime_param_syntax: Option<ast::LifetimeParam>,
46 pub(super) function_syntax: Option<ast::Fn>,
47 pub(super) use_item_syntax: Option<ast::Use>,
48 pub(super) record_lit_syntax: Option<ast::RecordExpr>,
49 pub(super) record_pat_syntax: Option<ast::RecordPat>,
50 pub(super) record_field_syntax: Option<ast::RecordExprField>,
51 pub(super) impl_def: Option<ast::Impl>,
52 pub(super) lifetime_allowed: bool,
53 /// FIXME: `ActiveParameter` is string-based, which is very very wrong
54 pub(super) active_parameter: Option<ActiveParameter>,
55 pub(super) is_param: bool,
56 pub(super) is_label_ref: bool,
57 /// If a name-binding or reference to a const in a pattern.
58 /// Irrefutable patterns (like let) are excluded.
59 pub(super) is_pat_binding_or_const: bool,
60 pub(super) is_irrefutable_pat_binding: bool,
61 /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path.
62 pub(super) is_trivial_path: bool,
63 /// If not a trivial path, the prefix (qualifier).
64 pub(super) path_qual: Option<ast::Path>,
65 pub(super) after_if: bool,
66 /// `true` if we are a statement or a last expr in the block.
67 pub(super) can_be_stmt: bool,
68 /// `true` if we expect an expression at the cursor position.
69 pub(super) is_expr: bool,
70 /// Something is typed at the "top" level, in module or impl/trait.
71 pub(super) is_new_item: bool,
72 /// The receiver if this is a field or method access, i.e. writing something.$0
73 pub(super) dot_receiver: Option<ast::Expr>,
74 pub(super) dot_receiver_is_ambiguous_float_literal: bool,
75 /// If this is a call (method or function) in particular, i.e. the () are already there.
76 pub(super) is_call: bool,
77 /// Like `is_call`, but for tuple patterns.
78 pub(super) is_pattern_call: bool,
79 /// If this is a macro call, i.e. the () are already there.
80 pub(super) is_macro_call: bool,
81 pub(super) is_path_type: bool,
82 pub(super) has_type_args: bool,
83 pub(super) attribute_under_caret: Option<ast::Attr>,
84 pub(super) mod_declaration_under_caret: Option<ast::Module>,
85 pub(super) unsafe_is_prev: bool,
86 pub(super) if_is_prev: bool,
87 pub(super) block_expr_parent: bool,
88 pub(super) bind_pat_parent: bool,
89 pub(super) ref_pat_parent: bool,
90 pub(super) in_loop_body: bool,
91 pub(super) has_trait_parent: bool,
92 pub(super) has_impl_parent: bool,
93 pub(super) inside_impl_trait_block: bool,
94 pub(super) has_field_list_parent: bool,
95 pub(super) trait_as_prev_sibling: bool,
96 pub(super) impl_as_prev_sibling: bool,
97 pub(super) is_match_arm: bool,
98 pub(super) has_item_list_or_source_file_parent: bool,
99 pub(super) for_is_prev2: bool,
100 pub(super) fn_is_prev: bool,
101 pub(super) incomplete_let: bool,
102 pub(super) locals: Vec<(String, Local)>,
105 impl<'a> CompletionContext<'a> {
107 db: &'a RootDatabase,
108 position: FilePosition,
109 config: &'a CompletionConfig,
110 ) -> Option<CompletionContext<'a>> {
111 let sema = Semantics::new(db);
113 let original_file = sema.parse(position.file_id);
115 // Insert a fake ident to get a valid parse tree. We will use this file
116 // to determine context, though the original_file will be used for
117 // actual completion.
118 let file_with_fake_ident = {
119 let parse = db.parse(position.file_id);
120 let edit = Indel::insert(position.offset, "intellijRulezz".to_string());
121 parse.reparse(&edit).tree()
123 let fake_ident_token =
124 file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
126 let krate = sema.to_module_def(position.file_id).map(|m| m.krate());
128 original_file.syntax().token_at_offset(position.offset).left_biased()?;
129 let token = sema.descend_into_macros(original_token.clone());
130 let scope = sema.scope_at_offset(&token, position.offset);
131 let mut locals = vec![];
132 scope.process_all_names(&mut |name, scope| {
133 if let ScopeDef::Local(local) = scope {
134 locals.push((name.to_string(), local));
137 let mut ctx = CompletionContext {
146 lifetime_allowed: false,
149 name_ref_syntax: None,
150 lifetime_syntax: None,
151 lifetime_param_syntax: None,
152 function_syntax: None,
153 use_item_syntax: None,
154 record_lit_syntax: None,
155 record_pat_syntax: None,
156 record_field_syntax: None,
158 active_parameter: ActiveParameter::at(db, position),
161 is_pat_binding_or_const: false,
162 is_irrefutable_pat_binding: false,
163 is_trivial_path: false,
170 dot_receiver_is_ambiguous_float_literal: false,
172 is_pattern_call: false,
173 is_macro_call: false,
175 has_type_args: false,
176 attribute_under_caret: None,
177 mod_declaration_under_caret: None,
178 unsafe_is_prev: false,
180 block_expr_parent: false,
181 bind_pat_parent: false,
182 ref_pat_parent: false,
184 has_trait_parent: false,
185 has_impl_parent: false,
186 inside_impl_trait_block: false,
187 has_field_list_parent: false,
188 trait_as_prev_sibling: false,
189 impl_as_prev_sibling: false,
191 has_item_list_or_source_file_parent: false,
194 incomplete_let: false,
198 let mut original_file = original_file.syntax().clone();
199 let mut hypothetical_file = file_with_fake_ident.syntax().clone();
200 let mut offset = position.offset;
201 let mut fake_ident_token = fake_ident_token;
203 // Are we inside a macro call?
204 while let (Some(actual_macro_call), Some(macro_call_with_fake_ident)) = (
205 find_node_at_offset::<ast::MacroCall>(&original_file, offset),
206 find_node_at_offset::<ast::MacroCall>(&hypothetical_file, offset),
208 if actual_macro_call.path().as_ref().map(|s| s.syntax().text())
209 != macro_call_with_fake_ident.path().as_ref().map(|s| s.syntax().text())
213 let hypothetical_args = match macro_call_with_fake_ident.token_tree() {
217 if let (Some(actual_expansion), Some(hypothetical_expansion)) = (
218 ctx.sema.expand(&actual_macro_call),
219 ctx.sema.speculative_expand(
225 let new_offset = hypothetical_expansion.1.text_range().start();
226 if new_offset > actual_expansion.text_range().end() {
229 original_file = actual_expansion;
230 hypothetical_file = hypothetical_expansion.0;
231 fake_ident_token = hypothetical_expansion.1;
237 ctx.fill_keyword_patterns(&hypothetical_file, offset);
238 ctx.fill(&original_file, hypothetical_file, offset);
242 /// Checks whether completions in that particular case don't make much sense.
244 /// - `fn $0` -- we expect function name, it's unlikely that "hint" will be helpful.
245 /// Exception for this case is `impl Trait for Foo`, where we would like to hint trait method names.
246 /// - `for _ i$0` -- obviously, it'll be "in" keyword.
247 pub(crate) fn no_completion_required(&self) -> bool {
248 (self.fn_is_prev && !self.inside_impl_trait_block) || self.for_is_prev2
251 /// The range of the identifier that is being completed.
252 pub(crate) fn source_range(&self) -> TextRange {
253 // check kind of macro-expanded token, but use range of original token
254 let kind = self.token.kind();
255 if kind == IDENT || kind == LIFETIME_IDENT || kind == UNDERSCORE || kind.is_keyword() {
256 cov_mark::hit!(completes_if_prefix_is_keyword);
257 self.original_token.text_range()
259 TextRange::empty(self.position.offset)
263 fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: TextSize) {
264 let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap();
265 let syntax_element = NodeOrToken::Token(fake_ident_token);
266 self.block_expr_parent = has_block_expr_parent(syntax_element.clone());
267 self.unsafe_is_prev = unsafe_is_prev(syntax_element.clone());
268 self.if_is_prev = if_is_prev(syntax_element.clone());
269 self.bind_pat_parent = has_bind_pat_parent(syntax_element.clone());
270 self.ref_pat_parent = has_ref_parent(syntax_element.clone());
271 self.in_loop_body = is_in_loop_body(syntax_element.clone());
272 self.has_trait_parent = has_trait_parent(syntax_element.clone());
273 self.has_impl_parent = has_impl_parent(syntax_element.clone());
274 self.inside_impl_trait_block = inside_impl_trait_block(syntax_element.clone());
275 self.has_field_list_parent = has_field_list_parent(syntax_element.clone());
276 self.impl_as_prev_sibling = has_impl_as_prev_sibling(syntax_element.clone());
277 self.trait_as_prev_sibling = has_trait_as_prev_sibling(syntax_element.clone());
278 self.is_match_arm = is_match_arm(syntax_element.clone());
279 self.has_item_list_or_source_file_parent =
280 has_item_list_or_source_file_parent(syntax_element.clone());
281 self.mod_declaration_under_caret =
282 find_node_at_offset::<ast::Module>(&file_with_fake_ident, offset)
283 .filter(|module| module.item_list().is_none());
284 self.for_is_prev2 = for_is_prev2(syntax_element.clone());
285 self.fn_is_prev = fn_is_prev(syntax_element.clone());
286 self.incomplete_let =
287 syntax_element.ancestors().take(6).find_map(ast::LetStmt::cast).map_or(false, |it| {
288 it.syntax().text_range().end() == syntax_element.text_range().end()
292 fn fill_impl_def(&mut self) {
295 .token_ancestors_with_macros(self.token.clone())
296 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
297 .find_map(ast::Impl::cast);
302 original_file: &SyntaxNode,
303 file_with_fake_ident: SyntaxNode,
306 let (expected_type, expected_name) = {
307 let mut node = match self.token.parent() {
314 ast::LetStmt(it) => {
315 cov_mark::hit!(expected_type_let_with_leading_char);
316 cov_mark::hit!(expected_type_let_without_leading_char);
318 .and_then(|pat| self.sema.type_of_pat(&pat));
319 let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() {
320 ident.name().map(NameOrNameRef::Name)
327 ast::ArgList(_it) => {
328 cov_mark::hit!(expected_type_fn_param_with_leading_char);
329 cov_mark::hit!(expected_type_fn_param_without_leading_char);
330 ActiveParameter::at_token(
334 let name = ap.ident().map(NameOrNameRef::Name);
337 .unwrap_or((None, None))
339 ast::RecordExprFieldList(_it) => {
340 cov_mark::hit!(expected_type_struct_field_without_leading_char);
341 self.token.prev_sibling_or_token()
342 .and_then(|se| se.into_node())
343 .and_then(|node| ast::RecordExprField::cast(node))
344 .and_then(|rf| self.sema.resolve_record_field(&rf).zip(Some(rf)))
346 Some(f.0.signature_ty(self.db)),
347 rf.field_name().map(NameOrNameRef::NameRef),
349 .unwrap_or((None, None))
351 ast::RecordExprField(it) => {
352 cov_mark::hit!(expected_type_struct_field_with_leading_char);
354 .resolve_record_field(&it)
356 Some(f.0.signature_ty(self.db)),
357 it.field_name().map(NameOrNameRef::NameRef),
359 .unwrap_or((None, None))
361 ast::MatchExpr(it) => {
362 cov_mark::hit!(expected_type_match_arm_without_leading_char);
364 .and_then(|e| self.sema.type_of_expr(&e));
368 ast::IdentPat(it) => {
369 cov_mark::hit!(expected_type_if_let_with_leading_char);
370 cov_mark::hit!(expected_type_match_arm_with_leading_char);
371 let ty = self.sema.type_of_pat(&ast::Pat::from(it));
376 cov_mark::hit!(expected_type_fn_ret_with_leading_char);
377 cov_mark::hit!(expected_type_fn_ret_without_leading_char);
378 let ty = self.token.ancestors()
379 .find_map(|ancestor| ast::Expr::cast(ancestor))
380 .and_then(|expr| self.sema.type_of_expr(&expr));
385 match node.parent() {
390 None => (None, None),
397 self.expected_type = expected_type;
398 self.expected_name = expected_name;
399 self.attribute_under_caret = find_node_at_offset(&file_with_fake_ident, offset);
401 if let Some(lifetime) = find_node_at_offset::<ast::Lifetime>(&file_with_fake_ident, offset)
403 self.classify_lifetime(original_file, lifetime, offset);
406 // First, let's try to complete a reference to some declaration.
407 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&file_with_fake_ident, offset) {
408 // Special case, `trait T { fn foo(i_am_a_name_ref) {} }`.
410 if is_node::<ast::Param>(name_ref.syntax()) {
411 self.is_param = true;
414 // FIXME: remove this (V) duplication and make the check more precise
415 if name_ref.syntax().ancestors().find_map(ast::RecordPatFieldList::cast).is_some() {
416 self.record_pat_syntax =
417 self.sema.find_node_at_offset_with_macros(&original_file, offset);
419 self.classify_name_ref(original_file, name_ref, offset);
422 // Otherwise, see if this is a declaration. We can use heuristics to
423 // suggest declaration names, see `CompletionKind::Magic`.
424 if let Some(name) = find_node_at_offset::<ast::Name>(&file_with_fake_ident, offset) {
425 if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::IdentPat::cast) {
426 self.is_pat_binding_or_const = true;
427 if bind_pat.at_token().is_some()
428 || bind_pat.ref_token().is_some()
429 || bind_pat.mut_token().is_some()
431 self.is_pat_binding_or_const = false;
433 if bind_pat.syntax().parent().and_then(ast::RecordPatFieldList::cast).is_some() {
434 self.is_pat_binding_or_const = false;
436 if let Some(Some(pat)) = bind_pat.syntax().ancestors().find_map(|node| {
439 ast::LetStmt(it) => Some(it.pat()),
440 ast::Param(it) => Some(it.pat()),
445 if pat.syntax().text_range().contains_range(bind_pat.syntax().text_range()) {
446 self.is_pat_binding_or_const = false;
447 self.is_irrefutable_pat_binding = true;
451 self.fill_impl_def();
453 if is_node::<ast::Param>(name.syntax()) {
454 self.is_param = true;
457 // FIXME: remove this (^) duplication and make the check more precise
458 if name.syntax().ancestors().find_map(ast::RecordPatFieldList::cast).is_some() {
459 self.record_pat_syntax =
460 self.sema.find_node_at_offset_with_macros(&original_file, offset);
465 fn classify_lifetime(
467 original_file: &SyntaxNode,
468 lifetime: ast::Lifetime,
471 self.lifetime_syntax =
472 find_node_at_offset(original_file, lifetime.syntax().text_range().start());
473 if let Some(parent) = lifetime.syntax().parent() {
474 if parent.kind() == syntax::SyntaxKind::ERROR {
478 if parent.kind() != syntax::SyntaxKind::LABEL {
481 ast::LifetimeParam(_it) => {
482 self.lifetime_allowed = true;
483 self.lifetime_param_syntax =
484 self.sema.find_node_at_offset_with_macros(original_file, offset);
486 ast::BreakExpr(_it) => self.is_label_ref = true,
487 ast::ContinueExpr(_it) => self.is_label_ref = true,
488 ast::Label(_it) => (),
489 _ => self.lifetime_allowed = true,
496 fn classify_name_ref(
498 original_file: &SyntaxNode,
499 name_ref: ast::NameRef,
502 self.name_ref_syntax =
503 find_node_at_offset(original_file, name_ref.syntax().text_range().start());
504 let name_range = name_ref.syntax().text_range();
505 if ast::RecordExprField::for_field_name(&name_ref).is_some() {
506 self.record_lit_syntax =
507 self.sema.find_node_at_offset_with_macros(original_file, offset);
510 self.fill_impl_def();
512 let top_node = name_ref
515 .take_while(|it| it.text_range() == name_range)
519 match top_node.parent().map(|it| it.kind()) {
520 Some(SOURCE_FILE) | Some(ITEM_LIST) => {
521 self.is_new_item = true;
527 self.use_item_syntax =
528 self.sema.token_ancestors_with_macros(self.token.clone()).find_map(ast::Use::cast);
530 self.function_syntax = self
532 .token_ancestors_with_macros(self.token.clone())
533 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
534 .find_map(ast::Fn::cast);
536 self.record_field_syntax = self
538 .token_ancestors_with_macros(self.token.clone())
540 it.kind() != SOURCE_FILE && it.kind() != MODULE && it.kind() != CALL_EXPR
542 .find_map(ast::RecordExprField::cast);
544 let parent = match name_ref.syntax().parent() {
549 if let Some(segment) = ast::PathSegment::cast(parent.clone()) {
550 let path = segment.parent_path();
554 .and_then(ast::PathExpr::cast)
555 .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
557 self.is_macro_call = path.syntax().parent().and_then(ast::MacroCall::cast).is_some();
558 self.is_pattern_call =
559 path.syntax().parent().and_then(ast::TupleStructPat::cast).is_some();
561 self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some();
562 self.has_type_args = segment.generic_arg_list().is_some();
564 if let Some(path) = path_or_use_tree_qualifier(&path) {
565 self.path_qual = path
568 find_node_with_range::<ast::PathSegment>(
570 it.syntax().text_range(),
573 .map(|it| it.parent_path());
577 if let Some(segment) = path.segment() {
578 if segment.coloncolon_token().is_some() {
583 self.is_trivial_path = true;
585 // Find either enclosing expr statement (thing with `;`) or a
586 // block. If block, check that we are the last expr.
587 self.can_be_stmt = name_ref
591 if let Some(stmt) = ast::ExprStmt::cast(node.clone()) {
592 return Some(stmt.syntax().text_range() == name_ref.syntax().text_range());
594 if let Some(block) = ast::BlockExpr::cast(node) {
596 block.tail_expr().map(|e| e.syntax().text_range())
597 == Some(name_ref.syntax().text_range()),
603 self.is_expr = path.syntax().parent().and_then(ast::PathExpr::cast).is_some();
605 if let Some(off) = name_ref.syntax().text_range().start().checked_sub(2.into()) {
606 if let Some(if_expr) =
607 self.sema.find_node_at_offset_with_macros::<ast::IfExpr>(original_file, off)
609 if if_expr.syntax().text_range().end() < name_ref.syntax().text_range().start()
611 self.after_if = true;
616 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
617 // The receiver comes before the point of insertion of the fake
618 // ident, so it should have the same range in the non-modified file
619 self.dot_receiver = field_expr
621 .map(|e| e.syntax().text_range())
622 .and_then(|r| find_node_with_range(original_file, r));
623 self.dot_receiver_is_ambiguous_float_literal =
624 if let Some(ast::Expr::Literal(l)) = &self.dot_receiver {
626 ast::LiteralKind::FloatNumber { .. } => l.token().text().ends_with('.'),
633 if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) {
635 self.dot_receiver = method_call_expr
637 .map(|e| e.syntax().text_range())
638 .and_then(|r| find_node_with_range(original_file, r));
644 fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> {
645 syntax.covering_element(range).ancestors().find_map(N::cast)
648 fn is_node<N: AstNode>(node: &SyntaxNode) -> bool {
649 match node.ancestors().find_map(N::cast) {
651 Some(n) => n.syntax().text_range() == node.text_range(),
655 fn path_or_use_tree_qualifier(path: &ast::Path) -> Option<ast::Path> {
656 if let Some(qual) = path.qualifier() {
659 let use_tree_list = path.syntax().ancestors().find_map(ast::UseTreeList::cast)?;
660 let use_tree = use_tree_list.syntax().parent().and_then(ast::UseTree::cast)?;
666 use expect_test::{expect, Expect};
669 use crate::test_utils::{position, TEST_CONFIG};
671 use super::CompletionContext;
673 fn check_expected_type_and_name(ra_fixture: &str, expect: Expect) {
674 let (db, pos) = position(ra_fixture);
675 let completion_context = CompletionContext::new(&db, pos, &TEST_CONFIG).unwrap();
677 let ty = completion_context
679 .map(|t| t.display_test(&db).to_string())
680 .unwrap_or("?".to_owned());
682 let name = completion_context
684 .map_or_else(|| "?".to_owned(), |name| name.to_string());
686 expect.assert_eq(&format!("ty: {}, name: {}", ty, name));
690 fn expected_type_let_without_leading_char() {
691 cov_mark::check!(expected_type_let_without_leading_char);
692 check_expected_type_and_name(
698 expect![[r#"ty: u32, name: x"#]],
703 fn expected_type_let_with_leading_char() {
704 cov_mark::check!(expected_type_let_with_leading_char);
705 check_expected_type_and_name(
711 expect![[r#"ty: u32, name: x"#]],
716 fn expected_type_fn_param_without_leading_char() {
717 cov_mark::check!(expected_type_fn_param_without_leading_char);
718 check_expected_type_and_name(
726 expect![[r#"ty: u32, name: x"#]],
731 fn expected_type_fn_param_with_leading_char() {
732 cov_mark::check!(expected_type_fn_param_with_leading_char);
733 check_expected_type_and_name(
741 expect![[r#"ty: u32, name: x"#]],
746 fn expected_type_struct_field_without_leading_char() {
747 cov_mark::check!(expected_type_struct_field_without_leading_char);
748 check_expected_type_and_name(
750 struct Foo { a: u32 }
755 expect![[r#"ty: u32, name: a"#]],
760 fn expected_type_struct_field_with_leading_char() {
761 cov_mark::check!(expected_type_struct_field_with_leading_char);
762 check_expected_type_and_name(
764 struct Foo { a: u32 }
769 expect![[r#"ty: u32, name: a"#]],
774 fn expected_type_match_arm_without_leading_char() {
775 cov_mark::check!(expected_type_match_arm_without_leading_char);
776 check_expected_type_and_name(
783 expect![[r#"ty: E, name: ?"#]],
788 fn expected_type_match_arm_with_leading_char() {
789 cov_mark::check!(expected_type_match_arm_with_leading_char);
790 check_expected_type_and_name(
797 expect![[r#"ty: E, name: ?"#]],
802 fn expected_type_if_let_without_leading_char() {
803 check_expected_type_and_name(
805 enum Foo { Bar, Baz, Quux }
812 expect![[r#"ty: (), name: ?"#]],
813 ) // FIXME should be `ty: u32, name: ?`
817 fn expected_type_if_let_with_leading_char() {
818 cov_mark::check!(expected_type_if_let_with_leading_char);
819 check_expected_type_and_name(
821 enum Foo { Bar, Baz, Quux }
828 expect![[r#"ty: Foo, name: ?"#]],
833 fn expected_type_fn_ret_without_leading_char() {
834 cov_mark::check!(expected_type_fn_ret_without_leading_char);
835 check_expected_type_and_name(
841 expect![[r#"ty: (), name: ?"#]],
842 ) // FIXME this should be `ty: u32, name: ?`
846 fn expected_type_fn_ret_with_leading_char() {
847 cov_mark::check!(expected_type_fn_ret_with_leading_char);
848 check_expected_type_and_name(
854 expect![[r#"ty: u32, name: ?"#]],