2 use hir::{known, Callable, HasVisibility, HirDisplay, Semantics, TypeInfo};
3 use ide_db::helpers::FamousDefs;
4 use ide_db::RootDatabase;
5 use stdx::to_lower_snake_case;
7 ast::{self, ArgListOwner, AstNode, NameOwner},
8 match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T,
13 #[derive(Clone, Debug, PartialEq, Eq)]
14 pub struct InlayHintsConfig {
16 pub parameter_hints: bool,
17 pub chaining_hints: bool,
18 pub max_length: Option<usize>,
21 #[derive(Clone, Debug, PartialEq, Eq)]
29 pub struct InlayHint {
35 // Feature: Inlay Hints
37 // rust-analyzer shows additional information inline with the source code.
38 // Editors usually render this using read-only virtual text snippets interspersed with code.
40 // rust-analyzer shows hints for
42 // * types of local variables
43 // * names of function arguments
44 // * types of chained expressions
46 // **Note:** VS Code does not have native support for inlay hints https://github.com/microsoft/vscode/issues/16221[yet] and the hints are implemented using decorations.
47 // This approach has limitations, the caret movement and bracket highlighting near the edges of the hint may be weird:
48 // https://github.com/rust-analyzer/rust-analyzer/issues/1623[1], https://github.com/rust-analyzer/rust-analyzer/issues/3453[2].
51 // | Editor | Action Name
53 // | VS Code | **Rust Analyzer: Toggle inlay hints*
56 // image::https://user-images.githubusercontent.com/48062697/113020660-b5f98b80-917a-11eb-8d70-3be3fd558cdd.png[]
57 pub(crate) fn inlay_hints(
60 config: &InlayHintsConfig,
62 let _p = profile::span("inlay_hints");
63 let sema = Semantics::new(db);
64 let file = sema.parse(file_id);
66 let mut res = Vec::new();
67 for node in file.syntax().descendants() {
68 if let Some(expr) = ast::Expr::cast(node.clone()) {
69 get_chaining_hints(&mut res, &sema, config, expr);
74 ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); },
75 ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); },
76 ast::IdentPat(it) => { get_bind_pat_hints(&mut res, &sema, config, it); },
84 fn get_chaining_hints(
85 acc: &mut Vec<InlayHint>,
86 sema: &Semantics<RootDatabase>,
87 config: &InlayHintsConfig,
90 if !config.chaining_hints {
94 if matches!(expr, ast::Expr::RecordExpr(_)) {
98 let krate = sema.scope(expr.syntax()).module().map(|it| it.krate());
99 let famous_defs = FamousDefs(sema, krate);
101 let mut tokens = expr
103 .siblings_with_tokens(Direction::Next)
104 .filter_map(NodeOrToken::into_token)
105 .filter(|t| match t.kind() {
106 SyntaxKind::WHITESPACE if !t.text().contains('\n') => false,
107 SyntaxKind::COMMENT => false,
111 // Chaining can be defined as an expression whose next sibling tokens are newline and dot
112 // Ignoring extra whitespace and comments
113 let next = tokens.next()?.kind();
114 if next == SyntaxKind::WHITESPACE {
115 let mut next_next = tokens.next()?.kind();
116 while next_next == SyntaxKind::WHITESPACE {
117 next_next = tokens.next()?.kind();
119 if next_next == T![.] {
120 let ty = sema.type_of_expr(&expr)?.original;
124 if matches!(expr, ast::Expr::PathExpr(_)) {
125 if let Some(hir::Adt::Struct(st)) = ty.as_adt() {
126 if st.fields(sema.db).is_empty() {
132 range: expr.syntax().text_range(),
133 kind: InlayKind::ChainingHint,
134 label: hint_iterator(sema, &famous_defs, config, &ty).unwrap_or_else(|| {
135 ty.display_truncated(sema.db, config.max_length).to_string().into()
143 fn get_param_name_hints(
144 acc: &mut Vec<InlayHint>,
145 sema: &Semantics<RootDatabase>,
146 config: &InlayHintsConfig,
149 if !config.parameter_hints {
153 let (callable, arg_list) = get_callable(sema, &expr)?;
157 .zip(arg_list.args())
158 .filter_map(|((param, _ty), arg)| {
159 let param_name = match param? {
160 Either::Left(_) => "self".to_string(),
161 Either::Right(pat) => match pat {
162 ast::Pat::IdentPat(it) => it.name()?.to_string(),
166 Some((param_name, arg))
168 .filter(|(param_name, arg)| !should_hide_param_name_hint(sema, &callable, param_name, arg))
169 .map(|(param_name, arg)| InlayHint {
170 range: arg.syntax().text_range(),
171 kind: InlayKind::ParameterHint,
172 label: param_name.into(),
179 fn get_bind_pat_hints(
180 acc: &mut Vec<InlayHint>,
181 sema: &Semantics<RootDatabase>,
182 config: &InlayHintsConfig,
185 if !config.type_hints {
189 let krate = sema.scope(pat.syntax()).module().map(|it| it.krate());
190 let famous_defs = FamousDefs(sema, krate);
192 let ty = sema.type_of_pat(&pat.clone().into())?.original;
194 if should_not_display_type_hint(sema, &pat, &ty) {
199 range: match pat.name() {
200 Some(name) => name.syntax().text_range(),
201 None => pat.syntax().text_range(),
203 kind: InlayKind::TypeHint,
204 label: hint_iterator(sema, &famous_defs, config, &ty)
205 .unwrap_or_else(|| ty.display_truncated(sema.db, config.max_length).to_string().into()),
211 /// Checks if the type is an Iterator from std::iter and replaces its hint with an `impl Iterator<Item = Ty>`.
213 sema: &Semantics<RootDatabase>,
214 famous_defs: &FamousDefs,
215 config: &InlayHintsConfig,
217 ) -> Option<SmolStr> {
219 let strukt = ty.strip_references().as_adt()?;
220 let krate = strukt.module(db).krate();
221 if krate != famous_defs.core()? {
224 let iter_trait = famous_defs.core_iter_Iterator()?;
225 let iter_mod = famous_defs.core_iter()?;
227 // Assert that this struct comes from `core::iter`.
228 if !(strukt.visibility(db) == hir::Visibility::Public
229 && strukt.module(db).path_to_root(db).contains(&iter_mod))
234 if ty.impls_trait(db, iter_trait, &[]) {
235 let assoc_type_item = iter_trait.items(db).into_iter().find_map(|item| match item {
236 hir::AssocItem::TypeAlias(alias) if alias.name(db) == known::Item => Some(alias),
239 if let Some(ty) = ty.normalize_trait_assoc_type(db, &[], assoc_type_item) {
240 const LABEL_START: &str = "impl Iterator<Item = ";
241 const LABEL_END: &str = ">";
243 let ty_display = hint_iterator(sema, famous_defs, config, &ty)
244 .map(|assoc_type_impl| assoc_type_impl.to_string())
246 ty.display_truncated(
250 .map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())),
254 return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into());
261 fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::IdentPat, pat_ty: &hir::Type) -> bool {
262 if let Some(hir::Adt::Enum(enum_data)) = pat_ty.as_adt() {
263 let pat_text = bind_pat.to_string();
267 .map(|variant| variant.name(db).to_string())
268 .any(|enum_name| enum_name == pat_text)
274 fn should_not_display_type_hint(
275 sema: &Semantics<RootDatabase>,
276 bind_pat: &ast::IdentPat,
281 if pat_ty.is_unknown() {
285 if let Some(hir::Adt::Struct(s)) = pat_ty.as_adt() {
286 if s.fields(db).is_empty() && s.name(db).to_string() == bind_pat.to_string() {
291 for node in bind_pat.syntax().ancestors() {
294 ast::LetStmt(it) => return it.ty().is_some(),
295 ast::Param(it) => return it.ty().is_some(),
296 ast::MatchArm(_it) => return pat_is_enum_variant(db, bind_pat, pat_ty),
298 return it.condition().and_then(|condition| condition.pat()).is_some()
299 && pat_is_enum_variant(db, bind_pat, pat_ty);
301 ast::WhileExpr(it) => {
302 return it.condition().and_then(|condition| condition.pat()).is_some()
303 && pat_is_enum_variant(db, bind_pat, pat_ty);
305 ast::ForExpr(it) => {
306 // We *should* display hint only if user provided "in {expr}" and we know the type of expr (and it's not unit).
307 // Type of expr should be iterable.
308 return it.in_token().is_none() ||
310 .and_then(|iterable_expr| sema.type_of_expr(&iterable_expr))
311 .map(TypeInfo::original)
312 .map_or(true, |iterable_ty| iterable_ty.is_unknown() || iterable_ty.is_unit())
321 fn should_hide_param_name_hint(
322 sema: &Semantics<RootDatabase>,
323 callable: &hir::Callable,
325 argument: &ast::Expr,
327 // These are to be tested in the `parameter_hint_heuristics` test
329 // - the parameter name is a suffix of the function's name
330 // - the argument is an enum whose name is equal to the parameter
331 // - exact argument<->parameter match(ignoring leading underscore) or parameter is a prefix/suffix
332 // of argument with _ splitting it off
333 // - param starts with `ra_fixture`
334 // - param is a well known name in an unary function
336 let param_name = param_name.trim_start_matches('_');
337 if param_name.is_empty() {
341 let fn_name = match callable.kind() {
342 hir::CallableKind::Function(it) => Some(it.name(sema.db).to_string()),
345 let fn_name = fn_name.as_deref();
346 is_param_name_suffix_of_fn_name(param_name, callable, fn_name)
347 || is_enum_name_similar_to_param_name(sema, argument, param_name)
348 || is_argument_similar_to_param_name(argument, param_name)
349 || param_name.starts_with("ra_fixture")
350 || (callable.n_params() == 1 && is_obvious_param(param_name))
353 fn is_argument_similar_to_param_name(argument: &ast::Expr, param_name: &str) -> bool {
354 // check whether param_name and argument are the same or
355 // whether param_name is a prefix/suffix of argument(split at `_`)
356 let argument = match get_string_representation(argument) {
357 Some(argument) => argument,
358 None => return false,
361 let param_name = param_name.trim_start_matches('_');
362 let argument = argument.trim_start_matches('_');
363 if argument.strip_prefix(param_name).map_or(false, |s| s.starts_with('_')) {
366 if argument.strip_suffix(param_name).map_or(false, |s| s.ends_with('_')) {
369 argument == param_name
372 /// Hide the parameter name of an unary function if it is a `_` - prefixed suffix of the function's name, or equal.
374 /// `fn strip_suffix(suffix)` will be hidden.
375 /// `fn stripsuffix(suffix)` will not be hidden.
376 fn is_param_name_suffix_of_fn_name(
379 fn_name: Option<&str>,
381 match (callable.n_params(), fn_name) {
382 (1, Some(function)) => {
383 function == param_name
384 || (function.len() > param_name.len()
385 && function.ends_with(param_name)
386 && function[..function.len() - param_name.len()].ends_with('_'))
392 fn is_enum_name_similar_to_param_name(
393 sema: &Semantics<RootDatabase>,
394 argument: &ast::Expr,
397 match sema.type_of_expr(argument).and_then(|t| t.original.as_adt()) {
398 Some(hir::Adt::Enum(e)) => to_lower_snake_case(&e.name(sema.db).to_string()) == param_name,
403 fn get_string_representation(expr: &ast::Expr) -> Option<String> {
405 ast::Expr::MethodCallExpr(method_call_expr) => {
406 let name_ref = method_call_expr.name_ref()?;
407 match name_ref.text().as_str() {
408 "clone" | "as_ref" => method_call_expr.receiver().map(|rec| rec.to_string()),
409 name_ref => Some(name_ref.to_owned()),
412 ast::Expr::FieldExpr(field_expr) => Some(field_expr.name_ref()?.to_string()),
413 ast::Expr::PathExpr(path_expr) => Some(path_expr.path()?.segment()?.to_string()),
414 ast::Expr::PrefixExpr(prefix_expr) => get_string_representation(&prefix_expr.expr()?),
415 ast::Expr::RefExpr(ref_expr) => get_string_representation(&ref_expr.expr()?),
420 fn is_obvious_param(param_name: &str) -> bool {
421 // avoid displaying hints for common functions like map, filter, etc.
422 // or other obvious words used in std
423 let is_obvious_param_name =
424 matches!(param_name, "predicate" | "value" | "pat" | "rhs" | "other");
425 param_name.len() == 1 || is_obvious_param_name
429 sema: &Semantics<RootDatabase>,
431 ) -> Option<(hir::Callable, ast::ArgList)> {
433 ast::Expr::CallExpr(expr) => {
434 sema.type_of_expr(&expr.expr()?)?.original.as_callable(sema.db).zip(expr.arg_list())
436 ast::Expr::MethodCallExpr(expr) => {
437 sema.resolve_method_call_as_callable(expr).zip(expr.arg_list())
445 use expect_test::{expect, Expect};
446 use test_utils::extract_annotations;
448 use crate::{fixture, inlay_hints::InlayHintsConfig};
450 const TEST_CONFIG: InlayHintsConfig = InlayHintsConfig {
452 parameter_hints: true,
453 chaining_hints: true,
457 fn check(ra_fixture: &str) {
458 check_with_config(TEST_CONFIG, ra_fixture);
461 fn check_params(ra_fixture: &str) {
464 parameter_hints: true,
466 chaining_hints: false,
473 fn check_types(ra_fixture: &str) {
476 parameter_hints: false,
478 chaining_hints: false,
485 fn check_chains(ra_fixture: &str) {
488 parameter_hints: false,
490 chaining_hints: true,
497 fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) {
498 let (analysis, file_id) = fixture::file(&ra_fixture);
499 let expected = extract_annotations(&*analysis.file_text(file_id).unwrap());
500 let inlay_hints = analysis.inlay_hints(&config, file_id).unwrap();
502 inlay_hints.into_iter().map(|it| (it.range, it.label.to_string())).collect::<Vec<_>>();
503 assert_eq!(expected, actual, "\nExpected:\n{:#?}\n\nActual:\n{:#?}", expected, actual);
506 fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) {
507 let (analysis, file_id) = fixture::file(&ra_fixture);
508 let inlay_hints = analysis.inlay_hints(&config, file_id).unwrap();
509 expect.assert_debug_eq(&inlay_hints)
513 fn hints_disabled() {
517 parameter_hints: false,
518 chaining_hints: false,
522 fn foo(a: i32, b: i32) -> i32 { a + b }
529 // Parameter hint tests
532 fn param_hints_only() {
535 fn foo(a: i32, b: i32) -> i32 { a + b }
548 fn param_name_similar_to_fn_name_still_hints() {
551 fn max(x: i32, y: i32) -> i32 { x + y }
564 fn param_name_similar_to_fn_name() {
567 fn param_with_underscore(with_underscore: i32) -> i32 { with_underscore }
569 let _x = param_with_underscore(
576 fn param_with_underscore(underscore: i32) -> i32 { underscore }
578 let _x = param_with_underscore(
586 fn param_name_same_as_fn_name() {
589 fn foo(foo: i32) -> i32 { foo }
599 fn never_hide_param_when_multiple_params() {
602 fn foo(foo: i32, bar: i32) -> i32 { bar + baz }
615 fn param_hints_look_through_as_ref_and_clone() {
618 fn foo(bar: i32, baz: f32) {}
624 foo(bar.clone(), bar.clone());
626 foo(bar.as_ref(), bar.as_ref());
634 fn self_param_hints() {
640 fn foo(self: Self) {}
641 fn bar(self: &Self) {}
655 fn param_name_hints_show_for_literals() {
657 r#"pub fn test(a: i32, b: i32) -> [i32; 2] { [a, b] }
670 fn function_call_parameter_hint() {
679 struct NavigationTarget {}
684 fn method(&self, mut param: i32) -> i32 { param * 2 }
689 focus_range: Option<TextRange>,
690 full_range: TextRange,
692 docs: Option<String>,
693 ) -> NavigationTarget {
698 fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 {
704 let _: i32 = test_func(1, 2, "hello", 3, not_literal);
705 //^ foo ^ bar ^^^^^^^ msg ^^^^^^^^^^^ last
706 let t: Test = Test {};
709 Test::method(&t, 3456);
719 //^^^^^^^^^^^^ full_range
730 fn parameter_hint_heuristics() {
733 fn check(ra_fixture_thing: &str) {}
736 fn filter(predicate: i32) {}
738 fn strip_suffix(suffix: &str) {}
739 fn stripsuffix(suffix: &str) {}
740 fn same(same: u32) {}
741 fn same2(_same2: u32) {}
743 fn enum_matches_param_name(completion_kind: CompletionKind) {}
745 fn foo(param: u32) {}
746 fn bar(param_eter: u32) {}
748 enum CompletionKind {
752 fn non_ident_pat((a, b): (u32, u32)) {}
766 enum_matches_param_name(CompletionKind::Keyword);
780 let param_eter_end = 0;
782 let start_param_eter = 0;
783 bar(start_param_eter);
786 //^^^^^^^^^^^ param_eter
788 non_ident_pat((0, 0));
796 fn type_hints_only() {
799 fn foo(a: i32, b: i32) -> i32 { a + b }
808 fn type_hints_bindings_after_at() {
813 let ref foo @ bar @ ref mut baz = 0;
819 if let x @ Some(_) = Some(0) {}
821 let foo @ (bar, baz) = (3, 3);
830 fn default_generic_types_should_not_be_displayed() {
833 struct Test<K, T = u8> { k: K, t: T }
836 let zz = Test { t: 23u8, k: 33 };
841 //^^^^ || -> Test<i32>
847 fn shorten_iterators_in_associated_params() {
850 //- minicore: iterators
853 pub struct SomeIter<T> {}
855 impl<T> SomeIter<T> {
856 pub fn new() -> Self { SomeIter {} }
857 pub fn push(&mut self, t: T) {}
860 impl<T> Iterator for SomeIter<T> {
862 fn next(&mut self) -> Option<Self::Item> {
868 let mut some_iter = SomeIter::new();
869 //^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
870 some_iter.push(iter::repeat(2).take(2));
871 let iter_of_iters = some_iter.take(2);
872 //^^^^^^^^^^^^^ impl Iterator<Item = impl Iterator<Item = i32>>
879 fn infer_call_method_return_associated_types_with_generic() {
883 fn default() -> Self;
889 pub fn quux<T: Foo>() -> T::Bar {
890 let y = Default::default();
903 //- minicore: fn, sized
904 fn foo() -> impl Fn() { loop {} }
905 fn foo1() -> impl Fn(f64) { loop {} }
906 fn foo2() -> impl Fn(f64, f64) { loop {} }
907 fn foo3() -> impl Fn(f64, f64) -> u32 { loop {} }
908 fn foo4() -> &'static dyn Fn(f64, f64) -> u32 { loop {} }
909 fn foo5() -> &'static dyn Fn(&'static dyn Fn(f64, f64) -> u32, f64) -> u32 { loop {} }
910 fn foo6() -> impl Fn(f64, f64) -> u32 + Sized { loop {} }
911 fn foo7() -> *const (impl Fn(f64, f64) -> u32 + Sized) { loop {} }
919 // ^^^ impl Fn(f64, f64)
921 // ^^^ impl Fn(f64, f64) -> u32
923 // ^^^ &dyn Fn(f64, f64) -> u32
925 // ^^^ &dyn Fn(&dyn Fn(f64, f64) -> u32, f64) -> u32
927 // ^^^ impl Fn(f64, f64) -> u32
929 // ^^^ *const impl Fn(f64, f64) -> u32
936 fn fn_hints_ptr_rpit_fn_parentheses() {
939 //- minicore: fn, sized
942 fn foo1() -> *const impl Fn() { loop {} }
943 fn foo2() -> *const (impl Fn() + Sized) { loop {} }
944 fn foo3() -> *const (impl Fn() + ?Sized) { loop {} }
945 fn foo4() -> *const (impl Sized + Fn()) { loop {} }
946 fn foo5() -> *const (impl ?Sized + Fn()) { loop {} }
947 fn foo6() -> *const (impl Fn() + Trait) { loop {} }
948 fn foo7() -> *const (impl Fn() + Sized + Trait) { loop {} }
949 fn foo8() -> *const (impl Fn() + ?Sized + Trait) { loop {} }
950 fn foo9() -> *const (impl Fn() -> u8 + ?Sized) { loop {} }
951 fn foo10() -> *const (impl Fn() + Sized + ?Sized) { loop {} }
955 // ^^^ *const impl Fn()
957 // ^^^ *const impl Fn()
959 // ^^^ *const (impl Fn() + ?Sized)
961 // ^^^ *const impl Fn()
963 // ^^^ *const (impl Fn() + ?Sized)
965 // ^^^ *const (impl Fn() + Trait)
967 // ^^^ *const (impl Fn() + Trait)
969 // ^^^ *const (impl Fn() + Trait + ?Sized)
971 // ^^^ *const (impl Fn() -> u8 + ?Sized)
973 // ^^^ *const impl Fn()
980 fn unit_structs_have_no_type_hints() {
984 struct SyntheticSyntax;
989 Err(SyntheticSyntax) => (),
1000 enum Option<T> { None, Some(T) }
1002 #[derive(PartialEq)]
1003 struct Test { a: Option<u32>, b: u8 }
1006 struct InnerStruct {}
1016 let test = InnerStruct {};
1019 let test = unresolved();
1021 let test = (42, 'a');
1023 let (a, (b, (c,)) = (2, (3, (9.2,));
1035 //- minicore: option
1036 struct Test { a: Option<u32>, b: u8 }
1039 let test = Some(Test { a: Some(3), b: 1 });
1041 if let None = &test {};
1042 if let test = &test {};
1043 //^^^^ &Option<Test>
1044 if let Some(test) = &test {};
1046 if let Some(Test { a, b }) = &test {};
1047 //^ &Option<u32> ^ &u8
1048 if let Some(Test { a: x, b: y }) = &test {};
1049 //^ &Option<u32> ^ &u8
1050 if let Some(Test { a: Some(x), b: y }) = &test {};
1052 if let Some(Test { a: None, b: y }) = &test {};
1054 if let Some(Test { b: y, .. }) = &test {};
1065 //- minicore: option
1066 struct Test { a: Option<u32>, b: u8 }
1069 let test = Some(Test { a: Some(3), b: 1 });
1071 while let Some(Test { a: Some(x), b: y }) = &test {};
1078 fn match_arm_list() {
1081 //- minicore: option
1082 struct Test { a: Option<u32>, b: u8 }
1085 match Some(Test { a: Some(3), b: 1 }) {
1089 Some(Test { a: Some(x), b: y }) => (),
1098 fn incomplete_for_no_hint() {
1102 let data = &[1i32, 2, 3];
1109 pub struct Vec<T> {}
1112 pub fn new() -> Self { Vec {} }
1113 pub fn push(&mut self, t: T) {}
1116 impl<T> IntoIterator for Vec<T> {
1121 let mut data = Vec::new();
1126 println!("Unit expr");
1133 fn complete_for_hint() {
1136 //- minicore: iterator
1137 pub struct Vec<T> {}
1140 pub fn new() -> Self { Vec {} }
1141 pub fn push(&mut self, t: T) {}
1144 impl<T> IntoIterator for Vec<T> {
1149 let mut data = Vec::new();
1163 fn multi_dyn_trait_bounds() {
1166 pub struct Vec<T> {}
1169 pub fn new() -> Self { Vec {} }
1172 pub struct Box<T> {}
1178 let _v = Vec::<Box<&(dyn Display + Sync)>>::new();
1179 //^^ Vec<Box<&(dyn Display + Sync)>>
1180 let _v = Vec::<Box<*const (dyn Display + Sync)>>::new();
1181 //^^ Vec<Box<*const (dyn Display + Sync)>>
1182 let _v = Vec::<Box<dyn Display + Sync>>::new();
1183 //^^ Vec<Box<dyn Display + Sync>>
1190 fn shorten_iterator_hints() {
1193 //- minicore: iterators
1198 impl Iterator for MyIter {
1200 fn next(&mut self) -> Option<Self::Item> {
1208 let _x = iter::repeat(0);
1209 //^^ impl Iterator<Item = i32>
1210 fn generic<T: Clone>(t: T) {
1211 let _x = iter::repeat(t);
1212 //^^ impl Iterator<Item = T>
1213 let _chained = iter::repeat(t).take(10);
1214 //^^^^^^^^ impl Iterator<Item = T>
1228 (0..2).for_each(|increment| { start += increment; });
1232 //^^^^^^^^ |…| -> i32
1237 let _: i32 = multiply(1, 2);
1238 let multiply_ref = &multiply;
1239 //^^^^^^^^^^^^ &|…| -> i32
1241 let return_42 = || 42;
1242 //^^^^^^^^^ || -> i32
1248 fn hint_truncation() {
1250 InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG },
1254 struct VeryLongOuterName<T>(T);
1259 let b = VeryLongOuterName(0usize);
1260 //^ VeryLongOuterName<…>
1261 let c = Smol(Smol(0u32))
1267 // Chaining hint tests
1270 fn chaining_hints_ignore_comments() {
1273 parameter_hints: false,
1275 chaining_hints: true,
1280 impl A { fn into_b(self) -> B { self.0 } }
1282 impl B { fn into_c(self) -> C { self.0 } }
1287 .into_b() // This is a comment
1288 // This is another comment
1310 fn chaining_hints_without_newlines() {
1314 impl A { fn into_b(self) -> B { self.0 } }
1316 impl B { fn into_c(self) -> C { self.0 } }
1320 let c = A(B(C)).into_b().into_c();
1326 fn struct_access_chaining_hints() {
1329 parameter_hints: false,
1331 chaining_hints: true,
1335 struct A { pub b: B }
1336 struct B { pub c: C }
1341 fn foo(&self) -> i32 { 42 }
1345 let x = A { b: B { c: C(true) } }
1370 fn generic_chaining_hints() {
1373 parameter_hints: false,
1375 chaining_hints: true,
1382 struct X<T,R>(T, R);
1385 fn new(t: T) -> Self { A(t) }
1386 fn into_b(self) -> B<T> { B(self.0) }
1389 fn into_c(self) -> C<T> { C(self.0) }
1392 let c = A::new(X(42, true))
1402 label: "B<X<i32, bool>>",
1407 label: "A<X<i32, bool>>",
1415 fn shorten_iterator_chaining_hints() {
1418 parameter_hints: false,
1420 chaining_hints: true,
1424 //- minicore: iterators
1429 impl Iterator for MyIter {
1431 fn next(&mut self) -> Option<Self::Item> {
1437 let _x = MyIter.by_ref()
1449 label: "impl Iterator<Item = ()>",
1454 label: "impl Iterator<Item = ()>",
1459 label: "impl Iterator<Item = ()>",
1464 label: "&mut MyIter",