lisette-semantics 0.2.13

Little language inspired by Rust that compiles to Go
Documentation
use diagnostics::LisetteDiagnostic;
use syntax::ast::{Pattern, RestPattern};

pub fn check_rest_only_slice_pattern(pattern: &Pattern, diagnostics: &mut Vec<LisetteDiagnostic>) {
    if let Pattern::Or { patterns, .. } = pattern {
        for p in patterns {
            check_rest_only_slice_pattern(p, diagnostics);
        }
        return;
    }

    if let Pattern::Slice {
        prefix, rest, span, ..
    } = pattern
        && prefix.is_empty()
        && !matches!(rest, RestPattern::Absent)
    {
        let help = match rest {
            RestPattern::Bind { name, .. } => {
                format!("Use `let {}` instead", name)
            }
            _ => "Use `let _` instead".to_string(),
        };

        diagnostics.push(diagnostics::lint::rest_only_slice_pattern(span, help));
    }
}