//! 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.
//! 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:
//! <https://rust-analyzer.github.io/blog/2020/09/28/how-to-make-a-light-bulb.html>
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;
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;
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;
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;
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;
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,
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,
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,
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,
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(
)
}
+ #[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(
check_doc_test(
"generate_deref",
r#####"
+//- minicore: deref, deref_mut
struct A;
struct B {
$0a: A
a: A
}
-impl std::ops::Deref for B {
+impl core::ops::Deref for B {
type Target = A;
fn deref(&self) -> &Self::Target {
)
}
-#[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(
}
impl Person {
- /// Get a reference to the person's name.
- #[must_use]
fn $0name(&self) -> &str {
self.name.as_ref()
}
}
impl Person {
- /// Get a mutable reference to the person's name.
- #[must_use]
fn $0name_mut(&mut self) -> &mut String {
&mut self.name
}
}
impl Person {
- /// Set the person's name.
fn set_name(&mut self, name: String) {
self.name = name;
}
}
#[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() {}
}
"#####,