From 538ebd197c52f2551f550d7aa5c82f7b3412c99d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 8 May 2019 15:58:20 -0400 Subject: [PATCH 1/1] Added some comments, made `add_bounds` private. --- src/librustc_typeck/astconv.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index e37ad77b086..fe17d902c61 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -699,6 +699,15 @@ fn create_substs_for_ast_path<'a>(&self, }, ); + // Convert associated-type bindings or constraints into a separate vector. + // Example: Given this: + // + // T: Iterator + // + // The `T` is passed in as a self-type; the `Item = u32` is + // not a "type parameter" of the `Iterator` trait, but rather + // a restriction on `::Item`, so it is passed + // back separately. let assoc_bindings = generic_args.bindings.iter() .map(|binding| { let kind = if let hir::TyKind::AssocTyExistential(ref bounds) = binding.ty.node { @@ -899,7 +908,7 @@ pub fn is_unsized(&self, ast_bounds: &[hir::GenericBound], span: Span) -> bool { true } - pub fn add_bounds(&self, + fn add_bounds(&self, param_ty: Ty<'tcx>, ast_bounds: &[hir::GenericBound], bounds: &mut Bounds<'tcx>, @@ -1065,6 +1074,10 @@ fn add_predicates_for_ast_type_binding( match binding.kind { ConvertedBindingKind::Equality(ref ty) => { + // "Desugar" a constraint like `T: Iterator` this to + // the "projection predicate" for: + // + // `::Item = u32` bounds.projection_bounds.push((candidate.map_bound(|trait_ref| { ty::ProjectionPredicate { projection_ty: ty::ProjectionTy::from_ref_and_name( -- 2.44.0