Source: add_custom_impl.rs
Adds impl block for derived trait.
#[derive(Deb┃ug, Display)]
struct S;
#[derive(Display)]
struct S;
impl Debug for S {
$0
}
Source: add_explicit_type.rs
Specify type for a let binding.
fn main() {
let x┃ = 92;
}
fn main() {
let x: i32 = 92;
}
Source: raw_string.rs
Adds a hash to a raw string literal.
fn main() {
r#"Hello,┃ World!"#;
}
fn main() {
r##"Hello, World!"##;
}
Source: add_missing_impl_members.rs
Adds scaffold for overriding default impl members.
trait Trait {
Type X;
fn foo(&self);
fn bar(&self) {}
}
impl Trait for () {
Type X = ();
fn foo(&self) {}┃
}
trait Trait {
Type X;
fn foo(&self);
fn bar(&self) {}
}
impl Trait for () {
Type X = ();
fn foo(&self) {}
$0fn bar(&self) {}
}
Source: add_missing_impl_members.rs
Adds scaffold for required impl members.
trait Trait<T> {
Type X;
fn foo(&self) -> T;
fn bar(&self) {}
}
impl Trait<u32> for () {┃
}
trait Trait<T> {
Type X;
fn foo(&self) -> T;
fn bar(&self) {}
}
impl Trait<u32> for () {
fn foo(&self) -> u32 {
${0:todo!()}
}
}
Source: add_turbo_fish.rs
Adds ::<_>
to a call of a generic method or function.
fn make<T>() -> T { todo!() }
fn main() {
let x = make┃();
}
fn make<T>() -> T { todo!() }
fn main() {
let x = make::<${0:_}>();
}
Source: apply_demorgan.rs
Apply De Morgan’s law.
This transforms expressions of the form !l || !r
into !(l && r)
.
This also works with &&
. This assist can only be applied with the cursor
on either ||
or &&
, with both operands being a negation of some kind.
This means something of the form !x
or x != y
.
fn main() {
if x != 4 ||┃ !y {}
}
fn main() {
if !(x == 4 && y) {}
}
Source: auto_import.rs
If the name is unresolved, provides all possible imports for it.
fn main() {
let map = HashMap┃::new();
}
use std::collections::HashMap;
fn main() {
let map = HashMap::new();
}
Source: change_return_type_to_result.rs
Change the function’s return type to Result.
fn foo() -> i32┃ { 42i32 }
fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
Source: change_visibility.rs
Adds or changes existing visibility specifier.
┃fn frobnicate() {}
pub(crate) fn frobnicate() {}
Source: convert_integer_literal.rs
Converts the base of integer literals to other bases.
const _: i32 = 10┃;
const _: i32 = 0b1010;
Source: early_return.rs
Replace a large conditional with a guarded return.
fn main() {
┃if cond {
foo();
bar();
}
}
fn main() {
if !cond {
return;
}
foo();
bar();
}
Source: expand_glob_import.rs
Expands glob imports.
mod foo {
pub struct Bar;
pub struct Baz;
}
use foo::*┃;
fn qux(bar: Bar, baz: Baz) {}
mod foo {
pub struct Bar;
pub struct Baz;
}
use foo::{Baz, Bar};
fn qux(bar: Bar, baz: Baz) {}
Extracts a struct from enum variant.
enum A { ┃One(u32, u32) }
struct One(pub u32, pub u32);
enum A { One(One) }
Source: extract_variable.rs
Extracts subexpression into a variable.
fn main() {
┃(1 + 2)┃ * 4;
}
fn main() {
let $0var_name = (1 + 2);
var_name * 4;
}
Source: fill_match_arms.rs
Adds missing clauses to a match
expression.
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
┃
}
}
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
$0Action::Move { distance } => {}
Action::Stop => {}
}
}
Source: fix_visibility.rs
Makes inaccessible item public.
mod m {
fn frobnicate() {}
}
fn main() {
m::frobnicate┃() {}
}
mod m {
$0pub(crate) fn frobnicate() {}
}
fn main() {
m::frobnicate() {}
}
Source: flip_binexpr.rs
Flips operands of a binary expression.
fn main() {
let _ = 90 +┃ 2;
}
fn main() {
let _ = 2 + 90;
}
Source: flip_comma.rs
Flips two comma-separated items.
fn main() {
((1, 2),┃ (3, 4));
}
fn main() {
((3, 4), (1, 2));
}
Source: flip_trait_bound.rs
Flips two trait bounds.
fn foo<T: Clone +┃ Copy>() { }
fn foo<T: Copy + Clone>() { }
Source: generate_derive.rs
Adds a new #[derive()]
clause to a struct or enum.
struct Point {
x: u32,
y: u32,┃
}
#[derive($0)]
struct Point {
x: u32,
y: u32,
}
Source: generate_from_impl_for_enum.rs
Adds a From impl for an enum variant with one tuple field.
enum A { ┃One(u32) }
enum A { One(u32) }
impl From<u32> for A {
fn from(v: u32) -> Self {
A::One(v)
}
}
Source: generate_function.rs
Adds a stub function with a signature matching the function under the cursor.
struct Baz;
fn baz() -> Baz { Baz }
fn foo() {
bar┃("", baz());
}
struct Baz;
fn baz() -> Baz { Baz }
fn foo() {
bar("", baz());
}
fn bar(arg: &str, baz: Baz) ${0:-> ()} {
todo!()
}
Source: generate_impl.rs
Adds a new inherent impl for a type.
struct Ctx<T: Clone> {
data: T,┃
}
struct Ctx<T: Clone> {
data: T,
}
impl<T: Clone> Ctx<T> {
$0
}
Source: generate_new.rs
Adds a new inherent impl for a type.
struct Ctx<T: Clone> {
data: T,┃
}
struct Ctx<T: Clone> {
data: T,
}
impl<T: Clone> Ctx<T> {
fn $0new(data: T) -> Self { Self { data } }
}
Source: inline_local_variable.rs
Inlines local variable.
fn main() {
let x┃ = 1 + 2;
x * 4;
}
fn main() {
(1 + 2) * 4;
}
Source: introduce_named_lifetime.rs
Change an anonymous lifetime to a named lifetime.
impl Cursor<'_┃> {
fn node(self) -> &SyntaxNode {
match self {
Cursor::Replace(node) | Cursor::Before(node) => node,
}
}
}
impl<'a> Cursor<'a> {
fn node(self) -> &SyntaxNode {
match self {
Cursor::Replace(node) | Cursor::Before(node) => node,
}
}
}
Source: invert_if.rs
Apply invert_if
This transforms if expressions of the form if !x {A} else {B}
into if x {B} else {A}
This also works with !=
. This assist can only be applied with the cursor
on if
.
fn main() {
if┃ !y { A } else { B }
}
fn main() {
if y { B } else { A }
}
Source: raw_string.rs
Adds r#
to a plain string literal.
fn main() {
"Hello,┃ World!";
}
fn main() {
r#"Hello, World!"#;
}
Source: raw_string.rs
Turns a raw string into a plain string.
fn main() {
r#"Hello,┃ "World!""#;
}
fn main() {
"Hello, \"World!\"";
}
Source: merge_imports.rs
Merges two imports with a common prefix.
use std::┃fmt::Formatter;
use std::io;
use std::{fmt::Formatter, io};
Source: merge_match_arms.rs
Merges identical match arms.
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
┃Action::Move(..) => foo(),
Action::Stop => foo(),
}
}
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move(..) | Action::Stop => foo(),
}
}
Source: move_guard.rs
Moves if expression from match arm body into a guard.
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move { distance } => ┃if distance > 10 { foo() },
_ => (),
}
}
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move { distance } if distance > 10 => foo(),
_ => (),
}
}
Source: move_bounds.rs
Moves inline type bounds to a where clause.
fn apply<T, U, ┃F: FnOnce(T) -> U>(f: F, x: T) -> U {
f(x)
}
fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
f(x)
}
Source: move_guard.rs
Moves match guard into match arm body.
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move { distance } ┃if distance > 10 => foo(),
_ => (),
}
}
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move { distance } => if distance > 10 {
foo()
},
_ => (),
}
}
Source: qualify_path.rs
If the name is unresolved, provides all possible qualified paths for it.
fn main() {
let map = HashMap┃::new();
}
fn main() {
let map = std::collections::HashMap::new();
}
Source: remove_dbg.rs
Removes dbg!()
macro call.
fn main() {
┃dbg!(92);
}
fn main() {
92;
}
Source: raw_string.rs
Removes a hash from a raw string literal.
fn main() {
r#"Hello,┃ World!"#;
}
fn main() {
r"Hello, World!";
}
Source: remove_mut.rs
Removes the mut
keyword.
impl Walrus {
fn feed(&mut┃ self, amount: u32) {}
}
impl Walrus {
fn feed(&self, amount: u32) {}
}
Source: remove_unused_param.rs
Removes unused function parameter.
fn frobnicate(x: i32┃) {}
fn main() {
frobnicate(92);
}
fn frobnicate() {}
fn main() {
frobnicate();
}
Source: reorder_fields.rs
Reorder the fields of record literals and record patterns in the same order as in the definition.
struct Foo {foo: i32, bar: i32};
const test: Foo = ┃Foo {bar: 0, foo: 1}
struct Foo {foo: i32, bar: i32};
const test: Foo = Foo {foo: 1, bar: 0}
Source: replace_if_let_with_match.rs
Replaces if let
with an else branch with a match
expression.
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
┃if let Action::Move { distance } = action {
foo(distance)
} else {
bar()
}
}
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move { distance } => foo(distance),
_ => bar(),
}
}
Replaces impl Trait
function argument with the named generic.
fn foo(bar: ┃impl Bar) {}
fn foo<B: Bar>(bar: B) {}
Source: replace_let_with_if_let.rs
Replaces let
with an if-let
.
fn main(action: Action) {
┃let x = compute();
}
fn compute() -> Option<i32> { None }
fn main(action: Action) {
if let Some(x) = compute() {
}
}
fn compute() -> Option<i32> { None }
Adds a use statement for a given fully-qualified name.
fn process(map: std::collections::┃HashMap<String, String>) {}
use std::collections::HashMap;
fn process(map: HashMap<String, String>) {}
Source: replace_string_with_char.rs
Replace string with char.
fn main() {
find("{┃");
}
fn main() {
find('{');
}
Source: replace_unwrap_with_match.rs
Replaces unwrap
a match
expression. Works for Result and Option.
enum Result<T, E> { Ok(T), Err(E) }
fn main() {
let x: Result<i32, i32> = Result::Ok(92);
let y = x.┃unwrap();
}
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,
$0_ => unreachable!(),
};
}
Source: split_import.rs
Wraps the tail of import into braces.
use std::┃collections::HashMap;
use std::{collections::HashMap};
Source: unwrap_block.rs
This assist removes if…else, for, while and loop control statements to just keep the body.
fn foo() {
if true {┃
println!("foo");
}
}
fn foo() {
println!("foo");
}