@@ -1551,31 +1551,36 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1551
1551
where
1552
1552
T : IntoIterator < Item = ty:: Predicate < ' tcx > > + Clone ,
1553
1553
{
1554
+ let cause = self . misc ( self . last_span ) ;
1555
+ let obligations: Vec < _ > = predicates
1556
+ . into_iter ( )
1557
+ . map ( |p| traits:: Obligation :: new ( cause. clone ( ) , self . param_env , p) )
1558
+ . collect ( ) ;
1559
+
1560
+ // Micro-optimization
1561
+ if obligations. is_empty ( ) {
1562
+ return ;
1563
+ }
1564
+
1554
1565
// This intermediate vector is mildly unfortunate, in that we
1555
1566
// sometimes create it even when logging is disabled, but only
1556
1567
// if debug-info is enabled, and I doubt it is actually
1557
1568
// expensive. -nmatsakis
1558
1569
let predicates_vec: Vec < _ > = if cfg ! ( debug_assertions) {
1559
- predicates . clone ( ) . into_iter ( ) . collect ( )
1570
+ obligations . iter ( ) . map ( |o| o . predicate ) . collect ( )
1560
1571
} else {
1561
1572
Vec :: new ( )
1562
1573
} ;
1563
1574
1564
1575
debug ! (
1565
1576
"prove_predicates(predicates={:?}, location={:?})" ,
1566
- predicates_vec,
1567
- location,
1577
+ predicates_vec, location,
1568
1578
) ;
1569
1579
1570
1580
self . fully_perform_op (
1571
1581
location. at_self ( ) ,
1572
1582
|| format ! ( "prove_predicates({:?})" , predicates_vec) ,
1573
- |this| {
1574
- let cause = this. misc ( this. last_span ) ;
1575
- let obligations = predicates
1576
- . into_iter ( )
1577
- . map ( |p| traits:: Obligation :: new ( cause. clone ( ) , this. param_env , p) )
1578
- . collect ( ) ;
1583
+ |_this| {
1579
1584
Ok ( InferOk {
1580
1585
value : ( ) ,
1581
1586
obligations,
@@ -1615,12 +1620,18 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1615
1620
where
1616
1621
T : fmt:: Debug + TypeFoldable < ' tcx > ,
1617
1622
{
1623
+ // Micro-optimization: avoid work when we don't have to
1624
+ if !value. has_projections ( ) {
1625
+ return value. clone ( ) ;
1626
+ }
1627
+
1618
1628
debug ! ( "normalize(value={:?}, location={:?})" , value, location) ;
1619
1629
self . fully_perform_op (
1620
1630
location. to_locations ( ) ,
1621
1631
|| format ! ( "normalize(value={:?})" , value) ,
1622
1632
|this| {
1623
- let Normalized { value, obligations } = this. infcx
1633
+ let Normalized { value, obligations } = this
1634
+ . infcx
1624
1635
. at ( & this. misc ( this. last_span ) , this. param_env )
1625
1636
. normalize ( value)
1626
1637
. unwrap_or_else ( |NoSolution | {
0 commit comments