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 };
616 struct Test<K, T = u8> { k: K, t: T }
619 let $0zz$0 = Test { t: 23u8, k: 33 };
632 enum Option<T> { Some(T) }
635 fn main() { So$0me(12); }
652 enum Option<T> { Some(T) }
655 fn main() { let b$0ar = Some(12); }
668 fn hover_enum_variant() {
700 let s = Option::Som$0e(12);
722 fn hover_for_local_variable() {
724 r#"fn func(foo: i32) { fo$0o; }"#,
736 fn hover_for_local_variable_pat() {
738 r#"fn func(fo$0o: i32) {}"#,
750 fn hover_local_var_edge() {
752 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
764 fn hover_for_param_edge() {
766 r#"fn func($0foo: i32) {}"#,
778 fn hover_for_param_with_multiple_traits() {
788 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
793 _x: impl Deref<Target = u8> + DerefMut<Target = u8>
800 fn test_hover_infer_associated_method_result() {
803 struct Thing { x: u32 }
806 fn new() -> Thing { Thing { x: 0 } }
809 fn main() { let foo_$0test = Thing::new(); }
822 fn test_hover_infer_associated_method_exact() {
826 struct Thing { x: u32 }
829 fn new() -> Thing { Thing { x: 0 } }
833 fn main() { let foo_test = wrapper::Thing::new$0(); }
850 fn test_hover_infer_associated_const_in_pattern() {
881 fn test_hover_self() {
884 struct Thing { x: u32 }
886 fn new() -> Self { Self$0 { x: 0 } }
903 struct Thing { x: u32 }
905 fn new() -> Self$0 { Self { x: 0 } }
924 pub fn new() -> Self$0 { Thing::A }
943 pub fn thing(a: Self$0) {}
961 fn test_hover_shadowing_pat() {
982 fn test_hover_macro_invocation() {
985 macro_rules! foo { () => {} }
1004 fn test_hover_macro2_invocation() {
1012 fn f() { fo$0o!(); }
1035 fn test_hover_tuple_field() {
1037 r#"struct TS(String, i32$0);"#,
1049 fn test_hover_through_macro() {
1052 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1055 fn bar() { fo$0o(); }
1073 fn test_hover_through_attr() {
1076 //- proc_macros: identity
1077 #[proc_macros::identity]
1095 fn test_hover_through_expr_in_macro() {
1098 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1099 fn foo(bar:u32) { let a = id!(ba$0r); }
1112 fn test_hover_through_expr_in_macro_recursive() {
1115 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1116 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1117 fn foo(bar:u32) { let a = id!(ba$0r); }
1130 fn test_hover_through_func_in_macro_recursive() {
1133 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1134 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1135 fn bar() -> u32 { 0 }
1136 fn foo() { let a = id!([0u32, bar($0)] ); }
1148 fn test_hover_through_literal_string_in_macro() {
1151 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1153 let mastered_for_itunes = "";
1154 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1167 fn test_hover_through_assert_macro() {
1170 #[rustc_builtin_macro]
1171 macro_rules! assert {}
1173 fn bar() -> bool { true }
1193 fn test_hover_multiple_actions() {
1197 struct Foo { bar: Bar }
1199 fn foo(Foo { b$0ar }: &Foo) {}
1206 mod_path: "test::Bar",
1207 nav: NavigationTarget {
1215 description: "struct Bar",
1226 fn test_hover_through_literal_string_in_builtin_macro() {
1227 check_hover_no_result(
1229 #[rustc_builtin_macro]
1230 macro_rules! format {}
1233 format!("hel$0lo {}", 0);
1240 fn test_hover_non_ascii_space_doc() {
1243 /// <- `\u{3000}` here
1246 fn bar() { fo$0o(); }
1267 fn test_hover_function_show_qualifiers() {
1269 r#"async fn foo$0() {}"#,
1283 r#"pub const unsafe fn foo$0() {}"#,
1292 pub const unsafe fn foo()
1296 // Top level `pub(crate)` will be displayed as no visibility.
1298 r#"mod m { pub(crate) async unsafe extern "C" fn foo$0() {} }"#,
1307 pub(crate) async unsafe extern "C" fn foo()
1314 fn test_hover_trait_show_qualifiers() {
1316 r"unsafe trait foo$0() {}",
1333 fn test_hover_extern_crate() {
1336 //- /main.rs crate:main deps:std
1338 //- /std/lib.rs crate:std
1339 //! Standard library for this test
1353 Standard library for this test
1361 //- /main.rs crate:main deps:std
1362 extern crate std as ab$0c;
1363 //- /std/lib.rs crate:std
1364 //! Standard library for this test
1378 Standard library for this test
1387 fn test_hover_mod_with_same_name_as_function() {
1390 use self::m$0y::Bar;
1391 mod my { pub struct Bar; }
1410 fn test_hover_struct_doc_comment() {
1413 /// This is an example
1421 /// assert_eq!(6, my_crate::add_one(5));
1425 fn foo() { let bar = Ba$0r; }
1448 assert_eq!(6, my_crate::add_one(5));
1455 fn test_hover_struct_doc_attr() {
1461 fn foo() { let bar = Ba$0r; }
1482 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1486 #[doc = "bar docs 1"]
1487 #[doc = "bar docs 2"]
1490 fn foo() { let bar = Ba$0r; }
1513 fn test_hover_external_url() {
1517 /// [external](https://www.google.com)
1533 [external](https://www.google.com)
1538 // Check that we don't rewrite links which we can't identify
1540 fn test_hover_unknown_target() {
1566 fn test_hover_no_links() {
1567 check_hover_no_links(
1570 /// case 1. bare URL: https://www.example.com/
1571 /// case 2. inline URL with title: [example](https://www.example.com/)
1572 /// case 3. code reference: [`Result`]
1573 /// case 4. code reference but miss footnote: [`String`]
1574 /// case 5. autolink: <http://www.example.com/>
1575 /// case 6. email address: <test@example.com>
1576 /// case 7. reference: [example][example]
1577 /// case 8. collapsed link: [example][]
1578 /// case 9. shortcut link: [example]
1579 /// case 10. inline without URL: [example]()
1580 /// case 11. reference: [foo][foo]
1581 /// case 12. reference: [foo][bar]
1582 /// case 13. collapsed link: [foo][]
1583 /// case 14. shortcut link: [foo]
1584 /// case 15. inline without URL: [foo]()
1585 /// case 16. just escaped text: \[foo]
1586 /// case 17. inline link: [Foo](foo::Foo)
1588 /// [`Result`]: ../../std/result/enum.Result.html
1589 /// [^example]: https://www.example.com/
1606 case 1. bare URL: https://www.example.com/
1607 case 2. inline URL with title: [example](https://www.example.com/)
1608 case 3. code reference: `Result`
1609 case 4. code reference but miss footnote: `String`
1610 case 5. autolink: http://www.example.com/
1611 case 6. email address: test@example.com
1612 case 7. reference: example
1613 case 8. collapsed link: example
1614 case 9. shortcut link: example
1615 case 10. inline without URL: example
1616 case 11. reference: foo
1617 case 12. reference: foo
1618 case 13. collapsed link: foo
1619 case 14. shortcut link: foo
1620 case 15. inline without URL: foo
1621 case 16. just escaped text: \[foo\]
1622 case 17. inline link: Foo
1624 [^example]: https://www.example.com/
1630 fn test_hover_macro_generated_struct_fn_doc_comment() {
1631 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
1647 fn foo() { let bar = Bar; bar.fo$0o(); }
1668 fn test_hover_macro_generated_struct_fn_doc_attr() {
1669 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
1677 #[doc = "Do the foo"]
1685 fn foo() { let bar = Bar; bar.fo$0o(); }
1706 fn test_hover_trait_has_impl_action() {
1708 r#"trait foo$0() {}"#,
1725 fn test_hover_struct_has_impl_action() {
1727 r"struct foo$0() {}",
1744 fn test_hover_union_has_impl_action() {
1746 r#"union foo$0() {}"#,
1763 fn test_hover_enum_has_impl_action() {
1765 r"enum foo$0() { A, B }",
1782 fn test_hover_self_has_impl_action() {
1784 r#"struct foo where Self$0:;"#,
1801 fn test_hover_test_has_action() {
1819 use_name_in_title: false,
1820 nav: NavigationTarget {
1825 focus_range: 11..19,
1846 fn test_hover_test_mod_has_action() {
1858 use_name_in_title: false,
1859 nav: NavigationTarget {
1867 description: "mod tests",
1881 fn test_hover_struct_has_goto_type_action() {
1886 fn main() { let s$0t = S{ f1:0 }; }
1893 mod_path: "test::S",
1894 nav: NavigationTarget {
1902 description: "struct S",
1913 fn test_hover_generic_struct_has_goto_type_actions() {
1917 struct S<T>{ f1: T }
1919 fn main() { let s$0t = S{ f1:Arg(0) }; }
1926 mod_path: "test::S",
1927 nav: NavigationTarget {
1932 focus_range: 24..25,
1935 description: "struct S<T>",
1939 mod_path: "test::Arg",
1940 nav: NavigationTarget {
1948 description: "struct Arg",
1959 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
1963 struct S<T>{ f1: T }
1965 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
1972 mod_path: "test::S",
1973 nav: NavigationTarget {
1978 focus_range: 24..25,
1981 description: "struct S<T>",
1985 mod_path: "test::Arg",
1986 nav: NavigationTarget {
1994 description: "struct Arg",
2005 fn test_hover_tuple_has_goto_type_actions() {
2014 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2021 mod_path: "test::A",
2022 nav: NavigationTarget {
2030 description: "struct A",
2034 mod_path: "test::B",
2035 nav: NavigationTarget {
2040 focus_range: 22..23,
2043 description: "struct B",
2047 mod_path: "test::M::C",
2048 nav: NavigationTarget {
2053 focus_range: 53..54,
2056 description: "pub struct C",
2067 fn test_hover_return_impl_trait_has_goto_type_action() {
2071 fn foo() -> impl Foo {}
2073 fn main() { let s$0t = foo(); }
2080 mod_path: "test::Foo",
2081 nav: NavigationTarget {
2089 description: "trait Foo",
2100 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2105 fn foo() -> impl Foo<S> {}
2107 fn main() { let s$0t = foo(); }
2114 mod_path: "test::Foo",
2115 nav: NavigationTarget {
2123 description: "trait Foo<T>",
2127 mod_path: "test::S",
2128 nav: NavigationTarget {
2133 focus_range: 23..24,
2136 description: "struct S",
2147 fn test_hover_return_impl_traits_has_goto_type_action() {
2152 fn foo() -> impl Foo + Bar {}
2154 fn main() { let s$0t = foo(); }
2161 mod_path: "test::Foo",
2162 nav: NavigationTarget {
2170 description: "trait Foo",
2174 mod_path: "test::Bar",
2175 nav: NavigationTarget {
2180 focus_range: 19..22,
2183 description: "trait Bar",
2194 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2202 fn foo() -> impl Foo<S1> + Bar<S2> {}
2204 fn main() { let s$0t = foo(); }
2211 mod_path: "test::Foo",
2212 nav: NavigationTarget {
2220 description: "trait Foo<T>",
2224 mod_path: "test::Bar",
2225 nav: NavigationTarget {
2230 focus_range: 22..25,
2233 description: "trait Bar<T>",
2237 mod_path: "test::S1",
2238 nav: NavigationTarget {
2243 focus_range: 39..41,
2246 description: "struct S1",
2250 mod_path: "test::S2",
2251 nav: NavigationTarget {
2256 focus_range: 52..54,
2259 description: "struct S2",
2270 fn test_hover_arg_impl_trait_has_goto_type_action() {
2274 fn foo(ar$0g: &impl Foo) {}
2281 mod_path: "test::Foo",
2282 nav: NavigationTarget {
2290 description: "trait Foo",
2301 fn test_hover_arg_impl_traits_has_goto_type_action() {
2308 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2315 mod_path: "test::Foo",
2316 nav: NavigationTarget {
2324 description: "trait Foo",
2328 mod_path: "test::Bar",
2329 nav: NavigationTarget {
2334 focus_range: 19..22,
2337 description: "trait Bar<T>",
2341 mod_path: "test::S",
2342 nav: NavigationTarget {
2347 focus_range: 36..37,
2350 description: "struct S",
2361 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2364 //- minicore: future
2367 let fo$0o = async { S };
2375 mod_path: "core::future::Future",
2376 nav: NavigationTarget {
2380 full_range: 276..458,
2381 focus_range: 315..321,
2384 description: "pub trait Future",
2388 mod_path: "test::S",
2389 nav: NavigationTarget {
2397 description: "struct S",
2408 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2413 fn foo(ar$0g: &impl Foo<S>) {}
2420 mod_path: "test::Foo",
2421 nav: NavigationTarget {
2429 description: "trait Foo<T>",
2433 mod_path: "test::S",
2434 nav: NavigationTarget {
2439 focus_range: 23..24,
2442 description: "struct S",
2453 fn test_hover_dyn_return_has_goto_type_action() {
2461 fn foo() -> B<dyn Foo> {}
2463 fn main() { let s$0t = foo(); }
2470 mod_path: "test::B",
2471 nav: NavigationTarget {
2476 focus_range: 49..50,
2479 description: "struct B<T>",
2483 mod_path: "test::Foo",
2484 nav: NavigationTarget {
2492 description: "trait Foo",
2503 fn test_hover_dyn_arg_has_goto_type_action() {
2507 fn foo(ar$0g: &dyn Foo) {}
2514 mod_path: "test::Foo",
2515 nav: NavigationTarget {
2523 description: "trait Foo",
2534 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2539 fn foo(ar$0g: &dyn Foo<S>) {}
2546 mod_path: "test::Foo",
2547 nav: NavigationTarget {
2555 description: "trait Foo<T>",
2559 mod_path: "test::S",
2560 nav: NavigationTarget {
2565 focus_range: 23..24,
2568 description: "struct S",
2579 fn test_hover_goto_type_action_links_order() {
2582 trait ImplTrait<T> {}
2583 trait DynTrait<T> {}
2587 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2594 mod_path: "test::ImplTrait",
2595 nav: NavigationTarget {
2603 description: "trait ImplTrait<T>",
2607 mod_path: "test::B",
2608 nav: NavigationTarget {
2613 focus_range: 50..51,
2616 description: "struct B<T>",
2620 mod_path: "test::DynTrait",
2621 nav: NavigationTarget {
2626 focus_range: 28..36,
2629 description: "trait DynTrait<T>",
2633 mod_path: "test::S",
2634 nav: NavigationTarget {
2639 focus_range: 65..66,
2642 description: "struct S",
2653 fn test_hover_associated_type_has_goto_type_action() {
2658 fn get(self) -> Self::Item {}
2664 impl Foo for S { type Item = Bar; }
2666 fn test() -> impl Foo { S {} }
2668 fn main() { let s$0t = test().get(); }
2675 mod_path: "test::Foo",
2676 nav: NavigationTarget {
2684 description: "trait Foo",
2695 fn test_hover_const_param_has_goto_type_action() {
2699 struct Foo<const BAR: Bar>;
2701 impl<const BAR: Bar> Foo<BAR$0> {}
2708 mod_path: "test::Bar",
2709 nav: NavigationTarget {
2717 description: "struct Bar",
2728 fn test_hover_type_param_has_goto_type_action() {
2733 fn foo<T: Foo>(t: T$0){}
2740 mod_path: "test::Foo",
2741 nav: NavigationTarget {
2749 description: "trait Foo",
2760 fn test_hover_self_has_go_to_type() {
2773 mod_path: "test::Foo",
2774 nav: NavigationTarget {
2782 description: "struct Foo",
2793 fn hover_displays_normalized_crate_names() {
2796 //- /lib.rs crate:name-with-dashes
2798 pub struct Thing { x: u32 }
2801 pub fn new() -> Thing { Thing { x: 0 } }
2805 //- /main.rs crate:main deps:name-with-dashes
2806 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2812 name_with_dashes::wrapper::Thing
2816 pub fn new() -> Thing
2823 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2855 fn hover_self_param_shows_type() {
2874 fn hover_self_param_shows_type_for_arbitrary_self_type() {
2880 fn bar(sel$0f: Arc<Foo>) {}
2894 fn hover_doc_outer_inner() {
2901 /// This comment belongs to the function
2925 fn hover_doc_outer_inner_attribue() {
2928 #[doc = "Be quick;"]
2930 #![doc = "time is mana"]
2932 #[doc = "This comment belongs to the function"]
2956 fn hover_doc_block_style_indentend() {
2990 fn hover_comments_dont_highlight_parent() {
2991 cov_mark::check!(no_highlight_on_comment_hover);
2992 check_hover_no_result(
3020 fn hover_lifetime() {
3022 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3034 fn hover_type_param() {
3041 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
3065 // lifetimes bounds arent being tracked yet
3070 impl<T: 'static> Foo<T$0> {}
3083 fn hover_type_param_sized_bounds() {
3084 // implicit `: Sized` bound
3090 impl<T: Trait> Foo<T$0> {}
3105 impl<T: Trait + ?Sized> Foo<T$0> {}
3117 mod type_param_sized_bounds {
3121 fn single_implicit() {
3138 fn single_explicit() {
3142 fn foo<T$0: Sized>() {}
3155 fn single_relaxed() {
3159 fn foo<T$0: ?Sized>() {}
3172 fn multiple_implicit() {
3177 fn foo<T$0: Trait>() {}
3190 fn multiple_explicit() {
3195 fn foo<T$0: Trait + Sized>() {}
3208 fn multiple_relaxed() {
3213 fn foo<T$0: Trait + ?Sized>() {}
3230 fn foo<T$0: ?Sized + Sized + Sized>() {}
3244 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3258 fn hover_const_param() {
3261 struct Foo<const LEN: usize>;
3262 impl<const LEN: usize> Foo<LEN$0> {}
3275 fn hover_const_pat() {
3279 const FOO: usize = 3;
3295 const FOO: usize = 3
3306 fn hover_mod_def() {
3333 fn hover_self_in_use() {
3336 //! This should not appear
3338 /// But this should appear
3341 use foo::bar::{self$0};
3356 But this should appear
3362 fn hover_keyword() {
3365 //- /main.rs crate:main deps:std
3366 fn f() { retur$0n; }
3367 //- /libstd.rs crate:std
3368 /// Docs for return_keyword
3369 mod return_keyword {}
3380 Docs for return_keyword
3386 fn hover_builtin() {
3389 //- /main.rs crate:main deps:std
3390 cosnt _: &str$0 = ""; }
3392 //- /libstd.rs crate:std
3393 /// Docs for prim_str
3411 fn hover_macro_expanded_function() {
3414 struct S<'a, T>(&'a T);
3418 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3420 for<'a> T: Clone + 'a
3439 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3443 for<'a> T: Clone + 'a,
3450 fn hover_intra_doc_links() {
3455 /// This is the item. Cool!
3459 /// Gives you a [`TheItem$0`].
3461 /// [`TheItem`]: theitem::TheItem
3462 pub fn gimme() -> theitem::TheItem {
3479 This is the item. Cool!
3485 fn hover_generic_assoc() {
3488 fn foo<T: A>() where T::Assoc$0: {}
3508 let _: <T>::Assoc$0;
3548 fn string_shadowed_with_inner_items() {
3551 //- /main.rs crate:main deps:alloc
3553 /// Custom `String` type.
3562 //- /alloc.rs crate:alloc
3567 /// This is `alloc::String`.
3584 Custom `String` type.
3590 fn function_doesnt_shadow_crate_in_use_tree() {
3593 //- /main.rs crate:main deps:foo
3596 //- /foo.rs crate:foo
3610 fn hover_feature() {
3612 r#"#![feature(box_syntax$0)]"#,
3622 The tracking issue for this feature is: [#49733]
3624 [#49733]: https://github.com/rust-lang/rust/issues/49733
3626 See also [`box_patterns`](box-patterns.md)
3628 ------------------------
3630 Currently the only stable way to create a `Box` is via the `Box::new` method.
3631 Also it is not possible in stable Rust to destructure a `Box` in a match
3632 pattern. The unstable `box` keyword can be used to create a `Box`. An example
3636 #![feature(box_syntax)]
3650 r#"#![allow(arithmetic_overflow$0)]"#,
3652 *arithmetic_overflow*
3658 arithmetic operation overflows
3664 fn hover_clippy_lint() {
3666 r#"#![allow(clippy::almost_swapped$0)]"#,
3670 clippy::almost_swapped
3674 Checks for `foo = bar; bar = foo` sequences.
3680 fn hover_attr_path_qualifier() {
3683 //- /foo.rs crate:foo
3685 //- /lib.rs crate:main.rs deps:foo
3716 use bar::{self as foo$0};
3759 fn hover_attribute_in_macro() {
3763 macro_rules! identity {
3768 #[rustc_builtin_macro]
3790 fn hover_derive_input() {
3794 #[rustc_builtin_macro]
3815 #[rustc_builtin_macro]
3818 #[derive(foo::Copy$0)]
3836 fn hover_range_math() {
3839 fn f() { let expr = $01 + 2 * 3$0 }
3849 fn f() { let expr = 1 $0+ 2 * $03 }
3859 fn f() { let expr = 1 + $02 * 3$0 }
3869 fn hover_range_arrays() {
3872 fn f() { let expr = $0[1, 2, 3, 4]$0 }
3882 fn f() { let expr = [1, 2, $03, 4]$0 }
3892 fn f() { let expr = [1, 2, $03$0, 4] }
3902 fn hover_range_functions() {
3905 fn f<T>(a: &[T]) { }
3906 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
3916 fn f<T>(a: &[T]) { }
3917 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
3927 fn hover_range_shows_nothing_when_invalid() {
3928 check_hover_range_no_results(
3930 fn f<T>(a: &[T]) { }
3931 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
3935 check_hover_range_no_results(
3937 fn f<T>$0(a: &[T]) { }
3938 fn b() { f(&[1, 2, 3,$0 4, 5]); }
3942 check_hover_range_no_results(
3944 fn $0f() { let expr = [1, 2, 3, 4]$0 }
3950 fn hover_range_shows_unit_for_statements() {
3953 fn f<T>(a: &[T]) { }
3954 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
3964 fn f() { let expr$0 = $0[1, 2, 3, 4] }
3974 fn hover_range_for_pat() {
4001 fn hover_range_shows_coercions_if_applicable_expr() {
4005 let x: &u32 = $0&&&&&0$0;
4018 let x: *const u32 = $0&0$0;
4024 Coerced to: *const u32
4031 fn hover_range_shows_type_actions() {
4036 let x: &Foo = $0&&&&&Foo$0;
4044 mod_path: "test::Foo",
4045 nav: NavigationTarget {
4053 description: "struct Foo",
4064 fn hover_try_expr_res() {
4070 fn foo() -> Result<(), FooError> {
4071 Ok($0Result::<(), FooError>::Ok(())?$0)
4085 fn foo() -> Result<(), FooError> {
4086 Ok($0Result::<(), BarError>::Ok(())?$0)
4091 Try Error Type: BarError
4092 Propagated as: FooError
4099 fn hover_try_expr() {
4102 struct NotResult<T, U>(T, U);
4106 fn foo() -> NotResult<(), Looooong> {
4107 $0NotResult((), Short)?$0;
4112 Try Target Type: NotResult<(), Short>
4113 Propagated as: NotResult<(), Looooong>
4119 struct NotResult<T, U>(T, U);
4123 fn foo() -> NotResult<(), Short> {
4124 $0NotResult((), Looooong)?$0;
4129 Try Target Type: NotResult<(), Looooong>
4130 Propagated as: NotResult<(), Short>
4137 fn hover_try_expr_option() {
4138 cov_mark::check!(hover_try_expr_opt_opt);
4141 //- minicore: option, try
4143 fn foo() -> Option<()> {
4150 <Option<i32> as Try>::Output
4156 fn hover_deref_expr() {
4160 use core::ops::Deref;
4162 struct DerefExample<T> {
4166 impl<T> Deref for DerefExample<T> {
4169 fn deref(&self) -> &Self::Target {
4175 let x = DerefExample { value: 0 };
4176 let y: i32 = $0*x$0;
4181 Dereferenced from: DerefExample<i32>
4189 fn hover_deref_expr_with_coercion() {
4193 use core::ops::Deref;
4195 struct DerefExample<T> {
4199 impl<T> Deref for DerefExample<T> {
4202 fn deref(&self) -> &Self::Target {
4208 let x = DerefExample { value: &&&&&0 };
4209 let y: &i32 = $0*x$0;
4214 Dereferenced from: DerefExample<&&&&&i32>
4223 fn hover_intra_in_macro() {
4226 macro_rules! foo_macro {
4227 ($(#[$attr:meta])* $name:ident) => {
4234 /// Doc comment for [`Foo$0`]
4251 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4257 fn hover_intra_in_attr() {
4260 #[doc = "Doc comment for [`Foo$0`]"]
4276 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)