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_types() {
1334 r#"type foo$0 = fn(a: i32, b: i32) -> i32;"#,
1343 type foo = fn(a: i32, b: i32) -> i32
1350 fn test_hover_trait_show_qualifiers() {
1352 r"unsafe trait foo$0() {}",
1369 fn test_hover_extern_crate() {
1372 //- /main.rs crate:main deps:std
1374 //- /std/lib.rs crate:std
1375 //! Standard library for this test
1389 Standard library for this test
1397 //- /main.rs crate:main deps:std
1398 extern crate std as ab$0c;
1399 //- /std/lib.rs crate:std
1400 //! Standard library for this test
1414 Standard library for this test
1423 fn test_hover_mod_with_same_name_as_function() {
1426 use self::m$0y::Bar;
1427 mod my { pub struct Bar; }
1446 fn test_hover_struct_doc_comment() {
1449 /// This is an example
1457 /// assert_eq!(6, my_crate::add_one(5));
1461 fn foo() { let bar = Ba$0r; }
1484 assert_eq!(6, my_crate::add_one(5));
1491 fn test_hover_struct_doc_attr() {
1497 fn foo() { let bar = Ba$0r; }
1518 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1522 #[doc = "bar docs 1"]
1523 #[doc = "bar docs 2"]
1526 fn foo() { let bar = Ba$0r; }
1549 fn test_hover_external_url() {
1553 /// [external](https://www.google.com)
1569 [external](https://www.google.com)
1574 // Check that we don't rewrite links which we can't identify
1576 fn test_hover_unknown_target() {
1602 fn test_hover_no_links() {
1603 check_hover_no_links(
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][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][foo]
1617 /// case 12. reference: [foo][bar]
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](foo::Foo)
1624 /// [`Result`]: ../../std/result/enum.Result.html
1625 /// [^example]: https://www.example.com/
1642 case 1. bare URL: https://www.example.com/
1643 case 2. inline URL with title: [example](https://www.example.com/)
1644 case 3. code reference: `Result`
1645 case 4. code reference but miss footnote: `String`
1646 case 5. autolink: http://www.example.com/
1647 case 6. email address: test@example.com
1648 case 7. reference: example
1649 case 8. collapsed link: example
1650 case 9. shortcut link: example
1651 case 10. inline without URL: example
1652 case 11. reference: foo
1653 case 12. reference: foo
1654 case 13. collapsed link: foo
1655 case 14. shortcut link: foo
1656 case 15. inline without URL: foo
1657 case 16. just escaped text: \[foo\]
1658 case 17. inline link: Foo
1660 [^example]: https://www.example.com/
1666 fn test_hover_macro_generated_struct_fn_doc_comment() {
1667 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
1683 fn foo() { let bar = Bar; bar.fo$0o(); }
1704 fn test_hover_macro_generated_struct_fn_doc_attr() {
1705 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
1713 #[doc = "Do the foo"]
1721 fn foo() { let bar = Bar; bar.fo$0o(); }
1742 fn test_hover_trait_has_impl_action() {
1744 r#"trait foo$0() {}"#,
1761 fn test_hover_struct_has_impl_action() {
1763 r"struct foo$0() {}",
1780 fn test_hover_union_has_impl_action() {
1782 r#"union foo$0() {}"#,
1799 fn test_hover_enum_has_impl_action() {
1801 r"enum foo$0() { A, B }",
1818 fn test_hover_self_has_impl_action() {
1820 r#"struct foo where Self$0:;"#,
1837 fn test_hover_test_has_action() {
1855 use_name_in_title: false,
1856 nav: NavigationTarget {
1861 focus_range: 11..19,
1882 fn test_hover_test_mod_has_action() {
1894 use_name_in_title: false,
1895 nav: NavigationTarget {
1903 description: "mod tests",
1917 fn test_hover_struct_has_goto_type_action() {
1922 fn main() { let s$0t = S{ f1:0 }; }
1929 mod_path: "test::S",
1930 nav: NavigationTarget {
1938 description: "struct S",
1949 fn test_hover_generic_struct_has_goto_type_actions() {
1953 struct S<T>{ f1: T }
1955 fn main() { let s$0t = S{ f1:Arg(0) }; }
1962 mod_path: "test::S",
1963 nav: NavigationTarget {
1968 focus_range: 24..25,
1971 description: "struct S<T>",
1975 mod_path: "test::Arg",
1976 nav: NavigationTarget {
1984 description: "struct Arg",
1995 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
1999 struct S<T>{ f1: T }
2001 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2008 mod_path: "test::S",
2009 nav: NavigationTarget {
2014 focus_range: 24..25,
2017 description: "struct S<T>",
2021 mod_path: "test::Arg",
2022 nav: NavigationTarget {
2030 description: "struct Arg",
2041 fn test_hover_tuple_has_goto_type_actions() {
2050 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2057 mod_path: "test::A",
2058 nav: NavigationTarget {
2066 description: "struct A",
2070 mod_path: "test::B",
2071 nav: NavigationTarget {
2076 focus_range: 22..23,
2079 description: "struct B",
2083 mod_path: "test::M::C",
2084 nav: NavigationTarget {
2089 focus_range: 53..54,
2092 description: "pub struct C",
2103 fn test_hover_return_impl_trait_has_goto_type_action() {
2107 fn foo() -> impl Foo {}
2109 fn main() { let s$0t = foo(); }
2116 mod_path: "test::Foo",
2117 nav: NavigationTarget {
2125 description: "trait Foo",
2136 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2141 fn foo() -> impl Foo<S> {}
2143 fn main() { let s$0t = foo(); }
2150 mod_path: "test::Foo",
2151 nav: NavigationTarget {
2159 description: "trait Foo<T>",
2163 mod_path: "test::S",
2164 nav: NavigationTarget {
2169 focus_range: 23..24,
2172 description: "struct S",
2183 fn test_hover_return_impl_traits_has_goto_type_action() {
2188 fn foo() -> impl Foo + Bar {}
2190 fn main() { let s$0t = foo(); }
2197 mod_path: "test::Foo",
2198 nav: NavigationTarget {
2206 description: "trait Foo",
2210 mod_path: "test::Bar",
2211 nav: NavigationTarget {
2216 focus_range: 19..22,
2219 description: "trait Bar",
2230 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2238 fn foo() -> impl Foo<S1> + Bar<S2> {}
2240 fn main() { let s$0t = foo(); }
2247 mod_path: "test::Foo",
2248 nav: NavigationTarget {
2256 description: "trait Foo<T>",
2260 mod_path: "test::Bar",
2261 nav: NavigationTarget {
2266 focus_range: 22..25,
2269 description: "trait Bar<T>",
2273 mod_path: "test::S1",
2274 nav: NavigationTarget {
2279 focus_range: 39..41,
2282 description: "struct S1",
2286 mod_path: "test::S2",
2287 nav: NavigationTarget {
2292 focus_range: 52..54,
2295 description: "struct S2",
2306 fn test_hover_arg_impl_trait_has_goto_type_action() {
2310 fn foo(ar$0g: &impl Foo) {}
2317 mod_path: "test::Foo",
2318 nav: NavigationTarget {
2326 description: "trait Foo",
2337 fn test_hover_arg_impl_traits_has_goto_type_action() {
2344 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2351 mod_path: "test::Foo",
2352 nav: NavigationTarget {
2360 description: "trait Foo",
2364 mod_path: "test::Bar",
2365 nav: NavigationTarget {
2370 focus_range: 19..22,
2373 description: "trait Bar<T>",
2377 mod_path: "test::S",
2378 nav: NavigationTarget {
2383 focus_range: 36..37,
2386 description: "struct S",
2397 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2400 //- /main.rs crate:main deps:core
2401 // we don't use minicore here so that this test doesn't randomly fail
2402 // when someone edits minicore
2405 let fo$0o = async { S };
2407 //- /core.rs crate:core
2409 #[lang = "future_trait"]
2418 mod_path: "core::future::Future",
2419 nav: NavigationTarget {
2424 focus_range: 60..66,
2427 description: "pub trait Future",
2431 mod_path: "main::S",
2432 nav: NavigationTarget {
2437 focus_range: 108..109,
2440 description: "struct S",
2451 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2456 fn foo(ar$0g: &impl Foo<S>) {}
2463 mod_path: "test::Foo",
2464 nav: NavigationTarget {
2472 description: "trait Foo<T>",
2476 mod_path: "test::S",
2477 nav: NavigationTarget {
2482 focus_range: 23..24,
2485 description: "struct S",
2496 fn test_hover_dyn_return_has_goto_type_action() {
2504 fn foo() -> B<dyn Foo> {}
2506 fn main() { let s$0t = foo(); }
2513 mod_path: "test::B",
2514 nav: NavigationTarget {
2519 focus_range: 49..50,
2522 description: "struct B<T>",
2526 mod_path: "test::Foo",
2527 nav: NavigationTarget {
2535 description: "trait Foo",
2546 fn test_hover_dyn_arg_has_goto_type_action() {
2550 fn foo(ar$0g: &dyn Foo) {}
2557 mod_path: "test::Foo",
2558 nav: NavigationTarget {
2566 description: "trait Foo",
2577 fn test_hover_generic_dyn_arg_has_goto_type_action() {
2582 fn foo(ar$0g: &dyn Foo<S>) {}
2589 mod_path: "test::Foo",
2590 nav: NavigationTarget {
2598 description: "trait Foo<T>",
2602 mod_path: "test::S",
2603 nav: NavigationTarget {
2608 focus_range: 23..24,
2611 description: "struct S",
2622 fn test_hover_goto_type_action_links_order() {
2625 trait ImplTrait<T> {}
2626 trait DynTrait<T> {}
2630 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
2637 mod_path: "test::ImplTrait",
2638 nav: NavigationTarget {
2646 description: "trait ImplTrait<T>",
2650 mod_path: "test::B",
2651 nav: NavigationTarget {
2656 focus_range: 50..51,
2659 description: "struct B<T>",
2663 mod_path: "test::DynTrait",
2664 nav: NavigationTarget {
2669 focus_range: 28..36,
2672 description: "trait DynTrait<T>",
2676 mod_path: "test::S",
2677 nav: NavigationTarget {
2682 focus_range: 65..66,
2685 description: "struct S",
2696 fn test_hover_associated_type_has_goto_type_action() {
2701 fn get(self) -> Self::Item {}
2707 impl Foo for S { type Item = Bar; }
2709 fn test() -> impl Foo { S {} }
2711 fn main() { let s$0t = test().get(); }
2718 mod_path: "test::Foo",
2719 nav: NavigationTarget {
2727 description: "trait Foo",
2738 fn test_hover_const_param_has_goto_type_action() {
2742 struct Foo<const BAR: Bar>;
2744 impl<const BAR: Bar> Foo<BAR$0> {}
2751 mod_path: "test::Bar",
2752 nav: NavigationTarget {
2760 description: "struct Bar",
2771 fn test_hover_type_param_has_goto_type_action() {
2776 fn foo<T: Foo>(t: T$0){}
2783 mod_path: "test::Foo",
2784 nav: NavigationTarget {
2792 description: "trait Foo",
2803 fn test_hover_self_has_go_to_type() {
2816 mod_path: "test::Foo",
2817 nav: NavigationTarget {
2825 description: "struct Foo",
2836 fn hover_displays_normalized_crate_names() {
2839 //- /lib.rs crate:name-with-dashes
2841 pub struct Thing { x: u32 }
2844 pub fn new() -> Thing { Thing { x: 0 } }
2848 //- /main.rs crate:main deps:name-with-dashes
2849 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
2855 name_with_dashes::wrapper::Thing
2859 pub fn new() -> Thing
2866 fn hover_field_pat_shorthand_ref_match_ergonomics() {
2898 fn hover_self_param_shows_type() {
2917 fn hover_self_param_shows_type_for_arbitrary_self_type() {
2923 fn bar(sel$0f: Arc<Foo>) {}
2937 fn hover_doc_outer_inner() {
2944 /// This comment belongs to the function
2968 fn hover_doc_outer_inner_attribue() {
2971 #[doc = "Be quick;"]
2973 #![doc = "time is mana"]
2975 #[doc = "This comment belongs to the function"]
2999 fn hover_doc_block_style_indentend() {
3033 fn hover_comments_dont_highlight_parent() {
3034 cov_mark::check!(no_highlight_on_comment_hover);
3035 check_hover_no_result(
3063 fn hover_lifetime() {
3065 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3077 fn hover_type_param() {
3084 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
3108 // lifetimes bounds arent being tracked yet
3113 impl<T: 'static> Foo<T$0> {}
3126 fn hover_type_param_sized_bounds() {
3127 // implicit `: Sized` bound
3133 impl<T: Trait> Foo<T$0> {}
3148 impl<T: Trait + ?Sized> Foo<T$0> {}
3160 mod type_param_sized_bounds {
3164 fn single_implicit() {
3181 fn single_explicit() {
3185 fn foo<T$0: Sized>() {}
3198 fn single_relaxed() {
3202 fn foo<T$0: ?Sized>() {}
3215 fn multiple_implicit() {
3220 fn foo<T$0: Trait>() {}
3233 fn multiple_explicit() {
3238 fn foo<T$0: Trait + Sized>() {}
3251 fn multiple_relaxed() {
3256 fn foo<T$0: Trait + ?Sized>() {}
3273 fn foo<T$0: ?Sized + Sized + Sized>() {}
3287 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3301 fn hover_const_param() {
3304 struct Foo<const LEN: usize>;
3305 impl<const LEN: usize> Foo<LEN$0> {}
3318 fn hover_const_eval() {
3322 const FOO$0: usize = !0 & !(!0 >> 1);
3332 const FOO: usize = 9223372036854775808 (0x8000000000000000)
3343 const FOO$0: usize = {
3357 const FOO: usize = 25 (0x19)
3368 const FOO$0: usize = 1 << 10;
3378 const FOO: usize = 1024 (0x400)
3389 const FOO$0: usize = {
3391 let a = { let b = 2; let a = b; a } + { let a = 1; a + b };
3403 const FOO: usize = 7
3414 const FOO$0: usize = 2 - 3;
3424 const FOO: usize = 2 - 3
3435 const FOO$0: i32 = 2 - 3;
3456 const FOO$0: usize = 1 << 100;
3466 const FOO: usize = 1 << 100
3477 fn hover_const_pat() {
3481 const FOO: usize = 3;
3497 const FOO: usize = 3
3508 fn array_repeat_exp() {
3512 let til$0e4 = [0_u32; (4 * 8 * 8) / 32];
3526 fn hover_mod_def() {
3553 fn hover_self_in_use() {
3556 //! This should not appear
3558 /// But this should appear
3561 use foo::bar::{self$0};
3576 But this should appear
3582 fn hover_keyword() {
3585 //- /main.rs crate:main deps:std
3586 fn f() { retur$0n; }
3587 //- /libstd.rs crate:std
3588 /// Docs for return_keyword
3589 mod return_keyword {}
3600 Docs for return_keyword
3606 fn hover_keyword_as_primitive() {
3609 //- /main.rs crate:main deps:std
3610 type F = f$0n(i32) -> i32;
3611 //- /libstd.rs crate:std
3612 /// Docs for prim_fn
3630 fn hover_builtin() {
3633 //- /main.rs crate:main deps:std
3634 cosnt _: &str$0 = ""; }
3636 //- /libstd.rs crate:std
3637 /// Docs for prim_str
3655 fn hover_macro_expanded_function() {
3658 struct S<'a, T>(&'a T);
3662 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3664 for<'a> T: Clone + 'a
3683 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3687 for<'a> T: Clone + 'a,
3694 fn hover_intra_doc_links() {
3699 /// This is the item. Cool!
3703 /// Gives you a [`TheItem$0`].
3705 /// [`TheItem`]: theitem::TheItem
3706 pub fn gimme() -> theitem::TheItem {
3723 This is the item. Cool!
3729 fn hover_generic_assoc() {
3732 fn foo<T: A>() where T::Assoc$0: {}
3752 let _: <T>::Assoc$0;
3792 fn string_shadowed_with_inner_items() {
3795 //- /main.rs crate:main deps:alloc
3797 /// Custom `String` type.
3806 //- /alloc.rs crate:alloc
3811 /// This is `alloc::String`.
3828 Custom `String` type.
3834 fn function_doesnt_shadow_crate_in_use_tree() {
3837 //- /main.rs crate:main deps:foo
3840 //- /foo.rs crate:foo
3854 fn hover_feature() {
3856 r#"#![feature(box_syntax$0)]"#,
3866 The tracking issue for this feature is: [#49733]
3868 [#49733]: https://github.com/rust-lang/rust/issues/49733
3870 See also [`box_patterns`](box-patterns.md)
3872 ------------------------
3874 Currently the only stable way to create a `Box` is via the `Box::new` method.
3875 Also it is not possible in stable Rust to destructure a `Box` in a match
3876 pattern. The unstable `box` keyword can be used to create a `Box`. An example
3880 #![feature(box_syntax)]
3894 r#"#![allow(arithmetic_overflow$0)]"#,
3896 *arithmetic_overflow*
3902 arithmetic operation overflows
3908 fn hover_clippy_lint() {
3910 r#"#![allow(clippy::almost_swapped$0)]"#,
3914 clippy::almost_swapped
3918 Checks for `foo = bar; bar = foo` sequences.
3924 fn hover_attr_path_qualifier() {
3927 //- /foo.rs crate:foo
3929 //- /lib.rs crate:main.rs deps:foo
3960 use bar::{self as foo$0};
4003 fn hover_attribute_in_macro() {
4007 macro_rules! identity {
4012 #[rustc_builtin_macro]
4034 fn hover_derive_input() {
4038 #[rustc_builtin_macro]
4059 #[rustc_builtin_macro]
4062 #[derive(foo::Copy$0)]
4080 fn hover_range_math() {
4083 fn f() { let expr = $01 + 2 * 3$0 }
4093 fn f() { let expr = 1 $0+ 2 * $03 }
4103 fn f() { let expr = 1 + $02 * 3$0 }
4113 fn hover_range_arrays() {
4116 fn f() { let expr = $0[1, 2, 3, 4]$0 }
4126 fn f() { let expr = [1, 2, $03, 4]$0 }
4136 fn f() { let expr = [1, 2, $03$0, 4] }
4146 fn hover_range_functions() {
4149 fn f<T>(a: &[T]) { }
4150 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
4160 fn f<T>(a: &[T]) { }
4161 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
4171 fn hover_range_shows_nothing_when_invalid() {
4172 check_hover_range_no_results(
4174 fn f<T>(a: &[T]) { }
4175 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
4179 check_hover_range_no_results(
4181 fn f<T>$0(a: &[T]) { }
4182 fn b() { f(&[1, 2, 3,$0 4, 5]); }
4186 check_hover_range_no_results(
4188 fn $0f() { let expr = [1, 2, 3, 4]$0 }
4194 fn hover_range_shows_unit_for_statements() {
4197 fn f<T>(a: &[T]) { }
4198 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
4208 fn f() { let expr$0 = $0[1, 2, 3, 4] }
4218 fn hover_range_for_pat() {
4245 fn hover_range_shows_coercions_if_applicable_expr() {
4249 let x: &u32 = $0&&&&&0$0;
4262 let x: *const u32 = $0&0$0;
4268 Coerced to: *const u32
4275 fn hover_range_shows_type_actions() {
4280 let x: &Foo = $0&&&&&Foo$0;
4288 mod_path: "test::Foo",
4289 nav: NavigationTarget {
4297 description: "struct Foo",
4308 fn hover_try_expr_res() {
4314 fn foo() -> Result<(), FooError> {
4315 Ok($0Result::<(), FooError>::Ok(())?$0)
4329 fn foo() -> Result<(), FooError> {
4330 Ok($0Result::<(), BarError>::Ok(())?$0)
4335 Try Error Type: BarError
4336 Propagated as: FooError
4343 fn hover_try_expr() {
4346 struct NotResult<T, U>(T, U);
4350 fn foo() -> NotResult<(), Looooong> {
4351 $0NotResult((), Short)?$0;
4356 Try Target Type: NotResult<(), Short>
4357 Propagated as: NotResult<(), Looooong>
4363 struct NotResult<T, U>(T, U);
4367 fn foo() -> NotResult<(), Short> {
4368 $0NotResult((), Looooong)?$0;
4373 Try Target Type: NotResult<(), Looooong>
4374 Propagated as: NotResult<(), Short>
4381 fn hover_try_expr_option() {
4382 cov_mark::check!(hover_try_expr_opt_opt);
4385 //- minicore: option, try
4387 fn foo() -> Option<()> {
4394 <Option<i32> as Try>::Output
4400 fn hover_deref_expr() {
4404 use core::ops::Deref;
4406 struct DerefExample<T> {
4410 impl<T> Deref for DerefExample<T> {
4413 fn deref(&self) -> &Self::Target {
4419 let x = DerefExample { value: 0 };
4420 let y: i32 = $0*x$0;
4425 Dereferenced from: DerefExample<i32>
4433 fn hover_deref_expr_with_coercion() {
4437 use core::ops::Deref;
4439 struct DerefExample<T> {
4443 impl<T> Deref for DerefExample<T> {
4446 fn deref(&self) -> &Self::Target {
4452 let x = DerefExample { value: &&&&&0 };
4453 let y: &i32 = $0*x$0;
4458 Dereferenced from: DerefExample<&&&&&i32>
4467 fn hover_intra_in_macro() {
4470 macro_rules! foo_macro {
4471 ($(#[$attr:meta])* $name:ident) => {
4478 /// Doc comment for [`Foo$0`]
4495 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4501 fn hover_intra_in_attr() {
4504 #[doc = "Doc comment for [`Foo$0`]"]
4520 Doc comment for [`Foo`](https://doc.rust-lang.org/nightly/test/struct.Foo.html)
4526 fn hover_inert_attr() {
4543 * \#\[doc(hidden|inline|...)\]
4544 * \#\[doc = string\]
4563 * \#\[allow(lint1, lint2, ..., /\*opt\*/ reason = "...")\]