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_label_to_loop() {
129 fn doctest_add_lifetime_to_type() {
131 "add_lifetime_to_type",
148 fn doctest_add_missing_match_arms() {
150 "add_missing_match_arms",
152 enum Action { Move { distance: u32 }, Stop }
154 fn handle(action: Action) {
161 enum Action { Move { distance: u32 }, Stop }
163 fn handle(action: Action) {
165 $0Action::Move { distance } => todo!(),
166 Action::Stop => todo!(),
174 fn doctest_add_return_type() {
181 fn foo() -> i32 { 42i32 }
187 fn doctest_add_turbo_fish() {
191 fn make<T>() -> T { todo!() }
197 fn make<T>() -> T { todo!() }
199 let x = make::<${0:_}>();
206 fn doctest_apply_demorgan() {
211 if x != 4 ||$0 y < 3.14 {}
216 if !(x == 4 && y >= 3.14) {}
223 fn doctest_auto_import() {
228 let map = HashMap$0::new();
230 pub mod std { pub mod collections { pub struct HashMap { } } }
233 use std::collections::HashMap;
236 let map = HashMap::new();
238 pub mod std { pub mod collections { pub struct HashMap { } } }
244 fn doctest_change_visibility() {
251 pub(crate) fn frobnicate() {}
257 fn doctest_convert_bool_then_to_if() {
259 "convert_bool_then_to_if",
261 //- minicore: bool_impl
263 (0 == 0).then$0(|| val)
279 fn doctest_convert_for_loop_with_for_each() {
281 "convert_for_loop_with_for_each",
284 let x = vec![1, 2, 3];
292 let x = vec![1, 2, 3];
293 x.into_iter().for_each(|v| {
302 fn doctest_convert_if_to_bool_then() {
304 "convert_if_to_bool_then",
324 fn doctest_convert_integer_literal() {
326 "convert_integer_literal",
331 const _: i32 = 0b1010;
337 fn doctest_convert_into_to_from() {
339 "convert_into_to_from",
342 impl $0Into<Thing> for usize {
343 fn into(self) -> Thing {
352 impl From<usize> for Thing {
353 fn from(val: usize) -> Self {
365 fn doctest_convert_iter_for_each_to_for() {
367 "convert_iter_for_each_to_for",
369 //- minicore: iterators
372 let iter = iter::repeat((9, 2));
373 iter.for_each$0(|(x, y)| {
374 println!("x: {}, y: {}", x, y);
381 let iter = iter::repeat((9, 2));
383 println!("x: {}, y: {}", x, y);
391 fn doctest_convert_let_else_to_match() {
393 "convert_let_else_to_match",
396 let Ok(mut x) = f() else$0 { return };
401 let mut x = match f() {
411 fn doctest_convert_to_guarded_return() {
413 "convert_to_guarded_return",
435 fn doctest_convert_tuple_struct_to_named_struct() {
437 "convert_tuple_struct_to_named_struct",
439 struct Point$0(f32, f32);
442 pub fn new(x: f32, y: f32) -> Self {
446 pub fn x(&self) -> f32 {
450 pub fn y(&self) -> f32 {
456 struct Point { field1: f32, field2: f32 }
459 pub fn new(x: f32, y: f32) -> Self {
460 Point { field1: x, field2: y }
463 pub fn x(&self) -> f32 {
467 pub fn y(&self) -> f32 {
476 fn doctest_convert_while_to_loop() {
478 "convert_while_to_loop",
500 fn doctest_destructure_tuple_binding() {
502 "destructure_tuple_binding",
511 let ($0_0, _1) = (1,2);
519 fn doctest_expand_glob_import() {
521 "expand_glob_import",
530 fn qux(bar: Bar, baz: Baz) {}
540 fn qux(bar: Bar, baz: Baz) {}
546 fn doctest_extract_function() {
565 fn $0fun_name(n: i32) {
575 fn doctest_extract_module() {
579 $0fn foo(name: i32) -> i32 {
583 fn bar(name: i32) -> i32 {
589 pub(crate) fn foo(name: i32) -> i32 {
594 fn bar(name: i32) -> i32 {
602 fn doctest_extract_struct_from_enum_variant() {
604 "extract_struct_from_enum_variant",
606 enum A { $0One(u32, u32) }
609 struct One(u32, u32);
617 fn doctest_extract_type_alias() {
619 "extract_type_alias",
622 field: $0(u8, u8, u8)$0,
626 type $0Type = (u8, u8, u8);
636 fn doctest_extract_variable() {
646 let $0var_name = (1 + 2);
654 fn doctest_fix_visibility() {
667 $0pub(crate) fn frobnicate() {}
677 fn doctest_flip_binexpr() {
694 fn doctest_flip_comma() {
711 fn doctest_flip_trait_bound() {
715 fn foo<T: Clone +$0 Copy>() { }
718 fn foo<T: Copy + Clone>() { }
724 fn doctest_generate_constant() {
728 struct S { i: usize }
729 impl S { pub fn new(n: usize) {} }
731 let v = S::new(CAPA$0CITY);
735 struct S { i: usize }
736 impl S { pub fn new(n: usize) {} }
738 const CAPACITY: usize = $0;
739 let v = S::new(CAPACITY);
746 fn doctest_generate_default_from_enum_variant() {
748 "generate_default_from_enum_variant",
763 impl Default for Version {
764 fn default() -> Self {
773 fn doctest_generate_default_from_new() {
775 "generate_default_from_new",
777 struct Example { _inner: () }
780 pub fn n$0ew() -> Self {
786 struct Example { _inner: () }
789 pub fn new() -> Self {
794 impl Default for Example {
795 fn default() -> Self {
804 fn doctest_generate_delegate_methods() {
806 "generate_delegate_methods",
810 fn age(&self) -> u8 {
822 fn age(&self) -> u8 {
832 $0fn age(&self) -> u8 {
841 fn doctest_generate_deref() {
845 //- minicore: deref, deref_mut
857 impl core::ops::Deref for B {
860 fn deref(&self) -> &Self::Target {
869 fn doctest_generate_derive() {
889 fn doctest_generate_doc_example() {
891 "generate_doc_example",
893 /// Adds two numbers.$0
894 pub fn add(a: i32, b: i32) -> i32 { a + b }
897 /// Adds two numbers.
904 /// assert_eq!(add(a, b), );
906 pub fn add(a: i32, b: i32) -> i32 { a + b }
912 fn doctest_generate_documentation_template() {
914 "generate_documentation_template",
918 pub unsafe fn set_len$0(&mut self, len: usize) -> Result<(), std::io::Error> {
926 /// Sets the length of this [`S`].
930 /// This function will return an error if .
935 pub unsafe fn set_len(&mut self, len: usize) -> Result<(), std::io::Error> {
944 fn doctest_generate_enum_as_method() {
946 "generate_enum_as_method",
960 fn as_text(&self) -> Option<&String> {
961 if let Self::Text(v) = self {
973 fn doctest_generate_enum_is_method() {
975 "generate_enum_is_method",
991 /// Returns `true` if the version is [`Minor`].
993 /// [`Minor`]: Version::Minor
995 fn is_minor(&self) -> bool {
996 matches!(self, Self::Minor)
1004 fn doctest_generate_enum_try_into_method() {
1006 "generate_enum_try_into_method",
1020 fn try_into_text(self) -> Result<String, Self> {
1021 if let Self::Text(v) = self {
1033 fn doctest_generate_enum_variant() {
1035 "generate_enum_variant",
1042 let country = Countries::Lesotho$0;
1052 let country = Countries::Lesotho;
1059 fn doctest_generate_from_impl_for_enum() {
1061 "generate_from_impl_for_enum",
1063 enum A { $0One(u32) }
1068 impl From<u32> for A {
1069 fn from(v: u32) -> Self {
1078 fn doctest_generate_function() {
1080 "generate_function",
1083 fn baz() -> Baz { Baz }
1091 fn baz() -> Baz { Baz }
1096 fn bar(arg: &str, baz: Baz) ${0:-> _} {
1105 fn doctest_generate_getter() {
1109 //- minicore: as_ref
1111 impl AsRef<str> for String {
1112 fn as_ref(&self) -> &str {
1123 impl AsRef<str> for String {
1124 fn as_ref(&self) -> &str {
1134 fn $0name(&self) -> &str {
1143 fn doctest_generate_getter_mut() {
1145 "generate_getter_mut",
1157 fn $0name_mut(&mut self) -> &mut String {
1166 fn doctest_generate_impl() {
1170 struct Ctx<T: Clone> {
1175 struct Ctx<T: Clone> {
1179 impl<T: Clone> Ctx<T> {
1187 fn doctest_generate_is_empty_from_len() {
1189 "generate_is_empty_from_len",
1191 struct MyStruct { data: Vec<String> }
1195 p$0ub fn len(&self) -> usize {
1201 struct MyStruct { data: Vec<String> }
1205 pub fn len(&self) -> usize {
1210 pub fn is_empty(&self) -> bool {
1219 fn doctest_generate_new() {
1223 struct Ctx<T: Clone> {
1228 struct Ctx<T: Clone> {
1232 impl<T: Clone> Ctx<T> {
1233 fn $0new(data: T) -> Self { Self { data } }
1240 fn doctest_generate_setter() {
1254 fn set_name(&mut self, name: String) {
1263 fn doctest_inline_call() {
1267 //- minicore: option
1268 fn foo(name: Option<&str>) {
1269 let name = name.unwrap$0();
1273 fn foo(name: Option<&str>) {
1274 let name = match name {
1276 None => panic!("called `Option::unwrap()` on a `None` value"),
1284 fn doctest_inline_into_callers() {
1286 "inline_into_callers",
1288 fn print(_: &str) {}
1289 fn foo$0(word: &str) {
1290 if !word.is_empty() {
1295 foo("안녕하세요");
1300 fn print(_: &str) {}
1304 let word = "안녕하세요";
1305 if !word.is_empty() {
1310 let word = "여러분";
1311 if !word.is_empty() {
1321 fn doctest_inline_local_variable() {
1323 "inline_local_variable",
1339 fn doctest_inline_type_alias() {
1341 "inline_type_alias",
1343 type A<T = u32> = Vec<T>;
1350 type A<T = u32> = Vec<T>;
1360 fn doctest_introduce_named_generic() {
1362 "introduce_named_generic",
1364 fn foo(bar: $0impl Bar) {}
1367 fn foo<B: Bar>(bar: B) {}
1373 fn doctest_introduce_named_lifetime() {
1375 "introduce_named_lifetime",
1378 fn node(self) -> &SyntaxNode {
1380 Cursor::Replace(node) | Cursor::Before(node) => node,
1386 impl<'a> Cursor<'a> {
1387 fn node(self) -> &SyntaxNode {
1389 Cursor::Replace(node) | Cursor::Before(node) => node,
1398 fn doctest_invert_if() {
1403 if$0 !y { A } else { B }
1408 if y { B } else { A }
1415 fn doctest_line_to_block() {
1432 fn doctest_make_raw_string() {
1449 fn doctest_make_usual_string() {
1451 "make_usual_string",
1454 r#"Hello,$0 "World!""#;
1459 "Hello, \"World!\"";
1466 fn doctest_merge_imports() {
1470 use std::$0fmt::Formatter;
1474 use std::{fmt::Formatter, io};
1480 fn doctest_merge_match_arms() {
1484 enum Action { Move { distance: u32 }, Stop }
1486 fn handle(action: Action) {
1488 $0Action::Move(..) => foo(),
1489 Action::Stop => foo(),
1494 enum Action { Move { distance: u32 }, Stop }
1496 fn handle(action: Action) {
1498 Action::Move(..) | Action::Stop => foo(),
1506 fn doctest_move_arm_cond_to_match_guard() {
1508 "move_arm_cond_to_match_guard",
1510 enum Action { Move { distance: u32 }, Stop }
1512 fn handle(action: Action) {
1514 Action::Move { distance } => $0if distance > 10 { foo() },
1520 enum Action { Move { distance: u32 }, Stop }
1522 fn handle(action: Action) {
1524 Action::Move { distance } if distance > 10 => foo(),
1533 fn doctest_move_bounds_to_where_clause() {
1535 "move_bounds_to_where_clause",
1537 fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U {
1542 fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
1550 fn doctest_move_from_mod_rs() {
1566 fn doctest_move_guard_to_arm_body() {
1568 "move_guard_to_arm_body",
1570 enum Action { Move { distance: u32 }, Stop }
1572 fn handle(action: Action) {
1574 Action::Move { distance } $0if distance > 10 => foo(),
1580 enum Action { Move { distance: u32 }, Stop }
1582 fn handle(action: Action) {
1584 Action::Move { distance } => if distance > 10 {
1595 fn doctest_move_module_to_file() {
1597 "move_module_to_file",
1610 fn doctest_move_to_mod_rs() {
1626 fn doctest_promote_local_to_const() {
1628 "promote_local_to_const",
1634 println!("It's true");
1636 println!("It's false");
1642 const $0FOO: bool = true;
1645 println!("It's true");
1647 println!("It's false");
1655 fn doctest_pull_assignment_up() {
1657 "pull_assignment_up",
1684 fn doctest_qualify_method_call() {
1686 "qualify_method_call",
1711 fn doctest_qualify_path() {
1716 let map = HashMap$0::new();
1718 pub mod std { pub mod collections { pub struct HashMap { } } }
1722 let map = std::collections::HashMap::new();
1724 pub mod std { pub mod collections { pub struct HashMap { } } }
1730 fn doctest_reformat_number_literal() {
1732 "reformat_number_literal",
1734 const _: i32 = 1012345$0;
1737 const _: i32 = 1_012_345;
1743 fn doctest_remove_dbg() {
1760 fn doctest_remove_hash() {
1765 r#"Hello,$0 World!"#;
1777 fn doctest_remove_mut() {
1782 fn feed(&mut$0 self, amount: u32) {}
1787 fn feed(&self, amount: u32) {}
1794 fn doctest_remove_unused_param() {
1796 "remove_unused_param",
1798 fn frobnicate(x: i32$0) {}
1815 fn doctest_reorder_fields() {
1819 struct Foo {foo: i32, bar: i32};
1820 const test: Foo = $0Foo {bar: 0, foo: 1}
1823 struct Foo {foo: i32, bar: i32};
1824 const test: Foo = Foo {foo: 1, bar: 0}
1830 fn doctest_reorder_impl_items() {
1832 "reorder_impl_items",
1841 $0impl Foo for Bar {
1865 fn doctest_replace_char_with_string() {
1867 "replace_char_with_string",
1882 fn doctest_replace_derive_with_manual_impl() {
1884 "replace_derive_with_manual_impl",
1886 //- minicore: derive
1887 trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
1888 #[derive(Deb$0ug, Display)]
1892 trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
1897 $0fn fmt(&self, f: &mut Formatter) -> Result<()> {
1898 f.debug_struct("S").finish()
1906 fn doctest_replace_if_let_with_match() {
1908 "replace_if_let_with_match",
1910 enum Action { Move { distance: u32 }, Stop }
1912 fn handle(action: Action) {
1913 $0if let Action::Move { distance } = action {
1921 enum Action { Move { distance: u32 }, Stop }
1923 fn handle(action: Action) {
1925 Action::Move { distance } => foo(distance),
1934 fn doctest_replace_let_with_if_let() {
1936 "replace_let_with_if_let",
1938 enum Option<T> { Some(T), None }
1940 fn main(action: Action) {
1941 $0let x = compute();
1944 fn compute() -> Option<i32> { None }
1947 enum Option<T> { Some(T), None }
1949 fn main(action: Action) {
1950 if let Some(x) = compute() {
1954 fn compute() -> Option<i32> { None }
1960 fn doctest_replace_match_with_if_let() {
1962 "replace_match_with_if_let",
1964 enum Action { Move { distance: u32 }, Stop }
1966 fn handle(action: Action) {
1968 Action::Move { distance } => foo(distance),
1974 enum Action { Move { distance: u32 }, Stop }
1976 fn handle(action: Action) {
1977 if let Action::Move { distance } = action {
1988 fn doctest_replace_qualified_name_with_use() {
1990 "replace_qualified_name_with_use",
1992 mod std { pub mod collections { pub struct HashMap<T, U>(T, U); } }
1993 fn process(map: std::collections::$0HashMap<String, String>) {}
1996 use std::collections::HashMap;
1998 mod std { pub mod collections { pub struct HashMap<T, U>(T, U); } }
1999 fn process(map: HashMap<String, String>) {}
2005 fn doctest_replace_string_with_char() {
2007 "replace_string_with_char",
2022 fn doctest_replace_try_expr_with_match() {
2024 "replace_try_expr_with_match",
2028 let pat = Some(true)$0?;
2033 let pat = match Some(true) {
2035 None => return None,
2043 fn doctest_replace_turbofish_with_explicit_type() {
2045 "replace_turbofish_with_explicit_type",
2047 fn make<T>() -> T { ) }
2049 let a = make$0::<i32>();
2053 fn make<T>() -> T { ) }
2055 let a: i32 = make();
2062 fn doctest_sort_items() {
2066 struct $0Foo$0 { second: u32, first: String }
2069 struct Foo { first: String, second: u32 }
2075 fn doctest_sort_items_1() {
2080 fn second(&self) -> u32;
2081 fn first(&self) -> String;
2086 fn first(&self) -> String;
2087 fn second(&self) -> u32;
2094 fn doctest_sort_items_2() {
2100 fn second(&self) -> u32;
2101 fn first(&self) -> String;
2107 fn first(&self) -> String;
2108 fn second(&self) -> u32;
2115 fn doctest_sort_items_3() {
2121 Cat { weight: f64, name: String },
2126 Cat { weight: f64, name: String },
2134 fn doctest_sort_items_4() {
2140 Cat $0{ weight: f64, name: String }$0,
2146 Cat { name: String, weight: f64 },
2153 fn doctest_split_import() {
2157 use std::$0collections::HashMap;
2160 use std::{collections::HashMap};
2166 fn doctest_toggle_ignore() {
2172 assert_eq!(2 + 2, 5);
2179 assert_eq!(2 + 2, 5);
2186 fn doctest_unmerge_use() {
2190 use std::fmt::{Debug, Display$0};
2193 use std::fmt::{Debug};
2194 use std::fmt::Display;
2200 fn doctest_unnecessary_async() {
2202 "unnecessary_async",
2204 pub async f$0n foo() {}
2205 pub async fn bar() { foo().await }
2209 pub async fn bar() { foo() }
2215 fn doctest_unwrap_block() {
2234 fn doctest_unwrap_result_return_type() {
2236 "unwrap_result_return_type",
2238 //- minicore: result
2239 fn foo() -> Result<i32>$0 { Ok(42i32) }
2242 fn foo() -> i32 { 42i32 }
2248 fn doctest_wrap_return_type_in_result() {
2250 "wrap_return_type_in_result",
2252 //- minicore: result
2253 fn foo() -> i32$0 { 42i32 }
2256 fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }