diff options
Diffstat (limited to 'crates/ide/src')
-rw-r--r-- | crates/ide/src/doc_links.rs | 28 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 29 | ||||
-rw-r--r-- | crates/ide/src/runnables.rs | 84 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting.rs | 3 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 3 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlighting.html | 19 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 19 |
8 files changed, 143 insertions, 46 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index b9d8b8a2b..250f10f9f 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs | |||
@@ -132,7 +132,8 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { | |||
132 | let import_map = db.import_map(krate.into()); | 132 | let import_map = db.import_map(krate.into()); |
133 | let base = once(krate.display_name(db)?.to_string()) | 133 | let base = once(krate.display_name(db)?.to_string()) |
134 | .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) | 134 | .chain(import_map.path_of(ns)?.segments.iter().map(|name| name.to_string())) |
135 | .join("/"); | 135 | .join("/") |
136 | + "/"; | ||
136 | 137 | ||
137 | let filename = get_symbol_filename(db, &target_def); | 138 | let filename = get_symbol_filename(db, &target_def); |
138 | let fragment = match definition { | 139 | let fragment = match definition { |
@@ -152,9 +153,16 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { | |||
152 | _ => None, | 153 | _ => None, |
153 | }; | 154 | }; |
154 | 155 | ||
155 | get_doc_url(db, &krate) | 156 | get_doc_url(db, &krate)? |
156 | .and_then(|url| url.join(&base).ok()) | 157 | .join(&base) |
157 | .and_then(|url| filename.as_deref().and_then(|f| url.join(f).ok())) | 158 | .ok() |
159 | .and_then(|mut url| { | ||
160 | if !matches!(definition, Definition::ModuleDef(ModuleDef::Module(..))) { | ||
161 | url.path_segments_mut().ok()?.pop(); | ||
162 | }; | ||
163 | Some(url) | ||
164 | }) | ||
165 | .and_then(|url| url.join(filename.as_deref()?).ok()) | ||
158 | .and_then( | 166 | .and_then( |
159 | |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) }, | 167 | |url| if let Some(fragment) = fragment { url.join(&fragment).ok() } else { Some(url) }, |
160 | ) | 168 | ) |
@@ -522,6 +530,18 @@ pub struct Foo { | |||
522 | ); | 530 | ); |
523 | } | 531 | } |
524 | 532 | ||
533 | #[test] | ||
534 | fn test_module() { | ||
535 | check( | ||
536 | r#" | ||
537 | pub mod foo { | ||
538 | pub mod ba<|>r {} | ||
539 | } | ||
540 | "#, | ||
541 | expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]], | ||
542 | ) | ||
543 | } | ||
544 | |||
525 | // FIXME: ImportMap will return re-export paths instead of public module | 545 | // FIXME: ImportMap will return re-export paths instead of public module |
526 | // paths. The correct path to documentation will never be a re-export. | 546 | // paths. The correct path to documentation will never be a re-export. |
527 | // This problem stops us from resolving stdlib items included in the prelude | 547 | // This problem stops us from resolving stdlib items included in the prelude |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 6466422c5..0332c7be0 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -2128,7 +2128,7 @@ fn foo_<|>test() {} | |||
2128 | ignore: false, | 2128 | ignore: false, |
2129 | }, | 2129 | }, |
2130 | }, | 2130 | }, |
2131 | cfg_exprs: [], | 2131 | cfg: None, |
2132 | }, | 2132 | }, |
2133 | ), | 2133 | ), |
2134 | ] | 2134 | ] |
@@ -2166,7 +2166,7 @@ mod tests<|> { | |||
2166 | kind: TestMod { | 2166 | kind: TestMod { |
2167 | path: "tests", | 2167 | path: "tests", |
2168 | }, | 2168 | }, |
2169 | cfg_exprs: [], | 2169 | cfg: None, |
2170 | }, | 2170 | }, |
2171 | ), | 2171 | ), |
2172 | ] | 2172 | ] |
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index cccea129a..49d8e4ae1 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -378,7 +378,11 @@ fn is_enum_name_similar_to_param_name( | |||
378 | fn get_string_representation(expr: &ast::Expr) -> Option<String> { | 378 | fn get_string_representation(expr: &ast::Expr) -> Option<String> { |
379 | match expr { | 379 | match expr { |
380 | ast::Expr::MethodCallExpr(method_call_expr) => { | 380 | ast::Expr::MethodCallExpr(method_call_expr) => { |
381 | Some(method_call_expr.name_ref()?.to_string()) | 381 | let name_ref = method_call_expr.name_ref()?; |
382 | match name_ref.text().as_str() { | ||
383 | "clone" => method_call_expr.receiver().map(|rec| rec.to_string()), | ||
384 | name_ref => Some(name_ref.to_owned()), | ||
385 | } | ||
382 | } | 386 | } |
383 | ast::Expr::RefExpr(ref_expr) => get_string_representation(&ref_expr.expr()?), | 387 | ast::Expr::RefExpr(ref_expr) => get_string_representation(&ref_expr.expr()?), |
384 | _ => Some(expr.to_string()), | 388 | _ => Some(expr.to_string()), |
@@ -1208,4 +1212,27 @@ fn main() { | |||
1208 | "#, | 1212 | "#, |
1209 | ); | 1213 | ); |
1210 | } | 1214 | } |
1215 | |||
1216 | #[test] | ||
1217 | fn hide_param_hints_for_clones() { | ||
1218 | check_with_config( | ||
1219 | InlayHintsConfig { | ||
1220 | parameter_hints: true, | ||
1221 | type_hints: false, | ||
1222 | chaining_hints: false, | ||
1223 | max_length: None, | ||
1224 | }, | ||
1225 | r#" | ||
1226 | fn foo(bar: i32, baz: String, qux: f32) {} | ||
1227 | |||
1228 | fn main() { | ||
1229 | let bar = 3; | ||
1230 | let baz = &"baz"; | ||
1231 | let fez = 1.0; | ||
1232 | foo(bar.clone(), baz.clone(), fez.clone()); | ||
1233 | //^^^^^^^^^^^ qux | ||
1234 | } | ||
1235 | "#, | ||
1236 | ); | ||
1237 | } | ||
1211 | } | 1238 | } |
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 752ef2f21..eb82456ad 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -15,7 +15,7 @@ use crate::{display::ToNav, FileId, NavigationTarget}; | |||
15 | pub struct Runnable { | 15 | pub struct Runnable { |
16 | pub nav: NavigationTarget, | 16 | pub nav: NavigationTarget, |
17 | pub kind: RunnableKind, | 17 | pub kind: RunnableKind, |
18 | pub cfg_exprs: Vec<CfgExpr>, | 18 | pub cfg: Option<CfgExpr>, |
19 | } | 19 | } |
20 | 20 | ||
21 | #[derive(Debug, Clone)] | 21 | #[derive(Debug, Clone)] |
@@ -168,7 +168,7 @@ fn runnable_fn( | |||
168 | }; | 168 | }; |
169 | 169 | ||
170 | let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def)); | 170 | let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def)); |
171 | let cfg_exprs = attrs.cfg().collect(); | 171 | let cfg = attrs.cfg(); |
172 | 172 | ||
173 | let nav = if let RunnableKind::DocTest { .. } = kind { | 173 | let nav = if let RunnableKind::DocTest { .. } = kind { |
174 | NavigationTarget::from_doc_commented( | 174 | NavigationTarget::from_doc_commented( |
@@ -179,7 +179,7 @@ fn runnable_fn( | |||
179 | } else { | 179 | } else { |
180 | NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &fn_def)) | 180 | NavigationTarget::from_named(sema.db, InFile::new(file_id.into(), &fn_def)) |
181 | }; | 181 | }; |
182 | Some(Runnable { nav, kind, cfg_exprs }) | 182 | Some(Runnable { nav, kind, cfg }) |
183 | } | 183 | } |
184 | 184 | ||
185 | #[derive(Debug, Copy, Clone)] | 185 | #[derive(Debug, Copy, Clone)] |
@@ -255,9 +255,9 @@ fn runnable_mod( | |||
255 | .join("::"); | 255 | .join("::"); |
256 | 256 | ||
257 | let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &module)); | 257 | let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &module)); |
258 | let cfg_exprs = attrs.cfg().collect(); | 258 | let cfg = attrs.cfg(); |
259 | let nav = module_def.to_nav(sema.db); | 259 | let nav = module_def.to_nav(sema.db); |
260 | Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg_exprs }) | 260 | Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg }) |
261 | } | 261 | } |
262 | 262 | ||
263 | // We could create runnables for modules with number_of_test_submodules > 0, | 263 | // We could create runnables for modules with number_of_test_submodules > 0, |
@@ -348,7 +348,7 @@ fn bench() {} | |||
348 | docs: None, | 348 | docs: None, |
349 | }, | 349 | }, |
350 | kind: Bin, | 350 | kind: Bin, |
351 | cfg_exprs: [], | 351 | cfg: None, |
352 | }, | 352 | }, |
353 | Runnable { | 353 | Runnable { |
354 | nav: NavigationTarget { | 354 | nav: NavigationTarget { |
@@ -373,7 +373,7 @@ fn bench() {} | |||
373 | ignore: false, | 373 | ignore: false, |
374 | }, | 374 | }, |
375 | }, | 375 | }, |
376 | cfg_exprs: [], | 376 | cfg: None, |
377 | }, | 377 | }, |
378 | Runnable { | 378 | Runnable { |
379 | nav: NavigationTarget { | 379 | nav: NavigationTarget { |
@@ -398,7 +398,7 @@ fn bench() {} | |||
398 | ignore: true, | 398 | ignore: true, |
399 | }, | 399 | }, |
400 | }, | 400 | }, |
401 | cfg_exprs: [], | 401 | cfg: None, |
402 | }, | 402 | }, |
403 | Runnable { | 403 | Runnable { |
404 | nav: NavigationTarget { | 404 | nav: NavigationTarget { |
@@ -420,7 +420,7 @@ fn bench() {} | |||
420 | "bench", | 420 | "bench", |
421 | ), | 421 | ), |
422 | }, | 422 | }, |
423 | cfg_exprs: [], | 423 | cfg: None, |
424 | }, | 424 | }, |
425 | ] | 425 | ] |
426 | "#]], | 426 | "#]], |
@@ -507,7 +507,7 @@ fn should_have_no_runnable_6() {} | |||
507 | docs: None, | 507 | docs: None, |
508 | }, | 508 | }, |
509 | kind: Bin, | 509 | kind: Bin, |
510 | cfg_exprs: [], | 510 | cfg: None, |
511 | }, | 511 | }, |
512 | Runnable { | 512 | Runnable { |
513 | nav: NavigationTarget { | 513 | nav: NavigationTarget { |
@@ -527,7 +527,7 @@ fn should_have_no_runnable_6() {} | |||
527 | "should_have_runnable", | 527 | "should_have_runnable", |
528 | ), | 528 | ), |
529 | }, | 529 | }, |
530 | cfg_exprs: [], | 530 | cfg: None, |
531 | }, | 531 | }, |
532 | Runnable { | 532 | Runnable { |
533 | nav: NavigationTarget { | 533 | nav: NavigationTarget { |
@@ -547,7 +547,7 @@ fn should_have_no_runnable_6() {} | |||
547 | "should_have_runnable_1", | 547 | "should_have_runnable_1", |
548 | ), | 548 | ), |
549 | }, | 549 | }, |
550 | cfg_exprs: [], | 550 | cfg: None, |
551 | }, | 551 | }, |
552 | Runnable { | 552 | Runnable { |
553 | nav: NavigationTarget { | 553 | nav: NavigationTarget { |
@@ -567,7 +567,7 @@ fn should_have_no_runnable_6() {} | |||
567 | "should_have_runnable_2", | 567 | "should_have_runnable_2", |
568 | ), | 568 | ), |
569 | }, | 569 | }, |
570 | cfg_exprs: [], | 570 | cfg: None, |
571 | }, | 571 | }, |
572 | ] | 572 | ] |
573 | "#]], | 573 | "#]], |
@@ -609,7 +609,7 @@ impl Data { | |||
609 | docs: None, | 609 | docs: None, |
610 | }, | 610 | }, |
611 | kind: Bin, | 611 | kind: Bin, |
612 | cfg_exprs: [], | 612 | cfg: None, |
613 | }, | 613 | }, |
614 | Runnable { | 614 | Runnable { |
615 | nav: NavigationTarget { | 615 | nav: NavigationTarget { |
@@ -629,7 +629,7 @@ impl Data { | |||
629 | "Data::foo", | 629 | "Data::foo", |
630 | ), | 630 | ), |
631 | }, | 631 | }, |
632 | cfg_exprs: [], | 632 | cfg: None, |
633 | }, | 633 | }, |
634 | ] | 634 | ] |
635 | "#]], | 635 | "#]], |
@@ -668,7 +668,7 @@ mod test_mod { | |||
668 | kind: TestMod { | 668 | kind: TestMod { |
669 | path: "test_mod", | 669 | path: "test_mod", |
670 | }, | 670 | }, |
671 | cfg_exprs: [], | 671 | cfg: None, |
672 | }, | 672 | }, |
673 | Runnable { | 673 | Runnable { |
674 | nav: NavigationTarget { | 674 | nav: NavigationTarget { |
@@ -693,7 +693,7 @@ mod test_mod { | |||
693 | ignore: false, | 693 | ignore: false, |
694 | }, | 694 | }, |
695 | }, | 695 | }, |
696 | cfg_exprs: [], | 696 | cfg: None, |
697 | }, | 697 | }, |
698 | ] | 698 | ] |
699 | "#]], | 699 | "#]], |
@@ -748,7 +748,7 @@ mod root_tests { | |||
748 | kind: TestMod { | 748 | kind: TestMod { |
749 | path: "root_tests::nested_tests_0", | 749 | path: "root_tests::nested_tests_0", |
750 | }, | 750 | }, |
751 | cfg_exprs: [], | 751 | cfg: None, |
752 | }, | 752 | }, |
753 | Runnable { | 753 | Runnable { |
754 | nav: NavigationTarget { | 754 | nav: NavigationTarget { |
@@ -768,7 +768,7 @@ mod root_tests { | |||
768 | kind: TestMod { | 768 | kind: TestMod { |
769 | path: "root_tests::nested_tests_0::nested_tests_1", | 769 | path: "root_tests::nested_tests_0::nested_tests_1", |
770 | }, | 770 | }, |
771 | cfg_exprs: [], | 771 | cfg: None, |
772 | }, | 772 | }, |
773 | Runnable { | 773 | Runnable { |
774 | nav: NavigationTarget { | 774 | nav: NavigationTarget { |
@@ -793,7 +793,7 @@ mod root_tests { | |||
793 | ignore: false, | 793 | ignore: false, |
794 | }, | 794 | }, |
795 | }, | 795 | }, |
796 | cfg_exprs: [], | 796 | cfg: None, |
797 | }, | 797 | }, |
798 | Runnable { | 798 | Runnable { |
799 | nav: NavigationTarget { | 799 | nav: NavigationTarget { |
@@ -818,7 +818,7 @@ mod root_tests { | |||
818 | ignore: false, | 818 | ignore: false, |
819 | }, | 819 | }, |
820 | }, | 820 | }, |
821 | cfg_exprs: [], | 821 | cfg: None, |
822 | }, | 822 | }, |
823 | Runnable { | 823 | Runnable { |
824 | nav: NavigationTarget { | 824 | nav: NavigationTarget { |
@@ -838,7 +838,7 @@ mod root_tests { | |||
838 | kind: TestMod { | 838 | kind: TestMod { |
839 | path: "root_tests::nested_tests_0::nested_tests_2", | 839 | path: "root_tests::nested_tests_0::nested_tests_2", |
840 | }, | 840 | }, |
841 | cfg_exprs: [], | 841 | cfg: None, |
842 | }, | 842 | }, |
843 | Runnable { | 843 | Runnable { |
844 | nav: NavigationTarget { | 844 | nav: NavigationTarget { |
@@ -863,7 +863,7 @@ mod root_tests { | |||
863 | ignore: false, | 863 | ignore: false, |
864 | }, | 864 | }, |
865 | }, | 865 | }, |
866 | cfg_exprs: [], | 866 | cfg: None, |
867 | }, | 867 | }, |
868 | ] | 868 | ] |
869 | "#]], | 869 | "#]], |
@@ -906,12 +906,14 @@ fn test_foo1() {} | |||
906 | ignore: false, | 906 | ignore: false, |
907 | }, | 907 | }, |
908 | }, | 908 | }, |
909 | cfg_exprs: [ | 909 | cfg: Some( |
910 | KeyValue { | 910 | Atom( |
911 | key: "feature", | 911 | KeyValue { |
912 | value: "foo", | 912 | key: "feature", |
913 | }, | 913 | value: "foo", |
914 | ], | 914 | }, |
915 | ), | ||
916 | ), | ||
915 | }, | 917 | }, |
916 | ] | 918 | ] |
917 | "#]], | 919 | "#]], |
@@ -954,20 +956,24 @@ fn test_foo1() {} | |||
954 | ignore: false, | 956 | ignore: false, |
955 | }, | 957 | }, |
956 | }, | 958 | }, |
957 | cfg_exprs: [ | 959 | cfg: Some( |
958 | All( | 960 | All( |
959 | [ | 961 | [ |
960 | KeyValue { | 962 | Atom( |
961 | key: "feature", | 963 | KeyValue { |
962 | value: "foo", | 964 | key: "feature", |
963 | }, | 965 | value: "foo", |
964 | KeyValue { | 966 | }, |
965 | key: "feature", | 967 | ), |
966 | value: "bar", | 968 | Atom( |
967 | }, | 969 | KeyValue { |
970 | key: "feature", | ||
971 | value: "bar", | ||
972 | }, | ||
973 | ), | ||
968 | ], | 974 | ], |
969 | ), | 975 | ), |
970 | ], | 976 | ), |
971 | }, | 977 | }, |
972 | ] | 978 | ] |
973 | "#]], | 979 | "#]], |
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index b35c03162..750848467 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs | |||
@@ -763,6 +763,9 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | |||
763 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { | 763 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { |
764 | h |= HighlightModifier::Mutable; | 764 | h |= HighlightModifier::Mutable; |
765 | } | 765 | } |
766 | if local.ty(db).as_callable(db).is_some() || local.ty(db).impls_fnonce(db) { | ||
767 | h |= HighlightModifier::Callable; | ||
768 | } | ||
766 | return h; | 769 | return h; |
767 | } | 770 | } |
768 | } | 771 | } |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index c1b817f06..e8f78ad52 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -64,6 +64,7 @@ pub enum HighlightModifier { | |||
64 | Mutable, | 64 | Mutable, |
65 | Consuming, | 65 | Consuming, |
66 | Unsafe, | 66 | Unsafe, |
67 | Callable, | ||
67 | } | 68 | } |
68 | 69 | ||
69 | impl HighlightTag { | 70 | impl HighlightTag { |
@@ -122,6 +123,7 @@ impl HighlightModifier { | |||
122 | HighlightModifier::Mutable, | 123 | HighlightModifier::Mutable, |
123 | HighlightModifier::Consuming, | 124 | HighlightModifier::Consuming, |
124 | HighlightModifier::Unsafe, | 125 | HighlightModifier::Unsafe, |
126 | HighlightModifier::Callable, | ||
125 | ]; | 127 | ]; |
126 | 128 | ||
127 | fn as_str(self) -> &'static str { | 129 | fn as_str(self) -> &'static str { |
@@ -134,6 +136,7 @@ impl HighlightModifier { | |||
134 | HighlightModifier::Mutable => "mutable", | 136 | HighlightModifier::Mutable => "mutable", |
135 | HighlightModifier::Consuming => "consuming", | 137 | HighlightModifier::Consuming => "consuming", |
136 | HighlightModifier::Unsafe => "unsafe", | 138 | HighlightModifier::Unsafe => "unsafe", |
139 | HighlightModifier::Callable => "callable", | ||
137 | } | 140 | } |
138 | } | 141 | } |
139 | 142 | ||
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 0bb0928e4..0cb84866d 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html | |||
@@ -44,6 +44,17 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
44 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">Copy</span> <span class="punctuation">{</span><span class="punctuation">}</span> | 44 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">Copy</span> <span class="punctuation">{</span><span class="punctuation">}</span> |
45 | <span class="punctuation">}</span> | 45 | <span class="punctuation">}</span> |
46 | 46 | ||
47 | <span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration">ops</span> <span class="punctuation">{</span> | ||
48 | <span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">lang</span><span class="attribute"> </span><span class="operator">=</span><span class="attribute"> </span><span class="string_literal">"fn_once"</span><span class="attribute">]</span> | ||
49 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">FnOnce</span><span class="punctuation"><</span><span class="type_param declaration">Args</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">}</span> | ||
50 | |||
51 | <span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">lang</span><span class="attribute"> </span><span class="operator">=</span><span class="attribute"> </span><span class="string_literal">"fn_mut"</span><span class="attribute">]</span> | ||
52 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">FnMut</span><span class="punctuation"><</span><span class="type_param declaration">Args</span><span class="punctuation">></span><span class="punctuation">:</span> <span class="trait">FnOnce</span><span class="punctuation"><</span><span class="type_param">Args</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">}</span> | ||
53 | |||
54 | <span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">lang</span><span class="attribute"> </span><span class="operator">=</span><span class="attribute"> </span><span class="string_literal">"fn"</span><span class="attribute">]</span> | ||
55 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">Fn</span><span class="punctuation"><</span><span class="type_param declaration">Args</span><span class="punctuation">></span><span class="punctuation">:</span> <span class="trait">FnMut</span><span class="punctuation"><</span><span class="type_param">Args</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">}</span> | ||
56 | <span class="punctuation">}</span> | ||
57 | |||
47 | 58 | ||
48 | <span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span> | 59 | <span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span> |
49 | <span class="keyword">pub</span> <span class="field declaration">x</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span> | 60 | <span class="keyword">pub</span> <span class="field declaration">x</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span> |
@@ -99,6 +110,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
99 | <span class="function">foo</span><span class="operator">::</span><span class="punctuation"><</span><span class="lifetime">'a</span><span class="punctuation">,</span> <span class="builtin_type">i32</span><span class="punctuation">></span><span class="punctuation">(</span><span class="punctuation">)</span> | 110 | <span class="function">foo</span><span class="operator">::</span><span class="punctuation"><</span><span class="lifetime">'a</span><span class="punctuation">,</span> <span class="builtin_type">i32</span><span class="punctuation">></span><span class="punctuation">(</span><span class="punctuation">)</span> |
100 | <span class="punctuation">}</span> | 111 | <span class="punctuation">}</span> |
101 | 112 | ||
113 | <span class="keyword">use</span> <span class="module">ops</span><span class="operator">::</span><span class="trait">Fn</span><span class="punctuation">;</span> | ||
114 | <span class="keyword">fn</span> <span class="function declaration">baz</span><span class="punctuation"><</span><span class="type_param declaration">F</span><span class="punctuation">:</span> <span class="trait">Fn</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">></span><span class="punctuation">(</span><span class="value_param declaration callable">f</span><span class="punctuation">:</span> <span class="type_param">F</span><span class="punctuation">)</span> <span class="punctuation">{</span> | ||
115 | <span class="value_param callable">f</span><span class="punctuation">(</span><span class="punctuation">)</span> | ||
116 | <span class="punctuation">}</span> | ||
117 | |||
102 | <span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> <span class="punctuation">{</span> | 118 | <span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> <span class="punctuation">{</span> |
103 | <span class="punctuation">(</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">:</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">)</span> <span class="operator">=</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">}</span> | 119 | <span class="punctuation">(</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">:</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">)</span> <span class="operator">=</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">}</span> |
104 | <span class="punctuation">}</span> | 120 | <span class="punctuation">}</span> |
@@ -157,6 +173,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
157 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function">quop</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 173 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function">quop</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
158 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function mutable">qux</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 174 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function mutable">qux</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
159 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function">baz</span><span class="punctuation">(</span><span class="variable mutable">copy</span><span class="punctuation">)</span><span class="punctuation">;</span> | 175 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function">baz</span><span class="punctuation">(</span><span class="variable mutable">copy</span><span class="punctuation">)</span><span class="punctuation">;</span> |
176 | |||
177 | <span class="keyword">let</span> <span class="variable declaration callable">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="punctuation">;</span> | ||
178 | <span class="keyword">let</span> <span class="variable declaration callable">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function">baz</span><span class="punctuation">;</span> | ||
160 | <span class="punctuation">}</span> | 179 | <span class="punctuation">}</span> |
161 | 180 | ||
162 | <span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation"><</span><span class="type_param declaration">T</span><span class="punctuation">></span> <span class="punctuation">{</span> | 181 | <span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation"><</span><span class="type_param declaration">T</span><span class="punctuation">></span> <span class="punctuation">{</span> |
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 126363b8b..da20c300e 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -18,6 +18,17 @@ pub mod marker { | |||
18 | pub trait Copy {} | 18 | pub trait Copy {} |
19 | } | 19 | } |
20 | 20 | ||
21 | pub mod ops { | ||
22 | #[lang = "fn_once"] | ||
23 | pub trait FnOnce<Args> {} | ||
24 | |||
25 | #[lang = "fn_mut"] | ||
26 | pub trait FnMut<Args>: FnOnce<Args> {} | ||
27 | |||
28 | #[lang = "fn"] | ||
29 | pub trait Fn<Args>: FnMut<Args> {} | ||
30 | } | ||
31 | |||
21 | 32 | ||
22 | struct Foo { | 33 | struct Foo { |
23 | pub x: i32, | 34 | pub x: i32, |
@@ -73,6 +84,11 @@ fn foo<'a, T>() -> T { | |||
73 | foo::<'a, i32>() | 84 | foo::<'a, i32>() |
74 | } | 85 | } |
75 | 86 | ||
87 | use ops::Fn; | ||
88 | fn baz<F: Fn() -> ()>(f: F) { | ||
89 | f() | ||
90 | } | ||
91 | |||
76 | macro_rules! def_fn { | 92 | macro_rules! def_fn { |
77 | ($($tt:tt)*) => {$($tt)*} | 93 | ($($tt:tt)*) => {$($tt)*} |
78 | } | 94 | } |
@@ -131,6 +147,9 @@ fn main() { | |||
131 | copy.quop(); | 147 | copy.quop(); |
132 | copy.qux(); | 148 | copy.qux(); |
133 | copy.baz(copy); | 149 | copy.baz(copy); |
150 | |||
151 | let a = |x| x; | ||
152 | let bar = Foo::baz; | ||
134 | } | 153 | } |
135 | 154 | ||
136 | enum Option<T> { | 155 | enum Option<T> { |