Change test to not rely on trait inference

This commit is contained in:
Phil Ellison 2019-08-11 15:03:27 +01:00 committed by Aleksey Kladov
parent a40e390860
commit 456e72c4e4

View File

@ -285,34 +285,29 @@ fn div(x: i32, y: i32) -> Result<i32, String> {
fn test_wrap_return_type_handles_generic_functions() { fn test_wrap_return_type_handles_generic_functions() {
let before = r#" let before = r#"
//- /main.rs //- /main.rs
use std::{default::Default, result::Result::{self, Ok, Err}}; use std::result::Result::{self, Ok, Err};
fn div<T: Default, i32>(x: i32) -> Result<T, i32> { fn div<T>(x: T) -> Result<T, i32> {
if x == 0 { if x == 0 {
return Err(7); return Err(7);
} }
T::default() x
} }
//- /std/lib.rs //- /std/lib.rs
pub mod result { pub mod result {
pub enum Result<T, E> { Ok(T), Err(E) } pub enum Result<T, E> { Ok(T), Err(E) }
} }
pub mod default {
pub trait Default {
fn default() -> Self;
}
}
"#; "#;
// The formatting here is a bit odd due to how the parse_fixture function works in test_utils - // The formatting here is a bit odd due to how the parse_fixture function works in test_utils -
// it strips empty lines and leading whitespace. The important part of this test is that the final // it strips empty lines and leading whitespace. The important part of this test is that the final
// `x / y` expr is now wrapped in `Ok(..)` // expr is now wrapped in `Ok(..)`
let after = r#"use std::{default::Default, result::Result::{self, Ok, Err}}; let after = r#"use std::result::Result::{self, Ok, Err};
fn div<T: Default>(x: i32) -> Result<T, i32> { fn div<T>(x: T) -> Result<T, i32> {
if x == 0 { if x == 0 {
return Err(7); return Err(7);
} }
Ok(T::default()) Ok(x)
} }
"#; "#;
check_apply_diagnostic_fix_for_target_file("/main.rs", before, after); check_apply_diagnostic_fix_for_target_file("/main.rs", before, after);