mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
Fix new clippy warnings
This commit is contained in:
parent
27a50a3e6b
commit
a62fd31ab6
2 changed files with 16 additions and 16 deletions
|
@ -89,7 +89,7 @@ pub enum Guard {
|
||||||
|
|
||||||
/// Check
|
/// Check
|
||||||
|
|
||||||
pub fn check<'a>(
|
pub fn check(
|
||||||
region: Region,
|
region: Region,
|
||||||
context: Context,
|
context: Context,
|
||||||
matrix: Vec<Vec<Pattern>>,
|
matrix: Vec<Vec<Pattern>>,
|
||||||
|
@ -114,7 +114,7 @@ pub fn check<'a>(
|
||||||
/// The initial rows "matrix" are all of length 1
|
/// The initial rows "matrix" are all of length 1
|
||||||
/// The initial count of items per row "n" is also 1
|
/// The initial count of items per row "n" is also 1
|
||||||
/// The resulting rows are examples of missing patterns
|
/// The resulting rows are examples of missing patterns
|
||||||
fn is_exhaustive(matrix: &PatternMatrix, n: usize) -> PatternMatrix {
|
fn is_exhaustive(matrix: &RefPatternMatrix, n: usize) -> PatternMatrix {
|
||||||
if matrix.is_empty() {
|
if matrix.is_empty() {
|
||||||
vec![std::iter::repeat(Anything).take(n).collect()]
|
vec![std::iter::repeat(Anything).take(n).collect()]
|
||||||
} else if n == 0 {
|
} else if n == 0 {
|
||||||
|
@ -124,9 +124,9 @@ fn is_exhaustive(matrix: &PatternMatrix, n: usize) -> PatternMatrix {
|
||||||
let num_seen = ctors.len();
|
let num_seen = ctors.len();
|
||||||
|
|
||||||
if num_seen == 0 {
|
if num_seen == 0 {
|
||||||
let new_matrix = matrix
|
let new_matrix: Vec<_> = matrix
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(specialize_row_by_anything)
|
.filter_map(|row| specialize_row_by_anything(row))
|
||||||
.collect();
|
.collect();
|
||||||
let mut rest = is_exhaustive(&new_matrix, n - 1);
|
let mut rest = is_exhaustive(&new_matrix, n - 1);
|
||||||
|
|
||||||
|
@ -142,9 +142,9 @@ fn is_exhaustive(matrix: &PatternMatrix, n: usize) -> PatternMatrix {
|
||||||
let num_alts = alt_list.len();
|
let num_alts = alt_list.len();
|
||||||
|
|
||||||
if num_seen < num_alts {
|
if num_seen < num_alts {
|
||||||
let new_matrix = matrix
|
let new_matrix: Vec<_> = matrix
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(specialize_row_by_anything)
|
.filter_map(|row| specialize_row_by_anything(row))
|
||||||
.collect();
|
.collect();
|
||||||
let rest: Vec<Vec<Pattern>> = is_exhaustive(&new_matrix, n - 1);
|
let rest: Vec<Vec<Pattern>> = is_exhaustive(&new_matrix, n - 1);
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ fn is_exhaustive(matrix: &PatternMatrix, n: usize) -> PatternMatrix {
|
||||||
result
|
result
|
||||||
} else {
|
} else {
|
||||||
let is_alt_exhaustive = |Ctor { arity, tag_id, .. }| {
|
let is_alt_exhaustive = |Ctor { arity, tag_id, .. }| {
|
||||||
let new_matrix = matrix
|
let new_matrix: Vec<_> = matrix
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|r| specialize_row_by_ctor(tag_id, arity, r))
|
.filter_map(|r| specialize_row_by_ctor(tag_id, arity, r))
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -353,8 +353,8 @@ fn specialize_row_by_ctor2(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// INVARIANT: (length row == N) ==> (length result == arity + N - 1)
|
/// INVARIANT: (length row == N) ==> (length result == arity + N - 1)
|
||||||
fn specialize_row_by_ctor(tag_id: TagId, arity: usize, row: &Row) -> Option<Row> {
|
fn specialize_row_by_ctor(tag_id: TagId, arity: usize, row: &RefRow) -> Option<Row> {
|
||||||
let mut row = row.clone();
|
let mut row = row.to_vec();
|
||||||
|
|
||||||
let head = row.pop();
|
let head = row.pop();
|
||||||
let patterns = row;
|
let patterns = row;
|
||||||
|
@ -387,8 +387,8 @@ fn specialize_row_by_ctor(tag_id: TagId, arity: usize, row: &Row) -> Option<Row>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// INVARIANT: (length row == N) ==> (length result == N-1)
|
/// INVARIANT: (length row == N) ==> (length result == N-1)
|
||||||
fn specialize_row_by_anything(row: &Row) -> Option<Row> {
|
fn specialize_row_by_anything(row: &RefRow) -> Option<Row> {
|
||||||
let mut row = row.clone();
|
let mut row = row.to_vec();
|
||||||
|
|
||||||
match row.pop() {
|
match row.pop() {
|
||||||
Some(Anything) => Some(row),
|
Some(Anything) => Some(row),
|
||||||
|
@ -403,7 +403,7 @@ pub enum Complete {
|
||||||
No,
|
No,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_complete(matrix: &PatternMatrix) -> Complete {
|
fn is_complete(matrix: &RefPatternMatrix) -> Complete {
|
||||||
let ctors = collect_ctors(matrix);
|
let ctors = collect_ctors(matrix);
|
||||||
let length = ctors.len();
|
let length = ctors.len();
|
||||||
let mut it = ctors.into_iter();
|
let mut it = ctors.into_iter();
|
||||||
|
@ -424,6 +424,7 @@ fn is_complete(matrix: &PatternMatrix) -> Complete {
|
||||||
|
|
||||||
type RefPatternMatrix = [Vec<Pattern>];
|
type RefPatternMatrix = [Vec<Pattern>];
|
||||||
type PatternMatrix = Vec<Vec<Pattern>>;
|
type PatternMatrix = Vec<Vec<Pattern>>;
|
||||||
|
type RefRow = [Pattern];
|
||||||
type Row = Vec<Pattern>;
|
type Row = Vec<Pattern>;
|
||||||
|
|
||||||
fn collect_ctors(matrix: &RefPatternMatrix) -> MutMap<TagId, Union> {
|
fn collect_ctors(matrix: &RefPatternMatrix) -> MutMap<TagId, Union> {
|
||||||
|
|
|
@ -121,12 +121,11 @@ pub fn check_patterns<'a>(
|
||||||
) {
|
) {
|
||||||
match to_nonredundant_rows(region, patterns) {
|
match to_nonredundant_rows(region, patterns) {
|
||||||
Err(err) => errors.push(err),
|
Err(err) => errors.push(err),
|
||||||
Ok(matrix) => match roc_exhaustive::check(region, context, matrix) {
|
Ok(matrix) => {
|
||||||
Err(err) => {
|
if let Err(err) = roc_exhaustive::check(region, context, matrix) {
|
||||||
*errors = err;
|
*errors = err;
|
||||||
}
|
}
|
||||||
Ok(_) => {}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue