Abort on arity mismatch · rust-lang/rust@2af01a2 (original) (raw)

`@@ -1001,19 +1001,26 @@ impl<'p, Cx: TypeCx> PatStack<'p, Cx> {

`

1001

1001

`` /// Only call if ctor.is_covered_by(self.head().ctor()) is true.

``

1002

1002

`fn pop_head_constructor(

`

1003

1003

`&self,

`

``

1004

`+

cx: &Cx,

`

1004

1005

`ctor: &Constructor,

`

1005

1006

`ctor_arity: usize,

`

1006

1007

`ctor_is_relevant: bool,

`

1007

``

`-

) -> PatStack<'p, Cx> {

`

``

1008

`+

) -> Result<PatStack<'p, Cx>, Cx::Error> {

`

1008

1009

`// We pop the head pattern and push the new fields extracted from the arguments of

`

1009

1010

`` // self.head().

``

1010

1011

`let mut new_pats = self.head().specialize(ctor, ctor_arity);

`

``

1012

`+

if new_pats.len() != ctor_arity {

`

``

1013

`+

return Err(cx.bug(format_args!(

`

``

1014

`+

"uncaught type error: pattern {:?} has inconsistent arity (expected arity {ctor_arity})",

`

``

1015

`+

self.head().as_pat().unwrap()

`

``

1016

`+

)));

`

``

1017

`+

}

`

1011

1018

` new_pats.extend_from_slice(&self.pats[1..]);

`

1012

1019

`` // ctor is relevant for this row if it is the actual constructor of this row, or if the

``

1013

1020

`` // row has a wildcard and ctor is relevant for wildcards.

``

1014

1021

`let ctor_is_relevant =

`

1015

1022

` !matches!(self.head().ctor(), Constructor::Wildcard) || ctor_is_relevant;

`

1016

``

`-

PatStack { pats: new_pats, relevant: self.relevant && ctor_is_relevant }

`

``

1023

`+

Ok(PatStack { pats: new_pats, relevant: self.relevant && ctor_is_relevant })

`

1017

1024

`}

`

1018

1025

`}

`

1019

1026

``

`@@ -1083,18 +1090,19 @@ impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> {

`

1083

1090

`` /// Only call if ctor.is_covered_by(self.head().ctor()) is true.

``

1084

1091

`fn pop_head_constructor(

`

1085

1092

`&self,

`

``

1093

`+

cx: &Cx,

`

1086

1094

`ctor: &Constructor,

`

1087

1095

`ctor_arity: usize,

`

1088

1096

`ctor_is_relevant: bool,

`

1089

1097

`parent_row: usize,

`

1090

``

`-

) -> MatrixRow<'p, Cx> {

`

1091

``

`-

MatrixRow {

`

1092

``

`-

pats: self.pats.pop_head_constructor(ctor, ctor_arity, ctor_is_relevant),

`

``

1098

`+

) -> Result<MatrixRow<'p, Cx>, Cx::Error> {

`

``

1099

`+

Ok(MatrixRow {

`

``

1100

`+

pats: self.pats.pop_head_constructor(cx, ctor, ctor_arity, ctor_is_relevant)?,

`

1093

1101

` parent_row,

`

1094

1102

`is_under_guard: self.is_under_guard,

`

1095

1103

`useful: false,

`

1096

1104

`` intersects: BitSet::new_empty(0), // Initialized in Matrix::expand_and_push.

``

1097

``

`-

}

`

``

1105

`+

})

`

1098

1106

`}

`

1099

1107

`}

`

1100

1108

``

`@@ -1217,7 +1225,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {

`

1217

1225

`};

`

1218

1226

`for (i, row) in self.rows().enumerate() {

`

1219

1227

`if ctor.is_covered_by(pcx.cx, row.head().ctor())? {

`

1220

``

`-

let new_row = row.pop_head_constructor(ctor, arity, ctor_is_relevant, i);

`

``

1228

`+

let new_row = row.pop_head_constructor(pcx.cx, ctor, arity, ctor_is_relevant, i)?;

`

1221

1229

` matrix.expand_and_push(new_row);

`

1222

1230

`}

`

1223

1231

`}

`