1 //! See `CompletionContext` structure.
3 use hir::{Local, ScopeDef, Semantics, SemanticsScope, Type};
5 base_db::{FilePosition, SourceDatabase},
6 call_info::ActiveParameter,
10 algo::find_node_at_offset,
11 ast::{self, NameOrNameRef, NameOwner},
12 match_ast, AstNode, NodeOrToken,
13 SyntaxKind::{self, *},
14 SyntaxNode, SyntaxToken, TextRange, TextSize, T,
20 determine_location, determine_prev_sibling, for_is_prev2, inside_impl_trait_block,
21 is_in_loop_body, previous_token, ImmediateLocation, ImmediatePrevSibling,
26 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
27 pub(crate) enum PatternRefutability {
33 pub(super) enum PathKind {
39 pub(crate) struct PathCompletionContext {
40 /// If this is a call with () already there
41 call_kind: Option<CallKind>,
42 /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path.
43 pub(super) is_trivial_path: bool,
44 /// If not a trivial path, the prefix (qualifier).
45 pub(super) qualifier: Option<ast::Path>,
46 /// Whether the qualifier comes from a use tree parent or not
47 pub(super) use_tree_parent: bool,
48 pub(super) kind: Option<PathKind>,
49 /// Whether the path segment has type args or not.
50 pub(super) has_type_args: bool,
51 /// `true` if we are a statement or a last expr in the block.
52 pub(super) can_be_stmt: bool,
53 pub(super) in_loop_body: bool,
56 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
57 pub(crate) enum CallKind {
62 /// `CompletionContext` is created early during completion to figure out, where
63 /// exactly is the cursor, syntax-wise.
65 pub(crate) struct CompletionContext<'a> {
66 pub(super) sema: Semantics<'a, RootDatabase>,
67 pub(super) scope: SemanticsScope<'a>,
68 pub(super) db: &'a RootDatabase,
69 pub(super) config: &'a CompletionConfig,
70 pub(super) position: FilePosition,
71 /// The token before the cursor, in the original file.
72 pub(super) original_token: SyntaxToken,
73 /// The token before the cursor, in the macro-expanded file.
74 pub(super) token: SyntaxToken,
75 pub(super) krate: Option<hir::Crate>,
76 pub(super) expected_name: Option<NameOrNameRef>,
77 pub(super) expected_type: Option<Type>,
79 /// The parent function of the cursor position if it exists.
80 pub(super) function_def: Option<ast::Fn>,
81 /// The parent impl of the cursor position if it exists.
82 pub(super) impl_def: Option<ast::Impl>,
83 pub(super) name_ref_syntax: Option<ast::NameRef>,
85 // potentially set if we are completing a lifetime
86 pub(super) lifetime_syntax: Option<ast::Lifetime>,
87 pub(super) lifetime_param_syntax: Option<ast::LifetimeParam>,
88 pub(super) lifetime_allowed: bool,
89 pub(super) is_label_ref: bool,
91 // potentially set if we are completing a name
92 pub(super) is_pat_or_const: Option<PatternRefutability>,
93 pub(super) is_param: bool,
95 pub(super) completion_location: Option<ImmediateLocation>,
96 pub(super) prev_sibling: Option<ImmediatePrevSibling>,
97 pub(super) attribute_under_caret: Option<ast::Attr>,
98 pub(super) previous_token: Option<SyntaxToken>,
100 pub(super) path_context: Option<PathCompletionContext>,
101 pub(super) active_parameter: Option<ActiveParameter>,
102 pub(super) locals: Vec<(String, Local)>,
104 pub(super) incomplete_let: bool,
106 no_completion_required: bool,
109 impl<'a> CompletionContext<'a> {
111 db: &'a RootDatabase,
112 position: FilePosition,
113 config: &'a CompletionConfig,
114 ) -> Option<CompletionContext<'a>> {
115 let sema = Semantics::new(db);
117 let original_file = sema.parse(position.file_id);
119 // Insert a fake ident to get a valid parse tree. We will use this file
120 // to determine context, though the original_file will be used for
121 // actual completion.
122 let file_with_fake_ident = {
123 let parse = db.parse(position.file_id);
124 let edit = Indel::insert(position.offset, "intellijRulezz".to_string());
125 parse.reparse(&edit).tree()
127 let fake_ident_token =
128 file_with_fake_ident.syntax().token_at_offset(position.offset).right_biased().unwrap();
130 let krate = sema.to_module_def(position.file_id).map(|m| m.krate());
132 original_file.syntax().token_at_offset(position.offset).left_biased()?;
133 let token = sema.descend_into_macros(original_token.clone());
134 let scope = sema.scope_at_offset(&token, position.offset);
135 let mut locals = vec![];
136 scope.process_all_names(&mut |name, scope| {
137 if let ScopeDef::Local(local) = scope {
138 locals.push((name.to_string(), local));
141 let mut ctx = CompletionContext {
154 name_ref_syntax: None,
155 lifetime_syntax: None,
156 lifetime_param_syntax: None,
157 lifetime_allowed: false,
159 is_pat_or_const: None,
161 completion_location: None,
163 attribute_under_caret: None,
164 previous_token: None,
166 active_parameter: ActiveParameter::at(db, position),
168 incomplete_let: false,
169 no_completion_required: false,
172 let mut original_file = original_file.syntax().clone();
173 let mut speculative_file = file_with_fake_ident.syntax().clone();
174 let mut offset = position.offset;
175 let mut fake_ident_token = fake_ident_token;
177 // Are we inside a macro call?
178 while let (Some(actual_macro_call), Some(macro_call_with_fake_ident)) = (
179 find_node_at_offset::<ast::MacroCall>(&original_file, offset),
180 find_node_at_offset::<ast::MacroCall>(&speculative_file, offset),
182 if actual_macro_call.path().as_ref().map(|s| s.syntax().text())
183 != macro_call_with_fake_ident.path().as_ref().map(|s| s.syntax().text())
187 let speculative_args = match macro_call_with_fake_ident.token_tree() {
191 if let (Some(actual_expansion), Some(speculative_expansion)) = (
192 ctx.sema.expand(&actual_macro_call),
193 ctx.sema.speculative_expand(
199 let new_offset = speculative_expansion.1.text_range().start();
200 if new_offset > actual_expansion.text_range().end() {
203 original_file = actual_expansion;
204 speculative_file = speculative_expansion.0;
205 fake_ident_token = speculative_expansion.1;
211 ctx.fill(&original_file, speculative_file, offset);
215 /// Checks whether completions in that particular case don't make much sense.
217 /// - `fn $0` -- we expect function name, it's unlikely that "hint" will be helpful.
218 /// Exception for this case is `impl Trait for Foo`, where we would like to hint trait method names.
219 /// - `for _ i$0` -- obviously, it'll be "in" keyword.
220 pub(crate) fn no_completion_required(&self) -> bool {
221 self.no_completion_required
224 /// The range of the identifier that is being completed.
225 pub(crate) fn source_range(&self) -> TextRange {
226 // check kind of macro-expanded token, but use range of original token
227 let kind = self.token.kind();
228 if kind == IDENT || kind == LIFETIME_IDENT || kind == UNDERSCORE || kind.is_keyword() {
229 cov_mark::hit!(completes_if_prefix_is_keyword);
230 self.original_token.text_range()
231 } else if kind == CHAR {
232 // assume we are completing a lifetime but the user has only typed the '
233 cov_mark::hit!(completes_if_lifetime_without_idents);
234 TextRange::at(self.original_token.text_range().start(), TextSize::from(1))
236 TextRange::empty(self.position.offset)
240 pub(crate) fn previous_token_is(&self, kind: SyntaxKind) -> bool {
241 self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind)
244 pub(crate) fn expects_assoc_item(&self) -> bool {
245 matches!(self.completion_location, Some(ImmediateLocation::Trait | ImmediateLocation::Impl))
248 pub(crate) fn has_dot_receiver(&self) -> bool {
250 &self.completion_location,
251 Some(ImmediateLocation::FieldAccess { receiver, .. } | ImmediateLocation::MethodCall { receiver,.. })
252 if receiver.is_some()
256 pub(crate) fn dot_receiver(&self) -> Option<&ast::Expr> {
257 match &self.completion_location {
259 ImmediateLocation::MethodCall { receiver, .. }
260 | ImmediateLocation::FieldAccess { receiver, .. },
261 ) => receiver.as_ref(),
266 pub(crate) fn expects_non_trait_assoc_item(&self) -> bool {
267 matches!(self.completion_location, Some(ImmediateLocation::Impl))
270 pub(crate) fn expects_item(&self) -> bool {
271 matches!(self.completion_location, Some(ImmediateLocation::ItemList))
274 pub(crate) fn expects_generic_arg(&self) -> bool {
275 matches!(self.completion_location, Some(ImmediateLocation::GenericArgList(_)))
278 pub(crate) fn has_block_expr_parent(&self) -> bool {
279 matches!(self.completion_location, Some(ImmediateLocation::BlockExpr))
282 pub(crate) fn expects_ident_pat_or_ref_expr(&self) -> bool {
284 self.completion_location,
285 Some(ImmediateLocation::IdentPat | ImmediateLocation::RefExpr)
289 pub(crate) fn expect_field(&self) -> bool {
291 self.completion_location,
292 Some(ImmediateLocation::RecordField | ImmediateLocation::TupleField)
296 pub(crate) fn in_use_tree(&self) -> bool {
298 self.completion_location,
299 Some(ImmediateLocation::Use | ImmediateLocation::UseTree)
303 pub(crate) fn has_impl_or_trait_prev_sibling(&self) -> bool {
306 Some(ImmediatePrevSibling::ImplDefType | ImmediatePrevSibling::TraitDefName)
310 pub(crate) fn has_impl_prev_sibling(&self) -> bool {
311 matches!(self.prev_sibling, Some(ImmediatePrevSibling::ImplDefType))
314 pub(crate) fn has_visibility_prev_sibling(&self) -> bool {
315 matches!(self.prev_sibling, Some(ImmediatePrevSibling::Visibility))
318 pub(crate) fn after_if(&self) -> bool {
319 matches!(self.prev_sibling, Some(ImmediatePrevSibling::IfExpr))
322 pub(crate) fn is_path_disallowed(&self) -> bool {
323 self.attribute_under_caret.is_some()
324 || self.previous_token_is(T![unsafe])
327 Some(ImmediatePrevSibling::Attribute | ImmediatePrevSibling::Visibility)
330 self.completion_location,
332 ImmediateLocation::Attribute(_)
333 | ImmediateLocation::ModDeclaration(_)
334 | ImmediateLocation::RecordPat(_)
335 | ImmediateLocation::RecordExpr(_)
340 pub(crate) fn expects_expression(&self) -> bool {
341 matches!(self.path_context, Some(PathCompletionContext { kind: Some(PathKind::Expr), .. }))
344 pub(crate) fn expects_type(&self) -> bool {
345 matches!(self.path_context, Some(PathCompletionContext { kind: Some(PathKind::Type), .. }))
348 pub(crate) fn path_call_kind(&self) -> Option<CallKind> {
349 self.path_context.as_ref().and_then(|it| it.call_kind)
352 pub(crate) fn is_trivial_path(&self) -> bool {
353 matches!(self.path_context, Some(PathCompletionContext { is_trivial_path: true, .. }))
356 pub(crate) fn is_non_trivial_path(&self) -> bool {
357 matches!(self.path_context, Some(PathCompletionContext { is_trivial_path: false, .. }))
360 pub(crate) fn path_qual(&self) -> Option<&ast::Path> {
361 self.path_context.as_ref().and_then(|it| it.qualifier.as_ref())
364 fn fill_impl_def(&mut self) {
367 .token_ancestors_with_macros(self.token.clone())
368 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
369 .find_map(ast::Impl::cast);
372 fn expected_type_and_name(&self) -> (Option<Type>, Option<NameOrNameRef>) {
373 let mut node = match self.token.parent() {
375 None => return (None, None),
380 ast::LetStmt(it) => {
381 cov_mark::hit!(expected_type_let_with_leading_char);
382 cov_mark::hit!(expected_type_let_without_leading_char);
384 .and_then(|pat| self.sema.type_of_pat(&pat))
385 .or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)));
386 let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() {
387 ident.name().map(NameOrNameRef::Name)
394 ast::ArgList(_it) => {
395 cov_mark::hit!(expected_type_fn_param);
396 ActiveParameter::at_token(
400 let name = ap.ident().map(NameOrNameRef::Name);
401 let ty = if has_ref(&self.token) {
402 cov_mark::hit!(expected_type_fn_param_ref);
409 .unwrap_or((None, None))
411 ast::RecordExprFieldList(_it) => {
412 cov_mark::hit!(expected_type_struct_field_without_leading_char);
413 // wouldn't try {} be nice...
415 let expr_field = self.token.prev_sibling_or_token()?
417 .and_then(ast::RecordExprField::cast)?;
418 let (_, _, ty) = self.sema.resolve_record_field(&expr_field)?;
421 expr_field.field_name().map(NameOrNameRef::NameRef),
423 })().unwrap_or((None, None))
425 ast::RecordExprField(it) => {
426 cov_mark::hit!(expected_type_struct_field_with_leading_char);
428 it.expr().as_ref().and_then(|e| self.sema.type_of_expr(e)),
429 it.field_name().map(NameOrNameRef::NameRef),
432 ast::MatchExpr(it) => {
433 cov_mark::hit!(expected_type_match_arm_without_leading_char);
435 .and_then(|e| self.sema.type_of_expr(&e));
439 cov_mark::hit!(expected_type_if_let_without_leading_char);
440 let ty = it.condition()
441 .and_then(|cond| cond.expr())
442 .and_then(|e| self.sema.type_of_expr(&e));
445 ast::IdentPat(it) => {
446 cov_mark::hit!(expected_type_if_let_with_leading_char);
447 cov_mark::hit!(expected_type_match_arm_with_leading_char);
448 let ty = self.sema.type_of_pat(&ast::Pat::from(it));
452 cov_mark::hit!(expected_type_fn_ret_with_leading_char);
453 cov_mark::hit!(expected_type_fn_ret_without_leading_char);
454 let def = self.sema.to_def(&it);
455 (def.map(|def| def.ret_type(self.db)), None)
457 ast::ClosureExpr(it) => {
458 let ty = self.sema.type_of_expr(&it.into());
459 ty.and_then(|ty| ty.as_callable(self.db))
460 .map(|c| (Some(c.return_type()), None))
461 .unwrap_or((None, None))
463 ast::Stmt(_it) => (None, None),
465 match node.parent() {
470 None => (None, None),
480 original_file: &SyntaxNode,
481 file_with_fake_ident: SyntaxNode,
484 let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap();
485 let syntax_element = NodeOrToken::Token(fake_ident_token);
486 self.previous_token = previous_token(syntax_element.clone());
487 self.attribute_under_caret = syntax_element.ancestors().find_map(ast::Attr::cast);
488 self.no_completion_required = {
489 let inside_impl_trait_block = inside_impl_trait_block(syntax_element.clone());
490 let fn_is_prev = self.previous_token_is(T![fn]);
491 let for_is_prev2 = for_is_prev2(syntax_element.clone());
492 (fn_is_prev && !inside_impl_trait_block) || for_is_prev2
495 self.incomplete_let =
496 syntax_element.ancestors().take(6).find_map(ast::LetStmt::cast).map_or(false, |it| {
497 it.syntax().text_range().end() == syntax_element.text_range().end()
500 let (expected_type, expected_name) = self.expected_type_and_name();
501 self.expected_type = expected_type;
502 self.expected_name = expected_name;
504 let name_like = match find_node_at_offset(&file_with_fake_ident, offset) {
508 self.completion_location =
509 determine_location(&self.sema, original_file, offset, &name_like);
510 self.prev_sibling = determine_prev_sibling(&name_like);
512 ast::NameLike::Lifetime(lifetime) => {
513 self.classify_lifetime(original_file, lifetime, offset);
515 ast::NameLike::NameRef(name_ref) => {
516 self.classify_name_ref(original_file, name_ref);
518 ast::NameLike::Name(name) => {
519 self.classify_name(name);
524 fn classify_lifetime(
526 original_file: &SyntaxNode,
527 lifetime: ast::Lifetime,
530 self.lifetime_syntax =
531 find_node_at_offset(original_file, lifetime.syntax().text_range().start());
532 if let Some(parent) = lifetime.syntax().parent() {
533 if parent.kind() == ERROR {
539 ast::LifetimeParam(_it) => {
540 self.lifetime_allowed = true;
541 self.lifetime_param_syntax =
542 self.sema.find_node_at_offset_with_macros(original_file, offset);
544 ast::BreakExpr(_it) => self.is_label_ref = true,
545 ast::ContinueExpr(_it) => self.is_label_ref = true,
546 ast::Label(_it) => (),
547 _ => self.lifetime_allowed = true,
553 fn classify_name(&mut self, name: ast::Name) {
554 if let Some(bind_pat) = name.syntax().parent().and_then(ast::IdentPat::cast) {
555 self.is_pat_or_const = Some(PatternRefutability::Refutable);
556 // if any of these is here our bind pat can't be a const pat anymore
557 let complex_ident_pat = bind_pat.at_token().is_some()
558 || bind_pat.ref_token().is_some()
559 || bind_pat.mut_token().is_some();
560 if complex_ident_pat {
561 self.is_pat_or_const = None;
563 let irrefutable_pat = bind_pat.syntax().ancestors().find_map(|node| {
566 ast::LetStmt(it) => Some(it.pat()),
567 ast::Param(it) => Some(it.pat()),
572 if let Some(Some(pat)) = irrefutable_pat {
573 // This check is here since we could be inside a pattern in the initializer expression of the let statement.
574 if pat.syntax().text_range().contains_range(bind_pat.syntax().text_range()) {
575 self.is_pat_or_const = Some(PatternRefutability::Irrefutable);
579 let is_name_in_field_pat = bind_pat
582 .and_then(ast::RecordPatField::cast)
583 .map_or(false, |pat_field| pat_field.name_ref().is_none());
584 if is_name_in_field_pat {
585 self.is_pat_or_const = None;
589 self.fill_impl_def();
592 self.is_param |= is_node::<ast::Param>(name.syntax());
595 fn classify_name_ref(&mut self, original_file: &SyntaxNode, name_ref: ast::NameRef) {
596 self.fill_impl_def();
598 self.name_ref_syntax =
599 find_node_at_offset(original_file, name_ref.syntax().text_range().start());
601 self.function_def = self
603 .token_ancestors_with_macros(self.token.clone())
604 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
605 .find_map(ast::Fn::cast);
607 let parent = match name_ref.syntax().parent() {
612 if let Some(segment) = ast::PathSegment::cast(parent) {
613 let path_ctx = self.path_context.get_or_insert(PathCompletionContext {
615 is_trivial_path: false,
617 has_type_args: false,
620 use_tree_parent: false,
623 path_ctx.in_loop_body = is_in_loop_body(name_ref.syntax());
624 let path = segment.parent_path();
626 if let Some(p) = path.syntax().parent() {
627 path_ctx.call_kind = match_ast! {
629 ast::PathExpr(it) => it.syntax().parent().and_then(ast::CallExpr::cast).map(|_| CallKind::Expr),
630 ast::MacroCall(it) => it.excl_token().and(Some(CallKind::Mac)),
631 ast::TupleStructPat(_it) => Some(CallKind::Pat),
637 if let Some(parent) = path.syntax().parent() {
638 path_ctx.kind = match_ast! {
640 ast::PathType(_it) => Some(PathKind::Type),
641 ast::PathExpr(_it) => Some(PathKind::Expr),
646 path_ctx.has_type_args = segment.generic_arg_list().is_some();
648 if let Some((path, use_tree_parent)) = path_or_use_tree_qualifier(&path) {
649 path_ctx.use_tree_parent = use_tree_parent;
650 path_ctx.qualifier = path
653 find_node_with_range::<ast::PathSegment>(
655 it.syntax().text_range(),
658 .map(|it| it.parent_path());
662 if let Some(segment) = path.segment() {
663 if segment.coloncolon_token().is_some() {
668 path_ctx.is_trivial_path = true;
670 // Find either enclosing expr statement (thing with `;`) or a
671 // block. If block, check that we are the last expr.
672 path_ctx.can_be_stmt = name_ref
676 if let Some(stmt) = ast::ExprStmt::cast(node.clone()) {
677 return Some(stmt.syntax().text_range() == name_ref.syntax().text_range());
679 if let Some(block) = ast::BlockExpr::cast(node) {
681 block.tail_expr().map(|e| e.syntax().text_range())
682 == Some(name_ref.syntax().text_range()),
692 fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> {
693 syntax.covering_element(range).ancestors().find_map(N::cast)
696 fn is_node<N: AstNode>(node: &SyntaxNode) -> bool {
697 match node.ancestors().find_map(N::cast) {
699 Some(n) => n.syntax().text_range() == node.text_range(),
703 fn path_or_use_tree_qualifier(path: &ast::Path) -> Option<(ast::Path, bool)> {
704 if let Some(qual) = path.qualifier() {
705 return Some((qual, false));
707 let use_tree_list = path.syntax().ancestors().find_map(ast::UseTreeList::cast)?;
708 let use_tree = use_tree_list.syntax().parent().and_then(ast::UseTree::cast)?;
709 use_tree.path().zip(Some(true))
712 fn has_ref(token: &SyntaxToken) -> bool {
713 let mut token = token.clone();
714 for skip in [WHITESPACE, IDENT, T![mut]] {
715 if token.kind() == skip {
716 token = match token.prev_token() {
718 None => return false,
722 token.kind() == T![&]
727 use expect_test::{expect, Expect};
730 use crate::tests::{position, TEST_CONFIG};
732 use super::CompletionContext;
734 fn check_expected_type_and_name(ra_fixture: &str, expect: Expect) {
735 let (db, pos) = position(ra_fixture);
736 let completion_context = CompletionContext::new(&db, pos, &TEST_CONFIG).unwrap();
738 let ty = completion_context
740 .map(|t| t.display_test(&db).to_string())
741 .unwrap_or("?".to_owned());
743 let name = completion_context
745 .map_or_else(|| "?".to_owned(), |name| name.to_string());
747 expect.assert_eq(&format!("ty: {}, name: {}", ty, name));
751 fn expected_type_let_without_leading_char() {
752 cov_mark::check!(expected_type_let_without_leading_char);
753 check_expected_type_and_name(
759 expect![[r#"ty: u32, name: x"#]],
764 fn expected_type_let_with_leading_char() {
765 cov_mark::check!(expected_type_let_with_leading_char);
766 check_expected_type_and_name(
772 expect![[r#"ty: u32, name: x"#]],
777 fn expected_type_let_pat() {
778 check_expected_type_and_name(
784 expect![[r#"ty: u32, name: ?"#]],
786 check_expected_type_and_name(
792 expect![[r#"ty: u32, name: ?"#]],
797 fn expected_type_fn_param() {
798 cov_mark::check!(expected_type_fn_param);
799 check_expected_type_and_name(
801 fn foo() { bar($0); }
804 expect![[r#"ty: u32, name: x"#]],
806 check_expected_type_and_name(
808 fn foo() { bar(c$0); }
811 expect![[r#"ty: u32, name: x"#]],
816 fn expected_type_fn_param_ref() {
817 cov_mark::check!(expected_type_fn_param_ref);
818 check_expected_type_and_name(
820 fn foo() { bar(&$0); }
823 expect![[r#"ty: u32, name: x"#]],
825 check_expected_type_and_name(
827 fn foo() { bar(&mut $0); }
828 fn bar(x: &mut u32) {}
830 expect![[r#"ty: u32, name: x"#]],
832 check_expected_type_and_name(
834 fn foo() { bar(&c$0); }
837 expect![[r#"ty: u32, name: x"#]],
842 fn expected_type_struct_field_without_leading_char() {
843 cov_mark::check!(expected_type_struct_field_without_leading_char);
844 check_expected_type_and_name(
846 struct Foo { a: u32 }
851 expect![[r#"ty: u32, name: a"#]],
856 fn expected_type_generic_struct_field() {
857 check_expected_type_and_name(
859 struct Foo<T> { a: T }
860 fn foo() -> Foo<u32> {
864 expect![[r#"ty: u32, name: a"#]],
869 fn expected_type_struct_field_with_leading_char() {
870 cov_mark::check!(expected_type_struct_field_with_leading_char);
871 check_expected_type_and_name(
873 struct Foo { a: u32 }
878 expect![[r#"ty: u32, name: a"#]],
883 fn expected_type_match_arm_without_leading_char() {
884 cov_mark::check!(expected_type_match_arm_without_leading_char);
885 check_expected_type_and_name(
892 expect![[r#"ty: E, name: ?"#]],
897 fn expected_type_match_arm_with_leading_char() {
898 cov_mark::check!(expected_type_match_arm_with_leading_char);
899 check_expected_type_and_name(
906 expect![[r#"ty: E, name: ?"#]],
911 fn expected_type_if_let_without_leading_char() {
912 cov_mark::check!(expected_type_if_let_without_leading_char);
913 check_expected_type_and_name(
915 enum Foo { Bar, Baz, Quux }
922 expect![[r#"ty: Foo, name: ?"#]],
927 fn expected_type_if_let_with_leading_char() {
928 cov_mark::check!(expected_type_if_let_with_leading_char);
929 check_expected_type_and_name(
931 enum Foo { Bar, Baz, Quux }
938 expect![[r#"ty: Foo, name: ?"#]],
943 fn expected_type_fn_ret_without_leading_char() {
944 cov_mark::check!(expected_type_fn_ret_without_leading_char);
945 check_expected_type_and_name(
951 expect![[r#"ty: u32, name: ?"#]],
956 fn expected_type_fn_ret_with_leading_char() {
957 cov_mark::check!(expected_type_fn_ret_with_leading_char);
958 check_expected_type_and_name(
964 expect![[r#"ty: u32, name: ?"#]],
969 fn expected_type_fn_ret_fn_ref_fully_typed() {
970 check_expected_type_and_name(
976 expect![[r#"ty: u32, name: ?"#]],
981 fn expected_type_closure_param_return() {
982 // FIXME: make this work with `|| $0`
983 check_expected_type_and_name(
990 fn bar(f: impl FnOnce() -> u32) {}
992 expect![[r#"ty: u32, name: ?"#]],
997 fn expected_type_generic_function() {
998 check_expected_type_and_name(
1006 expect![[r#"ty: u32, name: t"#]],
1011 fn expected_type_generic_method() {
1012 check_expected_type_and_name(
1020 fn bar(self, t: T) {}
1023 expect![[r#"ty: u32, name: t"#]],