2020-02-07 21:35:34 +00:00
|
|
|
//! Generated file, do not edit by hand, see `xtask/src/codegen`
|
2019-10-25 11:16:46 +00:00
|
|
|
|
2020-05-06 08:21:35 +00:00
|
|
|
use super::check_doc_test;
|
2019-10-25 11:16:46 +00:00
|
|
|
|
2019-10-25 20:38:15 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_explicit_type() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-25 20:38:15 +00:00
|
|
|
"add_explicit_type",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
let x$0 = 92;
|
2019-10-25 20:38:15 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let x: i32 = 92;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
2020-03-26 19:59:35 +00:00
|
|
|
}
|
|
|
|
|
2019-10-27 09:22:53 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_hash() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 09:22:53 +00:00
|
|
|
"add_hash",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
r#"Hello,$0 World!"#;
|
2019-10-27 09:22:53 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r##"Hello, World!"##;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-25 20:38:15 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_impl_default_members() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-25 20:38:15 +00:00
|
|
|
"add_impl_default_members",
|
|
|
|
r#####"
|
2019-12-24 15:44:32 +00:00
|
|
|
trait Trait {
|
2020-12-25 17:15:31 +00:00
|
|
|
type X;
|
2019-10-25 20:38:15 +00:00
|
|
|
fn foo(&self);
|
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-12-24 15:44:32 +00:00
|
|
|
impl Trait for () {
|
2020-12-25 17:15:31 +00:00
|
|
|
type X = ();
|
2021-01-06 20:15:48 +00:00
|
|
|
fn foo(&self) {}$0
|
2019-10-25 20:38:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
2019-12-24 15:44:32 +00:00
|
|
|
trait Trait {
|
2020-12-25 17:15:31 +00:00
|
|
|
type X;
|
2019-10-25 20:38:15 +00:00
|
|
|
fn foo(&self);
|
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-12-24 15:44:32 +00:00
|
|
|
impl Trait for () {
|
2020-12-25 17:15:31 +00:00
|
|
|
type X = ();
|
2019-10-25 20:38:15 +00:00
|
|
|
fn foo(&self) {}
|
|
|
|
|
2020-08-17 07:47:13 +00:00
|
|
|
$0fn bar(&self) {}
|
2019-10-25 20:38:15 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_add_impl_missing_members() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-25 20:38:15 +00:00
|
|
|
"add_impl_missing_members",
|
|
|
|
r#####"
|
2019-12-24 15:44:32 +00:00
|
|
|
trait Trait<T> {
|
2020-12-25 17:15:31 +00:00
|
|
|
type X;
|
2019-12-24 15:44:32 +00:00
|
|
|
fn foo(&self) -> T;
|
2019-10-25 20:38:15 +00:00
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2021-01-06 20:15:48 +00:00
|
|
|
impl Trait<u32> for () {$0
|
2019-10-25 20:38:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
2019-12-24 15:44:32 +00:00
|
|
|
trait Trait<T> {
|
2020-12-25 17:15:31 +00:00
|
|
|
type X;
|
2019-12-24 15:44:32 +00:00
|
|
|
fn foo(&self) -> T;
|
2019-10-25 20:38:15 +00:00
|
|
|
fn bar(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-12-24 15:44:32 +00:00
|
|
|
impl Trait<u32> for () {
|
2020-12-25 17:15:31 +00:00
|
|
|
$0type X;
|
|
|
|
|
2020-05-20 00:07:21 +00:00
|
|
|
fn foo(&self) -> u32 {
|
2020-12-25 17:15:31 +00:00
|
|
|
todo!()
|
2020-05-02 09:50:43 +00:00
|
|
|
}
|
2019-10-25 20:38:15 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-17 14:15:23 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_lifetime_to_type() {
|
|
|
|
check_doc_test(
|
|
|
|
"add_lifetime_to_type",
|
|
|
|
r#####"
|
2021-01-21 08:53:24 +00:00
|
|
|
struct Point {
|
|
|
|
x: &$0u32,
|
2021-01-17 14:15:23 +00:00
|
|
|
y: u32,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Point<'a> {
|
|
|
|
x: &'a u32,
|
|
|
|
y: u32,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-19 22:07:00 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_add_turbo_fish() {
|
|
|
|
check_doc_test(
|
|
|
|
"add_turbo_fish",
|
|
|
|
r#####"
|
|
|
|
fn make<T>() -> T { todo!() }
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
let x = make$0();
|
2020-05-19 22:07:00 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn make<T>() -> T { todo!() }
|
|
|
|
fn main() {
|
|
|
|
let x = make::<${0:_}>();
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-25 20:38:15 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_apply_demorgan() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-25 20:38:15 +00:00
|
|
|
"apply_demorgan",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-02-22 15:23:42 +00:00
|
|
|
if x != 4 ||$0 y < 3.14 {}
|
2019-10-25 20:38:15 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-02-22 15:23:42 +00:00
|
|
|
if !(x == 4 && !(y < 3.14)) {}
|
2019-10-25 20:38:15 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-24 00:19:09 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_auto_import() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-12-24 00:19:09 +00:00
|
|
|
"auto_import",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
let map = HashMap$0::new();
|
2019-12-24 00:19:09 +00:00
|
|
|
}
|
2020-02-06 17:10:25 +00:00
|
|
|
pub mod std { pub mod collections { pub struct HashMap { } } }
|
2019-12-24 00:19:09 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
fn main() {
|
2020-02-06 17:10:25 +00:00
|
|
|
let map = HashMap::new();
|
2019-12-24 00:19:09 +00:00
|
|
|
}
|
2020-02-06 17:10:25 +00:00
|
|
|
pub mod std { pub mod collections { pub struct HashMap { } } }
|
2019-12-24 00:19:09 +00:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-26 14:37:04 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_change_visibility() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-26 14:37:04 +00:00
|
|
|
"change_visibility",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
$0fn frobnicate() {}
|
2019-10-26 14:37:04 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
pub(crate) fn frobnicate() {}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-09-29 18:48:43 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_convert_integer_literal() {
|
|
|
|
check_doc_test(
|
|
|
|
"convert_integer_literal",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
const _: i32 = 10$0;
|
2020-09-29 18:48:43 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
const _: i32 = 0b1010;
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-25 11:16:46 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_convert_to_guarded_return() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-25 11:16:46 +00:00
|
|
|
"convert_to_guarded_return",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0if cond {
|
2019-10-25 11:16:46 +00:00
|
|
|
foo();
|
|
|
|
bar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
if !cond {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foo();
|
|
|
|
bar();
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-26 14:37:04 +00:00
|
|
|
|
2020-08-02 20:07:56 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_expand_glob_import() {
|
|
|
|
check_doc_test(
|
|
|
|
"expand_glob_import",
|
|
|
|
r#####"
|
|
|
|
mod foo {
|
|
|
|
pub struct Bar;
|
|
|
|
pub struct Baz;
|
|
|
|
}
|
|
|
|
|
2021-01-06 20:15:48 +00:00
|
|
|
use foo::*$0;
|
2020-08-02 20:07:56 +00:00
|
|
|
|
|
|
|
fn qux(bar: Bar, baz: Baz) {}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
mod foo {
|
|
|
|
pub struct Bar;
|
|
|
|
pub struct Baz;
|
|
|
|
}
|
|
|
|
|
|
|
|
use foo::{Baz, Bar};
|
|
|
|
|
|
|
|
fn qux(bar: Bar, baz: Baz) {}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-03 07:57:11 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_extract_function() {
|
|
|
|
check_doc_test(
|
|
|
|
"extract_function",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let n = 1;
|
|
|
|
$0let m = n + 2;
|
|
|
|
let k = m + n;$0
|
|
|
|
let g = 3;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let n = 1;
|
|
|
|
fun_name(n);
|
|
|
|
let g = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn $0fun_name(n: i32) {
|
|
|
|
let m = n + 2;
|
|
|
|
let k = m + n;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-03 18:43:57 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_extract_struct_from_enum_variant() {
|
|
|
|
check_doc_test(
|
|
|
|
"extract_struct_from_enum_variant",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
enum A { $0One(u32, u32) }
|
2020-06-03 18:43:57 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct One(pub u32, pub u32);
|
|
|
|
|
|
|
|
enum A { One(One) }
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-06-26 23:21:43 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_extract_variable() {
|
|
|
|
check_doc_test(
|
|
|
|
"extract_variable",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0(1 + 2)$0 * 4;
|
2020-06-26 23:21:43 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let $0var_name = (1 + 2);
|
|
|
|
var_name * 4;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-26 14:37:04 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_fill_match_arms() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-26 14:37:04 +00:00
|
|
|
"fill_match_arms",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0
|
2019-10-26 14:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
2020-05-20 12:00:37 +00:00
|
|
|
$0Action::Move { distance } => {}
|
2020-03-24 02:23:30 +00:00
|
|
|
Action::Stop => {}
|
2019-10-26 14:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-26 16:08:13 +00:00
|
|
|
|
2020-05-20 11:33:13 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_fix_visibility() {
|
|
|
|
check_doc_test(
|
|
|
|
"fix_visibility",
|
|
|
|
r#####"
|
|
|
|
mod m {
|
|
|
|
fn frobnicate() {}
|
|
|
|
}
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
m::frobnicate$0() {}
|
2020-05-20 11:33:13 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
mod m {
|
2020-05-20 12:13:17 +00:00
|
|
|
$0pub(crate) fn frobnicate() {}
|
2020-05-20 11:33:13 +00:00
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
m::frobnicate() {}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-26 16:08:13 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_flip_binexpr() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-26 16:08:13 +00:00
|
|
|
"flip_binexpr",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
let _ = 90 +$0 2;
|
2019-10-26 16:08:13 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let _ = 2 + 90;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_flip_comma() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-26 16:08:13 +00:00
|
|
|
"flip_comma",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
((1, 2),$0 (3, 4));
|
2019-10-26 16:08:13 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
((3, 4), (1, 2));
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 13:56:53 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_flip_trait_bound() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 13:56:53 +00:00
|
|
|
"flip_trait_bound",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
fn foo<T: Clone +$0 Copy>() { }
|
2019-10-27 13:56:53 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn foo<T: Copy + Clone>() { }
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-13 21:00:44 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_generate_default_from_enum_variant() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_default_from_enum_variant",
|
|
|
|
r#####"
|
|
|
|
enum Version {
|
|
|
|
Undefined,
|
2021-01-06 20:15:48 +00:00
|
|
|
Minor$0,
|
2020-12-13 21:00:44 +00:00
|
|
|
Major,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Version {
|
|
|
|
Undefined,
|
|
|
|
Minor,
|
|
|
|
Major,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Version {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::Minor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-03 16:15:03 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_generate_derive() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_derive",
|
|
|
|
r#####"
|
|
|
|
struct Point {
|
|
|
|
x: u32,
|
2021-01-06 20:15:48 +00:00
|
|
|
y: u32,$0
|
2020-07-03 16:15:03 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
#[derive($0)]
|
|
|
|
struct Point {
|
|
|
|
x: u32,
|
|
|
|
y: u32,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-14 17:26:37 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_generate_enum_as_method() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_enum_as_method",
|
|
|
|
r#####"
|
|
|
|
enum Value {
|
|
|
|
Number(i32),
|
|
|
|
Text(String)$0,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Value {
|
|
|
|
Number(i32),
|
|
|
|
Text(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Value {
|
|
|
|
fn as_text(&self) -> Option<&String> {
|
|
|
|
if let Self::Text(v) = self {
|
|
|
|
Some(v)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-05 00:57:39 +00:00
|
|
|
#[test]
|
2021-02-14 09:09:56 +00:00
|
|
|
fn doctest_generate_enum_is_method() {
|
2021-02-05 00:57:39 +00:00
|
|
|
check_doc_test(
|
2021-02-14 09:09:56 +00:00
|
|
|
"generate_enum_is_method",
|
2021-02-05 00:57:39 +00:00
|
|
|
r#####"
|
|
|
|
enum Version {
|
|
|
|
Undefined,
|
|
|
|
Minor$0,
|
|
|
|
Major,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Version {
|
|
|
|
Undefined,
|
|
|
|
Minor,
|
|
|
|
Major,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Version {
|
2021-02-05 14:35:24 +00:00
|
|
|
/// Returns `true` if the version is [`Minor`].
|
2021-02-05 00:57:39 +00:00
|
|
|
fn is_minor(&self) -> bool {
|
|
|
|
matches!(self, Self::Minor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-16 21:43:21 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_generate_enum_try_into_method() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_enum_try_into_method",
|
|
|
|
r#####"
|
|
|
|
enum Value {
|
|
|
|
Number(i32),
|
|
|
|
Text(String)$0,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Value {
|
|
|
|
Number(i32),
|
|
|
|
Text(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Value {
|
|
|
|
fn try_into_text(self) -> Result<String, Self> {
|
|
|
|
if let Self::Text(v) = self {
|
|
|
|
Ok(v)
|
|
|
|
} else {
|
|
|
|
Err(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-03 16:15:03 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_generate_from_impl_for_enum() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_from_impl_for_enum",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
enum A { $0One(u32) }
|
2020-07-03 16:15:03 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum A { One(u32) }
|
|
|
|
|
|
|
|
impl From<u32> for A {
|
|
|
|
fn from(v: u32) -> Self {
|
2021-02-13 12:46:41 +00:00
|
|
|
Self::One(v)
|
2020-07-03 16:15:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_generate_function() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_function",
|
|
|
|
r#####"
|
|
|
|
struct Baz;
|
|
|
|
fn baz() -> Baz { Baz }
|
|
|
|
fn foo() {
|
2021-01-06 20:15:48 +00:00
|
|
|
bar$0("", baz());
|
2020-07-03 16:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Baz;
|
|
|
|
fn baz() -> Baz { Baz }
|
|
|
|
fn foo() {
|
|
|
|
bar("", baz());
|
|
|
|
}
|
|
|
|
|
2020-10-04 19:21:30 +00:00
|
|
|
fn bar(arg: &str, baz: Baz) ${0:-> ()} {
|
|
|
|
todo!()
|
2020-07-03 16:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-09 11:30:13 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_generate_getter() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_getter",
|
|
|
|
r#####"
|
|
|
|
struct Person {
|
|
|
|
nam$0e: String,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Person {
|
|
|
|
name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Person {
|
|
|
|
/// Get a reference to the person's name.
|
|
|
|
fn name(&self) -> &String {
|
|
|
|
&self.name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_generate_getter_mut() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_getter_mut",
|
|
|
|
r#####"
|
|
|
|
struct Person {
|
|
|
|
nam$0e: String,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Person {
|
|
|
|
name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Person {
|
|
|
|
/// Get a mutable reference to the person's name.
|
|
|
|
fn name_mut(&mut self) -> &mut String {
|
|
|
|
&mut self.name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-03 16:15:03 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_generate_impl() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_impl",
|
|
|
|
r#####"
|
|
|
|
struct Ctx<T: Clone> {
|
2021-01-06 20:15:48 +00:00
|
|
|
data: T,$0
|
2020-07-03 16:15:03 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Ctx<T: Clone> {
|
|
|
|
data: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Clone> Ctx<T> {
|
|
|
|
$0
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_generate_new() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_new",
|
|
|
|
r#####"
|
|
|
|
struct Ctx<T: Clone> {
|
2021-01-06 20:15:48 +00:00
|
|
|
data: T,$0
|
2020-07-03 16:15:03 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Ctx<T: Clone> {
|
|
|
|
data: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Clone> Ctx<T> {
|
|
|
|
fn $0new(data: T) -> Self { Self { data } }
|
|
|
|
}
|
2021-02-09 11:30:13 +00:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2020-07-03 16:15:03 +00:00
|
|
|
|
2021-02-09 11:30:13 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_generate_setter() {
|
|
|
|
check_doc_test(
|
|
|
|
"generate_setter",
|
|
|
|
r#####"
|
|
|
|
struct Person {
|
|
|
|
nam$0e: String,
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Person {
|
|
|
|
name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Person {
|
|
|
|
/// Set the person's name.
|
|
|
|
fn set_name(&mut self, name: String) {
|
|
|
|
self.name = name;
|
|
|
|
}
|
|
|
|
}
|
2020-07-03 16:15:03 +00:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-06 00:47:41 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_infer_function_return_type() {
|
|
|
|
check_doc_test(
|
|
|
|
"infer_function_return_type",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
fn foo() { 4$02i32 }
|
2020-11-06 00:47:41 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn foo() -> i32 { 42i32 }
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-02 05:47:35 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_inline_function() {
|
|
|
|
check_doc_test(
|
|
|
|
"inline_function",
|
|
|
|
r#####"
|
|
|
|
fn add(a: u32, b: u32) -> u32 { a + b }
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
let x = add$0(1, 2);
|
2021-01-02 05:47:35 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn add(a: u32, b: u32) -> u32 { a + b }
|
|
|
|
fn main() {
|
|
|
|
let x = {
|
|
|
|
let a = 1;
|
|
|
|
let b = 2;
|
|
|
|
a + b
|
|
|
|
};
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-26 16:08:13 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_inline_local_variable() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-26 16:08:13 +00:00
|
|
|
"inline_local_variable",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
let x$0 = 1 + 2;
|
2019-10-26 16:08:13 +00:00
|
|
|
x * 4;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
(1 + 2) * 4;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-26 16:58:18 +00:00
|
|
|
|
2020-06-01 13:36:51 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_introduce_named_lifetime() {
|
|
|
|
check_doc_test(
|
|
|
|
"introduce_named_lifetime",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
impl Cursor<'_$0> {
|
2020-06-01 13:36:51 +00:00
|
|
|
fn node(self) -> &SyntaxNode {
|
|
|
|
match self {
|
|
|
|
Cursor::Replace(node) | Cursor::Before(node) => node,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
impl<'a> Cursor<'a> {
|
|
|
|
fn node(self) -> &SyntaxNode {
|
|
|
|
match self {
|
|
|
|
Cursor::Replace(node) | Cursor::Before(node) => node,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-21 18:51:40 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_invert_if() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-11-21 18:51:40 +00:00
|
|
|
"invert_if",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
if$0 !y { A } else { B }
|
2019-11-21 18:51:40 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2019-11-24 05:14:57 +00:00
|
|
|
if y { B } else { A }
|
2019-11-21 18:51:40 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 09:22:53 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_make_raw_string() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 09:22:53 +00:00
|
|
|
"make_raw_string",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
"Hello,$0 World!";
|
2019-10-27 09:22:53 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r#"Hello, World!"#;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_make_usual_string() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 09:22:53 +00:00
|
|
|
"make_usual_string",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
r#"Hello,$0 "World!""#;
|
2019-10-27 09:22:53 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
"Hello, \"World!\"";
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-18 15:41:24 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_merge_imports() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2020-03-18 15:41:24 +00:00
|
|
|
"merge_imports",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
use std::$0fmt::Formatter;
|
2020-03-18 15:41:24 +00:00
|
|
|
use std::io;
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::{fmt::Formatter, io};
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 08:26:46 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_merge_match_arms() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 08:26:46 +00:00
|
|
|
"merge_match_arms",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0Action::Move(..) => foo(),
|
2019-10-27 08:26:46 +00:00
|
|
|
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() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 08:26:46 +00:00
|
|
|
"move_arm_cond_to_match_guard",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
2021-01-06 20:15:48 +00:00
|
|
|
Action::Move { distance } => $0if distance > 10 { foo() },
|
2019-10-27 08:26:46 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
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() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 08:26:46 +00:00
|
|
|
"move_bounds_to_where_clause",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U {
|
2019-10-27 08:26:46 +00:00
|
|
|
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() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 08:26:46 +00:00
|
|
|
"move_guard_to_arm_body",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
2021-01-06 20:15:48 +00:00
|
|
|
Action::Move { distance } $0if distance > 10 => foo(),
|
2019-10-27 08:26:46 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
2020-08-13 08:32:03 +00:00
|
|
|
Action::Move { distance } => if distance > 10 {
|
|
|
|
foo()
|
|
|
|
},
|
2019-10-27 08:26:46 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2019-10-27 09:22:53 +00:00
|
|
|
|
2021-01-06 13:24:47 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_move_module_to_file() {
|
|
|
|
check_doc_test(
|
|
|
|
"move_module_to_file",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
mod $0foo {
|
2021-01-06 13:24:47 +00:00
|
|
|
fn t() {}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
mod foo;
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:38:34 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_pull_assignment_up() {
|
|
|
|
check_doc_test(
|
|
|
|
"pull_assignment_up",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let mut foo = 6;
|
|
|
|
|
|
|
|
if true {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0foo = 5;
|
2021-01-04 13:38:34 +00:00
|
|
|
} else {
|
|
|
|
foo = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let mut foo = 6;
|
|
|
|
|
|
|
|
foo = if true {
|
|
|
|
5
|
|
|
|
} else {
|
|
|
|
4
|
|
|
|
};
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-10-14 19:40:51 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_qualify_path() {
|
|
|
|
check_doc_test(
|
|
|
|
"qualify_path",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
let map = HashMap$0::new();
|
2020-10-14 19:40:51 +00:00
|
|
|
}
|
|
|
|
pub mod std { pub mod collections { pub struct HashMap { } } }
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let map = std::collections::HashMap::new();
|
|
|
|
}
|
|
|
|
pub mod std { pub mod collections { pub struct HashMap { } } }
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 09:22:53 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_remove_dbg() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 09:22:53 +00:00
|
|
|
"remove_dbg",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0dbg!(92);
|
2019-10-27 09:22:53 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
92;
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_remove_hash() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 09:22:53 +00:00
|
|
|
"remove_hash",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
r#"Hello,$0 World!"#;
|
2019-10-27 09:22:53 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
r"Hello, World!";
|
|
|
|
}
|
2020-02-19 11:44:20 +00:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_remove_mut() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2020-02-19 11:44:20 +00:00
|
|
|
"remove_mut",
|
|
|
|
r#####"
|
|
|
|
impl Walrus {
|
2021-01-06 20:15:48 +00:00
|
|
|
fn feed(&mut$0 self, amount: u32) {}
|
2020-02-19 11:44:20 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
impl Walrus {
|
|
|
|
fn feed(&self, amount: u32) {}
|
|
|
|
}
|
2019-10-27 09:22:53 +00:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-19 16:44:33 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_remove_unused_param() {
|
|
|
|
check_doc_test(
|
|
|
|
"remove_unused_param",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
fn frobnicate(x: i32$0) {}
|
2020-08-19 16:44:33 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
frobnicate(92);
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn frobnicate() {}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
frobnicate();
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-11 18:32:58 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_reorder_fields() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2020-04-11 18:32:58 +00:00
|
|
|
"reorder_fields",
|
|
|
|
r#####"
|
|
|
|
struct Foo {foo: i32, bar: i32};
|
2021-01-06 20:15:48 +00:00
|
|
|
const test: Foo = $0Foo {bar: 0, foo: 1}
|
2020-04-11 18:32:58 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
struct Foo {foo: i32, bar: i32};
|
|
|
|
const test: Foo = Foo {foo: 1, bar: 0}
|
2020-12-10 19:42:04 +00:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_reorder_impl() {
|
|
|
|
check_doc_test(
|
|
|
|
"reorder_impl",
|
|
|
|
r#####"
|
|
|
|
trait Foo {
|
|
|
|
fn a() {}
|
|
|
|
fn b() {}
|
|
|
|
fn c() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Bar;
|
|
|
|
$0impl Foo for Bar {
|
|
|
|
fn b() {}
|
|
|
|
fn c() {}
|
|
|
|
fn a() {}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
trait Foo {
|
|
|
|
fn a() {}
|
|
|
|
fn b() {}
|
|
|
|
fn c() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Bar;
|
|
|
|
impl Foo for Bar {
|
|
|
|
fn a() {}
|
|
|
|
fn b() {}
|
|
|
|
fn c() {}
|
|
|
|
}
|
2020-04-11 18:32:58 +00:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-09 12:07:18 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_derive_with_manual_impl() {
|
|
|
|
check_doc_test(
|
|
|
|
"replace_derive_with_manual_impl",
|
|
|
|
r#####"
|
|
|
|
trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
|
2021-01-06 20:15:48 +00:00
|
|
|
#[derive(Deb$0ug, Display)]
|
2020-11-09 12:07:18 +00:00
|
|
|
struct S;
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
|
|
|
|
#[derive(Display)]
|
|
|
|
struct S;
|
|
|
|
|
|
|
|
impl Debug for S {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<()> {
|
|
|
|
${0:todo!()}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-28 18:11:41 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_for_loop_with_for_each() {
|
|
|
|
check_doc_test(
|
|
|
|
"replace_for_loop_with_for_each",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let x = vec![1, 2, 3];
|
|
|
|
for$0 v in x {
|
|
|
|
let y = v * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
let x = vec![1, 2, 3];
|
|
|
|
x.into_iter().for_each(|v| {
|
|
|
|
let y = v * 2;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 09:22:53 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_if_let_with_match() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 09:22:53 +00:00
|
|
|
"replace_if_let_with_match",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0if let Action::Move { distance } = action {
|
2019-10-27 09:22:53 +00:00
|
|
|
foo(distance)
|
|
|
|
} else {
|
|
|
|
bar()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
match action {
|
|
|
|
Action::Move { distance } => foo(distance),
|
|
|
|
_ => bar(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:28:08 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_impl_trait_with_generic() {
|
|
|
|
check_doc_test(
|
|
|
|
"replace_impl_trait_with_generic",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
fn foo(bar: $0impl Bar) {}
|
2020-09-04 12:28:08 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
2020-09-04 19:58:50 +00:00
|
|
|
fn foo<B: Bar>(bar: B) {}
|
2020-09-04 12:28:08 +00:00
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-27 11:12:17 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_let_with_if_let() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2020-03-27 11:12:17 +00:00
|
|
|
"replace_let_with_if_let",
|
|
|
|
r#####"
|
|
|
|
enum Option<T> { Some(T), None }
|
|
|
|
|
|
|
|
fn main(action: Action) {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0let x = compute();
|
2020-03-27 11:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-12-05 14:41:36 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_match_with_if_let() {
|
|
|
|
check_doc_test(
|
|
|
|
"replace_match_with_if_let",
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
2021-01-06 20:15:48 +00:00
|
|
|
$0match action {
|
2020-12-05 14:41:36 +00:00
|
|
|
Action::Move { distance } => foo(distance),
|
|
|
|
_ => bar(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
enum Action { Move { distance: u32 }, Stop }
|
|
|
|
|
|
|
|
fn handle(action: Action) {
|
|
|
|
if let Action::Move { distance } = action {
|
|
|
|
foo(distance)
|
|
|
|
} else {
|
|
|
|
bar()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-02-07 21:35:34 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_qualified_name_with_use() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2020-02-07 21:35:34 +00:00
|
|
|
"replace_qualified_name_with_use",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
fn process(map: std::collections::$0HashMap<String, String>) {}
|
2020-02-07 21:35:34 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
fn process(map: HashMap<String, String>) {}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-10-17 14:08:25 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_string_with_char() {
|
|
|
|
check_doc_test(
|
|
|
|
"replace_string_with_char",
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
2021-01-06 20:15:48 +00:00
|
|
|
find("{$0");
|
2020-10-17 14:08:25 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn main() {
|
|
|
|
find('{');
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-26 09:16:10 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_replace_unwrap_with_match() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2020-03-26 09:16:10 +00:00
|
|
|
"replace_unwrap_with_match",
|
|
|
|
r#####"
|
|
|
|
enum Result<T, E> { Ok(T), Err(E) }
|
|
|
|
fn main() {
|
|
|
|
let x: Result<i32, i32> = Result::Ok(92);
|
2021-01-06 20:15:48 +00:00
|
|
|
let y = x.$0unwrap();
|
2020-03-26 09:16:10 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
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,
|
2020-05-20 22:01:08 +00:00
|
|
|
$0_ => unreachable!(),
|
2020-03-26 09:16:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-27 09:22:53 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_split_import() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2019-10-27 09:22:53 +00:00
|
|
|
"split_import",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
use std::$0collections::HashMap;
|
2019-10-27 09:22:53 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::{collections::HashMap};
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2020-04-29 11:52:55 +00:00
|
|
|
|
2020-11-30 10:45:32 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_toggle_ignore() {
|
|
|
|
check_doc_test(
|
|
|
|
"toggle_ignore",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
$0#[test]
|
2020-11-30 10:45:32 +00:00
|
|
|
fn arithmetics {
|
|
|
|
assert_eq!(2 + 2, 5);
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn arithmetics {
|
|
|
|
assert_eq!(2 + 2, 5);
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-01-15 19:14:51 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_unmerge_use() {
|
|
|
|
check_doc_test(
|
|
|
|
"unmerge_use",
|
|
|
|
r#####"
|
|
|
|
use std::fmt::{Debug, Display$0};
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
use std::fmt::{Debug};
|
|
|
|
use std::fmt::Display;
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-29 11:52:55 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_unwrap_block() {
|
2020-05-06 08:21:35 +00:00
|
|
|
check_doc_test(
|
2020-04-29 11:52:55 +00:00
|
|
|
"unwrap_block",
|
|
|
|
r#####"
|
|
|
|
fn foo() {
|
2021-01-06 20:15:48 +00:00
|
|
|
if true {$0
|
2020-04-29 11:52:55 +00:00
|
|
|
println!("foo");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn foo() {
|
2020-04-29 12:53:47 +00:00
|
|
|
println!("foo");
|
2020-04-29 11:52:55 +00:00
|
|
|
}
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|
2020-11-09 12:18:40 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_wrap_return_type_in_result() {
|
|
|
|
check_doc_test(
|
|
|
|
"wrap_return_type_in_result",
|
|
|
|
r#####"
|
2021-01-06 20:15:48 +00:00
|
|
|
fn foo() -> i32$0 { 42i32 }
|
2020-11-09 12:18:40 +00:00
|
|
|
"#####,
|
|
|
|
r#####"
|
|
|
|
fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
|
|
|
|
"#####,
|
|
|
|
)
|
|
|
|
}
|