Skip to content

Commit fead5e2

Browse files
committed
---
yaml --- r: 159755 b: refs/heads/auto c: c8a94c5 h: refs/heads/master i: 159753: 754b3a0 159751: f1b3801 v: v3
1 parent be0dcd3 commit fead5e2

File tree

9 files changed

+156
-71
lines changed

9 files changed

+156
-71
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 9c808ffee44afad69aeeeec835601d44bf0e9147
13+
refs/heads/auto: c8a94c5dfaaf5f1dacc110bb81d292c4382554d9
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/middle/resolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,10 +5038,10 @@ impl<'a> Resolver<'a> {
50385038
visit::walk_ty(self, ty);
50395039
}
50405040

5041-
TyPolyTraitRef(ref poly_trait_ref) => {
5042-
self.resolve_poly_trait_reference(
5041+
TyPolyTraitRef(ref bounds) => {
5042+
self.resolve_type_parameter_bounds(
50435043
ty.id,
5044-
&**poly_trait_ref,
5044+
bounds,
50455045
TraitObject);
50465046
visit::walk_ty(self, ty);
50475047
}

branches/auto/src/librustc/middle/typeck/astconv.rs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -883,15 +883,8 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
883883

884884
ty::mk_closure(tcx, fn_decl)
885885
}
886-
ast::TyPolyTraitRef(ref data) => {
887-
// FIXME(#18639) this is just a placeholder for code to come
888-
let principal = instantiate_trait_ref(this, rscope, &data.trait_ref, None, None);
889-
let bounds = conv_existential_bounds(this,
890-
rscope,
891-
ast_ty.span,
892-
&[principal.clone()],
893-
&[]);
894-
ty::mk_trait(tcx, (*principal).clone(), bounds)
886+
ast::TyPolyTraitRef(ref bounds) => {
887+
conv_ty_poly_trait_ref(this, rscope, ast_ty.span, bounds.as_slice())
895888
}
896889
ast::TyPath(ref path, ref bounds, id) => {
897890
let a_def = match tcx.def_map.borrow().get(&id) {
@@ -1371,15 +1364,66 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
13711364
let ast_bound_refs: Vec<&ast::TyParamBound> =
13721365
ast_bounds.iter().collect();
13731366

1367+
let partitioned_bounds =
1368+
partition_bounds(this.tcx(), span, ast_bound_refs.as_slice());
1369+
1370+
conv_existential_bounds_from_partitioned_bounds(
1371+
this, rscope, span, main_trait_refs, partitioned_bounds)
1372+
}
1373+
1374+
fn conv_ty_poly_trait_ref<'tcx, AC, RS>(
1375+
this: &AC,
1376+
rscope: &RS,
1377+
span: Span,
1378+
ast_bounds: &[ast::TyParamBound])
1379+
-> ty::t
1380+
where AC: AstConv<'tcx>, RS:RegionScope
1381+
{
1382+
let ast_bounds: Vec<&ast::TyParamBound> = ast_bounds.iter().collect();
1383+
let mut partitioned_bounds = partition_bounds(this.tcx(), span, ast_bounds[]);
1384+
1385+
let main_trait_bound = match partitioned_bounds.trait_bounds.remove(0) {
1386+
Some(trait_bound) => {
1387+
Some(instantiate_poly_trait_ref(this, rscope, trait_bound, None, None))
1388+
}
1389+
None => {
1390+
this.tcx().sess.span_err(
1391+
span,
1392+
"at least one non-builtin trait is required for an object type");
1393+
None
1394+
}
1395+
};
1396+
1397+
let bounds = conv_existential_bounds_from_partitioned_bounds(this,
1398+
rscope,
1399+
span,
1400+
main_trait_bound.as_slice(),
1401+
partitioned_bounds);
1402+
1403+
match main_trait_bound {
1404+
None => ty::mk_err(),
1405+
Some(principal) => ty::mk_trait(this.tcx(), (*principal).clone(), bounds)
1406+
}
1407+
}
1408+
1409+
pub fn conv_existential_bounds_from_partitioned_bounds<'tcx, AC, RS>(
1410+
this: &AC,
1411+
rscope: &RS,
1412+
span: Span,
1413+
main_trait_refs: &[Rc<ty::TraitRef>],
1414+
partitioned_bounds: PartitionedBounds)
1415+
-> ty::ExistentialBounds
1416+
where AC: AstConv<'tcx>, RS:RegionScope
1417+
{
13741418
let PartitionedBounds { builtin_bounds,
13751419
trait_bounds,
13761420
region_bounds } =
1377-
partition_bounds(this.tcx(), span, ast_bound_refs.as_slice());
1421+
partitioned_bounds;
13781422

13791423
if !trait_bounds.is_empty() {
13801424
let b = &trait_bounds[0];
13811425
this.tcx().sess.span_err(
1382-
b.path.span,
1426+
b.trait_ref.path.span,
13831427
format!("only the builtin traits can be used \
13841428
as closure or object bounds").as_slice());
13851429
}

branches/auto/src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ pub enum Ty_ {
11541154
/// Type parameters are stored in the Path itself
11551155
TyPath(Path, Option<TyParamBounds>, NodeId), // for #7264; see above
11561156
/// A type like `for<'a> Foo<&'a Bar>`
1157-
TyPolyTraitRef(P<PolyTraitRef>),
1157+
TyPolyTraitRef(TyParamBounds),
11581158
/// A "qualified path", e.g. `<Vec<T> as SomeTrait>::SomeType`
11591159
TyQPath(P<QPath>),
11601160
/// No-op; kept solely so that we can pretty-print faithfully

branches/auto/src/libsyntax/ast_util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
494494
}
495495

496496
visit::walk_fn(self,
497-
function_kind,
498-
function_declaration,
499-
block,
500-
span);
497+
function_kind,
498+
function_declaration,
499+
block,
500+
span);
501501

502502
if !self.pass_through_items {
503503
match function_kind {

branches/auto/src/libsyntax/fold.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,12 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
445445
TyFixedLengthVec(ty, e) => {
446446
TyFixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
447447
}
448-
TyTypeof(expr) => TyTypeof(fld.fold_expr(expr)),
449-
TyPolyTraitRef(poly_trait_ref) => {
450-
TyPolyTraitRef(poly_trait_ref.map(|p| fld.fold_poly_trait_ref(p)))
451-
},
448+
TyTypeof(expr) => {
449+
TyTypeof(fld.fold_expr(expr))
450+
}
451+
TyPolyTraitRef(bounds) => {
452+
TyPolyTraitRef(bounds.move_map(|b| fld.fold_ty_param_bound(b)))
453+
}
452454
},
453455
span: fld.new_span(span)
454456
})

branches/auto/src/libsyntax/parse/parser.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,21 @@ impl<'a> Parser<'a> {
10231023
self.parse_ty_bare_fn_or_ty_closure(lifetime_defs)
10241024
} else if self.token == token::ModSep ||
10251025
self.token.is_ident() ||
1026-
self.token.is_path() {
1026+
self.token.is_path()
1027+
{
10271028
let trait_ref = self.parse_trait_ref();
1028-
TyPolyTraitRef(P(PolyTraitRef { bound_lifetimes: lifetime_defs,
1029-
trait_ref: trait_ref }))
1029+
let poly_trait_ref = ast::PolyTraitRef { bound_lifetimes: lifetime_defs,
1030+
trait_ref: trait_ref };
1031+
let other_bounds = if self.eat(&token::BinOp(token::Plus)) {
1032+
self.parse_ty_param_bounds()
1033+
} else {
1034+
OwnedSlice::empty()
1035+
};
1036+
let all_bounds =
1037+
Some(TraitTyParamBound(poly_trait_ref)).into_iter()
1038+
.chain(other_bounds.into_vec().into_iter())
1039+
.collect();
1040+
ast::TyPolyTraitRef(all_bounds)
10301041
} else {
10311042
self.parse_ty_closure(lifetime_defs)
10321043
}

branches/auto/src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,8 @@ impl<'a> State<'a> {
739739
ast::TyPath(ref path, ref bounds, _) => {
740740
try!(self.print_bounded_path(path, bounds));
741741
}
742-
ast::TyPolyTraitRef(ref poly_trait_ref) => {
743-
try!(self.print_poly_trait_ref(&**poly_trait_ref));
742+
ast::TyPolyTraitRef(ref bounds) => {
743+
try!(self.print_bounds("", bounds));
744744
}
745745
ast::TyQPath(ref qpath) => {
746746
try!(word(&mut self.s, "<"));

0 commit comments

Comments
 (0)