2020-02-07 15:35:34 -06:00
|
|
|
//! Generated file, do not edit by hand, see `xtask/src/codegen`
|
2019-10-25 06:16:46 -05:00
|
|
|
|
|
|
|
use super::check;
|
|
|
|
|
2019-10-19 06:19:06 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_custom_impl() {
|
|
|
|
check(
|
|
|
|
"add_custom_impl",
|
|
|
|
r#####"
|
|
|
|
#[derive(Deb<|>ug, Display)]
|
|
|
|
struct S;
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
#[derive(Display)]
|
|
|
|
struct S;
|
|
|
|
|
|
|
|
impl Debug for S {
|
|
|
|
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-25 15:38:15 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_derive() {
|
|
|
|
check(
|
|
|
|
"add_derive",
|
|
|
|
r#####"
|
|
|
|
struct Point {
|
|
|
|
x: u32,
|
|
|
|
y: u32,<|>
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
#[derive()]
|
|
|
|
struct Point {
|
|
|
|
x: u32,
|
|
|
|
y: u32,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_add_explicit_type() {
|
|
|
|
check(
|
|
|
|
"add_explicit_type",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let x<|> = 92;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let x: i32 = 92;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
2020-03-26 14:59:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_add_function() {
|
|
|
|
check(
|
|
|
|
"add_function",
|
|
|
|
r#####"
|
|
|
|
struct Baz;
|
|
|
|
fn baz() -> Baz { Baz }
|
|
|
|
fn foo() {
|
2020-04-16 16:53:25 -05:00
|
|
|
bar<|>("", baz());
|
2020-03-26 14:59:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Baz;
|
|
|
|
fn baz() -> Baz { Baz }
|
|
|
|
fn foo() {
|
2020-04-16 16:53:25 -05:00
|
|
|
bar("", baz());
|
2020-03-26 14:59:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bar(arg: &str, baz: Baz) {
|
2020-04-13 15:17:06 -05:00
|
|
|
todo!()
|
2020-03-26 14:59:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
"#####,
|
|
|
|
)
|
2019-10-25 15:38:15 -05:00
|
|
|
}
|
|
|
|
|
2019-10-27 04:22:53 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_hash() {
|
|
|
|
check(
|
|
|
|
"add_hash",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r#"Hello,<|> World!"#;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r##"Hello, World!"##;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-25 15:38:15 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_impl() {
|
|
|
|
check(
|
|
|
|
"add_impl",
|
|
|
|
r#####"
|
|
|
|
struct Ctx<T: Clone> {
|
|
|
|
data: T,<|>
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Ctx<T: Clone> {
|
|
|
|
data: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Clone> Ctx<T> {
|
|
|
|
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_add_impl_default_members() {
|
|
|
|
check(
|
|
|
|
"add_impl_default_members",
|
|
|
|
r#####"
|
2019-12-24 09:44:32 -06:00
|
|
|
trait Trait {
|
2019-10-25 15:38:15 -05:00
|
|
|
Type X;
|
|
|
|
fn foo(&self);
|
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-12-24 09:44:32 -06:00
|
|
|
impl Trait for () {
|
2019-10-25 15:38:15 -05:00
|
|
|
Type X = ();
|
|
|
|
fn foo(&self) {}<|>
|
|
|
|
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
2019-12-24 09:44:32 -06:00
|
|
|
trait Trait {
|
2019-10-25 15:38:15 -05:00
|
|
|
Type X;
|
|
|
|
fn foo(&self);
|
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-12-24 09:44:32 -06:00
|
|
|
impl Trait for () {
|
2019-10-25 15:38:15 -05:00
|
|
|
Type X = ();
|
|
|
|
fn foo(&self) {}
|
|
|
|
fn bar(&self) {}
|
|
|
|
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_add_impl_missing_members() {
|
|
|
|
check(
|
|
|
|
"add_impl_missing_members",
|
|
|
|
r#####"
|
2019-12-24 09:44:32 -06:00
|
|
|
trait Trait<T> {
|
2019-10-25 15:38:15 -05:00
|
|
|
Type X;
|
2019-12-24 09:44:32 -06:00
|
|
|
fn foo(&self) -> T;
|
2019-10-25 15:38:15 -05:00
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-12-24 09:44:32 -06:00
|
|
|
impl Trait<u32> for () {<|>
|
2019-10-25 15:38:15 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
2019-12-24 09:44:32 -06:00
|
|
|
trait Trait<T> {
|
2019-10-25 15:38:15 -05:00
|
|
|
Type X;
|
2019-12-24 09:44:32 -06:00
|
|
|
fn foo(&self) -> T;
|
2019-10-25 15:38:15 -05:00
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-12-24 09:44:32 -06:00
|
|
|
impl Trait<u32> for () {
|
2020-04-10 15:41:11 -05:00
|
|
|
fn foo(&self) -> u32 { todo!() }
|
2019-10-25 15:38:15 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-09 09:56:36 -06:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_new() {
|
|
|
|
check(
|
|
|
|
"add_new",
|
|
|
|
r#####"
|
|
|
|
struct Ctx<T: Clone> {
|
|
|
|
data: T,<|>
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Ctx<T: Clone> {
|
|
|
|
data: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Clone> Ctx<T> {
|
|
|
|
fn new(data: T) -> Self { Self { data } }
|
|
|
|
}
|
|
|
|
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-25 15:38:15 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_apply_demorgan() {
|
|
|
|
check(
|
|
|
|
"apply_demorgan",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
if x != 4 ||<|> !y {}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
if !(x == 4 && y) {}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-23 18:19:09 -06:00
|
|
|
#[test]
|
|
|
|
fn doctest_auto_import() {
|
|
|
|
check(
|
|
|
|
"auto_import",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let map = HashMap<|>::new();
|
|
|
|
}
|
2020-02-06 11:10:25 -06:00
|
|
|
pub mod std { pub mod collections { pub struct HashMap { } } }
|
2019-12-23 18:19:09 -06:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
fn main() {
|
2020-02-06 11:10:25 -06:00
|
|
|
let map = HashMap::new();
|
2019-12-23 18:19:09 -06:00
|
|
|
}
|
2020-02-06 11:10:25 -06:00
|
|
|
pub mod std { pub mod collections { pub struct HashMap { } } }
|
2019-12-23 18:19:09 -06:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-26 09:37:04 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_change_visibility() {
|
|
|
|
check(
|
|
|
|
"change_visibility",
|
|
|
|
r#####"
|
2019-10-26 13:17:39 -05:00
|
|
|
<|>fn frobnicate() {}
|
2019-10-26 09:37:04 -05:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
pub(crate) fn frobnicate() {}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-25 06:16:46 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_convert_to_guarded_return() {
|
|
|
|
check(
|
|
|
|
"convert_to_guarded_return",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
<|>if cond {
|
|
|
|
foo();
|
|
|
|
bar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
if !cond {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foo();
|
|
|
|
bar();
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-26 09:37:04 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_fill_match_arms() {
|
|
|
|
check(
|
|
|
|
"fill_match_arms",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
<|>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
2020-03-23 21:23:30 -05:00
|
|
|
Action::Move { distance } => {}
|
|
|
|
Action::Stop => {}
|
2019-10-26 09:37:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-26 11:08:13 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_flip_binexpr() {
|
|
|
|
check(
|
|
|
|
"flip_binexpr",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let _ = 90 +<|> 2;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let _ = 2 + 90;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_flip_comma() {
|
|
|
|
check(
|
|
|
|
"flip_comma",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
((1, 2),<|> (3, 4));
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
((3, 4), (1, 2));
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 08:56:53 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_flip_trait_bound() {
|
|
|
|
check(
|
|
|
|
"flip_trait_bound",
|
|
|
|
r#####"
|
|
|
|
fn foo<T: Clone +<|> Copy>() { }
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn foo<T: Copy + Clone>() { }
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-26 11:08:13 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_inline_local_variable() {
|
|
|
|
check(
|
|
|
|
"inline_local_variable",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let x<|> = 1 + 2;
|
|
|
|
x * 4;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
(1 + 2) * 4;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-26 11:58:18 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_introduce_variable() {
|
|
|
|
check(
|
|
|
|
"introduce_variable",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
<|>(1 + 2)<|> * 4;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let var_name = (1 + 2);
|
|
|
|
var_name * 4;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-27 03:26:46 -05:00
|
|
|
|
2019-11-21 12:51:40 -06:00
|
|
|
#[test]
|
|
|
|
fn doctest_invert_if() {
|
|
|
|
check(
|
|
|
|
"invert_if",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2019-11-23 23:14:57 -06:00
|
|
|
if<|> !y { A } else { B }
|
2019-11-21 12:51:40 -06:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2019-11-23 23:14:57 -06:00
|
|
|
if y { B } else { A }
|
2019-11-21 12:51:40 -06:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 04:22:53 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_make_raw_string() {
|
|
|
|
check(
|
|
|
|
"make_raw_string",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
"Hello,<|> World!";
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r#"Hello, World!"#;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_make_usual_string() {
|
|
|
|
check(
|
|
|
|
"make_usual_string",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r#"Hello,<|> "World!""#;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
"Hello, \"World!\"";
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:41:24 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_merge_imports() {
|
|
|
|
check(
|
|
|
|
"merge_imports",
|
|
|
|
r#####"
|
|
|
|
use std::<|>fmt::Formatter;
|
|
|
|
use std::io;
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::{fmt::Formatter, io};
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 03:26:46 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_merge_match_arms() {
|
|
|
|
check(
|
|
|
|
"merge_match_arms",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
<|>Action::Move(..) => foo(),
|
|
|
|
Action::Stop => foo(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
Action::Move(..) | Action::Stop => foo(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_move_arm_cond_to_match_guard() {
|
|
|
|
check(
|
|
|
|
"move_arm_cond_to_match_guard",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
Action::Move { distance } => <|>if distance > 10 { foo() },
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
Action::Move { distance } if distance > 10 => foo(),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_move_bounds_to_where_clause() {
|
|
|
|
check(
|
|
|
|
"move_bounds_to_where_clause",
|
|
|
|
r#####"
|
|
|
|
fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U {
|
|
|
|
f(x)
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
|
|
|
|
f(x)
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_move_guard_to_arm_body() {
|
|
|
|
check(
|
|
|
|
"move_guard_to_arm_body",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
Action::Move { distance } <|>if distance > 10 => foo(),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
Action::Move { distance } => if distance > 10 { foo() },
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-27 04:22:53 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_remove_dbg() {
|
|
|
|
check(
|
|
|
|
"remove_dbg",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
<|>dbg!(92);
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
92;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_remove_hash() {
|
|
|
|
check(
|
|
|
|
"remove_hash",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r#"Hello,<|> World!"#;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r"Hello, World!";
|
|
|
|
}
|
2020-02-19 05:44:20 -06:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_remove_mut() {
|
|
|
|
check(
|
|
|
|
"remove_mut",
|
|
|
|
r#####"
|
|
|
|
impl Walrus {
|
|
|
|
fn feed(&mut<|> self, amount: u32) {}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
impl Walrus {
|
|
|
|
fn feed(&self, amount: u32) {}
|
|
|
|
}
|
2019-10-27 04:22:53 -05:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-11 13:32:58 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_reorder_fields() {
|
|
|
|
check(
|
|
|
|
"reorder_fields",
|
|
|
|
r#####"
|
|
|
|
struct Foo {foo: i32, bar: i32};
|
|
|
|
const test: Foo = <|>Foo {bar: 0, foo: 1}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Foo {foo: i32, bar: i32};
|
|
|
|
const test: Foo = Foo {foo: 1, bar: 0}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 04:22:53 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_if_let_with_match() {
|
|
|
|
check(
|
|
|
|
"replace_if_let_with_match",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
<|>if let Action::Move { distance } = action {
|
|
|
|
foo(distance)
|
|
|
|
} else {
|
|
|
|
bar()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
Action::Move { distance } => foo(distance),
|
|
|
|
_ => bar(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-27 06:12:17 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_let_with_if_let() {
|
|
|
|
check(
|
|
|
|
"replace_let_with_if_let",
|
|
|
|
r#####"
|
|
|
|
enum Option<T> { Some(T), None }
|
|
|
|
|
|
|
|
fn main(action: Action) {
|
|
|
|
<|>let x = compute();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compute() -> Option<i32> { None }
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Option<T> { Some(T), None }
|
|
|
|
|
|
|
|
fn main(action: Action) {
|
|
|
|
if let Some(x) = compute() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compute() -> Option<i32> { None }
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:35:34 -06:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_qualified_name_with_use() {
|
|
|
|
check(
|
|
|
|
"replace_qualified_name_with_use",
|
|
|
|
r#####"
|
|
|
|
fn process(map: std::collections::<|>HashMap<String, String>) {}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
fn process(map: HashMap<String, String>) {}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-26 04:16:10 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_unwrap_with_match() {
|
|
|
|
check(
|
|
|
|
"replace_unwrap_with_match",
|
|
|
|
r#####"
|
|
|
|
enum Result<T, E> { Ok(T), Err(E) }
|
|
|
|
fn main() {
|
|
|
|
let x: Result<i32, i32> = Result::Ok(92);
|
|
|
|
let y = x.<|>unwrap();
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Result<T, E> { Ok(T), Err(E) }
|
|
|
|
fn main() {
|
|
|
|
let x: Result<i32, i32> = Result::Ok(92);
|
|
|
|
let y = match x {
|
|
|
|
Ok(a) => a,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 04:22:53 -05:00
|
|
|
#[test]
|
|
|
|
fn doctest_split_import() {
|
|
|
|
check(
|
|
|
|
"split_import",
|
|
|
|
r#####"
|
|
|
|
use std::<|>collections::HashMap;
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::{collections::HashMap};
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2020-04-29 06:52:55 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_unwrap_block() {
|
|
|
|
check(
|
|
|
|
"unwrap_block",
|
|
|
|
r#####"
|
|
|
|
fn foo() {
|
|
|
|
if true {<|>
|
|
|
|
println!("foo");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn foo() {
|
|
|
|
<|>println!("foo");
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|