@@ -281,6 +281,44 @@ fn div(x: i32, y: i32) -> Result<i32, String> {
281
281
check_apply_diagnostic_fix_for_target_file ( "/main.rs" , before, after) ;
282
282
}
283
283
284
+ #[ test]
285
+ fn test_wrap_return_type_handles_type_aliases ( ) {
286
+ let before = r#"
287
+ //- /main.rs
288
+ use std::{string::String, result::Result::{self, Ok, Err}};
289
+
290
+ type MyResult<T> = Result<T, String>;
291
+
292
+ fn div(x: i32, y: i32) -> MyResult<i32> {
293
+ if y == 0 {
294
+ return Err("div by zero".into());
295
+ }
296
+ x / y
297
+ }
298
+
299
+ //- /std/lib.rs
300
+ pub mod string {
301
+ pub struct String { }
302
+ }
303
+ pub mod result {
304
+ pub enum Result<T, E> { Ok(T), Err(E) }
305
+ }
306
+ "# ;
307
+ // The formatting here is a bit odd due to how the parse_fixture function works in test_utils -
308
+ // it strips empty lines and leading whitespace. The important part of this test is that the final
309
+ // `x / y` expr is now wrapped in `Ok(..)`
310
+ let after = r#"use std::{string::String, result::Result::{self, Ok, Err}};
311
+ type MyResult<T> = Result<T, String>;
312
+ fn div(x: i32, y: i32) -> MyResult<i32> {
313
+ if y == 0 {
314
+ return Err("div by zero".into());
315
+ }
316
+ Ok(x / y)
317
+ }
318
+ "# ;
319
+ check_apply_diagnostic_fix_for_target_file ( "/main.rs" , before, after) ;
320
+ }
321
+
284
322
#[ test]
285
323
fn test_wrap_return_type_not_applicable ( ) {
286
324
let content = r#"
0 commit comments