From: bors Date: Tue, 17 May 2022 19:01:18 +0000 (+0000) Subject: Auto merge of #12130 - weirane:let-else-let-match, r=weirane X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=187bd7d48afda84d6aff578274585d9835cbd4bb;hp=-c;p=rust.git Auto merge of #12130 - weirane:let-else-let-match, r=weirane Turn let-else statements into let and match Fixes #11906. --- 187bd7d48afda84d6aff578274585d9835cbd4bb diff --combined crates/ide-assists/src/lib.rs index c1751e8b406,4896c327198..a5dfb5d2953 --- a/crates/ide-assists/src/lib.rs +++ b/crates/ide-assists/src/lib.rs @@@ -37,7 -37,7 +37,7 @@@ //! should be available more or less everywhere, which isn't useful. So //! instead we only show it if the user *selects* the items they want to sort. //! * Consider grouping related assists together (see [`Assists::add_group`]). -//! * Make assists robust. If the assist depends on results of type-inference to +//! * Make assists robust. If the assist depends on results of type-inference too //! much, it might only fire in fully-correct code. This makes assist less //! useful and (worse) less predictable. The user should have a clear //! intuition when each particular assist is available. @@@ -54,6 -54,7 +54,6 @@@ //! something. If something *could* be a diagnostic, it should be a //! diagnostic. Conversely, it might be valuable to turn a diagnostic with a //! lot of false errors into an assist. -//! * //! //! See also this post: //! @@@ -106,8 -107,6 +106,8 @@@ mod handlers mod add_explicit_type; mod add_lifetime_to_type; mod add_missing_impl_members; + mod add_missing_match_arms; + mod add_attribute; mod add_turbo_fish; mod apply_demorgan; mod auto_import; @@@ -117,6 -116,7 +117,7 @@@ mod convert_integer_literal; mod convert_into_to_from; mod convert_iter_for_each_to_for; + mod convert_let_else_to_match; mod convert_tuple_struct_to_named_struct; mod convert_to_guarded_return; mod convert_while_to_loop; @@@ -127,6 -127,7 +128,6 @@@ mod extract_struct_from_enum_variant; mod extract_type_alias; mod extract_variable; - mod add_missing_match_arms; mod fix_visibility; mod flip_binexpr; mod flip_comma; @@@ -135,6 -136,7 +136,6 @@@ mod generate_default_from_enum_variant; mod generate_default_from_new; mod generate_deref; - mod generate_derive; mod generate_documentation_template; mod generate_enum_is_method; mod generate_enum_projection_method; @@@ -169,7 -171,7 +170,7 @@@ mod remove_mut; mod remove_unused_param; mod reorder_fields; - mod reorder_impl; + mod reorder_impl_items; mod replace_try_expr_with_match; mod replace_derive_with_manual_impl; mod replace_if_let_with_match; @@@ -190,7 -192,6 +191,7 @@@ pub(crate) fn all() -> &'static [Handler] { &[ // These are alphabetic for the foolish consistency + add_attribute::add_attribute, add_explicit_type::add_explicit_type, add_missing_match_arms::add_missing_match_arms, add_lifetime_to_type::add_lifetime_to_type, @@@ -206,6 -207,7 +207,7 @@@ convert_into_to_from::convert_into_to_from, convert_iter_for_each_to_for::convert_iter_for_each_to_for, convert_iter_for_each_to_for::convert_for_loop_with_for_each, + convert_let_else_to_match::convert_let_else_to_match, convert_to_guarded_return::convert_to_guarded_return, convert_tuple_struct_to_named_struct::convert_tuple_struct_to_named_struct, convert_while_to_loop::convert_while_to_loop, @@@ -220,6 -222,7 +222,6 @@@ generate_constant::generate_constant, generate_default_from_enum_variant::generate_default_from_enum_variant, generate_default_from_new::generate_default_from_new, - generate_derive::generate_derive, generate_documentation_template::generate_documentation_template, generate_enum_is_method::generate_enum_is_method, generate_enum_projection_method::generate_enum_as_method, @@@ -256,7 -259,7 +258,7 @@@ remove_mut::remove_mut, remove_unused_param::remove_unused_param, reorder_fields::reorder_fields, - reorder_impl::reorder_impl, + reorder_impl_items::reorder_impl_items, replace_try_expr_with_match::replace_try_expr_with_match, replace_derive_with_manual_impl::replace_derive_with_manual_impl, replace_if_let_with_match::replace_if_let_with_match, diff --combined crates/ide-assists/src/tests/generated.rs index d3917f6c97c,008dd7eec17..7772563b838 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@@ -2,26 -2,6 +2,26 @@@ use super::check_doc_test; +#[test] +fn doctest_add_attribute() { + check_doc_test( + "add_derive", + r#####" +struct Point { + x: u32, + y: u32,$0 +} +"#####, + r#####" +#[derive($0)] +struct Point { + x: u32, + y: u32, +} +"#####, + ) +} + #[test] fn doctest_add_explicit_type() { check_doc_test( @@@ -384,6 -364,26 +384,26 @@@ fn main() ) } + #[test] + fn doctest_convert_let_else_to_match() { + check_doc_test( + "convert_let_else_to_match", + r#####" + fn main() { + let Ok(mut x) = f() else$0 { return }; + } + "#####, + r#####" + fn main() { + let mut x = match f() { + Ok(x) => x, + _ => return, + }; + } + "#####, + ) + } + #[test] fn doctest_convert_to_guarded_return() { check_doc_test( @@@ -819,7 -819,6 +839,7 @@@ fn doctest_generate_deref() check_doc_test( "generate_deref", r#####" +//- minicore: deref, deref_mut struct A; struct B { $0a: A @@@ -831,7 -830,7 +851,7 @@@ struct B a: A } -impl std::ops::Deref for B { +impl core::ops::Deref for B { type Target = A; fn deref(&self) -> &Self::Target { @@@ -842,6 -841,26 +862,6 @@@ ) } -#[test] -fn doctest_generate_derive() { - check_doc_test( - "generate_derive", - r#####" -struct Point { - x: u32, - y: u32,$0 -} -"#####, - r#####" -#[derive($0)] -struct Point { - x: u32, - y: u32, -} -"#####, - ) -} - #[test] fn doctest_generate_documentation_template() { check_doc_test( @@@ -1037,6 -1056,8 +1057,6 @@@ struct Person } impl Person { - /// Get a reference to the person's name. - #[must_use] fn $0name(&self) -> &str { self.name.as_ref() } @@@ -1060,6 -1081,8 +1080,6 @@@ struct Person } impl Person { - /// Get a mutable reference to the person's name. - #[must_use] fn $0name_mut(&mut self) -> &mut String { &mut self.name } @@@ -1157,6 -1180,7 +1177,6 @@@ struct Person } impl Person { - /// Set the person's name. fn set_name(&mut self, name: String) { self.name = name; } @@@ -1733,34 -1757,34 +1753,34 @@@ const test: Foo = Foo {foo: 1, bar: 0 } #[test] -fn doctest_reorder_impl() { +fn doctest_reorder_impl_items() { check_doc_test( - "reorder_impl", + "reorder_impl_items", r#####" trait Foo { - fn a() {} - fn b() {} - fn c() {} + type A; + const B: u8; + fn c(); } struct Bar; $0impl Foo for Bar { - fn b() {} + const B: u8 = 17; fn c() {} - fn a() {} + type A = String; } "#####, r#####" trait Foo { - fn a() {} - fn b() {} - fn c() {} + type A; + const B: u8; + fn c(); } struct Bar; impl Foo for Bar { - fn a() {} - fn b() {} + type A = String; + const B: u8 = 17; fn c() {} } "#####,