1 //! Generated by `sourcegen_assists_docs`, do not edit by hand.
3 use super::check_doc_test;
6 fn doctest_add_explicit_type() {
23 fn doctest_add_hash() {
40 fn doctest_add_impl_default_members() {
42 "add_impl_default_members",
73 fn doctest_add_impl_missing_members() {
75 "add_impl_missing_members",
83 impl Trait<u32> for () {$0
94 impl Trait<u32> for () {
97 fn foo(&self) -> u32 {
106 fn doctest_add_lifetime_to_type() {
108 "add_lifetime_to_type",
125 fn doctest_add_missing_match_arms() {
127 "add_missing_match_arms",
129 enum Action { Move { distance: u32 }, Stop }
131 fn handle(action: Action) {
138 enum Action { Move { distance: u32 }, Stop }
140 fn handle(action: Action) {
142 $0Action::Move { distance } => todo!(),
143 Action::Stop => todo!(),
151 fn doctest_add_return_type() {
158 fn foo() -> i32 { 42i32 }
164 fn doctest_add_turbo_fish() {
168 fn make<T>() -> T { todo!() }
174 fn make<T>() -> T { todo!() }
176 let x = make::<${0:_}>();
183 fn doctest_apply_demorgan() {
188 if x != 4 ||$0 y < 3.14 {}
193 if !(x == 4 && y >= 3.14) {}
200 fn doctest_auto_import() {
205 let map = HashMap$0::new();
207 pub mod std { pub mod collections { pub struct HashMap { } } }
210 use std::collections::HashMap;
213 let map = HashMap::new();
215 pub mod std { pub mod collections { pub struct HashMap { } } }
221 fn doctest_change_visibility() {
228 pub(crate) fn frobnicate() {}
234 fn doctest_convert_bool_then_to_if() {
236 "convert_bool_then_to_if",
238 //- minicore: bool_impl
240 (0 == 0).then$0(|| val)
256 fn doctest_convert_for_loop_with_for_each() {
258 "convert_for_loop_with_for_each",
261 let x = vec![1, 2, 3];
269 let x = vec![1, 2, 3];
270 x.into_iter().for_each(|v| {
279 fn doctest_convert_if_to_bool_then() {
281 "convert_if_to_bool_then",
301 fn doctest_convert_integer_literal() {
303 "convert_integer_literal",
308 const _: i32 = 0b1010;
314 fn doctest_convert_into_to_from() {
316 "convert_into_to_from",
319 impl $0Into<Thing> for usize {
320 fn into(self) -> Thing {
329 impl From<usize> for Thing {
330 fn from(val: usize) -> Self {
342 fn doctest_convert_iter_for_each_to_for() {
344 "convert_iter_for_each_to_for",
346 //- minicore: iterators
349 let iter = iter::repeat((9, 2));
350 iter.for_each$0(|(x, y)| {
351 println!("x: {}, y: {}", x, y);
358 let iter = iter::repeat((9, 2));
360 println!("x: {}, y: {}", x, y);
368 fn doctest_convert_to_guarded_return() {
370 "convert_to_guarded_return",
392 fn doctest_convert_tuple_struct_to_named_struct() {
394 "convert_tuple_struct_to_named_struct",
396 struct Point$0(f32, f32);
399 pub fn new(x: f32, y: f32) -> Self {
403 pub fn x(&self) -> f32 {
407 pub fn y(&self) -> f32 {
413 struct Point { field1: f32, field2: f32 }
416 pub fn new(x: f32, y: f32) -> Self {
417 Point { field1: x, field2: y }
420 pub fn x(&self) -> f32 {
424 pub fn y(&self) -> f32 {
433 fn doctest_convert_while_to_loop() {
435 "convert_while_to_loop",
457 fn doctest_destructure_tuple_binding() {
459 "destructure_tuple_binding",
468 let ($0_0, _1) = (1,2);
476 fn doctest_expand_glob_import() {
478 "expand_glob_import",
487 fn qux(bar: Bar, baz: Baz) {}
497 fn qux(bar: Bar, baz: Baz) {}
503 fn doctest_extract_function() {
522 fn $0fun_name(n: i32) {
532 fn doctest_extract_module() {
536 $0fn foo(name: i32) -> i32 {
540 fn bar(name: i32) -> i32 {
546 pub(crate) fn foo(name: i32) -> i32 {
551 fn bar(name: i32) -> i32 {
559 fn doctest_extract_struct_from_enum_variant() {
561 "extract_struct_from_enum_variant",
563 enum A { $0One(u32, u32) }
566 struct One(u32, u32);
574 fn doctest_extract_type_alias() {
576 "extract_type_alias",
579 field: $0(u8, u8, u8)$0,
583 type $0Type = (u8, u8, u8);
593 fn doctest_extract_variable() {
603 let $0var_name = (1 + 2);
611 fn doctest_fix_visibility() {
624 $0pub(crate) fn frobnicate() {}
634 fn doctest_flip_binexpr() {
651 fn doctest_flip_comma() {
668 fn doctest_flip_trait_bound() {
672 fn foo<T: Clone +$0 Copy>() { }
675 fn foo<T: Copy + Clone>() { }
681 fn doctest_generate_constant() {
685 struct S { i: usize }
686 impl S { pub fn new(n: usize) {} }
688 let v = S::new(CAPA$0CITY);
692 struct S { i: usize }
693 impl S { pub fn new(n: usize) {} }
695 const CAPACITY: usize = $0;
696 let v = S::new(CAPACITY);
703 fn doctest_generate_default_from_enum_variant() {
705 "generate_default_from_enum_variant",
720 impl Default for Version {
721 fn default() -> Self {
730 fn doctest_generate_default_from_new() {
732 "generate_default_from_new",
734 struct Example { _inner: () }
737 pub fn n$0ew() -> Self {
743 struct Example { _inner: () }
746 pub fn new() -> Self {
751 impl Default for Example {
752 fn default() -> Self {
761 fn doctest_generate_delegate_methods() {
763 "generate_delegate_methods",
767 fn age(&self) -> u8 {
779 fn age(&self) -> u8 {
789 $0fn age(&self) -> u8 {
798 fn doctest_generate_deref() {
813 impl std::ops::Deref for B {
816 fn deref(&self) -> &Self::Target {
825 fn doctest_generate_derive() {
845 fn doctest_generate_documentation_template() {
847 "generate_documentation_template",
849 pub fn my_$0func(a: i32, b: i32) -> Result<(), std::io::Error> {
859 /// use test::my_func;
861 /// assert_eq!(my_func(a, b), );
866 /// This function will return an error if .
867 pub fn my_func(a: i32, b: i32) -> Result<(), std::io::Error> {
875 fn doctest_generate_enum_as_method() {
877 "generate_enum_as_method",
891 fn as_text(&self) -> Option<&String> {
892 if let Self::Text(v) = self {
904 fn doctest_generate_enum_is_method() {
906 "generate_enum_is_method",
922 /// Returns `true` if the version is [`Minor`].
924 /// [`Minor`]: Version::Minor
925 fn is_minor(&self) -> bool {
926 matches!(self, Self::Minor)
934 fn doctest_generate_enum_try_into_method() {
936 "generate_enum_try_into_method",
950 fn try_into_text(self) -> Result<String, Self> {
951 if let Self::Text(v) = self {
963 fn doctest_generate_from_impl_for_enum() {
965 "generate_from_impl_for_enum",
967 enum A { $0One(u32) }
972 impl From<u32> for A {
973 fn from(v: u32) -> Self {
982 fn doctest_generate_function() {
987 fn baz() -> Baz { Baz }
995 fn baz() -> Baz { Baz }
1000 fn bar(arg: &str, baz: Baz) ${0:-> _} {
1009 fn doctest_generate_getter() {
1013 //- minicore: as_ref
1015 impl AsRef<str> for String {
1016 fn as_ref(&self) -> &str {
1027 impl AsRef<str> for String {
1028 fn as_ref(&self) -> &str {
1038 /// Get a reference to the person's name.
1039 fn $0name(&self) -> &str {
1048 fn doctest_generate_getter_mut() {
1050 "generate_getter_mut",
1062 /// Get a mutable reference to the person's name.
1063 fn $0name_mut(&mut self) -> &mut String {
1072 fn doctest_generate_impl() {
1076 struct Ctx<T: Clone> {
1081 struct Ctx<T: Clone> {
1085 impl<T: Clone> Ctx<T> {
1093 fn doctest_generate_is_empty_from_len() {
1095 "generate_is_empty_from_len",
1097 struct MyStruct { data: Vec<String> }
1100 p$0ub fn len(&self) -> usize {
1106 struct MyStruct { data: Vec<String> }
1109 pub fn len(&self) -> usize {
1113 pub fn is_empty(&self) -> bool {
1122 fn doctest_generate_new() {
1126 struct Ctx<T: Clone> {
1131 struct Ctx<T: Clone> {
1135 impl<T: Clone> Ctx<T> {
1136 fn $0new(data: T) -> Self { Self { data } }
1143 fn doctest_generate_setter() {
1157 /// Set the person's name.
1158 fn set_name(&mut self, name: String) {
1167 fn doctest_inline_call() {
1171 //- minicore: option
1172 fn foo(name: Option<&str>) {
1173 let name = name.unwrap$0();
1177 fn foo(name: Option<&str>) {
1178 let name = match name {
1180 None => panic!("called `Option::unwrap()` on a `None` value"),
1188 fn doctest_inline_into_callers() {
1190 "inline_into_callers",
1192 fn print(_: &str) {}
1193 fn foo$0(word: &str) {
1194 if !word.is_empty() {
1199 foo("안녕하세요");
1204 fn print(_: &str) {}
1208 let word = "안녕하세요";
1209 if !word.is_empty() {
1214 let word = "여러분";
1215 if !word.is_empty() {
1225 fn doctest_inline_local_variable() {
1227 "inline_local_variable",
1243 fn doctest_introduce_named_generic() {
1245 "introduce_named_generic",
1247 fn foo(bar: $0impl Bar) {}
1250 fn foo<B: Bar>(bar: B) {}
1256 fn doctest_introduce_named_lifetime() {
1258 "introduce_named_lifetime",
1261 fn node(self) -> &SyntaxNode {
1263 Cursor::Replace(node) | Cursor::Before(node) => node,
1269 impl<'a> Cursor<'a> {
1270 fn node(self) -> &SyntaxNode {
1272 Cursor::Replace(node) | Cursor::Before(node) => node,
1281 fn doctest_invert_if() {
1286 if$0 !y { A } else { B }
1291 if y { B } else { A }
1298 fn doctest_line_to_block() {
1315 fn doctest_make_raw_string() {
1332 fn doctest_make_usual_string() {
1334 "make_usual_string",
1337 r#"Hello,$0 "World!""#;
1342 "Hello, \"World!\"";
1349 fn doctest_merge_imports() {
1353 use std::$0fmt::Formatter;
1357 use std::{fmt::Formatter, io};
1363 fn doctest_merge_match_arms() {
1367 enum Action { Move { distance: u32 }, Stop }
1369 fn handle(action: Action) {
1371 $0Action::Move(..) => foo(),
1372 Action::Stop => foo(),
1377 enum Action { Move { distance: u32 }, Stop }
1379 fn handle(action: Action) {
1381 Action::Move(..) | Action::Stop => foo(),
1389 fn doctest_move_arm_cond_to_match_guard() {
1391 "move_arm_cond_to_match_guard",
1393 enum Action { Move { distance: u32 }, Stop }
1395 fn handle(action: Action) {
1397 Action::Move { distance } => $0if distance > 10 { foo() },
1403 enum Action { Move { distance: u32 }, Stop }
1405 fn handle(action: Action) {
1407 Action::Move { distance } if distance > 10 => foo(),
1416 fn doctest_move_bounds_to_where_clause() {
1418 "move_bounds_to_where_clause",
1420 fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U {
1425 fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
1433 fn doctest_move_from_mod_rs() {
1449 fn doctest_move_guard_to_arm_body() {
1451 "move_guard_to_arm_body",
1453 enum Action { Move { distance: u32 }, Stop }
1455 fn handle(action: Action) {
1457 Action::Move { distance } $0if distance > 10 => foo(),
1463 enum Action { Move { distance: u32 }, Stop }
1465 fn handle(action: Action) {
1467 Action::Move { distance } => if distance > 10 {
1478 fn doctest_move_module_to_file() {
1480 "move_module_to_file",
1493 fn doctest_move_to_mod_rs() {
1509 fn doctest_promote_local_to_const() {
1511 "promote_local_to_const",
1517 println!("It's true");
1519 println!("It's false");
1525 const $0FOO: bool = true;
1528 println!("It's true");
1530 println!("It's false");
1538 fn doctest_pull_assignment_up() {
1540 "pull_assignment_up",
1567 fn doctest_qualify_method_call() {
1569 "qualify_method_call",
1594 fn doctest_qualify_path() {
1599 let map = HashMap$0::new();
1601 pub mod std { pub mod collections { pub struct HashMap { } } }
1605 let map = std::collections::HashMap::new();
1607 pub mod std { pub mod collections { pub struct HashMap { } } }
1613 fn doctest_reformat_number_literal() {
1615 "reformat_number_literal",
1617 const _: i32 = 1012345$0;
1620 const _: i32 = 1_012_345;
1626 fn doctest_remove_dbg() {
1643 fn doctest_remove_hash() {
1648 r#"Hello,$0 World!"#;
1660 fn doctest_remove_mut() {
1665 fn feed(&mut$0 self, amount: u32) {}
1670 fn feed(&self, amount: u32) {}
1677 fn doctest_remove_unused_param() {
1679 "remove_unused_param",
1681 fn frobnicate(x: i32$0) {}
1698 fn doctest_reorder_fields() {
1702 struct Foo {foo: i32, bar: i32};
1703 const test: Foo = $0Foo {bar: 0, foo: 1}
1706 struct Foo {foo: i32, bar: i32};
1707 const test: Foo = Foo {foo: 1, bar: 0}
1713 fn doctest_reorder_impl() {
1724 $0impl Foo for Bar {
1748 fn doctest_replace_char_with_string() {
1750 "replace_char_with_string",
1765 fn doctest_replace_derive_with_manual_impl() {
1767 "replace_derive_with_manual_impl",
1769 trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
1770 #[derive(Deb$0ug, Display)]
1774 trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
1779 $0fn fmt(&self, f: &mut Formatter) -> Result<()> {
1780 f.debug_struct("S").finish()
1788 fn doctest_replace_if_let_with_match() {
1790 "replace_if_let_with_match",
1792 enum Action { Move { distance: u32 }, Stop }
1794 fn handle(action: Action) {
1795 $0if let Action::Move { distance } = action {
1803 enum Action { Move { distance: u32 }, Stop }
1805 fn handle(action: Action) {
1807 Action::Move { distance } => foo(distance),
1816 fn doctest_replace_let_with_if_let() {
1818 "replace_let_with_if_let",
1820 enum Option<T> { Some(T), None }
1822 fn main(action: Action) {
1823 $0let x = compute();
1826 fn compute() -> Option<i32> { None }
1829 enum Option<T> { Some(T), None }
1831 fn main(action: Action) {
1832 if let Some(x) = compute() {
1836 fn compute() -> Option<i32> { None }
1842 fn doctest_replace_match_with_if_let() {
1844 "replace_match_with_if_let",
1846 enum Action { Move { distance: u32 }, Stop }
1848 fn handle(action: Action) {
1850 Action::Move { distance } => foo(distance),
1856 enum Action { Move { distance: u32 }, Stop }
1858 fn handle(action: Action) {
1859 if let Action::Move { distance } = action {
1870 fn doctest_replace_qualified_name_with_use() {
1872 "replace_qualified_name_with_use",
1874 mod std { pub mod collections { pub struct HashMap<T, U>(T, U); } }
1875 fn process(map: std::collections::$0HashMap<String, String>) {}
1878 use std::collections::HashMap;
1880 mod std { pub mod collections { pub struct HashMap<T, U>(T, U); } }
1881 fn process(map: HashMap<String, String>) {}
1887 fn doctest_replace_string_with_char() {
1889 "replace_string_with_char",
1904 fn doctest_replace_try_expr_with_match() {
1906 "replace_try_expr_with_match",
1910 let pat = Some(true)$0?;
1915 let pat = match Some(true) {
1917 None => return None,
1925 fn doctest_replace_turbofish_with_explicit_type() {
1927 "replace_turbofish_with_explicit_type",
1929 fn make<T>() -> T { ) }
1931 let a = make$0::<i32>();
1935 fn make<T>() -> T { ) }
1937 let a: i32 = make();
1944 fn doctest_sort_items() {
1948 struct $0Foo$0 { second: u32, first: String }
1951 struct Foo { first: String, second: u32 }
1957 fn doctest_sort_items_1() {
1962 fn second(&self) -> u32;
1963 fn first(&self) -> String;
1968 fn first(&self) -> String;
1969 fn second(&self) -> u32;
1976 fn doctest_sort_items_2() {
1982 fn second(&self) -> u32;
1983 fn first(&self) -> String;
1989 fn first(&self) -> String;
1990 fn second(&self) -> u32;
1997 fn doctest_sort_items_3() {
2003 Cat { weight: f64, name: String },
2008 Cat { weight: f64, name: String },
2016 fn doctest_sort_items_4() {
2022 Cat $0{ weight: f64, name: String }$0,
2028 Cat { name: String, weight: f64 },
2035 fn doctest_split_import() {
2039 use std::$0collections::HashMap;
2042 use std::{collections::HashMap};
2048 fn doctest_toggle_ignore() {
2054 assert_eq!(2 + 2, 5);
2061 assert_eq!(2 + 2, 5);
2068 fn doctest_unmerge_use() {
2072 use std::fmt::{Debug, Display$0};
2075 use std::fmt::{Debug};
2076 use std::fmt::Display;
2082 fn doctest_unwrap_block() {
2101 fn doctest_unwrap_result_return_type() {
2103 "unwrap_result_return_type",
2105 //- minicore: result
2106 fn foo() -> Result<i32>$0 { Ok(42i32) }
2109 fn foo() -> i32 { 42i32 }
2115 fn doctest_wrap_return_type_in_result() {
2117 "wrap_return_type_in_result",
2119 //- minicore: result
2120 fn foo() -> i32$0 { 42i32 }
2123 fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }