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);
11 &HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
12 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
15 assert!(hover.is_none(), "hover not expected but found: {:?}", hover.unwrap());
18 fn check(ra_fixture: &str, expect: Expect) {
19 let (analysis, position) = fixture::position(ra_fixture);
22 &HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
23 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
28 let content = analysis.db.file_text(position.file_id);
29 let hovered_element = &content[hover.range];
31 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
32 expect.assert_eq(&actual)
35 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
36 let (analysis, position) = fixture::position(ra_fixture);
39 &HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
40 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
45 let content = analysis.db.file_text(position.file_id);
46 let hovered_element = &content[hover.range];
48 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
49 expect.assert_eq(&actual)
52 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
53 let (analysis, position) = fixture::position(ra_fixture);
56 &HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::PlainText) },
57 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
62 let content = analysis.db.file_text(position.file_id);
63 let hovered_element = &content[hover.range];
65 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
66 expect.assert_eq(&actual)
69 fn check_actions(ra_fixture: &str, expect: Expect) {
70 let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
73 &HoverConfig { links_in_hover: true, documentation: Some(HoverDocFormat::Markdown) },
74 FileRange { file_id, range: position.range_or_empty() },
78 expect.assert_debug_eq(&hover.info.actions)
81 fn check_hover_range(ra_fixture: &str, expect: Expect) {
82 let (analysis, range) = fixture::range(ra_fixture);
85 &HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
90 expect.assert_eq(hover.info.markup.as_str())
93 fn check_hover_range_no_results(ra_fixture: &str) {
94 let (analysis, range) = fixture::range(ra_fixture);
97 &HoverConfig { links_in_hover: false, documentation: Some(HoverDocFormat::Markdown) },
101 assert!(hover.is_none());
105 fn hover_descend_macros_avoids_duplicates() {
108 macro_rules! dupe_use {
132 fn hover_shows_all_macro_descends() {
181 fn hover_shows_type_of_an_expression() {
184 pub fn foo() -> u32 { 1 }
187 let foo_test = foo()$0;
200 fn hover_remove_markdown_if_configured() {
201 check_hover_no_markdown(
203 pub fn foo() -> u32 { 1 }
206 let foo_test = foo()$0;
217 fn hover_shows_long_type_of_an_expression() {
220 struct Scan<A, B, C> { a: A, b: B, c: C }
221 struct Iter<I> { inner: I }
222 enum Option<T> { Some(T), None }
224 struct OtherStruct<T> { i: T }
226 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
227 Iter { inner: Scan { a, b, c } }
232 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
233 Option::Some(*memo + value)
236 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
243 let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
250 fn hover_shows_fn_signature() {
251 // Single file with result
254 pub fn foo() -> u32 { 1 }
256 fn main() { let foo_test = fo$0o(); }
271 // Multiple candidates but results are ambiguous.
275 pub fn foo() -> u32 { 1 }
278 pub fn foo() -> &str { "" }
281 pub fn foo(a: u32, b: u32) {}
288 fn main() { let foo_test = fo$0o(); }
298 // Use literal `crate` in path
303 fn foo() -> crate::X { X }
305 fn main() { f$0oo(); }
320 // Check `super` in path
325 mod m { pub fn foo() -> super::X { super::X } }
327 fn main() { m::f$0oo(); }
337 pub fn foo() -> super::X
344 fn hover_omits_unnamed_where_preds() {
347 pub fn foo(bar: impl T) { }
349 fn main() { fo$0o(); }
359 pub fn foo(bar: impl T)
365 pub fn foo<V: AsRef<str>>(bar: impl T, baz: V) { }
367 fn main() { fo$0o(); }
377 pub fn foo<V>(bar: impl T, baz: V)
386 fn hover_shows_fn_signature_with_type_params() {
389 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
391 fn main() { let foo_test = fo$0o(); }
401 pub fn foo<'a, T>(b: &'a T) -> &'a str
410 fn hover_shows_fn_signature_on_fn_name() {
413 pub fn foo$0(a: u32, b: u32) -> u32 {}
425 pub fn foo(a: u32, b: u32) -> u32
432 fn hover_shows_fn_doc() {
437 /// # use std::path::Path;
439 /// foo(Path::new("hello, world!"))
441 pub fn foo$0(_: &Path) {}
461 # use std::path::Path;
463 foo(Path::new("hello, world!"))
470 fn hover_shows_fn_doc_attr_raw_string() {
473 #[doc = r#"Raw string doc attr"#]
474 pub fn foo$0(_: &Path) {}
497 fn hover_shows_struct_field_info() {
498 // Hovering over the field when instantiating
501 struct Foo { field_a: u32 }
504 let foo = Foo { field_a$0: 0, };
520 // Hovering over the field in the definition
523 struct Foo { field_a$0: u32 }
526 let foo = Foo { field_a: 0 };
544 fn hover_const_static() {
546 r#"const foo$0: u32 = 123;"#,
582 r#"static foo$0: u32 = 456;"#,
591 static foo: u32 = 456
598 fn hover_default_generic_types() {
601 struct Test<K, T = u8> { k: K, t: T }
604 let zz$0 = Test { t: 23u8, k: 33 };
610 let zz: Test<i32, u8>
620 enum Option<T> { Some(T) }
623 fn main() { So$0me(12); }
640 enum Option<T> { Some(T) }
643 fn main() { let b$0ar = Some(12); }
656 fn hover_enum_variant() {
688 let s = Option::Som$0e(12);
710 fn hover_for_local_variable() {
712 r#"fn func(foo: i32) { fo$0o; }"#,
724 fn hover_for_local_variable_pat() {
726 r#"fn func(fo$0o: i32) {}"#,
738 fn hover_local_var_edge() {
740 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
752 fn hover_for_param_edge() {
754 r#"fn func($0foo: i32) {}"#,
766 fn hover_for_param_with_multiple_traits() {
776 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
781 _x: impl Deref<Target = u8> + DerefMut<Target = u8>
788 fn test_hover_infer_associated_method_result() {
791 struct Thing { x: u32 }
794 fn new() -> Thing { Thing { x: 0 } }
797 fn main() { let foo_$0test = Thing::new(); }
810 fn test_hover_infer_associated_method_exact() {
814 struct Thing { x: u32 }
817 fn new() -> Thing { Thing { x: 0 } }
821 fn main() { let foo_test = wrapper::Thing::new$0(); }
838 fn test_hover_infer_associated_const_in_pattern() {
869 fn test_hover_self() {
872 struct Thing { x: u32 }
874 fn new() -> Self { Self$0 { x: 0 } }
891 struct Thing { x: u32 }
893 fn new() -> Self$0 { Self { x: 0 } }
912 pub fn new() -> Self$0 { Thing::A }
931 pub fn thing(a: Self$0) {}
949 fn test_hover_shadowing_pat() {
970 fn test_hover_macro_invocation() {
973 macro_rules! foo { () => {} }
992 fn test_hover_macro2_invocation() {
1000 fn f() { fo$0o!(); }
1023 fn test_hover_tuple_field() {
1025 r#"struct TS(String, i32$0);"#,
1037 fn test_hover_through_macro() {
1040 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1043 fn bar() { fo$0o(); }
1061 fn test_hover_through_attr() {
1064 //- proc_macros: identity
1065 #[proc_macros::identity]
1083 fn test_hover_through_expr_in_macro() {
1086 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1087 fn foo(bar:u32) { let a = id!(ba$0r); }
1100 fn test_hover_through_expr_in_macro_recursive() {
1103 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1104 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1105 fn foo(bar:u32) { let a = id!(ba$0r); }
1118 fn test_hover_through_func_in_macro_recursive() {
1121 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1122 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1123 fn bar() -> u32 { 0 }
1124 fn foo() { let a = id!([0u32, bar($0)] ); }
1136 fn test_hover_through_literal_string_in_macro() {
1139 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1141 let mastered_for_itunes = "";
1142 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1155 fn test_hover_through_assert_macro() {
1158 #[rustc_builtin_macro]
1159 macro_rules! assert {}
1161 fn bar() -> bool { true }
1181 fn test_hover_multiple_actions() {
1185 struct Foo { bar: Bar }
1187 fn foo(Foo { b$0ar }: &Foo) {}
1194 mod_path: "test::Bar",
1195 nav: NavigationTarget {
1203 description: "struct Bar",
1214 fn test_hover_through_literal_string_in_builtin_macro() {
1215 check_hover_no_result(
1217 #[rustc_builtin_macro]
1218 macro_rules! format {}
1221 format!("hel$0lo {}", 0);
1228 fn test_hover_non_ascii_space_doc() {
1231 /// <- `\u{3000}` here
1234 fn bar() { fo$0o(); }
1255 fn test_hover_function_show_qualifiers() {
1257 r#"async fn foo$0() {}"#,
1271 r#"pub const unsafe fn foo$0() {}"#,
1280 pub const unsafe fn foo()
1284 // Top level `pub(crate)` will be displayed as no visibility.
1286 r#"mod m { pub(crate) async unsafe extern "C" fn foo$0() {} }"#,
1295 pub(crate) async unsafe extern "C" fn foo()
1302 fn test_hover_trait_show_qualifiers() {
1304 r"unsafe trait foo$0() {}",
1321 fn test_hover_extern_crate() {
1324 //- /main.rs crate:main deps:std
1326 //- /std/lib.rs crate:std
1327 //! Standard library for this test
1341 Standard library for this test
1349 //- /main.rs crate:main deps:std
1350 extern crate std as ab$0c;
1351 //- /std/lib.rs crate:std
1352 //! Standard library for this test
1366 Standard library for this test
1375 fn test_hover_mod_with_same_name_as_function() {
1378 use self::m$0y::Bar;
1379 mod my { pub struct Bar; }
1398 fn test_hover_struct_doc_comment() {
1401 /// This is an example
1409 /// assert_eq!(6, my_crate::add_one(5));
1413 fn foo() { let bar = Ba$0r; }
1436 assert_eq!(6, my_crate::add_one(5));
1443 fn test_hover_struct_doc_attr() {
1449 fn foo() { let bar = Ba$0r; }
1470 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1474 #[doc = "bar docs 1"]
1475 #[doc = "bar docs 2"]
1478 fn foo() { let bar = Ba$0r; }
1501 fn test_hover_external_url() {
1505 /// [external](https://www.google.com)
1521 [external](https://www.google.com)
1526 // Check that we don't rewrite links which we can't identify
1528 fn test_hover_unknown_target() {
1554 fn test_hover_no_links() {
1555 check_hover_no_links(
1558 /// case 1. bare URL: https://www.example.com/
1559 /// case 2. inline URL with title: [example](https://www.example.com/)
1560 /// case 3. code reference: [`Result`]
1561 /// case 4. code reference but miss footnote: [`String`]
1562 /// case 5. autolink: <http://www.example.com/>
1563 /// case 6. email address: <test@example.com>
1564 /// case 7. reference: [example][example]
1565 /// case 8. collapsed link: [example][]
1566 /// case 9. shortcut link: [example]
1567 /// case 10. inline without URL: [example]()
1568 /// case 11. reference: [foo][foo]
1569 /// case 12. reference: [foo][bar]
1570 /// case 13. collapsed link: [foo][]
1571 /// case 14. shortcut link: [foo]
1572 /// case 15. inline without URL: [foo]()
1573 /// case 16. just escaped text: \[foo]
1574 /// case 17. inline link: [Foo](foo::Foo)
1576 /// [`Result`]: ../../std/result/enum.Result.html
1577 /// [^example]: https://www.example.com/
1594 case 1. bare URL: https://www.example.com/
1595 case 2. inline URL with title: [example](https://www.example.com/)
1596 case 3. code reference: `Result`
1597 case 4. code reference but miss footnote: `String`
1598 case 5. autolink: http://www.example.com/
1599 case 6. email address: test@example.com
1600 case 7. reference: example
1601 case 8. collapsed link: example
1602 case 9. shortcut link: example
1603 case 10. inline without URL: example
1604 case 11. reference: foo
1605 case 12. reference: foo
1606 case 13. collapsed link: foo
1607 case 14. shortcut link: foo
1608 case 15. inline without URL: foo
1609 case 16. just escaped text: \[foo\]
1610 case 17. inline link: Foo
1612 [^example]: https://www.example.com/
1618 fn test_hover_macro_generated_struct_fn_doc_comment() {
1619 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
1635 fn foo() { let bar = Bar; bar.fo$0o(); }
1656 fn test_hover_macro_generated_struct_fn_doc_attr() {
1657 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
1665 #[doc = "Do the foo"]
1673 fn foo() { let bar = Bar; bar.fo$0o(); }
1694 fn test_hover_trait_has_impl_action() {
1696 r#"trait foo$0() {}"#,
1713 fn test_hover_struct_has_impl_action() {
1715 r"struct foo$0() {}",
1732 fn test_hover_union_has_impl_action() {
1734 r#"union foo$0() {}"#,
1751 fn test_hover_enum_has_impl_action() {
1753 r"enum foo$0() { A, B }",
1770 fn test_hover_self_has_impl_action() {
1772 r#"struct foo where Self$0:;"#,
1789 fn test_hover_test_has_action() {
1807 use_name_in_title: false,
1808 nav: NavigationTarget {
1813 focus_range: 11..19,
1834 fn test_hover_test_mod_has_action() {
1846 use_name_in_title: false,
1847 nav: NavigationTarget {
1855 description: "mod tests",
1869 fn test_hover_struct_has_goto_type_action() {
1874 fn main() { let s$0t = S{ f1:0 }; }
1881 mod_path: "test::S",
1882 nav: NavigationTarget {
1890 description: "struct S",
1901 fn test_hover_generic_struct_has_goto_type_actions() {
1905 struct S<T>{ f1: T }
1907 fn main() { let s$0t = S{ f1:Arg(0) }; }
1914 mod_path: "test::S",
1915 nav: NavigationTarget {
1920 focus_range: 24..25,
1923 description: "struct S<T>",
1927 mod_path: "test::Arg",
1928 nav: NavigationTarget {
1936 description: "struct Arg",
1947 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
1951 struct S<T>{ f1: T }
1953 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
1960 mod_path: "test::S",
1961 nav: NavigationTarget {
1966 focus_range: 24..25,
1969 description: "struct S<T>",
1973 mod_path: "test::Arg",
1974 nav: NavigationTarget {
1982 description: "struct Arg",
1993 fn test_hover_tuple_has_goto_type_actions() {
2002 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2009 mod_path: "test::A",
2010 nav: NavigationTarget {
2018 description: "struct A",
2022 mod_path: "test::B",
2023 nav: NavigationTarget {
2028 focus_range: 22..23,
2031 description: "struct B",
2035 mod_path: "test::M::C",
2036 nav: NavigationTarget {
2041 focus_range: 53..54,
2044 description: "pub struct C",
2055 fn test_hover_return_impl_trait_has_goto_type_action() {
2059 fn foo() -> impl Foo {}
2061 fn main() { let s$0t = foo(); }
2068 mod_path: "test::Foo",
2069 nav: NavigationTarget {
2077 description: "trait Foo",
2088 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2093 fn foo() -> impl Foo<S> {}
2095 fn main() { let s$0t = foo(); }
2102 mod_path: "test::Foo",
2103 nav: NavigationTarget {
2111 description: "trait Foo<T>",
2115 mod_path: "test::S",
2116 nav: NavigationTarget {
2121 focus_range: 23..24,
2124 description: "struct S",
2135 fn test_hover_return_impl_traits_has_goto_type_action() {
2140 fn foo() -> impl Foo + Bar {}
2142 fn main() { let s$0t = foo(); }
2149 mod_path: "test::Foo",
2150 nav: NavigationTarget {
2158 description: "trait Foo",
2162 mod_path: "test::Bar",
2163 nav: NavigationTarget {
2168 focus_range: 19..22,
2171 description: "trait Bar",
2182 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2190 fn foo() -> impl Foo<S1> + Bar<S2> {}
2192 fn main() { let s$0t = foo(); }
2199 mod_path: "test::Foo",
2200 nav: NavigationTarget {
2208 description: "trait Foo<T>",
2212 mod_path: "test::Bar",
2213 nav: NavigationTarget {
2218 focus_range: 22..25,
2221 description: "trait Bar<T>",
2225 mod_path: "test::S1",
2226 nav: NavigationTarget {
2231 focus_range: 39..41,
2234 description: "struct S1",
2238 mod_path: "test::S2",
2239 nav: NavigationTarget {
2244 focus_range: 52..54,
2247 description: "struct S2",
2258 fn test_hover_arg_impl_trait_has_goto_type_action() {
2262 fn foo(ar$0g: &impl Foo) {}
2269 mod_path: "test::Foo",
2270 nav: NavigationTarget {
2278 description: "trait Foo",
2289 fn test_hover_arg_impl_traits_has_goto_type_action() {
2296 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2303 mod_path: "test::Foo",
2304 nav: NavigationTarget {
2312 description: "trait Foo",
2316 mod_path: "test::Bar",
2317 nav: NavigationTarget {
2322 focus_range: 19..22,
2325 description: "trait Bar<T>",
2329 mod_path: "test::S",
2330 nav: NavigationTarget {
2335 focus_range: 36..37,
2338 description: "struct S",
2349 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2352 //- minicore: future
2355 let fo$0o = async { S };
2363 mod_path: "core::future::Future",
2364 nav: NavigationTarget {
2368 full_range: 276..458,
2369 focus_range: 315..321,
2372 description: "pub trait Future",
2376 mod_path: "test::S",
2377 nav: NavigationTarget {
2385 description: "struct S",
2396 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2401 fn foo(ar$0g: &impl Foo<S>) {}
2408 mod_path: "test::Foo",
2409 nav: NavigationTarget {
2417 description: "trait Foo<T>",
2421 mod_path: "test::S",
2422 nav: NavigationTarget {
2427 focus_range: 23..24,
2430 description: "struct S",
2441 fn test_hover_dyn_return_has_goto_type_action() {
2449 fn foo() -> B<dyn Foo> {}
2451 fn main() { let s$0t = foo(); }
2458 mod_path: "test::B",
2459 nav: NavigationTarget {
2464 focus_range: 49..50,
2467 description: "struct B<T>",
2471 mod_path: "test::Foo",
2472 nav: NavigationTarget {
2480 description: "trait Foo",
2491 fn test_hover_dyn_arg_has_goto_type_action() {
2495 fn foo(ar$0g: &dyn Foo) {}
2502 mod_path: "test::Foo",
2503 nav: NavigationTarget {
2511 description: "trait Foo",
2522 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2527 fn foo(ar$0g: &dyn Foo<S>) {}
2534 mod_path: "test::Foo",
2535 nav: NavigationTarget {
2543 description: "trait Foo<T>",
2547 mod_path: "test::S",
2548 nav: NavigationTarget {
2553 focus_range: 23..24,
2556 description: "struct S",
2567 fn test_hover_goto_type_action_links_order() {
2570 trait ImplTrait<T> {}
2571 trait DynTrait<T> {}
2575 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2582 mod_path: "test::ImplTrait",
2583 nav: NavigationTarget {
2591 description: "trait ImplTrait<T>",
2595 mod_path: "test::B",
2596 nav: NavigationTarget {
2601 focus_range: 50..51,
2604 description: "struct B<T>",
2608 mod_path: "test::DynTrait",
2609 nav: NavigationTarget {
2614 focus_range: 28..36,
2617 description: "trait DynTrait<T>",
2621 mod_path: "test::S",
2622 nav: NavigationTarget {
2627 focus_range: 65..66,
2630 description: "struct S",
2641 fn test_hover_associated_type_has_goto_type_action() {
2646 fn get(self) -> Self::Item {}
2652 impl Foo for S { type Item = Bar; }
2654 fn test() -> impl Foo { S {} }
2656 fn main() { let s$0t = test().get(); }
2663 mod_path: "test::Foo",
2664 nav: NavigationTarget {
2672 description: "trait Foo",
2683 fn test_hover_const_param_has_goto_type_action() {
2687 struct Foo<const BAR: Bar>;
2689 impl<const BAR: Bar> Foo<BAR$0> {}
2696 mod_path: "test::Bar",
2697 nav: NavigationTarget {
2705 description: "struct Bar",
2716 fn test_hover_type_param_has_goto_type_action() {
2721 fn foo<T: Foo>(t: T$0){}
2728 mod_path: "test::Foo",
2729 nav: NavigationTarget {
2737 description: "trait Foo",
2748 fn test_hover_self_has_go_to_type() {
2761 mod_path: "test::Foo",
2762 nav: NavigationTarget {
2770 description: "struct Foo",
2781 fn hover_displays_normalized_crate_names() {
2784 //- /lib.rs crate:name-with-dashes
2786 pub struct Thing { x: u32 }
2789 pub fn new() -> Thing { Thing { x: 0 } }
2793 //- /main.rs crate:main deps:name-with-dashes
2794 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2800 name_with_dashes::wrapper::Thing
2804 pub fn new() -> Thing
2811 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2843 fn hover_self_param_shows_type() {
2862 fn hover_self_param_shows_type_for_arbitrary_self_type() {
2868 fn bar(sel$0f: Arc<Foo>) {}
2882 fn hover_doc_outer_inner() {
2889 /// This comment belongs to the function
2913 fn hover_doc_outer_inner_attribue() {
2916 #[doc = "Be quick;"]
2918 #![doc = "time is mana"]
2920 #[doc = "This comment belongs to the function"]
2944 fn hover_doc_block_style_indentend() {
2978 fn hover_comments_dont_highlight_parent() {
2979 cov_mark::check!(no_highlight_on_comment_hover);
2980 check_hover_no_result(
3008 fn hover_lifetime() {
3010 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3022 fn hover_type_param() {
3029 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
3053 // lifetimes bounds arent being tracked yet
3058 impl<T: 'static> Foo<T$0> {}
3071 fn hover_type_param_sized_bounds() {
3072 // implicit `: Sized` bound
3078 impl<T: Trait> Foo<T$0> {}
3093 impl<T: Trait + ?Sized> Foo<T$0> {}
3105 mod type_param_sized_bounds {
3109 fn single_implicit() {
3126 fn single_explicit() {
3130 fn foo<T$0: Sized>() {}
3143 fn single_relaxed() {
3147 fn foo<T$0: ?Sized>() {}
3160 fn multiple_implicit() {
3165 fn foo<T$0: Trait>() {}
3178 fn multiple_explicit() {
3183 fn foo<T$0: Trait + Sized>() {}
3196 fn multiple_relaxed() {
3201 fn foo<T$0: Trait + ?Sized>() {}
3218 fn foo<T$0: ?Sized + Sized + Sized>() {}
3232 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3246 fn hover_const_param() {
3249 struct Foo<const LEN: usize>;
3250 impl<const LEN: usize> Foo<LEN$0> {}
3263 fn hover_const_pat() {
3267 const FOO: usize = 3;
3283 const FOO: usize = 3
3294 fn hover_mod_def() {
3321 fn hover_self_in_use() {
3324 //! This should not appear
3326 /// But this should appear
3329 use foo::bar::{self$0};
3344 But this should appear
3350 fn hover_keyword() {
3353 //- /main.rs crate:main deps:std
3354 fn f() { retur$0n; }
3355 //- /libstd.rs crate:std
3356 /// Docs for return_keyword
3357 mod return_keyword {}
3368 Docs for return_keyword
3374 fn hover_builtin() {
3377 //- /main.rs crate:main deps:std
3378 cosnt _: &str$0 = ""; }
3380 //- /libstd.rs crate:std
3381 /// Docs for prim_str
3399 fn hover_macro_expanded_function() {
3402 struct S<'a, T>(&'a T);
3406 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3408 for<'a> T: Clone + 'a
3427 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3431 for<'a> T: Clone + 'a,
3438 fn hover_intra_doc_links() {
3443 /// This is the item. Cool!
3447 /// Gives you a [`TheItem$0`].
3449 /// [`TheItem`]: theitem::TheItem
3450 pub fn gimme() -> theitem::TheItem {
3467 This is the item. Cool!
3473 fn hover_generic_assoc() {
3476 fn foo<T: A>() where T::Assoc$0: {}
3496 let _: <T>::Assoc$0;
3536 fn string_shadowed_with_inner_items() {
3539 //- /main.rs crate:main deps:alloc
3541 /// Custom `String` type.
3550 //- /alloc.rs crate:alloc
3555 /// This is `alloc::String`.
3572 Custom `String` type.
3578 fn function_doesnt_shadow_crate_in_use_tree() {
3581 //- /main.rs crate:main deps:foo
3584 //- /foo.rs crate:foo
3598 fn hover_feature() {
3600 r#"#![feature(box_syntax$0)]"#,
3610 The tracking issue for this feature is: [#49733]
3612 [#49733]: https://github.com/rust-lang/rust/issues/49733
3614 See also [`box_patterns`](box-patterns.md)
3616 ------------------------
3618 Currently the only stable way to create a `Box` is via the `Box::new` method.
3619 Also it is not possible in stable Rust to destructure a `Box` in a match
3620 pattern. The unstable `box` keyword can be used to create a `Box`. An example
3624 #![feature(box_syntax)]
3638 r#"#![allow(arithmetic_overflow$0)]"#,
3640 *arithmetic_overflow*
3646 arithmetic operation overflows
3652 fn hover_clippy_lint() {
3654 r#"#![allow(clippy::almost_swapped$0)]"#,
3658 clippy::almost_swapped
3662 Checks for `foo = bar; bar = foo` sequences.
3668 fn hover_attr_path_qualifier() {
3669 cov_mark::check!(name_ref_classify_attr_path_qualifier);
3672 //- /foo.rs crate:foo
3674 //- /lib.rs crate:main.rs deps:foo
3705 use bar::{self as foo$0};
3748 fn hover_attribute_in_macro() {
3752 macro_rules! identity {
3757 #[rustc_builtin_macro]
3779 fn hover_derive_input() {
3783 #[rustc_builtin_macro]
3804 #[rustc_builtin_macro]
3807 #[derive(foo::Copy$0)]
3825 fn hover_range_math() {
3828 fn f() { let expr = $01 + 2 * 3$0 }
3838 fn f() { let expr = 1 $0+ 2 * $03 }
3848 fn f() { let expr = 1 + $02 * 3$0 }
3858 fn hover_range_arrays() {
3861 fn f() { let expr = $0[1, 2, 3, 4]$0 }
3871 fn f() { let expr = [1, 2, $03, 4]$0 }
3881 fn f() { let expr = [1, 2, $03$0, 4] }
3891 fn hover_range_functions() {
3894 fn f<T>(a: &[T]) { }
3895 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
3905 fn f<T>(a: &[T]) { }
3906 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
3916 fn hover_range_shows_nothing_when_invalid() {
3917 check_hover_range_no_results(
3919 fn f<T>(a: &[T]) { }
3920 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
3924 check_hover_range_no_results(
3926 fn f<T>$0(a: &[T]) { }
3927 fn b() { f(&[1, 2, 3,$0 4, 5]); }
3931 check_hover_range_no_results(
3933 fn $0f() { let expr = [1, 2, 3, 4]$0 }
3939 fn hover_range_shows_unit_for_statements() {
3942 fn f<T>(a: &[T]) { }
3943 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
3953 fn f() { let expr$0 = $0[1, 2, 3, 4] }
3963 fn hover_range_for_pat() {
3990 fn hover_range_shows_coercions_if_applicable_expr() {
3994 let x: &u32 = $0&&&&&0$0;
4007 let x: *const u32 = $0&0$0;
4013 Coerced to: *const u32
4020 fn hover_range_shows_type_actions() {
4025 let x: &Foo = $0&&&&&Foo$0;
4033 mod_path: "test::Foo",
4034 nav: NavigationTarget {
4042 description: "struct Foo",
4053 fn hover_try_expr_res() {
4059 fn foo() -> Result<(), FooError> {
4060 Ok($0Result::<(), FooError>::Ok(())?$0)
4074 fn foo() -> Result<(), FooError> {
4075 Ok($0Result::<(), BarError>::Ok(())?$0)
4080 Try Error Type: BarError
4081 Propagated as: FooError
4088 fn hover_try_expr() {
4091 struct NotResult<T, U>(T, U);
4095 fn foo() -> NotResult<(), Looooong> {
4096 $0NotResult((), Short)?$0;
4101 Try Target Type: NotResult<(), Short>
4102 Propagated as: NotResult<(), Looooong>
4108 struct NotResult<T, U>(T, U);
4112 fn foo() -> NotResult<(), Short> {
4113 $0NotResult((), Looooong)?$0;
4118 Try Target Type: NotResult<(), Looooong>
4119 Propagated as: NotResult<(), Short>
4126 fn hover_try_expr_option() {
4127 cov_mark::check!(hover_try_expr_opt_opt);
4130 //- minicore: option, try
4132 fn foo() -> Option<()> {
4139 <Option<i32> as Try>::Output
4145 fn hover_deref_expr() {
4149 use core::ops::Deref;
4151 struct DerefExample<T> {
4155 impl<T> Deref for DerefExample<T> {
4158 fn deref(&self) -> &Self::Target {
4164 let x = DerefExample { value: 0 };
4165 let y: i32 = $0*x$0;
4170 Dereferenced from: DerefExample<i32>
4178 fn hover_deref_expr_with_coercion() {
4182 use core::ops::Deref;
4184 struct DerefExample<T> {
4188 impl<T> Deref for DerefExample<T> {
4191 fn deref(&self) -> &Self::Target {
4197 let x = DerefExample { value: &&&&&0 };
4198 let y: &i32 = $0*x$0;
4203 Dereferenced from: DerefExample<&&&&&i32>
4212 fn hover_intra_in_macro() {
4215 macro_rules! foo_macro {
4216 ($(#[$attr:meta])* $name:ident) => {
4223 /// Doc comment for [`Foo$0`]
4240 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4246 fn hover_intra_in_attr() {
4249 #[doc = "Doc comment for [`Foo$0`]"]
4265 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)