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_function_show_types() {
1316 r#"fn foo$0(a: i32, b:i32) -> i32 { 0 }"#,
1325 fn foo(a: i32, b: i32) -> i32
1332 fn test_hover_function_pointer_show_identifiers() {
1334 r#"type foo$0 = fn(a: i32, b: i32) -> i32;"#,
1343 type foo = fn(a: i32, b: i32) -> i32
1350 fn test_hover_function_pointer_no_identifier() {
1352 r#"type foo$0 = fn(i32, _: i32) -> i32;"#,
1361 type foo = fn(i32, i32) -> i32
1368 fn test_hover_trait_show_qualifiers() {
1370 r"unsafe trait foo$0() {}",
1387 fn test_hover_extern_crate() {
1390 //- /main.rs crate:main deps:std
1392 //- /std/lib.rs crate:std
1393 //! Standard library for this test
1407 Standard library for this test
1415 //- /main.rs crate:main deps:std
1416 extern crate std as ab$0c;
1417 //- /std/lib.rs crate:std
1418 //! Standard library for this test
1432 Standard library for this test
1441 fn test_hover_mod_with_same_name_as_function() {
1444 use self::m$0y::Bar;
1445 mod my { pub struct Bar; }
1464 fn test_hover_struct_doc_comment() {
1467 /// This is an example
1475 /// assert_eq!(6, my_crate::add_one(5));
1479 fn foo() { let bar = Ba$0r; }
1502 assert_eq!(6, my_crate::add_one(5));
1509 fn test_hover_struct_doc_attr() {
1515 fn foo() { let bar = Ba$0r; }
1536 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1540 #[doc = "bar docs 1"]
1541 #[doc = "bar docs 2"]
1544 fn foo() { let bar = Ba$0r; }
1567 fn test_hover_external_url() {
1571 /// [external](https://www.google.com)
1587 [external](https://www.google.com)
1592 // Check that we don't rewrite links which we can't identify
1594 fn test_hover_unknown_target() {
1620 fn test_hover_no_links() {
1621 check_hover_no_links(
1624 /// case 1. bare URL: https://www.example.com/
1625 /// case 2. inline URL with title: [example](https://www.example.com/)
1626 /// case 3. code reference: [`Result`]
1627 /// case 4. code reference but miss footnote: [`String`]
1628 /// case 5. autolink: <http://www.example.com/>
1629 /// case 6. email address: <test@example.com>
1630 /// case 7. reference: [example][example]
1631 /// case 8. collapsed link: [example][]
1632 /// case 9. shortcut link: [example]
1633 /// case 10. inline without URL: [example]()
1634 /// case 11. reference: [foo][foo]
1635 /// case 12. reference: [foo][bar]
1636 /// case 13. collapsed link: [foo][]
1637 /// case 14. shortcut link: [foo]
1638 /// case 15. inline without URL: [foo]()
1639 /// case 16. just escaped text: \[foo]
1640 /// case 17. inline link: [Foo](foo::Foo)
1642 /// [`Result`]: ../../std/result/enum.Result.html
1643 /// [^example]: https://www.example.com/
1660 case 1. bare URL: https://www.example.com/
1661 case 2. inline URL with title: [example](https://www.example.com/)
1662 case 3. code reference: `Result`
1663 case 4. code reference but miss footnote: `String`
1664 case 5. autolink: http://www.example.com/
1665 case 6. email address: test@example.com
1666 case 7. reference: example
1667 case 8. collapsed link: example
1668 case 9. shortcut link: example
1669 case 10. inline without URL: example
1670 case 11. reference: foo
1671 case 12. reference: foo
1672 case 13. collapsed link: foo
1673 case 14. shortcut link: foo
1674 case 15. inline without URL: foo
1675 case 16. just escaped text: \[foo\]
1676 case 17. inline link: Foo
1678 [^example]: https://www.example.com/
1684 fn test_hover_macro_generated_struct_fn_doc_comment() {
1685 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
1701 fn foo() { let bar = Bar; bar.fo$0o(); }
1722 fn test_hover_macro_generated_struct_fn_doc_attr() {
1723 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
1731 #[doc = "Do the foo"]
1739 fn foo() { let bar = Bar; bar.fo$0o(); }
1760 fn test_hover_trait_has_impl_action() {
1762 r#"trait foo$0() {}"#,
1779 fn test_hover_struct_has_impl_action() {
1781 r"struct foo$0() {}",
1798 fn test_hover_union_has_impl_action() {
1800 r#"union foo$0() {}"#,
1817 fn test_hover_enum_has_impl_action() {
1819 r"enum foo$0() { A, B }",
1836 fn test_hover_self_has_impl_action() {
1838 r#"struct foo where Self$0:;"#,
1855 fn test_hover_test_has_action() {
1873 use_name_in_title: false,
1874 nav: NavigationTarget {
1879 focus_range: 11..19,
1900 fn test_hover_test_mod_has_action() {
1912 use_name_in_title: false,
1913 nav: NavigationTarget {
1921 description: "mod tests",
1935 fn test_hover_struct_has_goto_type_action() {
1940 fn main() { let s$0t = S{ f1:0 }; }
1947 mod_path: "test::S",
1948 nav: NavigationTarget {
1956 description: "struct S",
1967 fn test_hover_generic_struct_has_goto_type_actions() {
1971 struct S<T>{ f1: T }
1973 fn main() { let s$0t = S{ f1:Arg(0) }; }
1980 mod_path: "test::S",
1981 nav: NavigationTarget {
1986 focus_range: 24..25,
1989 description: "struct S<T>",
1993 mod_path: "test::Arg",
1994 nav: NavigationTarget {
2002 description: "struct Arg",
2013 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2017 struct S<T>{ f1: T }
2019 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2026 mod_path: "test::S",
2027 nav: NavigationTarget {
2032 focus_range: 24..25,
2035 description: "struct S<T>",
2039 mod_path: "test::Arg",
2040 nav: NavigationTarget {
2048 description: "struct Arg",
2059 fn test_hover_tuple_has_goto_type_actions() {
2068 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2075 mod_path: "test::A",
2076 nav: NavigationTarget {
2084 description: "struct A",
2088 mod_path: "test::B",
2089 nav: NavigationTarget {
2094 focus_range: 22..23,
2097 description: "struct B",
2101 mod_path: "test::M::C",
2102 nav: NavigationTarget {
2107 focus_range: 53..54,
2110 description: "pub struct C",
2121 fn test_hover_return_impl_trait_has_goto_type_action() {
2125 fn foo() -> impl Foo {}
2127 fn main() { let s$0t = foo(); }
2134 mod_path: "test::Foo",
2135 nav: NavigationTarget {
2143 description: "trait Foo",
2154 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2159 fn foo() -> impl Foo<S> {}
2161 fn main() { let s$0t = foo(); }
2168 mod_path: "test::Foo",
2169 nav: NavigationTarget {
2177 description: "trait Foo<T>",
2181 mod_path: "test::S",
2182 nav: NavigationTarget {
2187 focus_range: 23..24,
2190 description: "struct S",
2201 fn test_hover_return_impl_traits_has_goto_type_action() {
2206 fn foo() -> impl Foo + Bar {}
2208 fn main() { let s$0t = foo(); }
2215 mod_path: "test::Foo",
2216 nav: NavigationTarget {
2224 description: "trait Foo",
2228 mod_path: "test::Bar",
2229 nav: NavigationTarget {
2234 focus_range: 19..22,
2237 description: "trait Bar",
2248 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2256 fn foo() -> impl Foo<S1> + Bar<S2> {}
2258 fn main() { let s$0t = foo(); }
2265 mod_path: "test::Foo",
2266 nav: NavigationTarget {
2274 description: "trait Foo<T>",
2278 mod_path: "test::Bar",
2279 nav: NavigationTarget {
2284 focus_range: 22..25,
2287 description: "trait Bar<T>",
2291 mod_path: "test::S1",
2292 nav: NavigationTarget {
2297 focus_range: 39..41,
2300 description: "struct S1",
2304 mod_path: "test::S2",
2305 nav: NavigationTarget {
2310 focus_range: 52..54,
2313 description: "struct S2",
2324 fn test_hover_arg_impl_trait_has_goto_type_action() {
2328 fn foo(ar$0g: &impl Foo) {}
2335 mod_path: "test::Foo",
2336 nav: NavigationTarget {
2344 description: "trait Foo",
2355 fn test_hover_arg_impl_traits_has_goto_type_action() {
2362 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2369 mod_path: "test::Foo",
2370 nav: NavigationTarget {
2378 description: "trait Foo",
2382 mod_path: "test::Bar",
2383 nav: NavigationTarget {
2388 focus_range: 19..22,
2391 description: "trait Bar<T>",
2395 mod_path: "test::S",
2396 nav: NavigationTarget {
2401 focus_range: 36..37,
2404 description: "struct S",
2415 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2418 //- /main.rs crate:main deps:core
2419 // we don't use minicore here so that this test doesn't randomly fail
2420 // when someone edits minicore
2423 let fo$0o = async { S };
2425 //- /core.rs crate:core
2427 #[lang = "future_trait"]
2436 mod_path: "core::future::Future",
2437 nav: NavigationTarget {
2442 focus_range: 60..66,
2445 description: "pub trait Future",
2449 mod_path: "main::S",
2450 nav: NavigationTarget {
2455 focus_range: 108..109,
2458 description: "struct S",
2469 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2474 fn foo(ar$0g: &impl Foo<S>) {}
2481 mod_path: "test::Foo",
2482 nav: NavigationTarget {
2490 description: "trait Foo<T>",
2494 mod_path: "test::S",
2495 nav: NavigationTarget {
2500 focus_range: 23..24,
2503 description: "struct S",
2514 fn test_hover_dyn_return_has_goto_type_action() {
2522 fn foo() -> B<dyn Foo> {}
2524 fn main() { let s$0t = foo(); }
2531 mod_path: "test::B",
2532 nav: NavigationTarget {
2537 focus_range: 49..50,
2540 description: "struct B<T>",
2544 mod_path: "test::Foo",
2545 nav: NavigationTarget {
2553 description: "trait Foo",
2564 fn test_hover_dyn_arg_has_goto_type_action() {
2568 fn foo(ar$0g: &dyn Foo) {}
2575 mod_path: "test::Foo",
2576 nav: NavigationTarget {
2584 description: "trait Foo",
2595 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2600 fn foo(ar$0g: &dyn Foo<S>) {}
2607 mod_path: "test::Foo",
2608 nav: NavigationTarget {
2616 description: "trait Foo<T>",
2620 mod_path: "test::S",
2621 nav: NavigationTarget {
2626 focus_range: 23..24,
2629 description: "struct S",
2640 fn test_hover_goto_type_action_links_order() {
2643 trait ImplTrait<T> {}
2644 trait DynTrait<T> {}
2648 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2655 mod_path: "test::ImplTrait",
2656 nav: NavigationTarget {
2664 description: "trait ImplTrait<T>",
2668 mod_path: "test::B",
2669 nav: NavigationTarget {
2674 focus_range: 50..51,
2677 description: "struct B<T>",
2681 mod_path: "test::DynTrait",
2682 nav: NavigationTarget {
2687 focus_range: 28..36,
2690 description: "trait DynTrait<T>",
2694 mod_path: "test::S",
2695 nav: NavigationTarget {
2700 focus_range: 65..66,
2703 description: "struct S",
2714 fn test_hover_associated_type_has_goto_type_action() {
2719 fn get(self) -> Self::Item {}
2725 impl Foo for S { type Item = Bar; }
2727 fn test() -> impl Foo { S {} }
2729 fn main() { let s$0t = test().get(); }
2736 mod_path: "test::Foo",
2737 nav: NavigationTarget {
2745 description: "trait Foo",
2756 fn test_hover_const_param_has_goto_type_action() {
2760 struct Foo<const BAR: Bar>;
2762 impl<const BAR: Bar> Foo<BAR$0> {}
2769 mod_path: "test::Bar",
2770 nav: NavigationTarget {
2778 description: "struct Bar",
2789 fn test_hover_type_param_has_goto_type_action() {
2794 fn foo<T: Foo>(t: T$0){}
2801 mod_path: "test::Foo",
2802 nav: NavigationTarget {
2810 description: "trait Foo",
2821 fn test_hover_self_has_go_to_type() {
2834 mod_path: "test::Foo",
2835 nav: NavigationTarget {
2843 description: "struct Foo",
2854 fn hover_displays_normalized_crate_names() {
2857 //- /lib.rs crate:name-with-dashes
2859 pub struct Thing { x: u32 }
2862 pub fn new() -> Thing { Thing { x: 0 } }
2866 //- /main.rs crate:main deps:name-with-dashes
2867 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2873 name_with_dashes::wrapper::Thing
2877 pub fn new() -> Thing
2884 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2916 fn hover_self_param_shows_type() {
2935 fn hover_self_param_shows_type_for_arbitrary_self_type() {
2941 fn bar(sel$0f: Arc<Foo>) {}
2955 fn hover_doc_outer_inner() {
2962 /// This comment belongs to the function
2986 fn hover_doc_outer_inner_attribue() {
2989 #[doc = "Be quick;"]
2991 #![doc = "time is mana"]
2993 #[doc = "This comment belongs to the function"]
3017 fn hover_doc_block_style_indentend() {
3051 fn hover_comments_dont_highlight_parent() {
3052 cov_mark::check!(no_highlight_on_comment_hover);
3053 check_hover_no_result(
3081 fn hover_lifetime() {
3083 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3095 fn hover_type_param() {
3102 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
3126 // lifetimes bounds arent being tracked yet
3131 impl<T: 'static> Foo<T$0> {}
3144 fn hover_type_param_sized_bounds() {
3145 // implicit `: Sized` bound
3151 impl<T: Trait> Foo<T$0> {}
3166 impl<T: Trait + ?Sized> Foo<T$0> {}
3178 mod type_param_sized_bounds {
3182 fn single_implicit() {
3199 fn single_explicit() {
3203 fn foo<T$0: Sized>() {}
3216 fn single_relaxed() {
3220 fn foo<T$0: ?Sized>() {}
3233 fn multiple_implicit() {
3238 fn foo<T$0: Trait>() {}
3251 fn multiple_explicit() {
3256 fn foo<T$0: Trait + Sized>() {}
3269 fn multiple_relaxed() {
3274 fn foo<T$0: Trait + ?Sized>() {}
3291 fn foo<T$0: ?Sized + Sized + Sized>() {}
3305 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3319 fn hover_const_param() {
3322 struct Foo<const LEN: usize>;
3323 impl<const LEN: usize> Foo<LEN$0> {}
3336 fn hover_const_eval() {
3340 const FOO$0: usize = !0 & !(!0 >> 1);
3350 const FOO: usize = 9223372036854775808 (0x8000000000000000)
3361 const FOO$0: usize = {
3375 const FOO: usize = 25 (0x19)
3386 const FOO$0: usize = 1 << 10;
3396 const FOO: usize = 1024 (0x400)
3407 const FOO$0: usize = {
3409 let a = { let b = 2; let a = b; a } + { let a = 1; a + b };
3421 const FOO: usize = 7
3432 const FOO$0: usize = 2 - 3;
3442 const FOO: usize = 2 - 3
3453 const FOO$0: i32 = 2 - 3;
3474 const FOO$0: usize = 1 << 100;
3484 const FOO: usize = 1 << 100
3495 fn hover_const_pat() {
3499 const FOO: usize = 3;
3515 const FOO: usize = 3
3526 fn array_repeat_exp() {
3530 let til$0e4 = [0_u32; (4 * 8 * 8) / 32];
3544 fn hover_mod_def() {
3571 fn hover_self_in_use() {
3574 //! This should not appear
3576 /// But this should appear
3579 use foo::bar::{self$0};
3594 But this should appear
3600 fn hover_keyword() {
3603 //- /main.rs crate:main deps:std
3604 fn f() { retur$0n; }
3605 //- /libstd.rs crate:std
3606 /// Docs for return_keyword
3607 mod return_keyword {}
3618 Docs for return_keyword
3624 fn hover_keyword_as_primitive() {
3627 //- /main.rs crate:main deps:std
3628 type F = f$0n(i32) -> i32;
3629 //- /libstd.rs crate:std
3630 /// Docs for prim_fn
3648 fn hover_builtin() {
3651 //- /main.rs crate:main deps:std
3652 cosnt _: &str$0 = ""; }
3654 //- /libstd.rs crate:std
3655 /// Docs for prim_str
3673 fn hover_macro_expanded_function() {
3676 struct S<'a, T>(&'a T);
3680 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3682 for<'a> T: Clone + 'a
3701 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3705 for<'a> T: Clone + 'a,
3712 fn hover_intra_doc_links() {
3717 /// This is the item. Cool!
3721 /// Gives you a [`TheItem$0`].
3723 /// [`TheItem`]: theitem::TheItem
3724 pub fn gimme() -> theitem::TheItem {
3741 This is the item. Cool!
3747 fn hover_generic_assoc() {
3750 fn foo<T: A>() where T::Assoc$0: {}
3770 let _: <T>::Assoc$0;
3810 fn string_shadowed_with_inner_items() {
3813 //- /main.rs crate:main deps:alloc
3815 /// Custom `String` type.
3824 //- /alloc.rs crate:alloc
3829 /// This is `alloc::String`.
3846 Custom `String` type.
3852 fn function_doesnt_shadow_crate_in_use_tree() {
3855 //- /main.rs crate:main deps:foo
3858 //- /foo.rs crate:foo
3872 fn hover_feature() {
3874 r#"#![feature(box_syntax$0)]"#,
3884 The tracking issue for this feature is: [#49733]
3886 [#49733]: https://github.com/rust-lang/rust/issues/49733
3888 See also [`box_patterns`](box-patterns.md)
3890 ------------------------
3892 Currently the only stable way to create a `Box` is via the `Box::new` method.
3893 Also it is not possible in stable Rust to destructure a `Box` in a match
3894 pattern. The unstable `box` keyword can be used to create a `Box`. An example
3898 #![feature(box_syntax)]
3912 r#"#![allow(arithmetic_overflow$0)]"#,
3914 *arithmetic_overflow*
3920 arithmetic operation overflows
3926 fn hover_clippy_lint() {
3928 r#"#![allow(clippy::almost_swapped$0)]"#,
3932 clippy::almost_swapped
3936 Checks for `foo = bar; bar = foo` sequences.
3942 fn hover_attr_path_qualifier() {
3945 //- /foo.rs crate:foo
3947 //- /lib.rs crate:main.rs deps:foo
3978 use bar::{self as foo$0};
4021 fn hover_attribute_in_macro() {
4025 macro_rules! identity {
4030 #[rustc_builtin_macro]
4052 fn hover_derive_input() {
4056 #[rustc_builtin_macro]
4077 #[rustc_builtin_macro]
4080 #[derive(foo::Copy$0)]
4098 fn hover_range_math() {
4101 fn f() { let expr = $01 + 2 * 3$0 }
4111 fn f() { let expr = 1 $0+ 2 * $03 }
4121 fn f() { let expr = 1 + $02 * 3$0 }
4131 fn hover_range_arrays() {
4134 fn f() { let expr = $0[1, 2, 3, 4]$0 }
4144 fn f() { let expr = [1, 2, $03, 4]$0 }
4154 fn f() { let expr = [1, 2, $03$0, 4] }
4164 fn hover_range_functions() {
4167 fn f<T>(a: &[T]) { }
4168 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
4178 fn f<T>(a: &[T]) { }
4179 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
4189 fn hover_range_shows_nothing_when_invalid() {
4190 check_hover_range_no_results(
4192 fn f<T>(a: &[T]) { }
4193 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
4197 check_hover_range_no_results(
4199 fn f<T>$0(a: &[T]) { }
4200 fn b() { f(&[1, 2, 3,$0 4, 5]); }
4204 check_hover_range_no_results(
4206 fn $0f() { let expr = [1, 2, 3, 4]$0 }
4212 fn hover_range_shows_unit_for_statements() {
4215 fn f<T>(a: &[T]) { }
4216 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
4226 fn f() { let expr$0 = $0[1, 2, 3, 4] }
4236 fn hover_range_for_pat() {
4263 fn hover_range_shows_coercions_if_applicable_expr() {
4267 let x: &u32 = $0&&&&&0$0;
4280 let x: *const u32 = $0&0$0;
4286 Coerced to: *const u32
4293 fn hover_range_shows_type_actions() {
4298 let x: &Foo = $0&&&&&Foo$0;
4306 mod_path: "test::Foo",
4307 nav: NavigationTarget {
4315 description: "struct Foo",
4326 fn hover_try_expr_res() {
4332 fn foo() -> Result<(), FooError> {
4333 Ok($0Result::<(), FooError>::Ok(())?$0)
4347 fn foo() -> Result<(), FooError> {
4348 Ok($0Result::<(), BarError>::Ok(())?$0)
4353 Try Error Type: BarError
4354 Propagated as: FooError
4361 fn hover_try_expr() {
4364 struct NotResult<T, U>(T, U);
4368 fn foo() -> NotResult<(), Looooong> {
4369 $0NotResult((), Short)?$0;
4374 Try Target Type: NotResult<(), Short>
4375 Propagated as: NotResult<(), Looooong>
4381 struct NotResult<T, U>(T, U);
4385 fn foo() -> NotResult<(), Short> {
4386 $0NotResult((), Looooong)?$0;
4391 Try Target Type: NotResult<(), Looooong>
4392 Propagated as: NotResult<(), Short>
4399 fn hover_try_expr_option() {
4400 cov_mark::check!(hover_try_expr_opt_opt);
4403 //- minicore: option, try
4405 fn foo() -> Option<()> {
4412 <Option<i32> as Try>::Output
4418 fn hover_deref_expr() {
4422 use core::ops::Deref;
4424 struct DerefExample<T> {
4428 impl<T> Deref for DerefExample<T> {
4431 fn deref(&self) -> &Self::Target {
4437 let x = DerefExample { value: 0 };
4438 let y: i32 = $0*x$0;
4443 Dereferenced from: DerefExample<i32>
4451 fn hover_deref_expr_with_coercion() {
4455 use core::ops::Deref;
4457 struct DerefExample<T> {
4461 impl<T> Deref for DerefExample<T> {
4464 fn deref(&self) -> &Self::Target {
4470 let x = DerefExample { value: &&&&&0 };
4471 let y: &i32 = $0*x$0;
4476 Dereferenced from: DerefExample<&&&&&i32>
4485 fn hover_intra_in_macro() {
4488 macro_rules! foo_macro {
4489 ($(#[$attr:meta])* $name:ident) => {
4496 /// Doc comment for [`Foo$0`]
4513 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4519 fn hover_intra_in_attr() {
4522 #[doc = "Doc comment for [`Foo$0`]"]
4538 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4544 fn hover_inert_attr() {
4561 * \#\[doc(hidden|inline|...)\]
4562 * \#\[doc = string\]
4581 * \#\[allow(lint1, lint2, ..., /\*opt\*/ reason = "...")\]