Skip to content

Commit 67dab2a

Browse files
committed
Include projection bounds in superpredicates.
Fixes #19451. Fixes #20345.
1 parent 9675488 commit 67dab2a

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

src/librustc/middle/ty.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5449,8 +5449,15 @@ pub fn predicates_for_trait_ref<'tcx>(tcx: &ctxt<'tcx>,
54495449
.map(|poly_trait_ref| ty::Binder(poly_trait_ref.0.subst(tcx, trait_ref.substs())))
54505450
.collect();
54515451

5452-
debug!("bounds_for_trait_ref: trait_bounds={}",
5453-
trait_bounds.repr(tcx));
5452+
let projection_bounds: Vec<_> =
5453+
trait_def.bounds.projection_bounds
5454+
.iter()
5455+
.map(|poly_proj| ty::Binder(poly_proj.0.subst(tcx, trait_ref.substs())))
5456+
.collect();
5457+
5458+
debug!("bounds_for_trait_ref: trait_bounds={} projection_bounds={}",
5459+
trait_bounds.repr(tcx),
5460+
projection_bounds.repr(tcx));
54545461

54555462
// The region bounds and builtin bounds do not currently introduce
54565463
// binders so we can just substitute in a straightforward way here.
@@ -5463,11 +5470,7 @@ pub fn predicates_for_trait_ref<'tcx>(tcx: &ctxt<'tcx>,
54635470
trait_bounds: trait_bounds,
54645471
region_bounds: region_bounds,
54655472
builtin_bounds: builtin_bounds,
5466-
5467-
// FIXME(#19451) -- if a trait has a bound like `trait Foo :
5468-
// Bar<T=X>`, we should probably be returning that, but this
5469-
// code here will just ignore it.
5470-
projection_bounds: Vec::new(),
5473+
projection_bounds: projection_bounds,
54715474
};
54725475

54735476
predicates(tcx, trait_ref.self_ty(), &bounds)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we correctly handle projection bounds appearing in the
12+
// supertrait list (and in conjunction with overloaded operators). In
13+
// this case, the `Result=Self` binding in the supertrait listing of
14+
// `Int` was being ignored.
15+
16+
#![feature(associated_types)]
17+
18+
trait Not {
19+
type Result;
20+
21+
fn not(self) -> Self::Result;
22+
}
23+
24+
trait Int: Not<Result=Self> {
25+
fn count_ones(self) -> uint;
26+
fn count_zeros(self) -> uint {
27+
// neither works
28+
let x: Self = self.not();
29+
0
30+
}
31+
}
32+
33+
fn main() { }

0 commit comments

Comments
 (0)