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;"#,
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_through_literal_string_in_builtin_macro() {
1140 check_hover_no_result(
1142 #[rustc_builtin_macro]
1143 macro_rules! format {}
1146 format!("hel$0lo {}", 0);
1153 fn test_hover_non_ascii_space_doc() {
1156 /// <- `\u{3000}` here
1159 fn bar() { fo$0o(); }
1180 fn test_hover_function_show_qualifiers() {
1182 r#"async fn foo$0() {}"#,
1196 r#"pub const unsafe fn foo$0() {}"#,
1205 pub const unsafe fn foo()
1209 // Top level `pub(crate)` will be displayed as no visibility.
1211 r#"mod m { pub(crate) async unsafe extern "C" fn foo$0() {} }"#,
1220 pub(crate) async unsafe extern "C" fn foo()
1227 fn test_hover_trait_show_qualifiers() {
1229 r"unsafe trait foo$0() {}",
1246 fn test_hover_extern_crate() {
1249 //- /main.rs crate:main deps:std
1251 //- /std/lib.rs crate:std
1252 //! Standard library for this test
1266 Standard library for this test
1274 //- /main.rs crate:main deps:std
1275 extern crate std as ab$0c;
1276 //- /std/lib.rs crate:std
1277 //! Standard library for this test
1291 Standard library for this test
1300 fn test_hover_mod_with_same_name_as_function() {
1303 use self::m$0y::Bar;
1304 mod my { pub struct Bar; }
1323 fn test_hover_struct_doc_comment() {
1326 /// This is an example
1334 /// assert_eq!(6, my_crate::add_one(5));
1338 fn foo() { let bar = Ba$0r; }
1361 assert_eq!(6, my_crate::add_one(5));
1368 fn test_hover_struct_doc_attr() {
1374 fn foo() { let bar = Ba$0r; }
1395 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1399 #[doc = "bar docs 1"]
1400 #[doc = "bar docs 2"]
1403 fn foo() { let bar = Ba$0r; }
1426 fn test_hover_external_url() {
1430 /// [external](https://www.google.com)
1446 [external](https://www.google.com)
1451 // Check that we don't rewrite links which we can't identify
1453 fn test_hover_unknown_target() {
1479 fn test_hover_no_links() {
1480 check_hover_no_links(
1483 /// case 1. bare URL: https://www.example.com/
1484 /// case 2. inline URL with title: [example](https://www.example.com/)
1485 /// case 3. code reference: [`Result`]
1486 /// case 4. code reference but miss footnote: [`String`]
1487 /// case 5. autolink: <http://www.example.com/>
1488 /// case 6. email address: <test@example.com>
1489 /// case 7. reference: [example][example]
1490 /// case 8. collapsed link: [example][]
1491 /// case 9. shortcut link: [example]
1492 /// case 10. inline without URL: [example]()
1493 /// case 11. reference: [foo][foo]
1494 /// case 12. reference: [foo][bar]
1495 /// case 13. collapsed link: [foo][]
1496 /// case 14. shortcut link: [foo]
1497 /// case 15. inline without URL: [foo]()
1498 /// case 16. just escaped text: \[foo]
1499 /// case 17. inline link: [Foo](foo::Foo)
1501 /// [`Result`]: ../../std/result/enum.Result.html
1502 /// [^example]: https://www.example.com/
1519 case 1. bare URL: https://www.example.com/
1520 case 2. inline URL with title: [example](https://www.example.com/)
1521 case 3. code reference: `Result`
1522 case 4. code reference but miss footnote: `String`
1523 case 5. autolink: http://www.example.com/
1524 case 6. email address: test@example.com
1525 case 7. reference: example
1526 case 8. collapsed link: example
1527 case 9. shortcut link: example
1528 case 10. inline without URL: example
1529 case 11. reference: foo
1530 case 12. reference: foo
1531 case 13. collapsed link: foo
1532 case 14. shortcut link: foo
1533 case 15. inline without URL: foo
1534 case 16. just escaped text: \[foo\]
1535 case 17. inline link: Foo
1537 [^example]: https://www.example.com/
1543 fn test_hover_macro_generated_struct_fn_doc_comment() {
1544 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
1560 fn foo() { let bar = Bar; bar.fo$0o(); }
1581 fn test_hover_macro_generated_struct_fn_doc_attr() {
1582 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
1590 #[doc = "Do the foo"]
1598 fn foo() { let bar = Bar; bar.fo$0o(); }
1619 fn test_hover_trait_has_impl_action() {
1621 r#"trait foo$0() {}"#,
1638 fn test_hover_struct_has_impl_action() {
1640 r"struct foo$0() {}",
1657 fn test_hover_union_has_impl_action() {
1659 r#"union foo$0() {}"#,
1676 fn test_hover_enum_has_impl_action() {
1678 r"enum foo$0() { A, B }",
1695 fn test_hover_self_has_impl_action() {
1697 r#"struct foo where Self$0:;"#,
1714 fn test_hover_test_has_action() {
1732 use_name_in_title: false,
1733 nav: NavigationTarget {
1738 focus_range: 11..19,
1759 fn test_hover_test_mod_has_action() {
1771 use_name_in_title: false,
1772 nav: NavigationTarget {
1780 description: "mod tests",
1794 fn test_hover_struct_has_goto_type_action() {
1799 fn main() { let s$0t = S{ f1:0 }; }
1806 mod_path: "test::S",
1807 nav: NavigationTarget {
1815 description: "struct S",
1826 fn test_hover_generic_struct_has_goto_type_actions() {
1830 struct S<T>{ f1: T }
1832 fn main() { let s$0t = S{ f1:Arg(0) }; }
1839 mod_path: "test::S",
1840 nav: NavigationTarget {
1845 focus_range: 24..25,
1848 description: "struct S<T>",
1852 mod_path: "test::Arg",
1853 nav: NavigationTarget {
1861 description: "struct Arg",
1872 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
1876 struct S<T>{ f1: T }
1878 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
1885 mod_path: "test::S",
1886 nav: NavigationTarget {
1891 focus_range: 24..25,
1894 description: "struct S<T>",
1898 mod_path: "test::Arg",
1899 nav: NavigationTarget {
1907 description: "struct Arg",
1918 fn test_hover_tuple_has_goto_type_actions() {
1927 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
1934 mod_path: "test::A",
1935 nav: NavigationTarget {
1943 description: "struct A",
1947 mod_path: "test::B",
1948 nav: NavigationTarget {
1953 focus_range: 22..23,
1956 description: "struct B",
1960 mod_path: "test::M::C",
1961 nav: NavigationTarget {
1966 focus_range: 53..54,
1969 description: "pub struct C",
1980 fn test_hover_return_impl_trait_has_goto_type_action() {
1984 fn foo() -> impl Foo {}
1986 fn main() { let s$0t = foo(); }
1993 mod_path: "test::Foo",
1994 nav: NavigationTarget {
2002 description: "trait Foo",
2013 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2018 fn foo() -> impl Foo<S> {}
2020 fn main() { let s$0t = foo(); }
2027 mod_path: "test::Foo",
2028 nav: NavigationTarget {
2036 description: "trait Foo<T>",
2040 mod_path: "test::S",
2041 nav: NavigationTarget {
2046 focus_range: 23..24,
2049 description: "struct S",
2060 fn test_hover_return_impl_traits_has_goto_type_action() {
2065 fn foo() -> impl Foo + Bar {}
2067 fn main() { let s$0t = foo(); }
2074 mod_path: "test::Foo",
2075 nav: NavigationTarget {
2083 description: "trait Foo",
2087 mod_path: "test::Bar",
2088 nav: NavigationTarget {
2093 focus_range: 19..22,
2096 description: "trait Bar",
2107 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2115 fn foo() -> impl Foo<S1> + Bar<S2> {}
2117 fn main() { let s$0t = foo(); }
2124 mod_path: "test::Foo",
2125 nav: NavigationTarget {
2133 description: "trait Foo<T>",
2137 mod_path: "test::Bar",
2138 nav: NavigationTarget {
2143 focus_range: 22..25,
2146 description: "trait Bar<T>",
2150 mod_path: "test::S1",
2151 nav: NavigationTarget {
2156 focus_range: 39..41,
2159 description: "struct S1",
2163 mod_path: "test::S2",
2164 nav: NavigationTarget {
2169 focus_range: 52..54,
2172 description: "struct S2",
2183 fn test_hover_arg_impl_trait_has_goto_type_action() {
2187 fn foo(ar$0g: &impl Foo) {}
2194 mod_path: "test::Foo",
2195 nav: NavigationTarget {
2203 description: "trait Foo",
2214 fn test_hover_arg_impl_traits_has_goto_type_action() {
2221 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2228 mod_path: "test::Foo",
2229 nav: NavigationTarget {
2237 description: "trait Foo",
2241 mod_path: "test::Bar",
2242 nav: NavigationTarget {
2247 focus_range: 19..22,
2250 description: "trait Bar<T>",
2254 mod_path: "test::S",
2255 nav: NavigationTarget {
2260 focus_range: 36..37,
2263 description: "struct S",
2274 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2277 //- minicore: future
2280 let fo$0o = async { S };
2288 mod_path: "core::future::Future",
2289 nav: NavigationTarget {
2293 full_range: 276..458,
2294 focus_range: 315..321,
2297 description: "pub trait Future",
2301 mod_path: "test::S",
2302 nav: NavigationTarget {
2310 description: "struct S",
2321 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2326 fn foo(ar$0g: &impl Foo<S>) {}
2333 mod_path: "test::Foo",
2334 nav: NavigationTarget {
2342 description: "trait Foo<T>",
2346 mod_path: "test::S",
2347 nav: NavigationTarget {
2352 focus_range: 23..24,
2355 description: "struct S",
2366 fn test_hover_dyn_return_has_goto_type_action() {
2374 fn foo() -> B<dyn Foo> {}
2376 fn main() { let s$0t = foo(); }
2383 mod_path: "test::B",
2384 nav: NavigationTarget {
2389 focus_range: 49..50,
2392 description: "struct B<T>",
2396 mod_path: "test::Foo",
2397 nav: NavigationTarget {
2405 description: "trait Foo",
2416 fn test_hover_dyn_arg_has_goto_type_action() {
2420 fn foo(ar$0g: &dyn Foo) {}
2427 mod_path: "test::Foo",
2428 nav: NavigationTarget {
2436 description: "trait Foo",
2447 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2452 fn foo(ar$0g: &dyn Foo<S>) {}
2459 mod_path: "test::Foo",
2460 nav: NavigationTarget {
2468 description: "trait Foo<T>",
2472 mod_path: "test::S",
2473 nav: NavigationTarget {
2478 focus_range: 23..24,
2481 description: "struct S",
2492 fn test_hover_goto_type_action_links_order() {
2495 trait ImplTrait<T> {}
2496 trait DynTrait<T> {}
2500 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2507 mod_path: "test::ImplTrait",
2508 nav: NavigationTarget {
2516 description: "trait ImplTrait<T>",
2520 mod_path: "test::B",
2521 nav: NavigationTarget {
2526 focus_range: 50..51,
2529 description: "struct B<T>",
2533 mod_path: "test::DynTrait",
2534 nav: NavigationTarget {
2539 focus_range: 28..36,
2542 description: "trait DynTrait<T>",
2546 mod_path: "test::S",
2547 nav: NavigationTarget {
2552 focus_range: 65..66,
2555 description: "struct S",
2566 fn test_hover_associated_type_has_goto_type_action() {
2571 fn get(self) -> Self::Item {}
2577 impl Foo for S { type Item = Bar; }
2579 fn test() -> impl Foo { S {} }
2581 fn main() { let s$0t = test().get(); }
2588 mod_path: "test::Foo",
2589 nav: NavigationTarget {
2597 description: "trait Foo",
2608 fn test_hover_const_param_has_goto_type_action() {
2612 struct Foo<const BAR: Bar>;
2614 impl<const BAR: Bar> Foo<BAR$0> {}
2621 mod_path: "test::Bar",
2622 nav: NavigationTarget {
2630 description: "struct Bar",
2641 fn test_hover_type_param_has_goto_type_action() {
2646 fn foo<T: Foo>(t: T$0){}
2653 mod_path: "test::Foo",
2654 nav: NavigationTarget {
2662 description: "trait Foo",
2673 fn test_hover_self_has_go_to_type() {
2686 mod_path: "test::Foo",
2687 nav: NavigationTarget {
2695 description: "struct Foo",
2706 fn hover_displays_normalized_crate_names() {
2709 //- /lib.rs crate:name-with-dashes
2711 pub struct Thing { x: u32 }
2714 pub fn new() -> Thing { Thing { x: 0 } }
2718 //- /main.rs crate:main deps:name-with-dashes
2719 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2725 name_with_dashes::wrapper::Thing
2729 pub fn new() -> Thing
2736 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2768 fn hover_self_param_shows_type() {
2787 fn hover_self_param_shows_type_for_arbitrary_self_type() {
2793 fn bar(sel$0f: Arc<Foo>) {}
2807 fn hover_doc_outer_inner() {
2814 /// This comment belongs to the function
2838 fn hover_doc_outer_inner_attribue() {
2841 #[doc = "Be quick;"]
2843 #![doc = "time is mana"]
2845 #[doc = "This comment belongs to the function"]
2869 fn hover_doc_block_style_indentend() {
2903 fn hover_comments_dont_highlight_parent() {
2904 cov_mark::check!(no_highlight_on_comment_hover);
2905 check_hover_no_result(
2933 fn hover_lifetime() {
2935 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
2947 fn hover_type_param() {
2954 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
2978 // lifetimes bounds arent being tracked yet
2983 impl<T: 'static> Foo<T$0> {}
2996 fn hover_type_param_sized_bounds() {
2997 // implicit `: Sized` bound
3003 impl<T: Trait> Foo<T$0> {}
3018 impl<T: Trait + ?Sized> Foo<T$0> {}
3030 mod type_param_sized_bounds {
3034 fn single_implicit() {
3051 fn single_explicit() {
3055 fn foo<T$0: Sized>() {}
3068 fn single_relaxed() {
3072 fn foo<T$0: ?Sized>() {}
3085 fn multiple_implicit() {
3090 fn foo<T$0: Trait>() {}
3103 fn multiple_explicit() {
3108 fn foo<T$0: Trait + Sized>() {}
3121 fn multiple_relaxed() {
3126 fn foo<T$0: Trait + ?Sized>() {}
3143 fn foo<T$0: ?Sized + Sized + Sized>() {}
3157 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3171 fn hover_const_param() {
3174 struct Foo<const LEN: usize>;
3175 impl<const LEN: usize> Foo<LEN$0> {}
3188 fn hover_const_pat() {
3192 const FOO: usize = 3;
3208 const FOO: usize = 3
3219 fn hover_mod_def() {
3246 fn hover_self_in_use() {
3249 //! This should not appear
3251 /// But this should appear
3254 use foo::bar::{self$0};
3269 But this should appear
3275 fn hover_keyword() {
3278 //- /main.rs crate:main deps:std
3279 fn f() { retur$0n; }
3280 //- /libstd.rs crate:std
3281 /// Docs for return_keyword
3282 mod return_keyword {}
3293 Docs for return_keyword
3299 fn hover_builtin() {
3302 //- /main.rs crate:main deps:std
3303 cosnt _: &str$0 = ""; }
3305 //- /libstd.rs crate:std
3306 /// Docs for prim_str
3324 fn hover_macro_expanded_function() {
3327 struct S<'a, T>(&'a T);
3331 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3333 for<'a> T: Clone + 'a
3352 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3356 for<'a> T: Clone + 'a,
3363 fn hover_intra_doc_links() {
3368 /// This is the item. Cool!
3372 /// Gives you a [`TheItem$0`].
3374 /// [`TheItem`]: theitem::TheItem
3375 pub fn gimme() -> theitem::TheItem {
3392 This is the item. Cool!
3398 fn hover_generic_assoc() {
3401 fn foo<T: A>() where T::Assoc$0: {}
3421 let _: <T>::Assoc$0;
3461 fn string_shadowed_with_inner_items() {
3464 //- /main.rs crate:main deps:alloc
3466 /// Custom `String` type.
3475 //- /alloc.rs crate:alloc
3480 /// This is `alloc::String`.
3497 Custom `String` type.
3503 fn function_doesnt_shadow_crate_in_use_tree() {
3506 //- /main.rs crate:main deps:foo
3509 //- /foo.rs crate:foo
3523 fn hover_feature() {
3525 r#"#![feature(box_syntax$0)]"#,
3535 The tracking issue for this feature is: [#49733]
3537 [#49733]: https://github.com/rust-lang/rust/issues/49733
3539 See also [`box_patterns`](box-patterns.md)
3541 ------------------------
3543 Currently the only stable way to create a `Box` is via the `Box::new` method.
3544 Also it is not possible in stable Rust to destructure a `Box` in a match
3545 pattern. The unstable `box` keyword can be used to create a `Box`. An example
3549 #![feature(box_syntax)]
3563 r#"#![allow(arithmetic_overflow$0)]"#,
3565 *arithmetic_overflow*
3571 arithmetic operation overflows
3577 fn hover_clippy_lint() {
3579 r#"#![allow(clippy::almost_swapped$0)]"#,
3583 clippy::almost_swapped
3587 Checks for `foo = bar; bar = foo` sequences.
3593 fn hover_attr_path_qualifier() {
3594 cov_mark::check!(name_ref_classify_attr_path_qualifier);
3597 //- /foo.rs crate:foo
3599 //- /lib.rs crate:main.rs deps:foo
3630 use bar::{self as foo$0};
3673 fn hover_attribute_in_macro() {
3677 macro_rules! identity {
3682 #[rustc_builtin_macro]
3704 fn hover_derive_input() {
3708 #[rustc_builtin_macro]
3729 #[rustc_builtin_macro]
3732 #[derive(foo::Copy$0)]
3750 fn hover_range_math() {
3753 fn f() { let expr = $01 + 2 * 3$0 }
3763 fn f() { let expr = 1 $0+ 2 * $03 }
3773 fn f() { let expr = 1 + $02 * 3$0 }
3783 fn hover_range_arrays() {
3786 fn f() { let expr = $0[1, 2, 3, 4]$0 }
3796 fn f() { let expr = [1, 2, $03, 4]$0 }
3806 fn f() { let expr = [1, 2, $03$0, 4] }
3816 fn hover_range_functions() {
3819 fn f<T>(a: &[T]) { }
3820 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
3830 fn f<T>(a: &[T]) { }
3831 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
3841 fn hover_range_shows_nothing_when_invalid() {
3842 check_hover_range_no_results(
3844 fn f<T>(a: &[T]) { }
3845 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
3849 check_hover_range_no_results(
3851 fn f<T>$0(a: &[T]) { }
3852 fn b() { f(&[1, 2, 3,$0 4, 5]); }
3856 check_hover_range_no_results(
3858 fn $0f() { let expr = [1, 2, 3, 4]$0 }
3864 fn hover_range_shows_unit_for_statements() {
3867 fn f<T>(a: &[T]) { }
3868 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
3878 fn f() { let expr$0 = $0[1, 2, 3, 4] }
3888 fn hover_range_for_pat() {
3915 fn hover_range_shows_coercions_if_applicable_expr() {
3919 let x: &u32 = $0&&&&&0$0;
3932 let x: *const u32 = $0&0$0;
3938 Coerced to: *const u32
3945 fn hover_range_shows_type_actions() {
3950 let x: &Foo = $0&&&&&Foo$0;
3958 mod_path: "test::Foo",
3959 nav: NavigationTarget {
3967 description: "struct Foo",
3978 fn hover_try_expr_res() {
3984 fn foo() -> Result<(), FooError> {
3985 Ok($0Result::<(), FooError>::Ok(())?$0)
3999 fn foo() -> Result<(), FooError> {
4000 Ok($0Result::<(), BarError>::Ok(())?$0)
4005 Try Error Type: BarError
4006 Propagated as: FooError
4013 fn hover_try_expr() {
4016 struct NotResult<T, U>(T, U);
4020 fn foo() -> NotResult<(), Looooong> {
4021 $0NotResult((), Short)?$0;
4026 Try Target Type: NotResult<(), Short>
4027 Propagated as: NotResult<(), Looooong>
4033 struct NotResult<T, U>(T, U);
4037 fn foo() -> NotResult<(), Short> {
4038 $0NotResult((), Looooong)?$0;
4043 Try Target Type: NotResult<(), Looooong>
4044 Propagated as: NotResult<(), Short>
4051 fn hover_try_expr_option() {
4052 cov_mark::check!(hover_try_expr_opt_opt);
4055 //- minicore: option, try
4057 fn foo() -> Option<()> {
4064 <Option<i32> as Try>::Output
4070 fn hover_deref_expr() {
4074 use core::ops::Deref;
4076 struct DerefExample<T> {
4080 impl<T> Deref for DerefExample<T> {
4083 fn deref(&self) -> &Self::Target {
4089 let x = DerefExample { value: 0 };
4090 let y: i32 = $0*x$0;
4095 Dereferenced from: DerefExample<i32>
4103 fn hover_deref_expr_with_coercion() {
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>
4137 fn hover_intra_in_macro() {
4140 macro_rules! foo_macro {
4141 ($(#[$attr:meta])* $name:ident) => {
4148 /// Doc comment for [`Foo$0`]
4165 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4171 fn hover_intra_in_attr() {
4174 #[doc = "Doc comment for [`Foo$0`]"]
4190 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)