···1919 strings::to_snake_case,
2020 type_::{
2121 self, FieldMap, ModuleValueConstructor, Type, TypeVar, TypedCallArg, ValueConstructor,
2222- error::{ModuleSuggestion, VariableOrigin},
2222+ error::{ModuleSuggestion, VariableDeclarationKind, VariableOrigin},
2323 printer::{Names, Printer},
2424 },
2525};
···59695969 };
5970597059715971 // We can only inline it if it comes from a regular variable pattern,
59725972- // not a complex pattern or generated assignment.
59725972+ // not a complex pattern or generated assignment. We can also only inline
59735973+ // variables assigned by `let` statements, as it doesn't make sense to do
59745974+ // so with any other kind of variable.
59735975 match origin {
59745974- VariableOrigin::Variable(_) => {}
59755975- VariableOrigin::LabelShorthand(_)
59765976+ VariableOrigin::Variable {
59775977+ kind: VariableDeclarationKind::LetPattern,
59785978+ ..
59795979+ } => {}
59805980+ VariableOrigin::Variable { .. }
59815981+ | VariableOrigin::LabelShorthand(_)
59765982 | VariableOrigin::AssignmentPattern
59775983 | VariableOrigin::Generated => return,
59785984 }
···59895995 ) {
59905996 // We can only inline it if it is a regular variable pattern
59915997 match origin {
59925992- VariableOrigin::Variable(_) => {}
59935993- VariableOrigin::LabelShorthand(_)
59985998+ VariableOrigin::Variable {
59995999+ kind: VariableDeclarationKind::LetPattern,
60006000+ ..
60016001+ } => {}
60026002+ VariableOrigin::Variable { .. }
60036003+ | VariableOrigin::LabelShorthand(_)
59946004 | VariableOrigin::AssignmentPattern
59956005 | VariableOrigin::Generated => return,
59966006 }
···712712/// The origin of a variable. Used to determine how it can be ignored when unused.
713713pub enum VariableOrigin {
714714 /// A variable that can be ignored by prefixing with an underscore, `_name`
715715- Variable(EcoString),
715715+ Variable {
716716+ name: EcoString,
717717+ kind: VariableDeclarationKind,
718718+ },
716719 /// A variable from label shorthand syntax, which can be ignored with an underscore: `label: _`
717720 LabelShorthand(EcoString),
718721 /// A variable from an assignment pattern, which can be ignored by removing `as name`,
···721724 Generated,
722725}
723726727727+#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
728728+pub enum VariableDeclarationKind {
729729+ LetPattern,
730730+ UsePattern,
731731+ ClausePattern,
732732+ FunctionParameter,
733733+ Implicit,
734734+}
735735+724736impl VariableOrigin {
725737 pub fn how_to_ignore(&self) -> Option<String> {
726738 match self {
727727- VariableOrigin::Variable(name) => {
739739+ VariableOrigin::Variable { name, .. } => {
728740 Some(format!("You can ignore it with an underscore: `_{name}`."))
729741 }
730742 VariableOrigin::LabelShorthand(label) => Some(format!(