@@ -1382,40 +1382,35 @@ pub fn can_coerce<'tcx>(
13821382/// }
13831383/// let final_ty = coerce.complete(fcx);
13841384/// ```
1385- pub ( crate ) struct CoerceMany < ' tcx , ' exprs , E : AsCoercionSite > {
1385+ pub ( crate ) struct CoerceMany < ' tcx > {
13861386 expected_ty : Ty < ' tcx > ,
13871387 final_ty : Option < Ty < ' tcx > > ,
1388- expressions : Expressions < ' tcx , ' exprs , E > ,
1388+ expressions : Vec < & ' tcx hir :: Expr < ' tcx > > ,
13891389 pushed : usize ,
13901390}
13911391
13921392/// The type of a `CoerceMany` that is storing up the expressions into
13931393/// a buffer. We use this in `check/mod.rs` for things like `break`.
1394- pub ( crate ) type DynamicCoerceMany < ' tcx > = CoerceMany < ' tcx , ' tcx , & ' tcx hir :: Expr < ' tcx > > ;
1394+ pub ( crate ) type DynamicCoerceMany < ' tcx > = CoerceMany < ' tcx > ;
13951395
1396- enum Expressions < ' tcx , ' exprs , E : AsCoercionSite > {
1397- Dynamic ( Vec < & ' tcx hir:: Expr < ' tcx > > ) ,
1398- UpFront ( & ' exprs [ E ] ) ,
1399- }
1400-
1401- impl < ' tcx , ' exprs , E : AsCoercionSite > CoerceMany < ' tcx , ' exprs , E > {
1396+ impl < ' tcx > CoerceMany < ' tcx > {
14021397 /// The usual case; collect the set of expressions dynamically.
14031398 /// If the full set of coercion sites is known before hand,
14041399 /// consider `with_coercion_sites()` instead to avoid allocation.
14051400 pub ( crate ) fn new ( expected_ty : Ty < ' tcx > ) -> Self {
1406- Self :: make ( expected_ty, Expressions :: Dynamic ( vec ! [ ] ) )
1401+ Self :: make ( expected_ty, Vec :: with_capacity ( 1 ) )
14071402 }
14081403
14091404 /// As an optimization, you can create a `CoerceMany` with a
14101405 /// preexisting slice of expressions. In this case, you are
14111406 /// expected to pass each element in the slice to `coerce(...)` in
14121407 /// order. This is used with arrays in particular to avoid
14131408 /// needlessly cloning the slice.
1414- pub ( crate ) fn with_coercion_sites ( expected_ty : Ty < ' tcx > , coercion_sites : & ' exprs [ E ] ) -> Self {
1415- Self :: make ( expected_ty, Expressions :: UpFront ( coercion_sites) )
1409+ pub ( crate ) fn with_coercion_sites ( expected_ty : Ty < ' tcx > , coercion_sites : usize ) -> Self {
1410+ Self :: make ( expected_ty, Vec :: with_capacity ( coercion_sites) )
14161411 }
14171412
1418- fn make ( expected_ty : Ty < ' tcx > , expressions : Expressions < ' tcx , ' exprs , E > ) -> Self {
1413+ fn make ( expected_ty : Ty < ' tcx > , expressions : Vec < & ' tcx hir :: Expr < ' tcx > > ) -> Self {
14191414 CoerceMany { expected_ty, final_ty : None , expressions, pushed : 0 }
14201415 }
14211416
@@ -1541,22 +1536,13 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15411536 Some ( cause. clone ( ) ) ,
15421537 )
15431538 } else {
1544- match self . expressions {
1545- Expressions :: Dynamic ( ref exprs) => fcx. try_find_coercion_lub (
1546- cause,
1547- exprs,
1548- self . merged_ty ( ) ,
1549- expression,
1550- expression_ty,
1551- ) ,
1552- Expressions :: UpFront ( coercion_sites) => fcx. try_find_coercion_lub (
1553- cause,
1554- & coercion_sites[ 0 ..self . pushed ] ,
1555- self . merged_ty ( ) ,
1556- expression,
1557- expression_ty,
1558- ) ,
1559- }
1539+ fcx. try_find_coercion_lub (
1540+ cause,
1541+ & self . expressions ,
1542+ self . merged_ty ( ) ,
1543+ expression,
1544+ expression_ty,
1545+ )
15601546 }
15611547 } else {
15621548 // this is a hack for cases where we default to `()` because
@@ -1591,17 +1577,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15911577 Ok ( v) => {
15921578 self . final_ty = Some ( v) ;
15931579 if let Some ( e) = expression {
1594- match self . expressions {
1595- Expressions :: Dynamic ( ref mut buffer) => buffer. push ( e) ,
1596- Expressions :: UpFront ( coercion_sites) => {
1597- // if the user gave us an array to validate, check that we got
1598- // the next expression in the list, as expected
1599- assert_eq ! (
1600- coercion_sites[ self . pushed] . as_coercion_site( ) . hir_id,
1601- e. hir_id
1602- ) ;
1603- }
1604- }
1580+ self . expressions . push ( e) ;
16051581 self . pushed += 1 ;
16061582 }
16071583 }
0 commit comments