@@ -1152,7 +1152,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1152
1152
}
1153
1153
_ => {
1154
1154
if ty:: trait_has_default_impl ( self . tcx ( ) , def_id) {
1155
- candidates. vec . push ( DefaultImplCandidate ( def_id. clone ( ) ) )
1155
+ match self . constituent_types_for_ty ( self_ty) {
1156
+ Some ( _) => {
1157
+ candidates. vec . push ( DefaultImplCandidate ( def_id. clone ( ) ) )
1158
+ }
1159
+ None => {
1160
+ candidates. ambiguous = true ;
1161
+ }
1162
+ }
1156
1163
}
1157
1164
}
1158
1165
}
@@ -1625,7 +1632,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1625
1632
}
1626
1633
}
1627
1634
1628
- fn constituent_ty_obligations ( & self , t : Ty < ' tcx > ) -> Vec < Ty < ' tcx > > {
1635
+ fn constituent_types_for_ty ( & self , t : Ty < ' tcx > ) -> Option < Vec < Ty < ' tcx > > > {
1629
1636
match t. sty {
1630
1637
ty:: ty_uint( _) |
1631
1638
ty:: ty_int( _) |
@@ -1636,7 +1643,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1636
1643
ty:: ty_err |
1637
1644
ty:: ty_param( ..) |
1638
1645
ty:: ty_char => {
1639
- Vec :: new ( )
1646
+ Some ( Vec :: new ( ) )
1640
1647
}
1641
1648
1642
1649
ty:: ty_trait( ..) |
@@ -1649,50 +1656,50 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1649
1656
}
1650
1657
1651
1658
ty:: ty_uniq( referent_ty) => { // Box<T>
1652
- vec ! [ referent_ty]
1659
+ Some ( vec ! [ referent_ty] )
1653
1660
}
1654
1661
1655
- ty:: ty_open( element_ty) => { vec ! [ element_ty] } ,
1662
+ ty:: ty_open( element_ty) => { Some ( vec ! [ element_ty] ) } ,
1656
1663
1657
1664
ty:: ty_ptr( ty:: mt { ty : element_ty, ..} ) |
1658
1665
ty:: ty_rptr( _, ty:: mt { ty : element_ty, ..} ) => {
1659
- vec ! [ element_ty]
1666
+ Some ( vec ! [ element_ty] )
1660
1667
} ,
1661
1668
1662
1669
ty:: ty_vec( element_ty, _) => {
1663
- vec ! [ element_ty]
1670
+ Some ( vec ! [ element_ty] )
1664
1671
}
1665
1672
1666
1673
ty:: ty_tup( ref tys) => {
1667
1674
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
1668
- tys. clone ( )
1675
+ Some ( tys. clone ( ) )
1669
1676
}
1670
1677
1671
1678
ty:: ty_closure( def_id, _, substs) => {
1672
1679
assert_eq ! ( def_id. krate, ast:: LOCAL_CRATE ) ;
1673
1680
1674
1681
match self . closure_typer . closure_upvars ( def_id, substs) {
1675
1682
Some ( upvars) => {
1676
- upvars. iter ( ) . map ( |c| c. ty ) . collect ( )
1683
+ Some ( upvars. iter ( ) . map ( |c| c. ty ) . collect ( ) )
1677
1684
}
1678
1685
None => {
1679
- Vec :: new ( )
1686
+ None
1680
1687
}
1681
1688
}
1682
1689
}
1683
1690
1684
1691
ty:: ty_struct( def_id, substs) => {
1685
- ty:: struct_fields ( self . tcx ( ) , def_id, substs) . iter ( )
1686
- . map ( |f| f. mt . ty )
1687
- . collect ( )
1692
+ Some ( ty:: struct_fields ( self . tcx ( ) , def_id, substs) . iter ( )
1693
+ . map ( |f| f. mt . ty )
1694
+ . collect ( ) )
1688
1695
}
1689
1696
1690
1697
ty:: ty_enum( def_id, substs) => {
1691
- ty:: substd_enum_variants ( self . tcx ( ) , def_id, substs)
1692
- . iter ( )
1693
- . flat_map ( |variant| variant. args . iter ( ) )
1694
- . map ( |& ty| ty)
1695
- . collect ( )
1698
+ Some ( ty:: substd_enum_variants ( self . tcx ( ) , def_id, substs)
1699
+ . iter ( )
1700
+ . flat_map ( |variant| variant. args . iter ( ) )
1701
+ . map ( |& ty| ty)
1702
+ . collect ( ) )
1696
1703
}
1697
1704
}
1698
1705
}
@@ -1891,8 +1898,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1891
1898
impl_def_id. repr( self . tcx( ) ) ) ;
1892
1899
1893
1900
let self_ty = self . infcx . shallow_resolve ( obligation. predicate . 0 . self_ty ( ) ) ;
1894
- let types = self . constituent_ty_obligations ( self_ty) ;
1895
- Ok ( self . vtable_default_impl ( obligation, impl_def_id, types) )
1901
+ match self . constituent_types_for_ty ( self_ty) {
1902
+ Some ( types) => {
1903
+ Ok ( self . vtable_default_impl ( obligation, impl_def_id, types) )
1904
+ }
1905
+ None => {
1906
+ self . tcx ( ) . sess . bug (
1907
+ & format ! (
1908
+ "asked to confirm default implementation for ambiguous type: {}" ,
1909
+ self_ty. repr( self . tcx( ) ) ) [ ] ) ;
1910
+ }
1911
+ }
1896
1912
}
1897
1913
1898
1914
/// See `confirm_default_impl_candidate`
0 commit comments