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;"#,
555 const foo: u32 = 123 (0x7B)
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 pub struct Thing { x: u32 }
829 pub fn new() -> Thing { Thing { x: 0 } }
833 fn main() { let foo_test = wrapper::Thing::new$0(); }
843 pub fn new() -> Thing
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 //- /main.rs crate:main deps:core
2365 // we don't use minicore here so that this test doesn't randomly fail
2366 // when someone edits minicore
2369 let fo$0o = async { S };
2371 //- /core.rs crate:core
2373 #[lang = "future_trait"]
2382 mod_path: "core::future::Future",
2383 nav: NavigationTarget {
2388 focus_range: 60..66,
2391 description: "pub trait Future",
2395 mod_path: "main::S",
2396 nav: NavigationTarget {
2401 focus_range: 108..109,
2404 description: "struct S",
2415 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2420 fn foo(ar$0g: &impl Foo<S>) {}
2427 mod_path: "test::Foo",
2428 nav: NavigationTarget {
2436 description: "trait Foo<T>",
2440 mod_path: "test::S",
2441 nav: NavigationTarget {
2446 focus_range: 23..24,
2449 description: "struct S",
2460 fn test_hover_dyn_return_has_goto_type_action() {
2468 fn foo() -> B<dyn Foo> {}
2470 fn main() { let s$0t = foo(); }
2477 mod_path: "test::B",
2478 nav: NavigationTarget {
2483 focus_range: 49..50,
2486 description: "struct B<T>",
2490 mod_path: "test::Foo",
2491 nav: NavigationTarget {
2499 description: "trait Foo",
2510 fn test_hover_dyn_arg_has_goto_type_action() {
2514 fn foo(ar$0g: &dyn Foo) {}
2521 mod_path: "test::Foo",
2522 nav: NavigationTarget {
2530 description: "trait Foo",
2541 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2546 fn foo(ar$0g: &dyn Foo<S>) {}
2553 mod_path: "test::Foo",
2554 nav: NavigationTarget {
2562 description: "trait Foo<T>",
2566 mod_path: "test::S",
2567 nav: NavigationTarget {
2572 focus_range: 23..24,
2575 description: "struct S",
2586 fn test_hover_goto_type_action_links_order() {
2589 trait ImplTrait<T> {}
2590 trait DynTrait<T> {}
2594 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2601 mod_path: "test::ImplTrait",
2602 nav: NavigationTarget {
2610 description: "trait ImplTrait<T>",
2614 mod_path: "test::B",
2615 nav: NavigationTarget {
2620 focus_range: 50..51,
2623 description: "struct B<T>",
2627 mod_path: "test::DynTrait",
2628 nav: NavigationTarget {
2633 focus_range: 28..36,
2636 description: "trait DynTrait<T>",
2640 mod_path: "test::S",
2641 nav: NavigationTarget {
2646 focus_range: 65..66,
2649 description: "struct S",
2660 fn test_hover_associated_type_has_goto_type_action() {
2665 fn get(self) -> Self::Item {}
2671 impl Foo for S { type Item = Bar; }
2673 fn test() -> impl Foo { S {} }
2675 fn main() { let s$0t = test().get(); }
2682 mod_path: "test::Foo",
2683 nav: NavigationTarget {
2691 description: "trait Foo",
2702 fn test_hover_const_param_has_goto_type_action() {
2706 struct Foo<const BAR: Bar>;
2708 impl<const BAR: Bar> Foo<BAR$0> {}
2715 mod_path: "test::Bar",
2716 nav: NavigationTarget {
2724 description: "struct Bar",
2735 fn test_hover_type_param_has_goto_type_action() {
2740 fn foo<T: Foo>(t: T$0){}
2747 mod_path: "test::Foo",
2748 nav: NavigationTarget {
2756 description: "trait Foo",
2767 fn test_hover_self_has_go_to_type() {
2780 mod_path: "test::Foo",
2781 nav: NavigationTarget {
2789 description: "struct Foo",
2800 fn hover_displays_normalized_crate_names() {
2803 //- /lib.rs crate:name-with-dashes
2805 pub struct Thing { x: u32 }
2808 pub fn new() -> Thing { Thing { x: 0 } }
2812 //- /main.rs crate:main deps:name-with-dashes
2813 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2819 name_with_dashes::wrapper::Thing
2823 pub fn new() -> Thing
2830 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2862 fn hover_self_param_shows_type() {
2881 fn hover_self_param_shows_type_for_arbitrary_self_type() {
2887 fn bar(sel$0f: Arc<Foo>) {}
2901 fn hover_doc_outer_inner() {
2908 /// This comment belongs to the function
2932 fn hover_doc_outer_inner_attribue() {
2935 #[doc = "Be quick;"]
2937 #![doc = "time is mana"]
2939 #[doc = "This comment belongs to the function"]
2963 fn hover_doc_block_style_indentend() {
2997 fn hover_comments_dont_highlight_parent() {
2998 cov_mark::check!(no_highlight_on_comment_hover);
2999 check_hover_no_result(
3027 fn hover_lifetime() {
3029 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3041 fn hover_type_param() {
3048 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
3072 // lifetimes bounds arent being tracked yet
3077 impl<T: 'static> Foo<T$0> {}
3090 fn hover_type_param_sized_bounds() {
3091 // implicit `: Sized` bound
3097 impl<T: Trait> Foo<T$0> {}
3112 impl<T: Trait + ?Sized> Foo<T$0> {}
3124 mod type_param_sized_bounds {
3128 fn single_implicit() {
3145 fn single_explicit() {
3149 fn foo<T$0: Sized>() {}
3162 fn single_relaxed() {
3166 fn foo<T$0: ?Sized>() {}
3179 fn multiple_implicit() {
3184 fn foo<T$0: Trait>() {}
3197 fn multiple_explicit() {
3202 fn foo<T$0: Trait + Sized>() {}
3215 fn multiple_relaxed() {
3220 fn foo<T$0: Trait + ?Sized>() {}
3237 fn foo<T$0: ?Sized + Sized + Sized>() {}
3251 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3265 fn hover_const_param() {
3268 struct Foo<const LEN: usize>;
3269 impl<const LEN: usize> Foo<LEN$0> {}
3282 fn hover_const_eval() {
3286 const FOO$0: usize = !0 & !(!0 >> 1);
3296 const FOO: usize = 9223372036854775808 (0x8000000000000000)
3307 const FOO$0: usize = {
3321 const FOO: usize = 25 (0x19)
3332 const FOO$0: usize = 1 << 10;
3342 const FOO: usize = 1024 (0x400)
3353 const FOO$0: usize = {
3355 let a = { let b = 2; let a = b; a } + { let a = 1; a + b };
3367 const FOO: usize = 7
3378 const FOO$0: usize = 2 - 3;
3388 const FOO: usize = 2 - 3
3399 const FOO$0: i32 = 2 - 3;
3420 const FOO$0: usize = 1 << 100;
3430 const FOO: usize = 1 << 100
3441 fn hover_const_pat() {
3445 const FOO: usize = 3;
3461 const FOO: usize = 3
3472 fn array_repeat_exp() {
3476 let til$0e4 = [0_u32; (4 * 8 * 8) / 32];
3490 fn hover_mod_def() {
3517 fn hover_self_in_use() {
3520 //! This should not appear
3522 /// But this should appear
3525 use foo::bar::{self$0};
3540 But this should appear
3546 fn hover_keyword() {
3549 //- /main.rs crate:main deps:std
3550 fn f() { retur$0n; }
3551 //- /libstd.rs crate:std
3552 /// Docs for return_keyword
3553 mod return_keyword {}
3564 Docs for return_keyword
3570 fn hover_keyword_as_primitive() {
3573 //- /main.rs crate:main deps:std
3574 type F = f$0n(i32) -> i32;
3575 //- /libstd.rs crate:std
3576 /// Docs for prim_fn
3594 fn hover_builtin() {
3597 //- /main.rs crate:main deps:std
3598 cosnt _: &str$0 = ""; }
3600 //- /libstd.rs crate:std
3601 /// Docs for prim_str
3619 fn hover_macro_expanded_function() {
3622 struct S<'a, T>(&'a T);
3626 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3628 for<'a> T: Clone + 'a
3647 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3651 for<'a> T: Clone + 'a,
3658 fn hover_intra_doc_links() {
3663 /// This is the item. Cool!
3667 /// Gives you a [`TheItem$0`].
3669 /// [`TheItem`]: theitem::TheItem
3670 pub fn gimme() -> theitem::TheItem {
3687 This is the item. Cool!
3693 fn hover_generic_assoc() {
3696 fn foo<T: A>() where T::Assoc$0: {}
3716 let _: <T>::Assoc$0;
3756 fn string_shadowed_with_inner_items() {
3759 //- /main.rs crate:main deps:alloc
3761 /// Custom `String` type.
3770 //- /alloc.rs crate:alloc
3775 /// This is `alloc::String`.
3792 Custom `String` type.
3798 fn function_doesnt_shadow_crate_in_use_tree() {
3801 //- /main.rs crate:main deps:foo
3804 //- /foo.rs crate:foo
3818 fn hover_feature() {
3820 r#"#![feature(box_syntax$0)]"#,
3830 The tracking issue for this feature is: [#49733]
3832 [#49733]: https://github.com/rust-lang/rust/issues/49733
3834 See also [`box_patterns`](box-patterns.md)
3836 ------------------------
3838 Currently the only stable way to create a `Box` is via the `Box::new` method.
3839 Also it is not possible in stable Rust to destructure a `Box` in a match
3840 pattern. The unstable `box` keyword can be used to create a `Box`. An example
3844 #![feature(box_syntax)]
3858 r#"#![allow(arithmetic_overflow$0)]"#,
3860 *arithmetic_overflow*
3866 arithmetic operation overflows
3872 fn hover_clippy_lint() {
3874 r#"#![allow(clippy::almost_swapped$0)]"#,
3878 clippy::almost_swapped
3882 Checks for `foo = bar; bar = foo` sequences.
3888 fn hover_attr_path_qualifier() {
3891 //- /foo.rs crate:foo
3893 //- /lib.rs crate:main.rs deps:foo
3924 use bar::{self as foo$0};
3967 fn hover_attribute_in_macro() {
3971 macro_rules! identity {
3976 #[rustc_builtin_macro]
3998 fn hover_derive_input() {
4002 #[rustc_builtin_macro]
4023 #[rustc_builtin_macro]
4026 #[derive(foo::Copy$0)]
4044 fn hover_range_math() {
4047 fn f() { let expr = $01 + 2 * 3$0 }
4057 fn f() { let expr = 1 $0+ 2 * $03 }
4067 fn f() { let expr = 1 + $02 * 3$0 }
4077 fn hover_range_arrays() {
4080 fn f() { let expr = $0[1, 2, 3, 4]$0 }
4090 fn f() { let expr = [1, 2, $03, 4]$0 }
4100 fn f() { let expr = [1, 2, $03$0, 4] }
4110 fn hover_range_functions() {
4113 fn f<T>(a: &[T]) { }
4114 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
4124 fn f<T>(a: &[T]) { }
4125 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
4135 fn hover_range_shows_nothing_when_invalid() {
4136 check_hover_range_no_results(
4138 fn f<T>(a: &[T]) { }
4139 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
4143 check_hover_range_no_results(
4145 fn f<T>$0(a: &[T]) { }
4146 fn b() { f(&[1, 2, 3,$0 4, 5]); }
4150 check_hover_range_no_results(
4152 fn $0f() { let expr = [1, 2, 3, 4]$0 }
4158 fn hover_range_shows_unit_for_statements() {
4161 fn f<T>(a: &[T]) { }
4162 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
4172 fn f() { let expr$0 = $0[1, 2, 3, 4] }
4182 fn hover_range_for_pat() {
4209 fn hover_range_shows_coercions_if_applicable_expr() {
4213 let x: &u32 = $0&&&&&0$0;
4226 let x: *const u32 = $0&0$0;
4232 Coerced to: *const u32
4239 fn hover_range_shows_type_actions() {
4244 let x: &Foo = $0&&&&&Foo$0;
4252 mod_path: "test::Foo",
4253 nav: NavigationTarget {
4261 description: "struct Foo",
4272 fn hover_try_expr_res() {
4278 fn foo() -> Result<(), FooError> {
4279 Ok($0Result::<(), FooError>::Ok(())?$0)
4293 fn foo() -> Result<(), FooError> {
4294 Ok($0Result::<(), BarError>::Ok(())?$0)
4299 Try Error Type: BarError
4300 Propagated as: FooError
4307 fn hover_try_expr() {
4310 struct NotResult<T, U>(T, U);
4314 fn foo() -> NotResult<(), Looooong> {
4315 $0NotResult((), Short)?$0;
4320 Try Target Type: NotResult<(), Short>
4321 Propagated as: NotResult<(), Looooong>
4327 struct NotResult<T, U>(T, U);
4331 fn foo() -> NotResult<(), Short> {
4332 $0NotResult((), Looooong)?$0;
4337 Try Target Type: NotResult<(), Looooong>
4338 Propagated as: NotResult<(), Short>
4345 fn hover_try_expr_option() {
4346 cov_mark::check!(hover_try_expr_opt_opt);
4349 //- minicore: option, try
4351 fn foo() -> Option<()> {
4358 <Option<i32> as Try>::Output
4364 fn hover_deref_expr() {
4368 use core::ops::Deref;
4370 struct DerefExample<T> {
4374 impl<T> Deref for DerefExample<T> {
4377 fn deref(&self) -> &Self::Target {
4383 let x = DerefExample { value: 0 };
4384 let y: i32 = $0*x$0;
4389 Dereferenced from: DerefExample<i32>
4397 fn hover_deref_expr_with_coercion() {
4401 use core::ops::Deref;
4403 struct DerefExample<T> {
4407 impl<T> Deref for DerefExample<T> {
4410 fn deref(&self) -> &Self::Target {
4416 let x = DerefExample { value: &&&&&0 };
4417 let y: &i32 = $0*x$0;
4422 Dereferenced from: DerefExample<&&&&&i32>
4431 fn hover_intra_in_macro() {
4434 macro_rules! foo_macro {
4435 ($(#[$attr:meta])* $name:ident) => {
4442 /// Doc comment for [`Foo$0`]
4459 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4465 fn hover_intra_in_attr() {
4468 #[doc = "Doc comment for [`Foo$0`]"]
4484 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4490 fn hover_inert_attr() {
4507 * \#\[doc(hidden|inline|...)\]
4508 * \#\[doc = string\]
4527 * \#\[allow(lint1, lint2, ..., /\*opt\*/ reason = "...")\]