1 use expect_test::{expect, Expect};
2 use ide_db::base_db::{FileLoader, FileRange};
5 use crate::{fixture, hover::HoverDocFormat, HoverConfig};
7 fn check_hover_no_result(ra_fixture: &str) {
8 let (analysis, position) = fixture::position(ra_fixture);
13 documentation: Some(HoverDocFormat::Markdown),
16 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
19 assert!(hover.is_none(), "hover not expected but found: {:?}", hover.unwrap());
23 fn check(ra_fixture: &str, expect: Expect) {
24 let (analysis, position) = fixture::position(ra_fixture);
29 documentation: Some(HoverDocFormat::Markdown),
32 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
37 let content = analysis.db.file_text(position.file_id);
38 let hovered_element = &content[hover.range];
40 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
41 expect.assert_eq(&actual)
44 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
45 let (analysis, position) = fixture::position(ra_fixture);
49 links_in_hover: false,
50 documentation: Some(HoverDocFormat::Markdown),
53 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
58 let content = analysis.db.file_text(position.file_id);
59 let hovered_element = &content[hover.range];
61 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
62 expect.assert_eq(&actual)
65 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
66 let (analysis, position) = fixture::position(ra_fixture);
71 documentation: Some(HoverDocFormat::PlainText),
74 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
79 let content = analysis.db.file_text(position.file_id);
80 let hovered_element = &content[hover.range];
82 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
83 expect.assert_eq(&actual)
86 fn check_actions(ra_fixture: &str, expect: Expect) {
87 let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
92 documentation: Some(HoverDocFormat::Markdown),
95 FileRange { file_id, range: position.range_or_empty() },
99 expect.assert_debug_eq(&hover.info.actions)
102 fn check_hover_range(ra_fixture: &str, expect: Expect) {
103 let (analysis, range) = fixture::range(ra_fixture);
107 links_in_hover: false,
108 documentation: Some(HoverDocFormat::Markdown),
115 expect.assert_eq(hover.info.markup.as_str())
118 fn check_hover_range_no_results(ra_fixture: &str) {
119 let (analysis, range) = fixture::range(ra_fixture);
123 links_in_hover: false,
124 documentation: Some(HoverDocFormat::Markdown),
130 assert!(hover.is_none());
134 fn hover_descend_macros_avoids_duplicates() {
137 macro_rules! dupe_use {
161 fn hover_shows_all_macro_descends() {
210 fn hover_shows_type_of_an_expression() {
213 pub fn foo() -> u32 { 1 }
216 let foo_test = foo()$0;
229 fn hover_remove_markdown_if_configured() {
230 check_hover_no_markdown(
232 pub fn foo() -> u32 { 1 }
235 let foo_test = foo()$0;
246 fn hover_shows_long_type_of_an_expression() {
249 struct Scan<A, B, C> { a: A, b: B, c: C }
250 struct Iter<I> { inner: I }
251 enum Option<T> { Some(T), None }
253 struct OtherStruct<T> { i: T }
255 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
256 Iter { inner: Scan { a, b, c } }
261 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
262 Option::Some(*memo + value)
265 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
272 let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
279 fn hover_shows_fn_signature() {
280 // Single file with result
283 pub fn foo() -> u32 { 1 }
285 fn main() { let foo_test = fo$0o(); }
300 // Multiple candidates but results are ambiguous.
304 pub fn foo() -> u32 { 1 }
307 pub fn foo() -> &str { "" }
310 pub fn foo(a: u32, b: u32) {}
317 fn main() { let foo_test = fo$0o(); }
327 // Use literal `crate` in path
332 fn foo() -> crate::X { X }
334 fn main() { f$0oo(); }
349 // Check `super` in path
354 mod m { pub fn foo() -> super::X { super::X } }
356 fn main() { m::f$0oo(); }
366 pub fn foo() -> super::X
373 fn hover_omits_unnamed_where_preds() {
376 pub fn foo(bar: impl T) { }
378 fn main() { fo$0o(); }
388 pub fn foo(bar: impl T)
394 pub fn foo<V: AsRef<str>>(bar: impl T, baz: V) { }
396 fn main() { fo$0o(); }
406 pub fn foo<V>(bar: impl T, baz: V)
415 fn hover_shows_fn_signature_with_type_params() {
418 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
420 fn main() { let foo_test = fo$0o(); }
430 pub fn foo<'a, T>(b: &'a T) -> &'a str
439 fn hover_shows_fn_signature_on_fn_name() {
442 pub fn foo$0(a: u32, b: u32) -> u32 {}
454 pub fn foo(a: u32, b: u32) -> u32
461 fn hover_shows_fn_doc() {
466 /// # use std::path::Path;
468 /// foo(Path::new("hello, world!"))
470 pub fn foo$0(_: &Path) {}
490 # use std::path::Path;
492 foo(Path::new("hello, world!"))
499 fn hover_shows_fn_doc_attr_raw_string() {
502 #[doc = r#"Raw string doc attr"#]
503 pub fn foo$0(_: &Path) {}
526 fn hover_shows_struct_field_info() {
527 // Hovering over the field when instantiating
530 struct Foo { field_a: u32 }
533 let foo = Foo { field_a$0: 0, };
549 // Hovering over the field in the definition
552 struct Foo { field_a$0: u32 }
555 let foo = Foo { field_a: 0 };
573 fn hover_const_static() {
575 r#"const foo$0: u32 = 123;"#,
584 const foo: u32 = 123 (0x7B)
611 r#"static foo$0: u32 = 456;"#,
620 static foo: u32 = 456
627 fn hover_default_generic_types() {
630 struct Test<K, T = u8> { k: K, t: T }
633 let zz$0 = Test { t: 23u8, k: 33 };
645 struct Test<K, T = u8> { k: K, t: T }
648 let $0zz$0 = Test { t: 23u8, k: 33 };
661 enum Option<T> { Some(T) }
664 fn main() { So$0me(12); }
681 enum Option<T> { Some(T) }
684 fn main() { let b$0ar = Some(12); }
697 fn hover_enum_variant() {
730 let s = Option::Som$0e(12);
752 fn hover_for_local_variable() {
754 r#"fn func(foo: i32) { fo$0o; }"#,
766 fn hover_for_local_variable_pat() {
768 r#"fn func(fo$0o: i32) {}"#,
780 fn hover_local_var_edge() {
782 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
794 fn hover_for_param_edge() {
796 r#"fn func($0foo: i32) {}"#,
808 fn hover_for_param_with_multiple_traits() {
818 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
823 _x: impl Deref<Target = u8> + DerefMut<Target = u8>
830 fn test_hover_infer_associated_method_result() {
833 struct Thing { x: u32 }
836 fn new() -> Thing { Thing { x: 0 } }
839 fn main() { let foo_$0test = Thing::new(); }
852 fn test_hover_infer_associated_method_exact() {
856 pub struct Thing { x: u32 }
859 pub fn new() -> Thing { Thing { x: 0 } }
863 fn main() { let foo_test = wrapper::Thing::new$0(); }
873 pub fn new() -> Thing
880 fn test_hover_infer_associated_const_in_pattern() {
911 fn test_hover_self() {
914 struct Thing { x: u32 }
916 fn new() -> Self { Self$0 { x: 0 } }
933 struct Thing { x: u32 }
935 fn new() -> Self$0 { Self { x: 0 } }
954 pub fn new() -> Self$0 { Thing::A }
973 pub fn thing(a: Self$0) {}
991 fn test_hover_shadowing_pat() {
1012 fn test_hover_macro_invocation() {
1015 macro_rules! foo { () => {} }
1017 fn f() { fo$0o!(); }
1034 fn test_hover_macro2_invocation() {
1042 fn f() { fo$0o!(); }
1065 fn test_hover_tuple_field() {
1067 r#"struct TS(String, i32$0);"#,
1079 fn test_hover_through_macro() {
1082 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1085 fn bar() { fo$0o(); }
1103 fn test_hover_through_attr() {
1106 //- proc_macros: identity
1107 #[proc_macros::identity]
1125 fn test_hover_through_expr_in_macro() {
1128 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1129 fn foo(bar:u32) { let a = id!(ba$0r); }
1142 fn test_hover_through_expr_in_macro_recursive() {
1145 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1146 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1147 fn foo(bar:u32) { let a = id!(ba$0r); }
1160 fn test_hover_through_func_in_macro_recursive() {
1163 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1164 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1165 fn bar() -> u32 { 0 }
1166 fn foo() { let a = id!([0u32, bar($0)] ); }
1178 fn test_hover_through_literal_string_in_macro() {
1181 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*] } }
1183 let mastered_for_itunes = "";
1184 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1197 fn test_hover_through_assert_macro() {
1200 #[rustc_builtin_macro]
1201 macro_rules! assert {}
1203 fn bar() -> bool { true }
1223 fn test_hover_multiple_actions() {
1227 struct Foo { bar: Bar }
1229 fn foo(Foo { b$0ar }: &Foo) {}
1236 mod_path: "test::Bar",
1237 nav: NavigationTarget {
1245 description: "struct Bar",
1256 fn test_hover_through_literal_string_in_builtin_macro() {
1257 check_hover_no_result(
1259 #[rustc_builtin_macro]
1260 macro_rules! format {}
1263 format!("hel$0lo {}", 0);
1270 fn test_hover_non_ascii_space_doc() {
1273 /// <- `\u{3000}` here
1276 fn bar() { fo$0o(); }
1297 fn test_hover_function_show_qualifiers() {
1299 r#"async fn foo$0() {}"#,
1313 r#"pub const unsafe fn foo$0() {}"#,
1322 pub const unsafe fn foo()
1326 // Top level `pub(crate)` will be displayed as no visibility.
1328 r#"mod m { pub(crate) async unsafe extern "C" fn foo$0() {} }"#,
1337 pub(crate) async unsafe extern "C" fn foo()
1344 fn test_hover_function_show_types() {
1346 r#"fn foo$0(a: i32, b:i32) -> i32 { 0 }"#,
1355 fn foo(a: i32, b: i32) -> i32
1362 fn test_hover_function_pointer_show_identifiers() {
1364 r#"type foo$0 = fn(a: i32, b: i32) -> i32;"#,
1373 type foo = fn(a: i32, b: i32) -> i32
1380 fn test_hover_function_pointer_no_identifier() {
1382 r#"type foo$0 = fn(i32, _: i32) -> i32;"#,
1391 type foo = fn(i32, i32) -> i32
1398 fn test_hover_trait_show_qualifiers() {
1400 r"unsafe trait foo$0() {}",
1417 fn test_hover_extern_crate() {
1420 //- /main.rs crate:main deps:std
1422 //- /std/lib.rs crate:std
1423 //! Standard library for this test
1437 Standard library for this test
1445 //- /main.rs crate:main deps:std
1446 extern crate std as ab$0c;
1447 //- /std/lib.rs crate:std
1448 //! Standard library for this test
1462 Standard library for this test
1471 fn test_hover_mod_with_same_name_as_function() {
1474 use self::m$0y::Bar;
1475 mod my { pub struct Bar; }
1494 fn test_hover_struct_doc_comment() {
1497 /// This is an example
1505 /// assert_eq!(6, my_crate::add_one(5));
1509 fn foo() { let bar = Ba$0r; }
1532 assert_eq!(6, my_crate::add_one(5));
1539 fn test_hover_struct_doc_attr() {
1545 fn foo() { let bar = Ba$0r; }
1566 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1570 #[doc = "bar docs 1"]
1571 #[doc = "bar docs 2"]
1574 fn foo() { let bar = Ba$0r; }
1597 fn test_hover_external_url() {
1601 /// [external](https://www.google.com)
1617 [external](https://www.google.com)
1622 // Check that we don't rewrite links which we can't identify
1624 fn test_hover_unknown_target() {
1650 fn test_hover_no_links() {
1651 check_hover_no_links(
1654 /// case 1. bare URL: https://www.example.com/
1655 /// case 2. inline URL with title: [example](https://www.example.com/)
1656 /// case 3. code reference: [`Result`]
1657 /// case 4. code reference but miss footnote: [`String`]
1658 /// case 5. autolink: <http://www.example.com/>
1659 /// case 6. email address: <test@example.com>
1660 /// case 7. reference: [example][example]
1661 /// case 8. collapsed link: [example][]
1662 /// case 9. shortcut link: [example]
1663 /// case 10. inline without URL: [example]()
1664 /// case 11. reference: [foo][foo]
1665 /// case 12. reference: [foo][bar]
1666 /// case 13. collapsed link: [foo][]
1667 /// case 14. shortcut link: [foo]
1668 /// case 15. inline without URL: [foo]()
1669 /// case 16. just escaped text: \[foo]
1670 /// case 17. inline link: [Foo](foo::Foo)
1672 /// [`Result`]: ../../std/result/enum.Result.html
1673 /// [^example]: https://www.example.com/
1690 case 1. bare URL: https://www.example.com/
1691 case 2. inline URL with title: [example](https://www.example.com/)
1692 case 3. code reference: `Result`
1693 case 4. code reference but miss footnote: `String`
1694 case 5. autolink: http://www.example.com/
1695 case 6. email address: test@example.com
1696 case 7. reference: example
1697 case 8. collapsed link: example
1698 case 9. shortcut link: example
1699 case 10. inline without URL: example
1700 case 11. reference: foo
1701 case 12. reference: foo
1702 case 13. collapsed link: foo
1703 case 14. shortcut link: foo
1704 case 15. inline without URL: foo
1705 case 16. just escaped text: \[foo\]
1706 case 17. inline link: Foo
1708 [^example]: https://www.example.com/
1714 fn test_hover_macro_generated_struct_fn_doc_comment() {
1715 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
1731 fn foo() { let bar = Bar; bar.fo$0o(); }
1752 fn test_hover_macro_generated_struct_fn_doc_attr() {
1753 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
1761 #[doc = "Do the foo"]
1769 fn foo() { let bar = Bar; bar.fo$0o(); }
1790 fn test_hover_variadic_function() {
1794 pub fn foo(bar: i32, ...) -> i32;
1797 fn main() { let foo_test = unsafe { fo$0o(1, 2, 3); } }
1807 pub unsafe fn foo(bar: i32, ...) -> i32
1814 fn test_hover_trait_has_impl_action() {
1816 r#"trait foo$0() {}"#,
1833 fn test_hover_struct_has_impl_action() {
1835 r"struct foo$0() {}",
1852 fn test_hover_union_has_impl_action() {
1854 r#"union foo$0() {}"#,
1871 fn test_hover_enum_has_impl_action() {
1873 r"enum foo$0() { A, B }",
1890 fn test_hover_self_has_impl_action() {
1892 r#"struct foo where Self$0:;"#,
1909 fn test_hover_test_has_action() {
1927 use_name_in_title: false,
1928 nav: NavigationTarget {
1933 focus_range: 11..19,
1954 fn test_hover_test_mod_has_action() {
1966 use_name_in_title: false,
1967 nav: NavigationTarget {
1975 description: "mod tests",
1989 fn test_hover_struct_has_goto_type_action() {
1994 fn main() { let s$0t = S{ f1:0 }; }
2001 mod_path: "test::S",
2002 nav: NavigationTarget {
2010 description: "struct S",
2021 fn test_hover_generic_struct_has_goto_type_actions() {
2025 struct S<T>{ f1: T }
2027 fn main() { let s$0t = S{ f1:Arg(0) }; }
2034 mod_path: "test::S",
2035 nav: NavigationTarget {
2040 focus_range: 24..25,
2043 description: "struct S<T>",
2047 mod_path: "test::Arg",
2048 nav: NavigationTarget {
2056 description: "struct Arg",
2067 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2071 struct S<T>{ f1: T }
2073 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2080 mod_path: "test::S",
2081 nav: NavigationTarget {
2086 focus_range: 24..25,
2089 description: "struct S<T>",
2093 mod_path: "test::Arg",
2094 nav: NavigationTarget {
2102 description: "struct Arg",
2113 fn test_hover_tuple_has_goto_type_actions() {
2122 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2129 mod_path: "test::A",
2130 nav: NavigationTarget {
2138 description: "struct A",
2142 mod_path: "test::B",
2143 nav: NavigationTarget {
2148 focus_range: 22..23,
2151 description: "struct B",
2155 mod_path: "test::M::C",
2156 nav: NavigationTarget {
2161 focus_range: 53..54,
2164 description: "pub struct C",
2175 fn test_hover_return_impl_trait_has_goto_type_action() {
2179 fn foo() -> impl Foo {}
2181 fn main() { let s$0t = foo(); }
2188 mod_path: "test::Foo",
2189 nav: NavigationTarget {
2197 description: "trait Foo",
2208 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2213 fn foo() -> impl Foo<S> {}
2215 fn main() { let s$0t = foo(); }
2222 mod_path: "test::Foo",
2223 nav: NavigationTarget {
2231 description: "trait Foo<T>",
2235 mod_path: "test::S",
2236 nav: NavigationTarget {
2241 focus_range: 23..24,
2244 description: "struct S",
2255 fn test_hover_return_impl_traits_has_goto_type_action() {
2260 fn foo() -> impl Foo + Bar {}
2262 fn main() { let s$0t = foo(); }
2269 mod_path: "test::Foo",
2270 nav: NavigationTarget {
2278 description: "trait Foo",
2282 mod_path: "test::Bar",
2283 nav: NavigationTarget {
2288 focus_range: 19..22,
2291 description: "trait Bar",
2302 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2310 fn foo() -> impl Foo<S1> + Bar<S2> {}
2312 fn main() { let s$0t = foo(); }
2319 mod_path: "test::Foo",
2320 nav: NavigationTarget {
2328 description: "trait Foo<T>",
2332 mod_path: "test::Bar",
2333 nav: NavigationTarget {
2338 focus_range: 22..25,
2341 description: "trait Bar<T>",
2345 mod_path: "test::S1",
2346 nav: NavigationTarget {
2351 focus_range: 39..41,
2354 description: "struct S1",
2358 mod_path: "test::S2",
2359 nav: NavigationTarget {
2364 focus_range: 52..54,
2367 description: "struct S2",
2378 fn test_hover_arg_impl_trait_has_goto_type_action() {
2382 fn foo(ar$0g: &impl Foo) {}
2389 mod_path: "test::Foo",
2390 nav: NavigationTarget {
2398 description: "trait Foo",
2409 fn test_hover_arg_impl_traits_has_goto_type_action() {
2416 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2423 mod_path: "test::Foo",
2424 nav: NavigationTarget {
2432 description: "trait Foo",
2436 mod_path: "test::Bar",
2437 nav: NavigationTarget {
2442 focus_range: 19..22,
2445 description: "trait Bar<T>",
2449 mod_path: "test::S",
2450 nav: NavigationTarget {
2455 focus_range: 36..37,
2458 description: "struct S",
2469 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2472 //- /main.rs crate:main deps:core
2473 // we don't use minicore here so that this test doesn't randomly fail
2474 // when someone edits minicore
2477 let fo$0o = async { S };
2479 //- /core.rs crate:core
2481 #[lang = "future_trait"]
2490 mod_path: "core::future::Future",
2491 nav: NavigationTarget {
2496 focus_range: 60..66,
2499 description: "pub trait Future",
2503 mod_path: "main::S",
2504 nav: NavigationTarget {
2509 focus_range: 108..109,
2512 description: "struct S",
2523 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2528 fn foo(ar$0g: &impl Foo<S>) {}
2535 mod_path: "test::Foo",
2536 nav: NavigationTarget {
2544 description: "trait Foo<T>",
2548 mod_path: "test::S",
2549 nav: NavigationTarget {
2554 focus_range: 23..24,
2557 description: "struct S",
2568 fn test_hover_dyn_return_has_goto_type_action() {
2576 fn foo() -> B<dyn Foo> {}
2578 fn main() { let s$0t = foo(); }
2585 mod_path: "test::B",
2586 nav: NavigationTarget {
2591 focus_range: 49..50,
2594 description: "struct B<T>",
2598 mod_path: "test::Foo",
2599 nav: NavigationTarget {
2607 description: "trait Foo",
2618 fn test_hover_dyn_arg_has_goto_type_action() {
2622 fn foo(ar$0g: &dyn Foo) {}
2629 mod_path: "test::Foo",
2630 nav: NavigationTarget {
2638 description: "trait Foo",
2649 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2654 fn foo(ar$0g: &dyn Foo<S>) {}
2661 mod_path: "test::Foo",
2662 nav: NavigationTarget {
2670 description: "trait Foo<T>",
2674 mod_path: "test::S",
2675 nav: NavigationTarget {
2680 focus_range: 23..24,
2683 description: "struct S",
2694 fn test_hover_goto_type_action_links_order() {
2697 trait ImplTrait<T> {}
2698 trait DynTrait<T> {}
2702 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2709 mod_path: "test::ImplTrait",
2710 nav: NavigationTarget {
2718 description: "trait ImplTrait<T>",
2722 mod_path: "test::B",
2723 nav: NavigationTarget {
2728 focus_range: 50..51,
2731 description: "struct B<T>",
2735 mod_path: "test::DynTrait",
2736 nav: NavigationTarget {
2741 focus_range: 28..36,
2744 description: "trait DynTrait<T>",
2748 mod_path: "test::S",
2749 nav: NavigationTarget {
2754 focus_range: 65..66,
2757 description: "struct S",
2768 fn test_hover_associated_type_has_goto_type_action() {
2773 fn get(self) -> Self::Item {}
2779 impl Foo for S { type Item = Bar; }
2781 fn test() -> impl Foo { S {} }
2783 fn main() { let s$0t = test().get(); }
2790 mod_path: "test::Foo",
2791 nav: NavigationTarget {
2799 description: "trait Foo",
2810 fn test_hover_const_param_has_goto_type_action() {
2814 struct Foo<const BAR: Bar>;
2816 impl<const BAR: Bar> Foo<BAR$0> {}
2823 mod_path: "test::Bar",
2824 nav: NavigationTarget {
2832 description: "struct Bar",
2843 fn test_hover_type_param_has_goto_type_action() {
2848 fn foo<T: Foo>(t: T$0){}
2855 mod_path: "test::Foo",
2856 nav: NavigationTarget {
2864 description: "trait Foo",
2875 fn test_hover_self_has_go_to_type() {
2888 mod_path: "test::Foo",
2889 nav: NavigationTarget {
2897 description: "struct Foo",
2908 fn hover_displays_normalized_crate_names() {
2911 //- /lib.rs crate:name-with-dashes
2913 pub struct Thing { x: u32 }
2916 pub fn new() -> Thing { Thing { x: 0 } }
2920 //- /main.rs crate:main deps:name-with-dashes
2921 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2927 name_with_dashes::wrapper::Thing
2931 pub fn new() -> Thing
2938 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2970 fn const_generic_order() {
2974 struct S$0T<const C: usize = 1, T = Foo>(T);
2984 struct ST<const C: usize, T = Foo>
2991 fn const_generic_positive_i8_literal() {
2994 struct Const<const N: i8>;
2997 let v$0alue = Const::<1>;
3011 fn const_generic_zero_i8_literal() {
3014 struct Const<const N: i8>;
3017 let v$0alue = Const::<0>;
3031 fn const_generic_negative_i8_literal() {
3034 struct Const<const N: i8>;
3037 let v$0alue = Const::<-1>;
3044 let value: Const<-1>
3051 fn const_generic_bool_literal() {
3054 struct Const<const F: bool>;
3057 let v$0alue = Const::<true>;
3064 let value: Const<true>
3071 fn const_generic_char_literal() {
3074 struct Const<const C: char>;
3077 let v$0alue = Const::<'🦀'>;
3084 let value: Const<'🦀'>
3091 fn hover_self_param_shows_type() {
3110 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3116 fn bar(sel$0f: Arc<Foo>) {}
3130 fn hover_doc_outer_inner() {
3137 /// This comment belongs to the function
3161 fn hover_doc_outer_inner_attribue() {
3164 #[doc = "Be quick;"]
3166 #![doc = "time is mana"]
3168 #[doc = "This comment belongs to the function"]
3192 fn hover_doc_block_style_indentend() {
3226 fn hover_comments_dont_highlight_parent() {
3227 cov_mark::check!(no_highlight_on_comment_hover);
3228 check_hover_no_result(
3256 fn hover_lifetime() {
3258 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3270 fn hover_type_param() {
3277 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
3301 // lifetimes bounds arent being tracked yet
3306 impl<T: 'static> Foo<T$0> {}
3319 fn hover_type_param_sized_bounds() {
3320 // implicit `: Sized` bound
3326 impl<T: Trait> Foo<T$0> {}
3341 impl<T: Trait + ?Sized> Foo<T$0> {}
3353 mod type_param_sized_bounds {
3357 fn single_implicit() {
3374 fn single_explicit() {
3378 fn foo<T$0: Sized>() {}
3391 fn single_relaxed() {
3395 fn foo<T$0: ?Sized>() {}
3408 fn multiple_implicit() {
3413 fn foo<T$0: Trait>() {}
3426 fn multiple_explicit() {
3431 fn foo<T$0: Trait + Sized>() {}
3444 fn multiple_relaxed() {
3449 fn foo<T$0: Trait + ?Sized>() {}
3466 fn foo<T$0: ?Sized + Sized + Sized>() {}
3480 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3494 fn hover_const_generic_type_alias() {
3497 struct Foo<const LEN: usize>;
3498 type Fo$0o2 = Foo<2>;
3515 fn hover_const_param() {
3518 struct Foo<const LEN: usize>;
3519 impl<const LEN: usize> Foo<LEN$0> {}
3532 fn hover_const_eval_variant() {
3564 A$0 = (1 << 3) + (1 << 2),
3583 // enums in const eval
3590 B$0 = E::A as u8 + 1,
3609 // unspecified variant should increment by one
3638 fn hover_const_eval() {
3643 const FOO$0: usize = 1 << 3;
3653 const FOO: usize = 8
3665 const FOO$0: usize = (1 << 3) + (1 << 2);
3675 const FOO: usize = 12 (0xC)
3683 // show original body when const eval fails
3687 const FOO$0: usize = 2 - 3;
3697 const FOO: usize = 2 - 3
3705 // don't show hex for negatives
3709 const FOO$0: i32 = 2 - 3;
3730 const FOO$0: &str = "bar";
3740 const FOO: &str = "bar"
3748 // show char literal
3752 const FOO$0: char = 'a';
3762 const FOO: char = 'a'
3770 // show escaped char literal
3774 const FOO$0: char = '\x61';
3784 const FOO: char = 'a'
3792 // show byte literal
3796 const FOO$0: u8 = b'a';
3806 const FOO: u8 = 97 (0x61)
3814 // show escaped byte literal
3818 const FOO$0: u8 = b'\x61';
3828 const FOO: u8 = 97 (0x61)
3836 // show float literal
3840 const FOO$0: f64 = 1.0234;
3850 const FOO: f64 = 1.0234
3858 //show float typecasted from int
3862 const FOO$0: f32 = 1f32;
3872 const FOO: f32 = 1.0
3880 //show f64 typecasted from float
3884 const FOO$0: f64 = 1.0f64;
3894 const FOO: f64 = 1.0
3905 fn hover_const_pat() {
3909 const FOO: usize = 3;
3925 const FOO: usize = 3
3965 fn array_repeat_exp() {
3969 let til$0e4 = [0_u32; (4 * 8 * 8) / 32];
3983 fn hover_mod_def() {
4010 fn hover_self_in_use() {
4013 //! This should not appear
4015 /// But this should appear
4018 use foo::bar::{self$0};
4033 But this should appear
4039 fn hover_keyword() {
4042 //- /main.rs crate:main deps:std
4043 fn f() { retur$0n; }
4044 //- /libstd.rs crate:std
4045 /// Docs for return_keyword
4046 mod return_keyword {}
4057 Docs for return_keyword
4063 fn hover_keyword_doc() {
4066 //- /main.rs crate:main deps:std
4068 let bar = mov$0e || {};
4070 //- /libstd.rs crate:std
4071 #[doc(keyword = "move")]
4073 /// [closures][closure]
4075 /// <https://doc.rust-lang.org/nightly/book/ch13-01-closures.html>
4077 /// [closure]: ../book/ch13-01-closures.html
4078 /// [threads]: ../book/ch16-01-threads.html#using-move-closures-with-threads
4090 [closure](https://doc.rust-lang.org/nightly/book/ch13-01-closures.html)
4091 [closures](https://doc.rust-lang.org/nightly/book/ch13-01-closures.html)
4092 [threads](https://doc.rust-lang.org/nightly/book/ch16-01-threads.html#using-move-closures-with-threads)
4093 <https://doc.rust-lang.org/nightly/book/ch13-01-closures.html>
4099 fn hover_keyword_as_primitive() {
4102 //- /main.rs crate:main deps:std
4103 type F = f$0n(i32) -> i32;
4104 //- /libstd.rs crate:std
4105 /// Docs for prim_fn
4123 fn hover_builtin() {
4126 //- /main.rs crate:main deps:std
4127 cosnt _: &str$0 = ""; }
4129 //- /libstd.rs crate:std
4130 /// Docs for prim_str
4131 /// [`foo`](../std/keyword.foo.html)
4144 [`foo`](https://doc.rust-lang.org/nightly/std/keyword.foo.html)
4150 fn hover_macro_expanded_function() {
4153 struct S<'a, T>(&'a T);
4157 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
4159 for<'a> T: Clone + 'a
4178 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
4182 for<'a> T: Clone + 'a,
4189 fn hover_intra_doc_links() {
4194 /// This is the item. Cool!
4198 /// Gives you a [`TheItem$0`].
4200 /// [`TheItem`]: theitem::TheItem
4201 pub fn gimme() -> theitem::TheItem {
4218 This is the item. Cool!
4224 fn test_hover_trait_assoc_typealias() {
4249 type Bar = <Foo as t2::T2>::Ba$0r;
4250 // ^^^ unresolvedReference
4267 fn hover_generic_assoc() {
4270 fn foo<T: A>() where T::Assoc$0: {}
4290 let _: <T>::Assoc$0;
4330 fn string_shadowed_with_inner_items() {
4333 //- /main.rs crate:main deps:alloc
4335 /// Custom `String` type.
4344 //- /alloc.rs crate:alloc
4349 /// This is `alloc::String`.
4366 Custom `String` type.
4372 fn function_doesnt_shadow_crate_in_use_tree() {
4375 //- /main.rs crate:main deps:foo
4378 //- /foo.rs crate:foo
4392 fn hover_feature() {
4394 r#"#![feature(box_syntax$0)]"#,
4404 The tracking issue for this feature is: [#49733]
4406 [#49733]: https://github.com/rust-lang/rust/issues/49733
4408 See also [`box_patterns`](box-patterns.md)
4410 ------------------------
4412 Currently the only stable way to create a `Box` is via the `Box::new` method.
4413 Also it is not possible in stable Rust to destructure a `Box` in a match
4414 pattern. The unstable `box` keyword can be used to create a `Box`. An example
4418 #![feature(box_syntax)]
4432 r#"#![allow(arithmetic_overflow$0)]"#,
4434 *arithmetic_overflow*
4440 arithmetic operation overflows
4446 fn hover_clippy_lint() {
4448 r#"#![allow(clippy::almost_swapped$0)]"#,
4452 clippy::almost_swapped
4456 Checks for `foo = bar; bar = foo` sequences.
4462 fn hover_attr_path_qualifier() {
4465 //- /foo.rs crate:foo
4467 //- /lib.rs crate:main.rs deps:foo
4498 use bar::{self as foo$0};
4541 fn hover_attribute_in_macro() {
4545 macro_rules! identity {
4550 #[rustc_builtin_macro]
4572 fn hover_derive_input() {
4576 #[rustc_builtin_macro]
4597 #[rustc_builtin_macro]
4600 #[derive(foo::Copy$0)]
4618 fn hover_range_math() {
4621 fn f() { let expr = $01 + 2 * 3$0 }
4631 fn f() { let expr = 1 $0+ 2 * $03 }
4641 fn f() { let expr = 1 + $02 * 3$0 }
4651 fn hover_range_arrays() {
4654 fn f() { let expr = $0[1, 2, 3, 4]$0 }
4664 fn f() { let expr = [1, 2, $03, 4]$0 }
4674 fn f() { let expr = [1, 2, $03$0, 4] }
4684 fn hover_range_functions() {
4687 fn f<T>(a: &[T]) { }
4688 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
4698 fn f<T>(a: &[T]) { }
4699 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
4709 fn hover_range_shows_nothing_when_invalid() {
4710 check_hover_range_no_results(
4712 fn f<T>(a: &[T]) { }
4713 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
4717 check_hover_range_no_results(
4719 fn f<T>$0(a: &[T]) { }
4720 fn b() { f(&[1, 2, 3,$0 4, 5]); }
4724 check_hover_range_no_results(
4726 fn $0f() { let expr = [1, 2, 3, 4]$0 }
4732 fn hover_range_shows_unit_for_statements() {
4735 fn f<T>(a: &[T]) { }
4736 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
4746 fn f() { let expr$0 = $0[1, 2, 3, 4] }
4756 fn hover_range_for_pat() {
4783 fn hover_range_shows_coercions_if_applicable_expr() {
4787 let x: &u32 = $0&&&&&0$0;
4800 let x: *const u32 = $0&0$0;
4806 Coerced to: *const u32
4813 fn hover_range_shows_type_actions() {
4818 let x: &Foo = $0&&&&&Foo$0;
4826 mod_path: "test::Foo",
4827 nav: NavigationTarget {
4835 description: "struct Foo",
4846 fn hover_try_expr_res() {
4852 fn foo() -> Result<(), FooError> {
4853 Ok($0Result::<(), FooError>::Ok(())?$0)
4867 fn foo() -> Result<(), FooError> {
4868 Ok($0Result::<(), BarError>::Ok(())?$0)
4873 Try Error Type: BarError
4874 Propagated as: FooError
4881 fn hover_try_expr() {
4884 struct NotResult<T, U>(T, U);
4888 fn foo() -> NotResult<(), Looooong> {
4889 $0NotResult((), Short)?$0;
4894 Try Target Type: NotResult<(), Short>
4895 Propagated as: NotResult<(), Looooong>
4901 struct NotResult<T, U>(T, U);
4905 fn foo() -> NotResult<(), Short> {
4906 $0NotResult((), Looooong)?$0;
4911 Try Target Type: NotResult<(), Looooong>
4912 Propagated as: NotResult<(), Short>
4919 use core::ops::ControlFlow;
4920 fn foo() -> ControlFlow<()> {
4921 $0ControlFlow::Break(())?$0;
4922 ControlFlow::Continue(())
4927 Try Target Type: ControlFlow<(), {unknown}>
4928 Propagated as: ControlFlow<(), ()>
4935 fn hover_try_expr_option() {
4936 cov_mark::check!(hover_try_expr_opt_opt);
4939 //- minicore: option, try
4941 fn foo() -> Option<()> {
4954 fn hover_deref_expr() {
4958 use core::ops::Deref;
4960 struct DerefExample<T> {
4964 impl<T> Deref for DerefExample<T> {
4967 fn deref(&self) -> &Self::Target {
4973 let x = DerefExample { value: 0 };
4974 let y: i32 = $0*x$0;
4979 Dereferenced from: DerefExample<i32>
4987 fn hover_deref_expr_with_coercion() {
4991 use core::ops::Deref;
4993 struct DerefExample<T> {
4997 impl<T> Deref for DerefExample<T> {
5000 fn deref(&self) -> &Self::Target {
5006 let x = DerefExample { value: &&&&&0 };
5007 let y: &i32 = $0*x$0;
5012 Dereferenced from: DerefExample<&&&&&i32>
5021 fn hover_intra_in_macro() {
5024 macro_rules! foo_macro {
5025 ($(#[$attr:meta])* $name:ident) => {
5032 /// Doc comment for [`Foo$0`]
5049 Doc comment for [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
5055 fn hover_intra_in_attr() {
5058 #[doc = "Doc comment for [`Foo$0`]"]
5074 Doc comment for [`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
5080 fn hover_inert_attr() {
5097 * \#\[doc(hidden|inline|...)\]
5098 * \#\[doc = string\]
5117 * \#\[allow(lint1, lint2, ..., /\*opt\*/ reason = "...")\]
5123 fn hover_dollar_crate() {
5124 // $crate should be resolved to the right crate name.
5128 //- /main.rs crate:main deps:dep
5130 //- /dep.rs crate:dep
5133 ( $name:ident ) => { const $name: $crate::Type = $crate::Type; };
5146 const KONST: dep::Type = $crate::Type
5153 fn hover_record_variant() {
5157 RecordV$0 { field: u32 }
5168 RecordV { field: u32 }
5175 fn hover_trait_impl_assoc_item_def_doc_forwarding() {
5205 fn hover_ranged_macro_call() {
5208 macro_rules! __rust_force_expr {
5215 __rust_force_expr!($elem)
5241 struct Struct(usize);
5243 impl core::ops::Deref for Struct {
5244 type Target = usize;
5246 fn deref(&self) -> &Self::Target {
5263 fn deref(&self) -> &Self::Target
5270 fn static_const_macro_expanded_body() {
5277 f(e) // Prevent const eval from evaluating this constant, we want to print the body's code.
5303 pub static V: i8 = {
5319 pub static V: i8 = {