Skip to content

Commit 7be6d3c

Browse files
committed
---
yaml --- r: 187647 b: refs/heads/tmp c: 38ef5ee h: refs/heads/master i: 187645: bc9eb8b 187643: 3fbb5f1 187639: 6e4b6b8 187631: 550ac99 187615: 5eb3c92 187583: 09eb19b 187519: 8427372 187391: 56b3b57 v: v3
1 parent 4efb280 commit 7be6d3c

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: e8df95d77f65a3a1456f7e10d9d1dd209acf2879
37+
refs/heads/tmp: 38ef5ee48f7a2994a7fd8e6a1a818d378d51d40e
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/tmp/src/librustc/middle/traits/select.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11521152
}
11531153
_ => {
11541154
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+
}
11561163
}
11571164
}
11581165
}
@@ -1625,7 +1632,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16251632
}
16261633
}
16271634

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>>> {
16291636
match t.sty {
16301637
ty::ty_uint(_) |
16311638
ty::ty_int(_) |
@@ -1636,7 +1643,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16361643
ty::ty_err |
16371644
ty::ty_param(..) |
16381645
ty::ty_char => {
1639-
Vec::new()
1646+
Some(Vec::new())
16401647
}
16411648

16421649
ty::ty_trait(..) |
@@ -1649,50 +1656,50 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16491656
}
16501657

16511658
ty::ty_uniq(referent_ty) => { // Box<T>
1652-
vec![referent_ty]
1659+
Some(vec![referent_ty])
16531660
}
16541661

1655-
ty::ty_open(element_ty) => {vec![element_ty]},
1662+
ty::ty_open(element_ty) => {Some(vec![element_ty])},
16561663

16571664
ty::ty_ptr(ty::mt { ty: element_ty, ..}) |
16581665
ty::ty_rptr(_, ty::mt { ty: element_ty, ..}) => {
1659-
vec![element_ty]
1666+
Some(vec![element_ty])
16601667
},
16611668

16621669
ty::ty_vec(element_ty, _) => {
1663-
vec![element_ty]
1670+
Some(vec![element_ty])
16641671
}
16651672

16661673
ty::ty_tup(ref tys) => {
16671674
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
1668-
tys.clone()
1675+
Some(tys.clone())
16691676
}
16701677

16711678
ty::ty_closure(def_id, _, substs) => {
16721679
assert_eq!(def_id.krate, ast::LOCAL_CRATE);
16731680

16741681
match self.closure_typer.closure_upvars(def_id, substs) {
16751682
Some(upvars) => {
1676-
upvars.iter().map(|c| c.ty).collect()
1683+
Some(upvars.iter().map(|c| c.ty).collect())
16771684
}
16781685
None => {
1679-
Vec::new()
1686+
None
16801687
}
16811688
}
16821689
}
16831690

16841691
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())
16881695
}
16891696

16901697
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())
16961703
}
16971704
}
16981705
}
@@ -1891,8 +1898,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18911898
impl_def_id.repr(self.tcx()));
18921899

18931900
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+
}
18961912
}
18971913

18981914
/// See `confirm_default_impl_candidate`

0 commit comments

Comments
 (0)