Skip to content

New assist: Convert destructuring tuple assignment into individual assignments #20715

@ZylosLumen

Description

@ZylosLumen
struct Canvas {
  width: u16,
  height: u16,
}

impl Canvas {
  fn set_size(&mut self, w: u16, h: u16) -> &mut Self {
    (self.width, self.height) = (w, h);
    self
  }
}

=>

struct Canvas {
  width: u16,
  height: u16,
}

impl Canvas {
  fn set_size(&mut self, w: u16, h: u16) -> &mut Self {
    self.width = w;
    self.height = h;
    self
  }
}
struct XYZ {
  x: u8,
  y: u8,
  z: u8,
}

impl XYZ {
  fn xyz(&mut self, x: u8, y: u8, z: u8) {
    (self.x, (self.y, self.z)) = (x, (y, z))
  }
}

=>

struct XYZ {
  x: u8,
  y: u8,
  z: u8,
}

impl XYZ {
  fn xyz(&mut self, x: u8, y: u8, z: u8) {
    self.x = x;
    (self.y, self.z) = (y, z)
  }
}

etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions