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,
1762 fn test_hover_test_mod_has_action() {
1774 use_name_in_title: false,
1775 nav: NavigationTarget {
1783 description: "mod tests",
1797 fn test_hover_struct_has_goto_type_action() {
1802 fn main() { let s$0t = S{ f1:0 }; }
1809 mod_path: "test::S",
1810 nav: NavigationTarget {
1818 description: "struct S",
1829 fn test_hover_generic_struct_has_goto_type_actions() {
1833 struct S<T>{ f1: T }
1835 fn main() { let s$0t = S{ f1:Arg(0) }; }
1842 mod_path: "test::S",
1843 nav: NavigationTarget {
1848 focus_range: 24..25,
1851 description: "struct S<T>",
1855 mod_path: "test::Arg",
1856 nav: NavigationTarget {
1864 description: "struct Arg",
1875 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
1879 struct S<T>{ f1: T }
1881 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
1888 mod_path: "test::S",
1889 nav: NavigationTarget {
1894 focus_range: 24..25,
1897 description: "struct S<T>",
1901 mod_path: "test::Arg",
1902 nav: NavigationTarget {
1910 description: "struct Arg",
1921 fn test_hover_tuple_has_goto_type_actions() {
1930 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
1937 mod_path: "test::A",
1938 nav: NavigationTarget {
1946 description: "struct A",
1950 mod_path: "test::B",
1951 nav: NavigationTarget {
1956 focus_range: 22..23,
1959 description: "struct B",
1963 mod_path: "test::M::C",
1964 nav: NavigationTarget {
1969 focus_range: 53..54,
1972 description: "pub struct C",
1983 fn test_hover_return_impl_trait_has_goto_type_action() {
1987 fn foo() -> impl Foo {}
1989 fn main() { let s$0t = foo(); }
1996 mod_path: "test::Foo",
1997 nav: NavigationTarget {
2005 description: "trait Foo",
2016 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2021 fn foo() -> impl Foo<S> {}
2023 fn main() { let s$0t = foo(); }
2030 mod_path: "test::Foo",
2031 nav: NavigationTarget {
2039 description: "trait Foo<T>",
2043 mod_path: "test::S",
2044 nav: NavigationTarget {
2049 focus_range: 23..24,
2052 description: "struct S",
2063 fn test_hover_return_impl_traits_has_goto_type_action() {
2068 fn foo() -> impl Foo + Bar {}
2070 fn main() { let s$0t = foo(); }
2077 mod_path: "test::Foo",
2078 nav: NavigationTarget {
2086 description: "trait Foo",
2090 mod_path: "test::Bar",
2091 nav: NavigationTarget {
2096 focus_range: 19..22,
2099 description: "trait Bar",
2110 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2118 fn foo() -> impl Foo<S1> + Bar<S2> {}
2120 fn main() { let s$0t = foo(); }
2127 mod_path: "test::Foo",
2128 nav: NavigationTarget {
2136 description: "trait Foo<T>",
2140 mod_path: "test::Bar",
2141 nav: NavigationTarget {
2146 focus_range: 22..25,
2149 description: "trait Bar<T>",
2153 mod_path: "test::S1",
2154 nav: NavigationTarget {
2159 focus_range: 39..41,
2162 description: "struct S1",
2166 mod_path: "test::S2",
2167 nav: NavigationTarget {
2172 focus_range: 52..54,
2175 description: "struct S2",
2186 fn test_hover_arg_impl_trait_has_goto_type_action() {
2190 fn foo(ar$0g: &impl Foo) {}
2197 mod_path: "test::Foo",
2198 nav: NavigationTarget {
2206 description: "trait Foo",
2217 fn test_hover_arg_impl_traits_has_goto_type_action() {
2224 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2231 mod_path: "test::Foo",
2232 nav: NavigationTarget {
2240 description: "trait Foo",
2244 mod_path: "test::Bar",
2245 nav: NavigationTarget {
2250 focus_range: 19..22,
2253 description: "trait Bar<T>",
2257 mod_path: "test::S",
2258 nav: NavigationTarget {
2263 focus_range: 36..37,
2266 description: "struct S",
2277 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2280 //- minicore: future
2283 let fo$0o = async { S };
2291 mod_path: "core::future::Future",
2292 nav: NavigationTarget {
2296 full_range: 276..458,
2297 focus_range: 315..321,
2300 description: "pub trait Future",
2304 mod_path: "test::S",
2305 nav: NavigationTarget {
2313 description: "struct S",
2324 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2329 fn foo(ar$0g: &impl Foo<S>) {}
2336 mod_path: "test::Foo",
2337 nav: NavigationTarget {
2345 description: "trait Foo<T>",
2349 mod_path: "test::S",
2350 nav: NavigationTarget {
2355 focus_range: 23..24,
2358 description: "struct S",
2369 fn test_hover_dyn_return_has_goto_type_action() {
2377 fn foo() -> B<dyn Foo> {}
2379 fn main() { let s$0t = foo(); }
2386 mod_path: "test::B",
2387 nav: NavigationTarget {
2392 focus_range: 49..50,
2395 description: "struct B<T>",
2399 mod_path: "test::Foo",
2400 nav: NavigationTarget {
2408 description: "trait Foo",
2419 fn test_hover_dyn_arg_has_goto_type_action() {
2423 fn foo(ar$0g: &dyn Foo) {}
2430 mod_path: "test::Foo",
2431 nav: NavigationTarget {
2439 description: "trait Foo",
2450 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2455 fn foo(ar$0g: &dyn Foo<S>) {}
2462 mod_path: "test::Foo",
2463 nav: NavigationTarget {
2471 description: "trait Foo<T>",
2475 mod_path: "test::S",
2476 nav: NavigationTarget {
2481 focus_range: 23..24,
2484 description: "struct S",
2495 fn test_hover_goto_type_action_links_order() {
2498 trait ImplTrait<T> {}
2499 trait DynTrait<T> {}
2503 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2510 mod_path: "test::ImplTrait",
2511 nav: NavigationTarget {
2519 description: "trait ImplTrait<T>",
2523 mod_path: "test::B",
2524 nav: NavigationTarget {
2529 focus_range: 50..51,
2532 description: "struct B<T>",
2536 mod_path: "test::DynTrait",
2537 nav: NavigationTarget {
2542 focus_range: 28..36,
2545 description: "trait DynTrait<T>",
2549 mod_path: "test::S",
2550 nav: NavigationTarget {
2555 focus_range: 65..66,
2558 description: "struct S",
2569 fn test_hover_associated_type_has_goto_type_action() {
2574 fn get(self) -> Self::Item {}
2580 impl Foo for S { type Item = Bar; }
2582 fn test() -> impl Foo { S {} }
2584 fn main() { let s$0t = test().get(); }
2591 mod_path: "test::Foo",
2592 nav: NavigationTarget {
2600 description: "trait Foo",
2611 fn test_hover_const_param_has_goto_type_action() {
2615 struct Foo<const BAR: Bar>;
2617 impl<const BAR: Bar> Foo<BAR$0> {}
2624 mod_path: "test::Bar",
2625 nav: NavigationTarget {
2633 description: "struct Bar",
2644 fn test_hover_type_param_has_goto_type_action() {
2649 fn foo<T: Foo>(t: T$0){}
2656 mod_path: "test::Foo",
2657 nav: NavigationTarget {
2665 description: "trait Foo",
2676 fn test_hover_self_has_go_to_type() {
2689 mod_path: "test::Foo",
2690 nav: NavigationTarget {
2698 description: "struct Foo",
2709 fn hover_displays_normalized_crate_names() {
2712 //- /lib.rs crate:name-with-dashes
2714 pub struct Thing { x: u32 }
2717 pub fn new() -> Thing { Thing { x: 0 } }
2721 //- /main.rs crate:main deps:name-with-dashes
2722 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2728 name_with_dashes::wrapper::Thing
2732 pub fn new() -> Thing
2739 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2771 fn hover_self_param_shows_type() {
2790 fn hover_self_param_shows_type_for_arbitrary_self_type() {
2796 fn bar(sel$0f: Arc<Foo>) {}
2810 fn hover_doc_outer_inner() {
2817 /// This comment belongs to the function
2841 fn hover_doc_outer_inner_attribue() {
2844 #[doc = "Be quick;"]
2846 #![doc = "time is mana"]
2848 #[doc = "This comment belongs to the function"]
2872 fn hover_doc_block_style_indentend() {
2906 fn hover_comments_dont_highlight_parent() {
2907 cov_mark::check!(no_highlight_on_comment_hover);
2908 check_hover_no_result(
2936 fn hover_lifetime() {
2938 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
2950 fn hover_type_param() {
2957 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
2981 // lifetimes bounds arent being tracked yet
2986 impl<T: 'static> Foo<T$0> {}
2999 fn hover_type_param_sized_bounds() {
3000 // implicit `: Sized` bound
3006 impl<T: Trait> Foo<T$0> {}
3021 impl<T: Trait + ?Sized> Foo<T$0> {}
3033 mod type_param_sized_bounds {
3037 fn single_implicit() {
3054 fn single_explicit() {
3058 fn foo<T$0: Sized>() {}
3071 fn single_relaxed() {
3075 fn foo<T$0: ?Sized>() {}
3088 fn multiple_implicit() {
3093 fn foo<T$0: Trait>() {}
3106 fn multiple_explicit() {
3111 fn foo<T$0: Trait + Sized>() {}
3124 fn multiple_relaxed() {
3129 fn foo<T$0: Trait + ?Sized>() {}
3146 fn foo<T$0: ?Sized + Sized + Sized>() {}
3160 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3174 fn hover_const_param() {
3177 struct Foo<const LEN: usize>;
3178 impl<const LEN: usize> Foo<LEN$0> {}
3191 fn hover_const_pat() {
3195 const FOO: usize = 3;
3211 const FOO: usize = 3
3222 fn hover_mod_def() {
3249 fn hover_self_in_use() {
3252 //! This should not appear
3254 /// But this should appear
3257 use foo::bar::{self$0};
3272 But this should appear
3278 fn hover_keyword() {
3281 //- /main.rs crate:main deps:std
3282 fn f() { retur$0n; }
3283 //- /libstd.rs crate:std
3284 /// Docs for return_keyword
3285 mod return_keyword {}
3296 Docs for return_keyword
3302 fn hover_builtin() {
3305 //- /main.rs crate:main deps:std
3306 cosnt _: &str$0 = ""; }
3308 //- /libstd.rs crate:std
3309 /// Docs for prim_str
3327 fn hover_macro_expanded_function() {
3330 struct S<'a, T>(&'a T);
3334 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3336 for<'a> T: Clone + 'a
3355 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3359 for<'a> T: Clone + 'a,
3366 fn hover_intra_doc_links() {
3371 /// This is the item. Cool!
3375 /// Gives you a [`TheItem$0`].
3377 /// [`TheItem`]: theitem::TheItem
3378 pub fn gimme() -> theitem::TheItem {
3395 This is the item. Cool!
3401 fn hover_generic_assoc() {
3404 fn foo<T: A>() where T::Assoc$0: {}
3424 let _: <T>::Assoc$0;
3464 fn string_shadowed_with_inner_items() {
3467 //- /main.rs crate:main deps:alloc
3469 /// Custom `String` type.
3478 //- /alloc.rs crate:alloc
3483 /// This is `alloc::String`.
3500 Custom `String` type.
3506 fn function_doesnt_shadow_crate_in_use_tree() {
3509 //- /main.rs crate:main deps:foo
3512 //- /foo.rs crate:foo
3526 fn hover_feature() {
3528 r#"#![feature(box_syntax$0)]"#,
3538 The tracking issue for this feature is: [#49733]
3540 [#49733]: https://github.com/rust-lang/rust/issues/49733
3542 See also [`box_patterns`](box-patterns.md)
3544 ------------------------
3546 Currently the only stable way to create a `Box` is via the `Box::new` method.
3547 Also it is not possible in stable Rust to destructure a `Box` in a match
3548 pattern. The unstable `box` keyword can be used to create a `Box`. An example
3552 #![feature(box_syntax)]
3566 r#"#![allow(arithmetic_overflow$0)]"#,
3568 *arithmetic_overflow*
3574 arithmetic operation overflows
3580 fn hover_clippy_lint() {
3582 r#"#![allow(clippy::almost_swapped$0)]"#,
3586 clippy::almost_swapped
3590 Checks for `foo = bar; bar = foo` sequences.
3596 fn hover_attr_path_qualifier() {
3597 cov_mark::check!(name_ref_classify_attr_path_qualifier);
3600 //- /foo.rs crate:foo
3602 //- /lib.rs crate:main.rs deps:foo
3633 use bar::{self as foo$0};
3676 fn hover_attribute_in_macro() {
3680 macro_rules! identity {
3685 #[rustc_builtin_macro]
3707 fn hover_derive_input() {
3711 #[rustc_builtin_macro]
3732 #[rustc_builtin_macro]
3735 #[derive(foo::Copy$0)]
3753 fn hover_range_math() {
3756 fn f() { let expr = $01 + 2 * 3$0 }
3766 fn f() { let expr = 1 $0+ 2 * $03 }
3776 fn f() { let expr = 1 + $02 * 3$0 }
3786 fn hover_range_arrays() {
3789 fn f() { let expr = $0[1, 2, 3, 4]$0 }
3799 fn f() { let expr = [1, 2, $03, 4]$0 }
3809 fn f() { let expr = [1, 2, $03$0, 4] }
3819 fn hover_range_functions() {
3822 fn f<T>(a: &[T]) { }
3823 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
3833 fn f<T>(a: &[T]) { }
3834 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
3844 fn hover_range_shows_nothing_when_invalid() {
3845 check_hover_range_no_results(
3847 fn f<T>(a: &[T]) { }
3848 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
3852 check_hover_range_no_results(
3854 fn f<T>$0(a: &[T]) { }
3855 fn b() { f(&[1, 2, 3,$0 4, 5]); }
3859 check_hover_range_no_results(
3861 fn $0f() { let expr = [1, 2, 3, 4]$0 }
3867 fn hover_range_shows_unit_for_statements() {
3870 fn f<T>(a: &[T]) { }
3871 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
3881 fn f() { let expr$0 = $0[1, 2, 3, 4] }
3891 fn hover_range_for_pat() {
3918 fn hover_range_shows_coercions_if_applicable_expr() {
3922 let x: &u32 = $0&&&&&0$0;
3935 let x: *const u32 = $0&0$0;
3941 Coerced to: *const u32
3948 fn hover_range_shows_type_actions() {
3953 let x: &Foo = $0&&&&&Foo$0;
3961 mod_path: "test::Foo",
3962 nav: NavigationTarget {
3970 description: "struct Foo",
3981 fn hover_try_expr_res() {
3987 fn foo() -> Result<(), FooError> {
3988 Ok($0Result::<(), FooError>::Ok(())?$0)
4002 fn foo() -> Result<(), FooError> {
4003 Ok($0Result::<(), BarError>::Ok(())?$0)
4008 Try Error Type: BarError
4009 Propagated as: FooError
4016 fn hover_try_expr() {
4019 struct NotResult<T, U>(T, U);
4023 fn foo() -> NotResult<(), Looooong> {
4024 $0NotResult((), Short)?$0;
4029 Try Target Type: NotResult<(), Short>
4030 Propagated as: NotResult<(), Looooong>
4036 struct NotResult<T, U>(T, U);
4040 fn foo() -> NotResult<(), Short> {
4041 $0NotResult((), Looooong)?$0;
4046 Try Target Type: NotResult<(), Looooong>
4047 Propagated as: NotResult<(), Short>
4054 fn hover_try_expr_option() {
4055 cov_mark::check!(hover_try_expr_opt_opt);
4058 //- minicore: option, try
4060 fn foo() -> Option<()> {
4067 <Option<i32> as Try>::Output
4073 fn hover_deref_expr() {
4077 use core::ops::Deref;
4079 struct DerefExample<T> {
4083 impl<T> Deref for DerefExample<T> {
4086 fn deref(&self) -> &Self::Target {
4092 let x = DerefExample { value: 0 };
4093 let y: i32 = $0*x$0;
4098 Dereferenced from: DerefExample<i32>
4106 fn hover_deref_expr_with_coercion() {
4110 use core::ops::Deref;
4112 struct DerefExample<T> {
4116 impl<T> Deref for DerefExample<T> {
4119 fn deref(&self) -> &Self::Target {
4125 let x = DerefExample { value: &&&&&0 };
4126 let y: &i32 = $0*x$0;
4131 Dereferenced from: DerefExample<&&&&&i32>
4140 fn hover_intra_in_macro() {
4143 macro_rules! foo_macro {
4144 ($(#[$attr:meta])* $name:ident) => {
4151 /// Doc comment for [`Foo$0`]
4168 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4174 fn hover_intra_in_attr() {
4177 #[doc = "Doc comment for [`Foo$0`]"]
4193 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)