aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs
diff options
context:
space:
mode:
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.rs53
1 files changed, 25 insertions, 28 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..7e57353c6 100644
--- a/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs
+++ b/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs
@@ -97,25 +97,24 @@ mod tests {
97 fn test_replace_result_unwrap_with_match() { 97 fn test_replace_result_unwrap_with_match() {
98 check_assist( 98 check_assist(
99 replace_unwrap_with_match, 99 replace_unwrap_with_match,
100 r" 100 r#"
101enum Result<T, E> { Ok(T), Err(E) } 101//- minicore: result
102fn i<T>(a: T) -> T { a } 102fn i<T>(a: T) -> T { a }
103fn main() { 103fn main() {
104 let x: Result<i32, i32> = Result::Ok(92); 104 let x: Result<i32, i32> = Ok(92);
105 let y = i(x).$0unwrap(); 105 let y = i(x).$0unwrap();
106} 106}
107 ", 107"#,
108 r" 108 r#"
109enum Result<T, E> { Ok(T), Err(E) }
110fn i<T>(a: T) -> T { a } 109fn i<T>(a: T) -> T { a }
111fn main() { 110fn main() {
112 let x: Result<i32, i32> = Result::Ok(92); 111 let x: Result<i32, i32> = Ok(92);
113 let y = match i(x) { 112 let y = match i(x) {
114 Ok(it) => it, 113 Ok(it) => it,
115 $0_ => unreachable!(), 114 $0_ => unreachable!(),
116 }; 115 };
117} 116}
118 ", 117"#,
119 ) 118 )
120 } 119 }
121 120
@@ -123,25 +122,24 @@ fn main() {
123 fn test_replace_option_unwrap_with_match() { 122 fn test_replace_option_unwrap_with_match() {
124 check_assist( 123 check_assist(
125 replace_unwrap_with_match, 124 replace_unwrap_with_match,
126 r" 125 r#"
127enum Option<T> { Some(T), None } 126//- minicore: option
128fn i<T>(a: T) -> T { a } 127fn i<T>(a: T) -> T { a }
129fn main() { 128fn main() {
130 let x = Option::Some(92); 129 let x = Some(92);
131 let y = i(x).$0unwrap(); 130 let y = i(x).$0unwrap();
132} 131}
133 ", 132"#,
134 r" 133 r#"
135enum Option<T> { Some(T), None }
136fn i<T>(a: T) -> T { a } 134fn i<T>(a: T) -> T { a }
137fn main() { 135fn main() {
138 let x = Option::Some(92); 136 let x = Some(92);
139 let y = match i(x) { 137 let y = match i(x) {
140 Some(it) => it, 138 Some(it) => it,
141 $0_ => unreachable!(), 139 $0_ => unreachable!(),
142 }; 140 };
143} 141}
144 ", 142"#,
145 ); 143 );
146 } 144 }
147 145
@@ -149,25 +147,24 @@ fn main() {
149 fn test_replace_result_unwrap_with_match_chaining() { 147 fn test_replace_result_unwrap_with_match_chaining() {
150 check_assist( 148 check_assist(
151 replace_unwrap_with_match, 149 replace_unwrap_with_match,
152 r" 150 r#"
153enum Result<T, E> { Ok(T), Err(E) } 151//- minicore: result
154fn i<T>(a: T) -> T { a } 152fn i<T>(a: T) -> T { a }
155fn main() { 153fn main() {
156 let x: Result<i32, i32> = Result::Ok(92); 154 let x: Result<i32, i32> = Ok(92);
157 let y = i(x).$0unwrap().count_zeroes(); 155 let y = i(x).$0unwrap().count_zeroes();
158} 156}
159 ", 157"#,
160 r" 158 r#"
161enum Result<T, E> { Ok(T), Err(E) }
162fn i<T>(a: T) -> T { a } 159fn i<T>(a: T) -> T { a }
163fn main() { 160fn main() {
164 let x: Result<i32, i32> = Result::Ok(92); 161 let x: Result<i32, i32> = Ok(92);
165 let y = match i(x) { 162 let y = match i(x) {
166 Ok(it) => it, 163 Ok(it) => it,
167 $0_ => unreachable!(), 164 $0_ => unreachable!(),
168 }.count_zeroes(); 165 }.count_zeroes();
169} 166}
170 ", 167"#,
171 ) 168 )
172 } 169 }
173 170
@@ -175,14 +172,14 @@ fn main() {
175 fn replace_unwrap_with_match_target() { 172 fn replace_unwrap_with_match_target() {
176 check_assist_target( 173 check_assist_target(
177 replace_unwrap_with_match, 174 replace_unwrap_with_match,
178 r" 175 r#"
179enum Option<T> { Some(T), None } 176//- minicore: option
180fn i<T>(a: T) -> T { a } 177fn i<T>(a: T) -> T { a }
181fn main() { 178fn main() {
182 let x = Option::Some(92); 179 let x = Some(92);
183 let y = i(x).$0unwrap(); 180 let y = i(x).$0unwrap();
184} 181}
185 ", 182"#,
186 r"i(x).unwrap()", 183 r"i(x).unwrap()",
187 ); 184 );
188 } 185 }