Skip to content

Commit 215e229

Browse files
author
Jonas Schievink
committed
Update wrap return tests
Update "no diagnostic" tests, use `()` instead of `String`
1 parent 90331ea commit 215e229

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

crates/ra_ide/src/diagnostics.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -321,29 +321,26 @@ mod tests {
321321
fn test_wrap_return_type() {
322322
let before = r#"
323323
//- /main.rs
324-
use core::{string::String, result::Result::{self, Ok, Err}};
324+
use core::result::Result::{self, Ok, Err};
325325
326-
fn div(x: i32, y: i32) -> Result<i32, String> {
326+
fn div(x: i32, y: i32) -> Result<i32, ()> {
327327
if y == 0 {
328-
return Err("div by zero".into());
328+
return Err(());
329329
}
330330
x / y<|>
331331
}
332332
333333
//- /core/lib.rs
334-
pub mod string {
335-
pub struct String { }
336-
}
337334
pub mod result {
338335
pub enum Result<T, E> { Ok(T), Err(E) }
339336
}
340337
"#;
341338
let after = r#"
342-
use core::{string::String, result::Result::{self, Ok, Err}};
339+
use core::result::Result::{self, Ok, Err};
343340
344-
fn div(x: i32, y: i32) -> Result<i32, String> {
341+
fn div(x: i32, y: i32) -> Result<i32, ()> {
345342
if y == 0 {
346-
return Err("div by zero".into());
343+
return Err(());
347344
}
348345
Ok(x / y)
349346
}
@@ -386,32 +383,29 @@ mod tests {
386383
fn test_wrap_return_type_handles_type_aliases() {
387384
let before = r#"
388385
//- /main.rs
389-
use core::{string::String, result::Result::{self, Ok, Err}};
386+
use core::result::Result::{self, Ok, Err};
390387
391-
type MyResult<T> = Result<T, String>;
388+
type MyResult<T> = Result<T, ()>;
392389
393390
fn div(x: i32, y: i32) -> MyResult<i32> {
394391
if y == 0 {
395-
return Err("div by zero".into());
392+
return Err(());
396393
}
397394
x <|>/ y
398395
}
399396
400397
//- /core/lib.rs
401-
pub mod string {
402-
pub struct String { }
403-
}
404398
pub mod result {
405399
pub enum Result<T, E> { Ok(T), Err(E) }
406400
}
407401
"#;
408402
let after = r#"
409-
use core::{string::String, result::Result::{self, Ok, Err}};
403+
use core::result::Result::{self, Ok, Err};
410404
411-
type MyResult<T> = Result<T, String>;
405+
type MyResult<T> = Result<T, ()>;
412406
fn div(x: i32, y: i32) -> MyResult<i32> {
413407
if y == 0 {
414-
return Err("div by zero".into());
408+
return Err(());
415409
}
416410
Ok(x / y)
417411
}
@@ -423,16 +417,13 @@ mod tests {
423417
fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
424418
let content = r#"
425419
//- /main.rs
426-
use std::{string::String, result::Result::{self, Ok, Err}};
420+
use core::result::Result::{self, Ok, Err};
427421
428-
fn foo() -> Result<String, i32> {
422+
fn foo() -> Result<(), i32> {
429423
0<|>
430424
}
431425
432-
//- /std/lib.rs
433-
pub mod string {
434-
pub struct String { }
435-
}
426+
//- /core/lib.rs
436427
pub mod result {
437428
pub enum Result<T, E> { Ok(T), Err(E) }
438429
}
@@ -444,7 +435,7 @@ mod tests {
444435
fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() {
445436
let content = r#"
446437
//- /main.rs
447-
use std::{string::String, result::Result::{self, Ok, Err}};
438+
use core::result::Result::{self, Ok, Err};
448439
449440
enum SomeOtherEnum {
450441
Ok(i32),
@@ -455,10 +446,7 @@ mod tests {
455446
0<|>
456447
}
457448
458-
//- /std/lib.rs
459-
pub mod string {
460-
pub struct String { }
461-
}
449+
//- /core/lib.rs
462450
pub mod result {
463451
pub enum Result<T, E> { Ok(T), Err(E) }
464452
}

0 commit comments

Comments
 (0)