diff options
author | Aleksey Kladov <[email protected]> | 2020-05-20 22:50:29 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-05-20 22:50:42 +0100 |
commit | 8300132ed0676496ec4adda49eb682ac24bdb5b9 (patch) | |
tree | f261a04d3ab18c2c424f7933b8ee7dc4df0787c2 /crates/ra_assists/src/handlers/replace_if_let_with_match.rs | |
parent | 4677cea71994a593d56052767f625f46fd2e4a83 (diff) |
More snippets
Diffstat (limited to 'crates/ra_assists/src/handlers/replace_if_let_with_match.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/replace_if_let_with_match.rs | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs index 65f5fc6ab..e016f51c3 100644 --- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs | |||
@@ -68,7 +68,6 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext) | |||
68 | .indent(IndentLevel::from_node(if_expr.syntax())) | 68 | .indent(IndentLevel::from_node(if_expr.syntax())) |
69 | }; | 69 | }; |
70 | 70 | ||
71 | edit.set_cursor(if_expr.syntax().text_range().start()); | ||
72 | edit.replace_ast::<ast::Expr>(if_expr.into(), match_expr); | 71 | edit.replace_ast::<ast::Expr>(if_expr.into(), match_expr); |
73 | }) | 72 | }) |
74 | } | 73 | } |
@@ -83,7 +82,7 @@ mod tests { | |||
83 | fn test_replace_if_let_with_match_unwraps_simple_expressions() { | 82 | fn test_replace_if_let_with_match_unwraps_simple_expressions() { |
84 | check_assist( | 83 | check_assist( |
85 | replace_if_let_with_match, | 84 | replace_if_let_with_match, |
86 | " | 85 | r#" |
87 | impl VariantData { | 86 | impl VariantData { |
88 | pub fn is_struct(&self) -> bool { | 87 | pub fn is_struct(&self) -> bool { |
89 | if <|>let VariantData::Struct(..) = *self { | 88 | if <|>let VariantData::Struct(..) = *self { |
@@ -92,16 +91,16 @@ impl VariantData { | |||
92 | false | 91 | false |
93 | } | 92 | } |
94 | } | 93 | } |
95 | } ", | 94 | } "#, |
96 | " | 95 | r#" |
97 | impl VariantData { | 96 | impl VariantData { |
98 | pub fn is_struct(&self) -> bool { | 97 | pub fn is_struct(&self) -> bool { |
99 | <|>match *self { | 98 | match *self { |
100 | VariantData::Struct(..) => true, | 99 | VariantData::Struct(..) => true, |
101 | _ => false, | 100 | _ => false, |
102 | } | 101 | } |
103 | } | 102 | } |
104 | } ", | 103 | } "#, |
105 | ) | 104 | ) |
106 | } | 105 | } |
107 | 106 | ||
@@ -109,7 +108,7 @@ impl VariantData { | |||
109 | fn test_replace_if_let_with_match_doesnt_unwrap_multiline_expressions() { | 108 | fn test_replace_if_let_with_match_doesnt_unwrap_multiline_expressions() { |
110 | check_assist( | 109 | check_assist( |
111 | replace_if_let_with_match, | 110 | replace_if_let_with_match, |
112 | " | 111 | r#" |
113 | fn foo() { | 112 | fn foo() { |
114 | if <|>let VariantData::Struct(..) = a { | 113 | if <|>let VariantData::Struct(..) = a { |
115 | bar( | 114 | bar( |
@@ -118,10 +117,10 @@ fn foo() { | |||
118 | } else { | 117 | } else { |
119 | false | 118 | false |
120 | } | 119 | } |
121 | } ", | 120 | } "#, |
122 | " | 121 | r#" |
123 | fn foo() { | 122 | fn foo() { |
124 | <|>match a { | 123 | match a { |
125 | VariantData::Struct(..) => { | 124 | VariantData::Struct(..) => { |
126 | bar( | 125 | bar( |
127 | 123 | 126 | 123 |
@@ -129,7 +128,7 @@ fn foo() { | |||
129 | } | 128 | } |
130 | _ => false, | 129 | _ => false, |
131 | } | 130 | } |
132 | } ", | 131 | } "#, |
133 | ) | 132 | ) |
134 | } | 133 | } |
135 | 134 | ||
@@ -137,7 +136,7 @@ fn foo() { | |||
137 | fn replace_if_let_with_match_target() { | 136 | fn replace_if_let_with_match_target() { |
138 | check_assist_target( | 137 | check_assist_target( |
139 | replace_if_let_with_match, | 138 | replace_if_let_with_match, |
140 | " | 139 | r#" |
141 | impl VariantData { | 140 | impl VariantData { |
142 | pub fn is_struct(&self) -> bool { | 141 | pub fn is_struct(&self) -> bool { |
143 | if <|>let VariantData::Struct(..) = *self { | 142 | if <|>let VariantData::Struct(..) = *self { |
@@ -146,7 +145,7 @@ impl VariantData { | |||
146 | false | 145 | false |
147 | } | 146 | } |
148 | } | 147 | } |
149 | } ", | 148 | } "#, |
150 | "if let VariantData::Struct(..) = *self { | 149 | "if let VariantData::Struct(..) = *self { |
151 | true | 150 | true |
152 | } else { | 151 | } else { |
@@ -176,7 +175,7 @@ enum Option<T> { Some(T), None } | |||
176 | use Option::*; | 175 | use Option::*; |
177 | 176 | ||
178 | fn foo(x: Option<i32>) { | 177 | fn foo(x: Option<i32>) { |
179 | <|>match x { | 178 | match x { |
180 | Some(x) => println!("{}", x), | 179 | Some(x) => println!("{}", x), |
181 | None => println!("none"), | 180 | None => println!("none"), |
182 | } | 181 | } |
@@ -206,7 +205,7 @@ enum Result<T, E> { Ok(T), Err(E) } | |||
206 | use Result::*; | 205 | use Result::*; |
207 | 206 | ||
208 | fn foo(x: Result<i32, ()>) { | 207 | fn foo(x: Result<i32, ()>) { |
209 | <|>match x { | 208 | match x { |
210 | Ok(x) => println!("{}", x), | 209 | Ok(x) => println!("{}", x), |
211 | Err(_) => println!("none"), | 210 | Err(_) => println!("none"), |
212 | } | 211 | } |