diff options
Diffstat (limited to 'crates/ide_assists/src/handlers/replace_unwrap_with_match.rs')
-rw-r--r-- | crates/ide_assists/src/handlers/replace_unwrap_with_match.rs | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs index a3bfa221c..f39c48d8f 100644 --- a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs | |||
@@ -20,17 +20,16 @@ use ide_db::ty_filter::TryEnum; | |||
20 | // Replaces `unwrap` with a `match` expression. Works for Result and Option. | 20 | // Replaces `unwrap` with a `match` expression. Works for Result and Option. |
21 | // | 21 | // |
22 | // ``` | 22 | // ``` |
23 | // enum Result<T, E> { Ok(T), Err(E) } | 23 | // # //- minicore: result |
24 | // fn main() { | 24 | // fn main() { |
25 | // let x: Result<i32, i32> = Result::Ok(92); | 25 | // let x: Result<i32, i32> = Ok(92); |
26 | // let y = x.$0unwrap(); | 26 | // let y = x.$0unwrap(); |
27 | // } | 27 | // } |
28 | // ``` | 28 | // ``` |
29 | // -> | 29 | // -> |
30 | // ``` | 30 | // ``` |
31 | // enum Result<T, E> { Ok(T), Err(E) } | ||
32 | // fn main() { | 31 | // fn main() { |
33 | // let x: Result<i32, i32> = Result::Ok(92); | 32 | // let x: Result<i32, i32> = Ok(92); |
34 | // let y = match x { | 33 | // let y = match x { |
35 | // Ok(it) => it, | 34 | // Ok(it) => it, |
36 | // $0_ => unreachable!(), | 35 | // $0_ => unreachable!(), |
@@ -97,25 +96,24 @@ mod tests { | |||
97 | fn test_replace_result_unwrap_with_match() { | 96 | fn test_replace_result_unwrap_with_match() { |
98 | check_assist( | 97 | check_assist( |
99 | replace_unwrap_with_match, | 98 | replace_unwrap_with_match, |
100 | r" | 99 | r#" |
101 | enum Result<T, E> { Ok(T), Err(E) } | 100 | //- minicore: result |
102 | fn i<T>(a: T) -> T { a } | 101 | fn i<T>(a: T) -> T { a } |
103 | fn main() { | 102 | fn main() { |
104 | let x: Result<i32, i32> = Result::Ok(92); | 103 | let x: Result<i32, i32> = Ok(92); |
105 | let y = i(x).$0unwrap(); | 104 | let y = i(x).$0unwrap(); |
106 | } | 105 | } |
107 | ", | 106 | "#, |
108 | r" | 107 | r#" |
109 | enum Result<T, E> { Ok(T), Err(E) } | ||
110 | fn i<T>(a: T) -> T { a } | 108 | fn i<T>(a: T) -> T { a } |
111 | fn main() { | 109 | fn main() { |
112 | let x: Result<i32, i32> = Result::Ok(92); | 110 | let x: Result<i32, i32> = Ok(92); |
113 | let y = match i(x) { | 111 | let y = match i(x) { |
114 | Ok(it) => it, | 112 | Ok(it) => it, |
115 | $0_ => unreachable!(), | 113 | $0_ => unreachable!(), |
116 | }; | 114 | }; |
117 | } | 115 | } |
118 | ", | 116 | "#, |
119 | ) | 117 | ) |
120 | } | 118 | } |
121 | 119 | ||
@@ -123,25 +121,24 @@ fn main() { | |||
123 | fn test_replace_option_unwrap_with_match() { | 121 | fn test_replace_option_unwrap_with_match() { |
124 | check_assist( | 122 | check_assist( |
125 | replace_unwrap_with_match, | 123 | replace_unwrap_with_match, |
126 | r" | 124 | r#" |
127 | enum Option<T> { Some(T), None } | 125 | //- minicore: option |
128 | fn i<T>(a: T) -> T { a } | 126 | fn i<T>(a: T) -> T { a } |
129 | fn main() { | 127 | fn main() { |
130 | let x = Option::Some(92); | 128 | let x = Some(92); |
131 | let y = i(x).$0unwrap(); | 129 | let y = i(x).$0unwrap(); |
132 | } | 130 | } |
133 | ", | 131 | "#, |
134 | r" | 132 | r#" |
135 | enum Option<T> { Some(T), None } | ||
136 | fn i<T>(a: T) -> T { a } | 133 | fn i<T>(a: T) -> T { a } |
137 | fn main() { | 134 | fn main() { |
138 | let x = Option::Some(92); | 135 | let x = Some(92); |
139 | let y = match i(x) { | 136 | let y = match i(x) { |
140 | Some(it) => it, | 137 | Some(it) => it, |
141 | $0_ => unreachable!(), | 138 | $0_ => unreachable!(), |
142 | }; | 139 | }; |
143 | } | 140 | } |
144 | ", | 141 | "#, |
145 | ); | 142 | ); |
146 | } | 143 | } |
147 | 144 | ||
@@ -149,25 +146,24 @@ fn main() { | |||
149 | fn test_replace_result_unwrap_with_match_chaining() { | 146 | fn test_replace_result_unwrap_with_match_chaining() { |
150 | check_assist( | 147 | check_assist( |
151 | replace_unwrap_with_match, | 148 | replace_unwrap_with_match, |
152 | r" | 149 | r#" |
153 | enum Result<T, E> { Ok(T), Err(E) } | 150 | //- minicore: result |
154 | fn i<T>(a: T) -> T { a } | 151 | fn i<T>(a: T) -> T { a } |
155 | fn main() { | 152 | fn main() { |
156 | let x: Result<i32, i32> = Result::Ok(92); | 153 | let x: Result<i32, i32> = Ok(92); |
157 | let y = i(x).$0unwrap().count_zeroes(); | 154 | let y = i(x).$0unwrap().count_zeroes(); |
158 | } | 155 | } |
159 | ", | 156 | "#, |
160 | r" | 157 | r#" |
161 | enum Result<T, E> { Ok(T), Err(E) } | ||
162 | fn i<T>(a: T) -> T { a } | 158 | fn i<T>(a: T) -> T { a } |
163 | fn main() { | 159 | fn main() { |
164 | let x: Result<i32, i32> = Result::Ok(92); | 160 | let x: Result<i32, i32> = Ok(92); |
165 | let y = match i(x) { | 161 | let y = match i(x) { |
166 | Ok(it) => it, | 162 | Ok(it) => it, |
167 | $0_ => unreachable!(), | 163 | $0_ => unreachable!(), |
168 | }.count_zeroes(); | 164 | }.count_zeroes(); |
169 | } | 165 | } |
170 | ", | 166 | "#, |
171 | ) | 167 | ) |
172 | } | 168 | } |
173 | 169 | ||
@@ -175,14 +171,14 @@ fn main() { | |||
175 | fn replace_unwrap_with_match_target() { | 171 | fn replace_unwrap_with_match_target() { |
176 | check_assist_target( | 172 | check_assist_target( |
177 | replace_unwrap_with_match, | 173 | replace_unwrap_with_match, |
178 | r" | 174 | r#" |
179 | enum Option<T> { Some(T), None } | 175 | //- minicore: option |
180 | fn i<T>(a: T) -> T { a } | 176 | fn i<T>(a: T) -> T { a } |
181 | fn main() { | 177 | fn main() { |
182 | let x = Option::Some(92); | 178 | let x = Some(92); |
183 | let y = i(x).$0unwrap(); | 179 | let y = i(x).$0unwrap(); |
184 | } | 180 | } |
185 | ", | 181 | "#, |
186 | r"i(x).unwrap()", | 182 | r"i(x).unwrap()", |
187 | ); | 183 | ); |
188 | } | 184 | } |