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_shows_fn_signature_with_type_params() {
347 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
349 fn main() { let foo_test = fo$0o(); }
359 pub fn foo<'a, T>(b: &'a T) -> &'a str
368 fn hover_shows_fn_signature_on_fn_name() {
371 pub fn foo$0(a: u32, b: u32) -> u32 {}
383 pub fn foo(a: u32, b: u32) -> u32
390 fn hover_shows_fn_doc() {
395 /// # use std::path::Path;
397 /// foo(Path::new("hello, world!"))
399 pub fn foo$0(_: &Path) {}
419 # use std::path::Path;
421 foo(Path::new("hello, world!"))
428 fn hover_shows_fn_doc_attr_raw_string() {
431 #[doc = r#"Raw string doc attr"#]
432 pub fn foo$0(_: &Path) {}
455 fn hover_shows_struct_field_info() {
456 // Hovering over the field when instantiating
459 struct Foo { field_a: u32 }
462 let foo = Foo { field_a$0: 0, };
478 // Hovering over the field in the definition
481 struct Foo { field_a$0: u32 }
484 let foo = Foo { field_a: 0 };
502 fn hover_const_static() {
504 r#"const foo$0: u32 = 123;"#,
540 r#"static foo$0: u32 = 456;"#,
549 static foo: u32 = 456
556 fn hover_default_generic_types() {
559 struct Test<K, T = u8> { k: K, t: T }
562 let zz$0 = Test { t: 23u8, k: 33 };
568 let zz: Test<i32, u8>
578 enum Option<T> { Some(T) }
581 fn main() { So$0me(12); }
598 enum Option<T> { Some(T) }
601 fn main() { let b$0ar = Some(12); }
614 fn hover_enum_variant() {
646 let s = Option::Som$0e(12);
668 fn hover_for_local_variable() {
670 r#"fn func(foo: i32) { fo$0o; }"#,
682 fn hover_for_local_variable_pat() {
684 r#"fn func(fo$0o: i32) {}"#,
696 fn hover_local_var_edge() {
698 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
710 fn hover_for_param_edge() {
712 r#"fn func($0foo: i32) {}"#,
724 fn hover_for_param_with_multiple_traits() {
734 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
739 _x: impl Deref<Target = u8> + DerefMut<Target = u8>
746 fn test_hover_infer_associated_method_result() {
749 struct Thing { x: u32 }
752 fn new() -> Thing { Thing { x: 0 } }
755 fn main() { let foo_$0test = Thing::new(); }
768 fn test_hover_infer_associated_method_exact() {
772 struct Thing { x: u32 }
775 fn new() -> Thing { Thing { x: 0 } }
779 fn main() { let foo_test = wrapper::Thing::new$0(); }
796 fn test_hover_infer_associated_const_in_pattern() {
827 fn test_hover_self() {
830 struct Thing { x: u32 }
832 fn new() -> Self { Self$0 { x: 0 } }
849 struct Thing { x: u32 }
851 fn new() -> Self$0 { Self { x: 0 } }
870 pub fn new() -> Self$0 { Thing::A }
889 pub fn thing(a: Self$0) {}
907 fn test_hover_shadowing_pat() {
928 fn test_hover_macro_invocation() {
931 macro_rules! foo { () => {} }
950 fn test_hover_macro2_invocation() {
981 fn test_hover_tuple_field() {
983 r#"struct TS(String, i32$0);"#,
995 fn test_hover_through_macro() {
998 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1001 fn bar() { fo$0o(); }
1019 fn test_hover_through_attr() {
1022 //- proc_macros: identity
1023 #[proc_macros::identity]
1041 fn test_hover_through_expr_in_macro() {
1044 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1045 fn foo(bar:u32) { let a = id!(ba$0r); }
1058 fn test_hover_through_expr_in_macro_recursive() {
1061 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1062 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1063 fn foo(bar:u32) { let a = id!(ba$0r); }
1076 fn test_hover_through_func_in_macro_recursive() {
1079 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1080 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1081 fn bar() -> u32 { 0 }
1082 fn foo() { let a = id!([0u32, bar($0)] ); }
1094 fn test_hover_through_literal_string_in_macro() {
1097 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1099 let mastered_for_itunes = "";
1100 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1113 fn test_hover_through_assert_macro() {
1116 #[rustc_builtin_macro]
1117 macro_rules! assert {}
1119 fn bar() -> bool { true }
1139 fn test_hover_multiple_actions() {
1143 struct Foo { bar: Bar }
1145 fn foo(Foo { b$0ar }: &Foo) {}
1152 mod_path: "test::Bar",
1153 nav: NavigationTarget {
1161 description: "struct Bar",
1172 fn test_hover_through_literal_string_in_builtin_macro() {
1173 check_hover_no_result(
1175 #[rustc_builtin_macro]
1176 macro_rules! format {}
1179 format!("hel$0lo {}", 0);
1186 fn test_hover_non_ascii_space_doc() {
1189 /// <- `\u{3000}` here
1192 fn bar() { fo$0o(); }
1213 fn test_hover_function_show_qualifiers() {
1215 r#"async fn foo$0() {}"#,
1229 r#"pub const unsafe fn foo$0() {}"#,
1238 pub const unsafe fn foo()
1242 // Top level `pub(crate)` will be displayed as no visibility.
1244 r#"mod m { pub(crate) async unsafe extern "C" fn foo$0() {} }"#,
1253 pub(crate) async unsafe extern "C" fn foo()
1260 fn test_hover_trait_show_qualifiers() {
1262 r"unsafe trait foo$0() {}",
1279 fn test_hover_extern_crate() {
1282 //- /main.rs crate:main deps:std
1284 //- /std/lib.rs crate:std
1285 //! Standard library for this test
1299 Standard library for this test
1307 //- /main.rs crate:main deps:std
1308 extern crate std as ab$0c;
1309 //- /std/lib.rs crate:std
1310 //! Standard library for this test
1324 Standard library for this test
1333 fn test_hover_mod_with_same_name_as_function() {
1336 use self::m$0y::Bar;
1337 mod my { pub struct Bar; }
1356 fn test_hover_struct_doc_comment() {
1359 /// This is an example
1367 /// assert_eq!(6, my_crate::add_one(5));
1371 fn foo() { let bar = Ba$0r; }
1394 assert_eq!(6, my_crate::add_one(5));
1401 fn test_hover_struct_doc_attr() {
1407 fn foo() { let bar = Ba$0r; }
1428 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1432 #[doc = "bar docs 1"]
1433 #[doc = "bar docs 2"]
1436 fn foo() { let bar = Ba$0r; }
1459 fn test_hover_external_url() {
1463 /// [external](https://www.google.com)
1479 [external](https://www.google.com)
1484 // Check that we don't rewrite links which we can't identify
1486 fn test_hover_unknown_target() {
1512 fn test_hover_no_links() {
1513 check_hover_no_links(
1516 /// case 1. bare URL: https://www.example.com/
1517 /// case 2. inline URL with title: [example](https://www.example.com/)
1518 /// case 3. code reference: [`Result`]
1519 /// case 4. code reference but miss footnote: [`String`]
1520 /// case 5. autolink: <http://www.example.com/>
1521 /// case 6. email address: <test@example.com>
1522 /// case 7. reference: [example][example]
1523 /// case 8. collapsed link: [example][]
1524 /// case 9. shortcut link: [example]
1525 /// case 10. inline without URL: [example]()
1526 /// case 11. reference: [foo][foo]
1527 /// case 12. reference: [foo][bar]
1528 /// case 13. collapsed link: [foo][]
1529 /// case 14. shortcut link: [foo]
1530 /// case 15. inline without URL: [foo]()
1531 /// case 16. just escaped text: \[foo]
1532 /// case 17. inline link: [Foo](foo::Foo)
1534 /// [`Result`]: ../../std/result/enum.Result.html
1535 /// [^example]: https://www.example.com/
1552 case 1. bare URL: https://www.example.com/
1553 case 2. inline URL with title: [example](https://www.example.com/)
1554 case 3. code reference: `Result`
1555 case 4. code reference but miss footnote: `String`
1556 case 5. autolink: http://www.example.com/
1557 case 6. email address: test@example.com
1558 case 7. reference: example
1559 case 8. collapsed link: example
1560 case 9. shortcut link: example
1561 case 10. inline without URL: example
1562 case 11. reference: foo
1563 case 12. reference: foo
1564 case 13. collapsed link: foo
1565 case 14. shortcut link: foo
1566 case 15. inline without URL: foo
1567 case 16. just escaped text: \[foo\]
1568 case 17. inline link: Foo
1570 [^example]: https://www.example.com/
1576 fn test_hover_macro_generated_struct_fn_doc_comment() {
1577 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
1593 fn foo() { let bar = Bar; bar.fo$0o(); }
1614 fn test_hover_macro_generated_struct_fn_doc_attr() {
1615 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
1623 #[doc = "Do the foo"]
1631 fn foo() { let bar = Bar; bar.fo$0o(); }
1652 fn test_hover_trait_has_impl_action() {
1654 r#"trait foo$0() {}"#,
1671 fn test_hover_struct_has_impl_action() {
1673 r"struct foo$0() {}",
1690 fn test_hover_union_has_impl_action() {
1692 r#"union foo$0() {}"#,
1709 fn test_hover_enum_has_impl_action() {
1711 r"enum foo$0() { A, B }",
1728 fn test_hover_self_has_impl_action() {
1730 r#"struct foo where Self$0:;"#,
1747 fn test_hover_test_has_action() {
1765 use_name_in_title: false,
1766 nav: NavigationTarget {
1771 focus_range: 11..19,
1792 fn test_hover_test_mod_has_action() {
1804 use_name_in_title: false,
1805 nav: NavigationTarget {
1813 description: "mod tests",
1827 fn test_hover_struct_has_goto_type_action() {
1832 fn main() { let s$0t = S{ f1:0 }; }
1839 mod_path: "test::S",
1840 nav: NavigationTarget {
1848 description: "struct S",
1859 fn test_hover_generic_struct_has_goto_type_actions() {
1863 struct S<T>{ f1: T }
1865 fn main() { let s$0t = S{ f1:Arg(0) }; }
1872 mod_path: "test::S",
1873 nav: NavigationTarget {
1878 focus_range: 24..25,
1881 description: "struct S<T>",
1885 mod_path: "test::Arg",
1886 nav: NavigationTarget {
1894 description: "struct Arg",
1905 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
1909 struct S<T>{ f1: T }
1911 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
1918 mod_path: "test::S",
1919 nav: NavigationTarget {
1924 focus_range: 24..25,
1927 description: "struct S<T>",
1931 mod_path: "test::Arg",
1932 nav: NavigationTarget {
1940 description: "struct Arg",
1951 fn test_hover_tuple_has_goto_type_actions() {
1960 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
1967 mod_path: "test::A",
1968 nav: NavigationTarget {
1976 description: "struct A",
1980 mod_path: "test::B",
1981 nav: NavigationTarget {
1986 focus_range: 22..23,
1989 description: "struct B",
1993 mod_path: "test::M::C",
1994 nav: NavigationTarget {
1999 focus_range: 53..54,
2002 description: "pub struct C",
2013 fn test_hover_return_impl_trait_has_goto_type_action() {
2017 fn foo() -> impl Foo {}
2019 fn main() { let s$0t = foo(); }
2026 mod_path: "test::Foo",
2027 nav: NavigationTarget {
2035 description: "trait Foo",
2046 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2051 fn foo() -> impl Foo<S> {}
2053 fn main() { let s$0t = foo(); }
2060 mod_path: "test::Foo",
2061 nav: NavigationTarget {
2069 description: "trait Foo<T>",
2073 mod_path: "test::S",
2074 nav: NavigationTarget {
2079 focus_range: 23..24,
2082 description: "struct S",
2093 fn test_hover_return_impl_traits_has_goto_type_action() {
2098 fn foo() -> impl Foo + Bar {}
2100 fn main() { let s$0t = foo(); }
2107 mod_path: "test::Foo",
2108 nav: NavigationTarget {
2116 description: "trait Foo",
2120 mod_path: "test::Bar",
2121 nav: NavigationTarget {
2126 focus_range: 19..22,
2129 description: "trait Bar",
2140 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2148 fn foo() -> impl Foo<S1> + Bar<S2> {}
2150 fn main() { let s$0t = foo(); }
2157 mod_path: "test::Foo",
2158 nav: NavigationTarget {
2166 description: "trait Foo<T>",
2170 mod_path: "test::Bar",
2171 nav: NavigationTarget {
2176 focus_range: 22..25,
2179 description: "trait Bar<T>",
2183 mod_path: "test::S1",
2184 nav: NavigationTarget {
2189 focus_range: 39..41,
2192 description: "struct S1",
2196 mod_path: "test::S2",
2197 nav: NavigationTarget {
2202 focus_range: 52..54,
2205 description: "struct S2",
2216 fn test_hover_arg_impl_trait_has_goto_type_action() {
2220 fn foo(ar$0g: &impl Foo) {}
2227 mod_path: "test::Foo",
2228 nav: NavigationTarget {
2236 description: "trait Foo",
2247 fn test_hover_arg_impl_traits_has_goto_type_action() {
2254 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2261 mod_path: "test::Foo",
2262 nav: NavigationTarget {
2270 description: "trait Foo",
2274 mod_path: "test::Bar",
2275 nav: NavigationTarget {
2280 focus_range: 19..22,
2283 description: "trait Bar<T>",
2287 mod_path: "test::S",
2288 nav: NavigationTarget {
2293 focus_range: 36..37,
2296 description: "struct S",
2307 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2310 //- minicore: future
2313 let fo$0o = async { S };
2321 mod_path: "core::future::Future",
2322 nav: NavigationTarget {
2326 full_range: 276..458,
2327 focus_range: 315..321,
2330 description: "pub trait Future",
2334 mod_path: "test::S",
2335 nav: NavigationTarget {
2343 description: "struct S",
2354 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2359 fn foo(ar$0g: &impl Foo<S>) {}
2366 mod_path: "test::Foo",
2367 nav: NavigationTarget {
2375 description: "trait Foo<T>",
2379 mod_path: "test::S",
2380 nav: NavigationTarget {
2385 focus_range: 23..24,
2388 description: "struct S",
2399 fn test_hover_dyn_return_has_goto_type_action() {
2407 fn foo() -> B<dyn Foo> {}
2409 fn main() { let s$0t = foo(); }
2416 mod_path: "test::B",
2417 nav: NavigationTarget {
2422 focus_range: 49..50,
2425 description: "struct B<T>",
2429 mod_path: "test::Foo",
2430 nav: NavigationTarget {
2438 description: "trait Foo",
2449 fn test_hover_dyn_arg_has_goto_type_action() {
2453 fn foo(ar$0g: &dyn Foo) {}
2460 mod_path: "test::Foo",
2461 nav: NavigationTarget {
2469 description: "trait Foo",
2480 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2485 fn foo(ar$0g: &dyn Foo<S>) {}
2492 mod_path: "test::Foo",
2493 nav: NavigationTarget {
2501 description: "trait Foo<T>",
2505 mod_path: "test::S",
2506 nav: NavigationTarget {
2511 focus_range: 23..24,
2514 description: "struct S",
2525 fn test_hover_goto_type_action_links_order() {
2528 trait ImplTrait<T> {}
2529 trait DynTrait<T> {}
2533 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2540 mod_path: "test::ImplTrait",
2541 nav: NavigationTarget {
2549 description: "trait ImplTrait<T>",
2553 mod_path: "test::B",
2554 nav: NavigationTarget {
2559 focus_range: 50..51,
2562 description: "struct B<T>",
2566 mod_path: "test::DynTrait",
2567 nav: NavigationTarget {
2572 focus_range: 28..36,
2575 description: "trait DynTrait<T>",
2579 mod_path: "test::S",
2580 nav: NavigationTarget {
2585 focus_range: 65..66,
2588 description: "struct S",
2599 fn test_hover_associated_type_has_goto_type_action() {
2604 fn get(self) -> Self::Item {}
2610 impl Foo for S { type Item = Bar; }
2612 fn test() -> impl Foo { S {} }
2614 fn main() { let s$0t = test().get(); }
2621 mod_path: "test::Foo",
2622 nav: NavigationTarget {
2630 description: "trait Foo",
2641 fn test_hover_const_param_has_goto_type_action() {
2645 struct Foo<const BAR: Bar>;
2647 impl<const BAR: Bar> Foo<BAR$0> {}
2654 mod_path: "test::Bar",
2655 nav: NavigationTarget {
2663 description: "struct Bar",
2674 fn test_hover_type_param_has_goto_type_action() {
2679 fn foo<T: Foo>(t: T$0){}
2686 mod_path: "test::Foo",
2687 nav: NavigationTarget {
2695 description: "trait Foo",
2706 fn test_hover_self_has_go_to_type() {
2719 mod_path: "test::Foo",
2720 nav: NavigationTarget {
2728 description: "struct Foo",
2739 fn hover_displays_normalized_crate_names() {
2742 //- /lib.rs crate:name-with-dashes
2744 pub struct Thing { x: u32 }
2747 pub fn new() -> Thing { Thing { x: 0 } }
2751 //- /main.rs crate:main deps:name-with-dashes
2752 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2758 name_with_dashes::wrapper::Thing
2762 pub fn new() -> Thing
2769 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2801 fn hover_self_param_shows_type() {
2820 fn hover_self_param_shows_type_for_arbitrary_self_type() {
2826 fn bar(sel$0f: Arc<Foo>) {}
2840 fn hover_doc_outer_inner() {
2847 /// This comment belongs to the function
2871 fn hover_doc_outer_inner_attribue() {
2874 #[doc = "Be quick;"]
2876 #![doc = "time is mana"]
2878 #[doc = "This comment belongs to the function"]
2902 fn hover_doc_block_style_indentend() {
2936 fn hover_comments_dont_highlight_parent() {
2937 cov_mark::check!(no_highlight_on_comment_hover);
2938 check_hover_no_result(
2966 fn hover_lifetime() {
2968 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
2980 fn hover_type_param() {
2987 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
3011 // lifetimes bounds arent being tracked yet
3016 impl<T: 'static> Foo<T$0> {}
3029 fn hover_type_param_sized_bounds() {
3030 // implicit `: Sized` bound
3036 impl<T: Trait> Foo<T$0> {}
3051 impl<T: Trait + ?Sized> Foo<T$0> {}
3063 mod type_param_sized_bounds {
3067 fn single_implicit() {
3084 fn single_explicit() {
3088 fn foo<T$0: Sized>() {}
3101 fn single_relaxed() {
3105 fn foo<T$0: ?Sized>() {}
3118 fn multiple_implicit() {
3123 fn foo<T$0: Trait>() {}
3136 fn multiple_explicit() {
3141 fn foo<T$0: Trait + Sized>() {}
3154 fn multiple_relaxed() {
3159 fn foo<T$0: Trait + ?Sized>() {}
3176 fn foo<T$0: ?Sized + Sized + Sized>() {}
3190 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3204 fn hover_const_param() {
3207 struct Foo<const LEN: usize>;
3208 impl<const LEN: usize> Foo<LEN$0> {}
3221 fn hover_const_pat() {
3225 const FOO: usize = 3;
3241 const FOO: usize = 3
3252 fn hover_mod_def() {
3279 fn hover_self_in_use() {
3282 //! This should not appear
3284 /// But this should appear
3287 use foo::bar::{self$0};
3302 But this should appear
3308 fn hover_keyword() {
3311 //- /main.rs crate:main deps:std
3312 fn f() { retur$0n; }
3313 //- /libstd.rs crate:std
3314 /// Docs for return_keyword
3315 mod return_keyword {}
3326 Docs for return_keyword
3332 fn hover_builtin() {
3335 //- /main.rs crate:main deps:std
3336 cosnt _: &str$0 = ""; }
3338 //- /libstd.rs crate:std
3339 /// Docs for prim_str
3357 fn hover_macro_expanded_function() {
3360 struct S<'a, T>(&'a T);
3364 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3366 for<'a> T: Clone + 'a
3385 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3389 for<'a> T: Clone + 'a,
3396 fn hover_intra_doc_links() {
3401 /// This is the item. Cool!
3405 /// Gives you a [`TheItem$0`].
3407 /// [`TheItem`]: theitem::TheItem
3408 pub fn gimme() -> theitem::TheItem {
3425 This is the item. Cool!
3431 fn hover_generic_assoc() {
3434 fn foo<T: A>() where T::Assoc$0: {}
3454 let _: <T>::Assoc$0;
3494 fn string_shadowed_with_inner_items() {
3497 //- /main.rs crate:main deps:alloc
3499 /// Custom `String` type.
3508 //- /alloc.rs crate:alloc
3513 /// This is `alloc::String`.
3530 Custom `String` type.
3536 fn function_doesnt_shadow_crate_in_use_tree() {
3539 //- /main.rs crate:main deps:foo
3542 //- /foo.rs crate:foo
3556 fn hover_feature() {
3558 r#"#![feature(box_syntax$0)]"#,
3568 The tracking issue for this feature is: [#49733]
3570 [#49733]: https://github.com/rust-lang/rust/issues/49733
3572 See also [`box_patterns`](box-patterns.md)
3574 ------------------------
3576 Currently the only stable way to create a `Box` is via the `Box::new` method.
3577 Also it is not possible in stable Rust to destructure a `Box` in a match
3578 pattern. The unstable `box` keyword can be used to create a `Box`. An example
3582 #![feature(box_syntax)]
3596 r#"#![allow(arithmetic_overflow$0)]"#,
3598 *arithmetic_overflow*
3604 arithmetic operation overflows
3610 fn hover_clippy_lint() {
3612 r#"#![allow(clippy::almost_swapped$0)]"#,
3616 clippy::almost_swapped
3620 Checks for `foo = bar; bar = foo` sequences.
3626 fn hover_attr_path_qualifier() {
3627 cov_mark::check!(name_ref_classify_attr_path_qualifier);
3630 //- /foo.rs crate:foo
3632 //- /lib.rs crate:main.rs deps:foo
3663 use bar::{self as foo$0};
3706 fn hover_attribute_in_macro() {
3710 macro_rules! identity {
3715 #[rustc_builtin_macro]
3737 fn hover_derive_input() {
3741 #[rustc_builtin_macro]
3762 #[rustc_builtin_macro]
3765 #[derive(foo::Copy$0)]
3783 fn hover_range_math() {
3786 fn f() { let expr = $01 + 2 * 3$0 }
3796 fn f() { let expr = 1 $0+ 2 * $03 }
3806 fn f() { let expr = 1 + $02 * 3$0 }
3816 fn hover_range_arrays() {
3819 fn f() { let expr = $0[1, 2, 3, 4]$0 }
3829 fn f() { let expr = [1, 2, $03, 4]$0 }
3839 fn f() { let expr = [1, 2, $03$0, 4] }
3849 fn hover_range_functions() {
3852 fn f<T>(a: &[T]) { }
3853 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
3863 fn f<T>(a: &[T]) { }
3864 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
3874 fn hover_range_shows_nothing_when_invalid() {
3875 check_hover_range_no_results(
3877 fn f<T>(a: &[T]) { }
3878 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
3882 check_hover_range_no_results(
3884 fn f<T>$0(a: &[T]) { }
3885 fn b() { f(&[1, 2, 3,$0 4, 5]); }
3889 check_hover_range_no_results(
3891 fn $0f() { let expr = [1, 2, 3, 4]$0 }
3897 fn hover_range_shows_unit_for_statements() {
3900 fn f<T>(a: &[T]) { }
3901 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
3911 fn f() { let expr$0 = $0[1, 2, 3, 4] }
3921 fn hover_range_for_pat() {
3948 fn hover_range_shows_coercions_if_applicable_expr() {
3952 let x: &u32 = $0&&&&&0$0;
3965 let x: *const u32 = $0&0$0;
3971 Coerced to: *const u32
3978 fn hover_range_shows_type_actions() {
3983 let x: &Foo = $0&&&&&Foo$0;
3991 mod_path: "test::Foo",
3992 nav: NavigationTarget {
4000 description: "struct Foo",
4011 fn hover_try_expr_res() {
4017 fn foo() -> Result<(), FooError> {
4018 Ok($0Result::<(), FooError>::Ok(())?$0)
4032 fn foo() -> Result<(), FooError> {
4033 Ok($0Result::<(), BarError>::Ok(())?$0)
4038 Try Error Type: BarError
4039 Propagated as: FooError
4046 fn hover_try_expr() {
4049 struct NotResult<T, U>(T, U);
4053 fn foo() -> NotResult<(), Looooong> {
4054 $0NotResult((), Short)?$0;
4059 Try Target Type: NotResult<(), Short>
4060 Propagated as: NotResult<(), Looooong>
4066 struct NotResult<T, U>(T, U);
4070 fn foo() -> NotResult<(), Short> {
4071 $0NotResult((), Looooong)?$0;
4076 Try Target Type: NotResult<(), Looooong>
4077 Propagated as: NotResult<(), Short>
4084 fn hover_try_expr_option() {
4085 cov_mark::check!(hover_try_expr_opt_opt);
4088 //- minicore: option, try
4090 fn foo() -> Option<()> {
4097 <Option<i32> as Try>::Output
4103 fn hover_deref_expr() {
4107 use core::ops::Deref;
4109 struct DerefExample<T> {
4113 impl<T> Deref for DerefExample<T> {
4116 fn deref(&self) -> &Self::Target {
4122 let x = DerefExample { value: 0 };
4123 let y: i32 = $0*x$0;
4128 Dereferenced from: DerefExample<i32>
4136 fn hover_deref_expr_with_coercion() {
4140 use core::ops::Deref;
4142 struct DerefExample<T> {
4146 impl<T> Deref for DerefExample<T> {
4149 fn deref(&self) -> &Self::Target {
4155 let x = DerefExample { value: &&&&&0 };
4156 let y: &i32 = $0*x$0;
4161 Dereferenced from: DerefExample<&&&&&i32>
4170 fn hover_intra_in_macro() {
4173 macro_rules! foo_macro {
4174 ($(#[$attr:meta])* $name:ident) => {
4181 /// Doc comment for [`Foo$0`]
4198 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4204 fn hover_intra_in_attr() {
4207 #[doc = "Doc comment for [`Foo$0`]"]
4223 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)