2 use hir::{known, Callable, HirDisplay, Semantics};
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*
55 pub(crate) fn inlay_hints(
58 config: &InlayHintsConfig,
60 let _p = profile::span("inlay_hints");
61 let sema = Semantics::new(db);
62 let file = sema.parse(file_id);
64 let mut res = Vec::new();
65 for node in file.syntax().descendants() {
66 if let Some(expr) = ast::Expr::cast(node.clone()) {
67 get_chaining_hints(&mut res, &sema, config, expr);
72 ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); },
73 ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); },
74 ast::IdentPat(it) => { get_bind_pat_hints(&mut res, &sema, config, it); },
82 fn get_chaining_hints(
83 acc: &mut Vec<InlayHint>,
84 sema: &Semantics<RootDatabase>,
85 config: &InlayHintsConfig,
88 if !config.chaining_hints {
92 if matches!(expr, ast::Expr::RecordExpr(_)) {
96 let krate = sema.scope(expr.syntax()).module().map(|it| it.krate());
97 let famous_defs = FamousDefs(&sema, krate);
101 .siblings_with_tokens(Direction::Next)
102 .filter_map(NodeOrToken::into_token)
103 .filter(|t| match t.kind() {
104 SyntaxKind::WHITESPACE if !t.text().contains('\n') => false,
105 SyntaxKind::COMMENT => false,
109 // Chaining can be defined as an expression whose next sibling tokens are newline and dot
110 // Ignoring extra whitespace and comments
111 let next = tokens.next()?.kind();
112 if next == SyntaxKind::WHITESPACE {
113 let mut next_next = tokens.next()?.kind();
114 while next_next == SyntaxKind::WHITESPACE {
115 next_next = tokens.next()?.kind();
117 if next_next == T![.] {
118 let ty = sema.type_of_expr(&expr)?;
122 if matches!(expr, ast::Expr::PathExpr(_)) {
123 if let Some(hir::Adt::Struct(st)) = ty.as_adt() {
124 if st.fields(sema.db).is_empty() {
130 range: expr.syntax().text_range(),
131 kind: InlayKind::ChainingHint,
132 label: hint_iterator(sema, &famous_defs, config, &ty).unwrap_or_else(|| {
133 ty.display_truncated(sema.db, config.max_length).to_string().into()
141 fn get_param_name_hints(
142 acc: &mut Vec<InlayHint>,
143 sema: &Semantics<RootDatabase>,
144 config: &InlayHintsConfig,
147 if !config.parameter_hints {
151 let args = match &expr {
152 ast::Expr::CallExpr(expr) => expr.arg_list()?.args(),
153 ast::Expr::MethodCallExpr(expr) => expr.arg_list()?.args(),
157 let callable = get_callable(sema, &expr)?;
162 .filter_map(|((param, _ty), arg)| {
163 let param_name = match param? {
164 Either::Left(_) => "self".to_string(),
165 Either::Right(pat) => match pat {
166 ast::Pat::IdentPat(it) => it.name()?.to_string(),
170 Some((param_name, arg))
172 .filter(|(param_name, arg)| should_show_param_name_hint(sema, &callable, param_name, &arg))
173 .map(|(param_name, arg)| InlayHint {
174 range: arg.syntax().text_range(),
175 kind: InlayKind::ParameterHint,
176 label: param_name.into(),
183 fn get_bind_pat_hints(
184 acc: &mut Vec<InlayHint>,
185 sema: &Semantics<RootDatabase>,
186 config: &InlayHintsConfig,
189 if !config.type_hints {
193 let krate = sema.scope(pat.syntax()).module().map(|it| it.krate());
194 let famous_defs = FamousDefs(&sema, krate);
196 let ty = sema.type_of_pat(&pat.clone().into())?;
198 if should_not_display_type_hint(sema, &pat, &ty) {
202 range: 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 = std::iter::successors(Some(ty.clone()), |ty| ty.remove_ref())
221 .and_then(|strukt| strukt.as_adt())?;
222 let krate = strukt.krate(db)?;
223 if krate != famous_defs.core()? {
226 let iter_trait = famous_defs.core_iter_Iterator()?;
227 let iter_mod = famous_defs.core_iter()?;
228 // assert this struct comes from `core::iter`
229 iter_mod.visibility_of(db, &strukt.into()).filter(|&vis| vis == hir::Visibility::Public)?;
230 if ty.impls_trait(db, iter_trait, &[]) {
231 let assoc_type_item = iter_trait.items(db).into_iter().find_map(|item| match item {
232 hir::AssocItem::TypeAlias(alias) if alias.name(db) == known::Item => Some(alias),
235 if let Some(ty) = ty.normalize_trait_assoc_type(db, iter_trait, &[], assoc_type_item) {
236 const LABEL_START: &str = "impl Iterator<Item = ";
237 const LABEL_END: &str = ">";
239 let ty_display = hint_iterator(sema, famous_defs, config, &ty)
240 .map(|assoc_type_impl| assoc_type_impl.to_string())
242 ty.display_truncated(
246 .map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())),
250 return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into());
257 fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::IdentPat, pat_ty: &hir::Type) -> bool {
258 if let Some(hir::Adt::Enum(enum_data)) = pat_ty.as_adt() {
259 let pat_text = bind_pat.to_string();
263 .map(|variant| variant.name(db).to_string())
264 .any(|enum_name| enum_name == pat_text)
270 fn should_not_display_type_hint(
271 sema: &Semantics<RootDatabase>,
272 bind_pat: &ast::IdentPat,
277 if pat_ty.is_unknown() {
281 if let Some(hir::Adt::Struct(s)) = pat_ty.as_adt() {
282 if s.fields(db).is_empty() && s.name(db).to_string() == bind_pat.to_string() {
287 for node in bind_pat.syntax().ancestors() {
290 ast::LetStmt(it) => {
291 return it.ty().is_some()
294 return it.ty().is_some()
296 ast::MatchArm(_it) => {
297 return pat_is_enum_variant(db, bind_pat, pat_ty);
300 return it.condition().and_then(|condition| condition.pat()).is_some()
301 && pat_is_enum_variant(db, bind_pat, pat_ty);
303 ast::WhileExpr(it) => {
304 return it.condition().and_then(|condition| condition.pat()).is_some()
305 && pat_is_enum_variant(db, bind_pat, pat_ty);
307 ast::ForExpr(it) => {
308 // We *should* display hint only if user provided "in {expr}" and we know the type of expr (and it's not unit).
309 // Type of expr should be iterable.
310 return it.in_token().is_none() ||
312 .and_then(|iterable_expr|sema.type_of_expr(&iterable_expr))
313 .map(|iterable_ty| iterable_ty.is_unknown() || iterable_ty.is_unit())
323 fn should_show_param_name_hint(
324 sema: &Semantics<RootDatabase>,
325 callable: &hir::Callable,
327 argument: &ast::Expr,
329 let param_name = param_name.trim_start_matches('_');
330 let fn_name = match callable.kind() {
331 hir::CallableKind::Function(it) => Some(it.name(sema.db).to_string()),
332 hir::CallableKind::TupleStruct(_)
333 | hir::CallableKind::TupleEnumVariant(_)
334 | hir::CallableKind::Closure => None,
337 if param_name.is_empty()
338 || Some(param_name) == fn_name.as_ref().map(|s| s.trim_start_matches('_'))
339 || is_argument_similar_to_param_name(sema, argument, param_name)
340 || is_param_name_similar_to_fn_name(param_name, callable, fn_name.as_ref())
341 || param_name.starts_with("ra_fixture")
346 // avoid displaying hints for common functions like map, filter, etc.
347 // or other obvious words used in std
348 !(callable.n_params() == 1 && is_obvious_param(param_name))
351 fn is_argument_similar_to_param_name(
352 sema: &Semantics<RootDatabase>,
353 argument: &ast::Expr,
356 if is_enum_name_similar_to_param_name(sema, argument, param_name) {
359 match get_string_representation(argument) {
361 Some(argument_string) => {
362 let num_leading_underscores =
363 argument_string.bytes().take_while(|&c| c == b'_').count();
365 // Does the argument name begin with the parameter name? Ignore leading underscores.
366 let mut arg_bytes = argument_string.bytes().skip(num_leading_underscores);
367 let starts_with_pattern = param_name.bytes().all(
368 |expected| matches!(arg_bytes.next(), Some(actual) if expected.eq_ignore_ascii_case(&actual)),
371 if starts_with_pattern {
375 // Does the argument name end with the parameter name?
376 let mut arg_bytes = argument_string.bytes().skip(num_leading_underscores);
377 param_name.bytes().rev().all(
378 |expected| matches!(arg_bytes.next_back(), Some(actual) if expected.eq_ignore_ascii_case(&actual)),
384 fn is_param_name_similar_to_fn_name(
387 fn_name: Option<&String>,
389 // if it's the only parameter, don't show it if:
390 // - is the same as the function name, or
391 // - the function ends with '_' + param_name
393 match (callable.n_params(), fn_name) {
394 (1, Some(function)) => {
395 function == param_name
396 || (function.len() > param_name.len()
397 && function.ends_with(param_name)
398 && function[..function.len() - param_name.len()].ends_with('_'))
404 fn is_enum_name_similar_to_param_name(
405 sema: &Semantics<RootDatabase>,
406 argument: &ast::Expr,
409 match sema.type_of_expr(argument).and_then(|t| t.as_adt()) {
410 Some(hir::Adt::Enum(e)) => to_lower_snake_case(&e.name(sema.db).to_string()) == param_name,
415 fn get_string_representation(expr: &ast::Expr) -> Option<String> {
417 ast::Expr::MethodCallExpr(method_call_expr) => {
418 let name_ref = method_call_expr.name_ref()?;
419 match name_ref.text() {
420 "clone" => method_call_expr.receiver().map(|rec| rec.to_string()),
421 name_ref => Some(name_ref.to_owned()),
424 ast::Expr::FieldExpr(field_expr) => Some(field_expr.name_ref()?.to_string()),
425 ast::Expr::PathExpr(path_expr) => Some(path_expr.to_string()),
426 ast::Expr::PrefixExpr(prefix_expr) => get_string_representation(&prefix_expr.expr()?),
427 ast::Expr::RefExpr(ref_expr) => get_string_representation(&ref_expr.expr()?),
432 fn is_obvious_param(param_name: &str) -> bool {
433 let is_obvious_param_name =
434 matches!(param_name, "predicate" | "value" | "pat" | "rhs" | "other");
435 param_name.len() == 1 || is_obvious_param_name
438 fn get_callable(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<hir::Callable> {
440 ast::Expr::CallExpr(expr) => sema.type_of_expr(&expr.expr()?)?.as_callable(sema.db),
441 ast::Expr::MethodCallExpr(expr) => sema.resolve_method_call_as_callable(expr),
448 use expect_test::{expect, Expect};
449 use ide_db::helpers::FamousDefs;
450 use test_utils::extract_annotations;
452 use crate::{fixture, inlay_hints::InlayHintsConfig};
454 const TEST_CONFIG: InlayHintsConfig = InlayHintsConfig {
456 parameter_hints: true,
457 chaining_hints: true,
461 fn check(ra_fixture: &str) {
462 check_with_config(TEST_CONFIG, ra_fixture);
465 fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) {
467 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
468 let (analysis, file_id) = fixture::file(&ra_fixture);
469 let expected = extract_annotations(&*analysis.file_text(file_id).unwrap());
470 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
472 inlay_hints.into_iter().map(|it| (it.range, it.label.to_string())).collect::<Vec<_>>();
473 assert_eq!(expected, actual, "\nExpected:\n{:#?}\n\nActual:\n{:#?}", expected, actual);
476 fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) {
478 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
479 let (analysis, file_id) = fixture::file(&ra_fixture);
480 let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap();
481 expect.assert_debug_eq(&inlay_hints)
485 fn param_hints_only() {
488 parameter_hints: true,
490 chaining_hints: false,
494 fn foo(a: i32, b: i32) -> i32 { a + b }
507 fn param_name_similar_to_fn_name_still_hints() {
510 parameter_hints: true,
512 chaining_hints: false,
516 fn max(x: i32, y: i32) -> i32 { x + y }
529 fn param_name_similar_to_fn_name() {
532 parameter_hints: true,
534 chaining_hints: false,
538 fn param_with_underscore(with_underscore: i32) -> i32 { with_underscore }
540 let _x = param_with_underscore(
548 fn param_name_same_as_fn_name() {
551 parameter_hints: true,
553 chaining_hints: false,
557 fn foo(foo: i32) -> i32 { foo }
567 fn never_hide_param_when_multiple_params() {
570 parameter_hints: true,
572 chaining_hints: false,
576 fn foo(bar: i32, baz: i32) -> i32 { bar + baz }
589 fn hints_disabled() {
593 parameter_hints: false,
594 chaining_hints: false,
598 fn foo(a: i32, b: i32) -> i32 { a + b }
606 fn type_hints_only() {
610 parameter_hints: false,
611 chaining_hints: false,
615 fn foo(a: i32, b: i32) -> i32 { a + b }
624 fn default_generic_types_should_not_be_displayed() {
627 struct Test<K, T = u8> { k: K, t: T }
630 let zz = Test { t: 23u8, k: 33 };
635 //^^^^ || -> Test<i32>
645 enum Option<T> { None, Some(T) }
648 struct Test { a: Option<u32>, b: u8 }
651 struct InnerStruct {}
661 let test = InnerStruct {};
664 let test = unresolved();
666 let test = (42, 'a');
668 let (a, (b, (c,)) = (2, (3, (9.2,));
677 fn closure_parameters() {
683 (0..2).for_each(|increment| { start += increment; });
687 //^^^^^^^^ |…| -> i32
692 let _: i32 = multiply(1, 2);
693 let multiply_ref = &multiply;
694 //^^^^^^^^^^^^ &|…| -> i32
696 let return_42 = || 42;
697 //^^^^^^^^^ || -> i32
706 enum Option<T> { None, Some(T) }
709 struct Test { a: Option<u32>, b: u8 }
712 let test = Some(Test { a: Some(3), b: 1 });
714 if let None = &test {};
715 if let test = &test {};
717 if let Some(test) = &test {};
719 if let Some(Test { a, b }) = &test {};
720 //^ &Option<u32> ^ &u8
721 if let Some(Test { a: x, b: y }) = &test {};
722 //^ &Option<u32> ^ &u8
723 if let Some(Test { a: Some(x), b: y }) = &test {};
725 if let Some(Test { a: None, b: y }) = &test {};
727 if let Some(Test { b: y, .. }) = &test {};
738 enum Option<T> { None, Some(T) }
741 struct Test { a: Option<u32>, b: u8 }
744 let test = Some(Test { a: Some(3), b: 1 });
746 while let Some(Test { a: Some(x), b: y }) = &test {};
753 fn match_arm_list() {
756 enum Option<T> { None, Some(T) }
759 struct Test { a: Option<u32>, b: u8 }
762 match Some(Test { a: Some(3), b: 1 }) {
766 Some(Test { a: Some(x), b: y }) => (),
775 fn hint_truncation() {
777 InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG },
781 struct VeryLongOuterName<T>(T);
786 let b = VeryLongOuterName(0usize);
787 //^ VeryLongOuterName<…>
788 let c = Smol(Smol(0u32))
795 fn function_call_parameter_hint() {
798 enum Option<T> { None, Some(T) }
806 struct NavigationTarget {}
811 fn method(&self, mut param: i32) -> i32 { param * 2 }
816 focus_range: Option<TextRange>,
817 full_range: TextRange,
819 docs: Option<String>,
820 ) -> NavigationTarget {
825 fn test_func(mut foo: i32, bar: i32, msg: &str, _: i32, last: i32) -> i32 {
832 let _: i32 = test_func(1, 2, "hello", 3, not_literal);
833 //^ foo ^ bar ^^^^^^^ msg ^^^^^^^^^^^ last
834 let t: Test = Test {};
837 Test::method(&t, 3456);
847 //^^^^^^^^^^^^ full_range
858 fn omitted_parameters_hints_heuristics() {
860 InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG },
863 fn filter(predicate: i32) {}
865 struct TestVarContainer {
869 impl TestVarContainer {
870 fn test_var(&self) -> i32 {
878 fn map(self, f: i32) -> Self {
882 fn filter(self, predicate: i32) -> Self {
886 fn field(self, value: i32) -> Self {
890 fn no_hints_expected(&self, _: i32, test_var: i32) {}
892 fn frob(&self, frob: bool) {}
897 fn different_order(param: &Param) {}
898 fn different_order_mut(param: &mut Param) {}
899 fn has_underscore(_param: bool) {}
900 fn enum_matches_param_name(completion_kind: CompletionKind) {}
901 fn param_destructuring_omitted_1((a, b): (u32, u32)) {}
902 fn param_destructuring_omitted_2(TestVarContainer { test_var: _ }: TestVarContainer) {}
904 fn twiddle(twiddle: bool) {}
905 fn doo(_doo: bool) {}
907 enum CompletionKind {
912 let container: TestVarContainer = TestVarContainer { test_var: 42 };
913 let test: Test = Test {};
918 let test_processed: Test = test.map(1).filter(2).field(3);
920 let test_var: i32 = 55;
921 test_processed.no_hints_expected(22, test_var);
922 test_processed.no_hints_expected(33, container.test_var);
923 test_processed.no_hints_expected(44, container.test_var());
924 test_processed.frob(false);
929 const TWIDDLE_UPPERCASE: bool = true;
930 twiddle(TWIDDLE_UPPERCASE);
932 let mut param_begin: Param = Param {};
933 different_order(¶m_begin);
934 different_order(&mut param_begin);
936 let param: bool = true;
937 has_underscore(param);
939 enum_matches_param_name(CompletionKind::Keyword);
943 let _: f64 = a.div_euclid(b);
944 let _: f64 = a.abs_sub(b);
946 let range: (u32, u32) = (3, 5);
947 param_destructuring_omitted_1(range);
948 param_destructuring_omitted_2(container);
954 fn unit_structs_have_no_type_hints() {
956 InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG },
958 enum Result<T, E> { Ok(T), Err(E) }
961 struct SyntheticSyntax;
966 Err(SyntheticSyntax) => (),
973 fn chaining_hints_ignore_comments() {
976 parameter_hints: false,
978 chaining_hints: true,
983 impl A { fn into_b(self) -> B { self.0 } }
985 impl B { fn into_c(self) -> C { self.0 } }
990 .into_b() // This is a comment
991 // This is another comment
1013 fn chaining_hints_without_newlines() {
1016 parameter_hints: false,
1018 chaining_hints: true,
1023 impl A { fn into_b(self) -> B { self.0 } }
1025 impl B { fn into_c(self) -> C { self.0 } }
1029 let c = A(B(C)).into_b().into_c();
1035 fn struct_access_chaining_hints() {
1038 parameter_hints: false,
1040 chaining_hints: true,
1044 struct A { pub b: B }
1045 struct B { pub c: C }
1050 fn foo(&self) -> i32 { 42 }
1054 let x = A { b: B { c: C(true) } }
1079 fn generic_chaining_hints() {
1082 parameter_hints: false,
1084 chaining_hints: true,
1091 struct X<T,R>(T, R);
1094 fn new(t: T) -> Self { A(t) }
1095 fn into_b(self) -> B<T> { B(self.0) }
1098 fn into_c(self) -> C<T> { C(self.0) }
1101 let c = A::new(X(42, true))
1111 label: "B<X<i32, bool>>",
1116 label: "A<X<i32, bool>>",
1124 fn incomplete_for_no_hint() {
1128 let data = &[1i32, 2, 3];
1135 pub struct Vec<T> {}
1138 pub fn new() -> Self { Vec {} }
1139 pub fn push(&mut self, t: T) {}
1142 impl<T> IntoIterator for Vec<T> {
1147 let mut data = Vec::new();
1148 //^^^^^^^^ Vec<&str>
1152 println!("Unit expr");
1159 fn complete_for_hint() {
1162 pub struct Vec<T> {}
1165 pub fn new() -> Self { Vec {} }
1166 pub fn push(&mut self, t: T) {}
1169 impl<T> IntoIterator for Vec<T> {
1174 let mut data = Vec::new();
1175 //^^^^^^^^ Vec<&str>
1188 fn multi_dyn_trait_bounds() {
1192 parameter_hints: false,
1193 chaining_hints: false,
1197 pub struct Vec<T> {}
1200 pub fn new() -> Self { Vec {} }
1203 pub struct Box<T> {}
1209 let _v = Vec::<Box<&(dyn Display + Sync)>>::new();
1210 //^^ Vec<Box<&(dyn Display + Sync)>>
1211 let _v = Vec::<Box<*const (dyn Display + Sync)>>::new();
1212 //^^ Vec<Box<*const (dyn Display + Sync)>>
1213 let _v = Vec::<Box<dyn Display + Sync>>::new();
1214 //^^ Vec<Box<dyn Display + Sync>>
1221 fn shorten_iterator_hints() {
1224 parameter_hints: false,
1226 chaining_hints: false,
1234 impl Iterator for MyIter {
1236 fn next(&mut self) -> Option<Self::Item> {
1244 let _x = iter::repeat(0);
1245 //^^ impl Iterator<Item = i32>
1246 fn generic<T: Clone>(t: T) {
1247 let _x = iter::repeat(t);
1248 //^^ impl Iterator<Item = T>
1249 let _chained = iter::repeat(t).take(10);
1250 //^^^^^^^^ impl Iterator<Item = T>
1258 fn shorten_iterator_chaining_hints() {
1261 parameter_hints: false,
1263 chaining_hints: true,
1271 impl Iterator for MyIter {
1273 fn next(&mut self) -> Option<Self::Item> {
1279 let _x = MyIter.by_ref()
1291 label: "impl Iterator<Item = ()>",
1296 label: "impl Iterator<Item = ()>",
1301 label: "impl Iterator<Item = ()>",
1306 label: "&mut MyIter",
1314 fn shorten_iterators_in_associated_params() {
1317 parameter_hints: false,
1319 chaining_hints: false,
1325 pub struct SomeIter<T> {}
1327 impl<T> SomeIter<T> {
1328 pub fn new() -> Self { SomeIter {} }
1329 pub fn push(&mut self, t: T) {}
1332 impl<T> Iterator for SomeIter<T> {
1334 fn next(&mut self) -> Option<Self::Item> {
1340 let mut some_iter = SomeIter::new();
1341 //^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
1342 some_iter.push(iter::repeat(2).take(2));
1343 let iter_of_iters = some_iter.take(2);
1344 //^^^^^^^^^^^^^ impl Iterator<Item = impl Iterator<Item = i32>>
1351 fn hide_param_hints_for_clones() {
1354 parameter_hints: true,
1356 chaining_hints: false,
1360 fn foo(bar: i32, baz: String, qux: f32) {}
1366 foo(bar.clone(), baz.clone(), fez.clone());
1374 fn infer_call_method_return_associated_types_with_generic() {
1378 fn default() -> Self;
1384 pub fn quux<T: Foo>() -> T::Bar {
1385 let y = Default::default();
1395 fn self_param_hints() {
1401 fn foo(self: Self) {}
1402 fn bar(self: &Self) {}
1421 fn foo() -> impl Fn() { loop {} }
1422 fn foo1() -> impl Fn(f64) { loop {} }
1423 fn foo2() -> impl Fn(f64, f64) { loop {} }
1424 fn foo3() -> impl Fn(f64, f64) -> u32 { loop {} }
1425 fn foo4() -> &'static dyn Fn(f64, f64) -> u32 { loop {} }
1426 fn foo5() -> &'static dyn Fn(&'static dyn Fn(f64, f64) -> u32, f64) -> u32 { loop {} }
1427 fn foo6() -> impl Fn(f64, f64) -> u32 + Sized { loop {} }
1428 fn foo7() -> *const (impl Fn(f64, f64) -> u32 + Sized) { loop {} }
1436 // ^^^ impl Fn(f64, f64)
1438 // ^^^ impl Fn(f64, f64) -> u32
1440 // ^^^ &dyn Fn(f64, f64) -> u32
1442 // ^^^ &dyn Fn(&dyn Fn(f64, f64) -> u32, f64) -> u32
1444 // ^^^ impl Fn(f64, f64) -> u32 + Sized
1446 // ^^^ *const (impl Fn(f64, f64) -> u32 + Sized)
1453 fn param_name_hints_show_for_literals() {
1455 r#"pub fn test(a: i32, b: i32) -> [i32; 2] { [a, b] }