rust-analyzer/crates
bors[bot] 6a5100f4d5
Merge #2834
2834: refactor(ra_syntax.validation): removed code duplication from validate_literal() r=kiljacken a=Veetaha

Hi! This is my first ever contribution to this project.
I've taken some dirty job from issue #223

This is a simple atomic PR to remove code duplication according to FIXME comment in the function that is the main focus of the further development.

I just didn't want to mix refactoring with the implementation of new features...

I am not sure whether you prefer such atomic PRs here or you'd rather have a single PR that contains all atomic commits inside of it?

So if you want me to add all that validation in one PR I'll mark this one as WIP and update it when the work is finished, otherwise, I'll go with the option of creating separate PRs per each feature of validation of strings, numbers, and comments respectively.

### Comments about refactoring
Yeah, reducing the duplication is quite hard here, extracting into stateless functions could be another option but the number of their arguments would be very big and repeated across char and string implementations so that just writing their types and names would become cumbersome.
I tried the option of having everything captured implicitly in the closure but failed since rust doesn't have templated (or generic) closures as C++ does, this is needed because `unescape_byte*()` and `unescape_char|str()` have different return types...
Maybe I am missing something here? I may be wrong because I am not enough experienced in Rust...
Well, I am awaiting any kind of feedback!

Co-authored-by: Veetaha <gerzoh1@gmail.com>
2020-01-14 17:49:18 +00:00
..
ra_arena Switch to variant-granularity field type inference 2019-11-25 00:12:36 +03:00
ra_assists Tweak add_custom_impl 2020-01-14 09:08:45 -05:00
ra_batch Support setting cargo features 2019-12-13 18:16:34 +08:00
ra_cargo_watch Defer cargo check until after workspace load 2020-01-13 17:12:14 +01:00
ra_cfg Disable doctests 2019-11-17 18:35:05 +03:00
ra_cli Some clippy lints 2020-01-13 11:27:06 -05:00
ra_db Remove the Default impl for SourceRoot 2020-01-08 19:42:27 +01:00
ra_fmt fix 2190; add test for "replace if let with match" 2019-11-20 19:01:06 +01:00
ra_hir Move Type API to type 2020-01-14 14:42:52 +01:00
ra_hir_def Merge #2803 2020-01-11 23:00:37 +00:00
ra_hir_expand Use attr location for builtin macro goto-imp 2020-01-12 18:08:53 +08:00
ra_hir_ty Push resolver further up 2020-01-14 14:24:03 +01:00
ra_ide Move Type API to type 2020-01-14 14:42:52 +01:00
ra_lsp_server Tweak add_custom_impl 2020-01-14 09:08:45 -05:00
ra_mbe Add details about test_repeat_bad_var current state 2019-12-30 17:12:20 +01:00
ra_parser Readability 2020-01-13 11:38:53 -05:00
ra_prof Improve profiling output when duration filter is specified 2020-01-02 17:26:02 +01:00
ra_project_model Address nit 2020-01-10 22:41:52 +01:00
ra_syntax refactor(ra_syntax.validation): removed code duplication from validate_literal() function 2020-01-14 04:09:03 +02:00
ra_text_edit Disable doctests 2019-11-17 18:35:05 +03:00
ra_tt Refactoring 2019-12-18 13:10:37 +08:00
ra_vfs_glob Disable doctests 2019-11-17 18:35:05 +03:00
test_utils Refactor goto tests to always specify texts 2019-12-18 16:00:35 +01:00