diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 3ec0919bb8a..c0c4e5b517e 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -878,22 +878,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { pub fn compute_bounds( &self, param_ty: Ty<'tcx>, - ast_bounds: &[&hir::GenericBound<'_>], + ast_bounds: &[hir::GenericBound<'_>], sized_by_default: SizedByDefault, span: Span, ) -> Bounds<'tcx> { - let mut bounds = Bounds::default(); - - self.add_bounds(param_ty, ast_bounds, &mut bounds); - bounds.trait_bounds.sort_by_key(|(t, _, _)| t.def_id()); - - bounds.implicitly_sized = if let SizedByDefault::Yes = sized_by_default { - if !self.is_unsized(ast_bounds, span) { Some(span) } else { None } - } else { - None - }; - - bounds + let ast_bounds: Vec<_> = ast_bounds.iter().collect(); + self.compute_bounds_inner(param_ty, &ast_bounds, sized_by_default, span) } pub fn compute_bounds_that_match_assoc_type( @@ -916,7 +906,28 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } - self.compute_bounds(param_ty, &result, sized_by_default, span) + self.compute_bounds_inner(param_ty, &result, sized_by_default, span) + } + + fn compute_bounds_inner( + &self, + param_ty: Ty<'tcx>, + ast_bounds: &[&hir::GenericBound<'_>], + sized_by_default: SizedByDefault, + span: Span, + ) -> Bounds<'tcx> { + let mut bounds = Bounds::default(); + + self.add_bounds(param_ty, ast_bounds, &mut bounds); + bounds.trait_bounds.sort_by_key(|(t, _, _)| t.def_id()); + + bounds.implicitly_sized = if let SizedByDefault::Yes = sized_by_default { + if !self.is_unsized(ast_bounds, span) { Some(span) } else { None } + } else { + None + }; + + bounds } /// Given an HIR binding like `Item = Foo` or `Item: Foo`, pushes the corresponding predicates diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 8d5e518c151..32527a77934 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -1072,7 +1072,6 @@ fn super_predicates_that_define_assoc_type( assoc_name, ) } else { - let bounds: Vec<_> = bounds.iter().collect(); AstConv::compute_bounds(&icx, self_param_ty, &bounds, SizedByDefault::No, item.span) }; @@ -2030,8 +2029,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP index += 1; let sized = SizedByDefault::Yes; - let bounds: Vec<_> = param.bounds.iter().collect(); - let bounds = AstConv::compute_bounds(&icx, param_ty, &bounds, sized, param.span); + let bounds = + AstConv::compute_bounds(&icx, param_ty, ¶m.bounds, sized, param.span); predicates.extend(bounds.predicates(tcx, param_ty)); } GenericParamKind::Const { .. } => { diff --git a/compiler/rustc_typeck/src/collect/item_bounds.rs b/compiler/rustc_typeck/src/collect/item_bounds.rs index 62586d793b4..dd1da7d9cff 100644 --- a/compiler/rustc_typeck/src/collect/item_bounds.rs +++ b/compiler/rustc_typeck/src/collect/item_bounds.rs @@ -25,7 +25,6 @@ fn associated_type_bounds<'tcx>( InternalSubsts::identity_for_item(tcx, assoc_item_def_id), ); - let bounds: Vec<_> = bounds.iter().collect(); let bounds = AstConv::compute_bounds( &ItemCtxt::new(tcx, assoc_item_def_id), item_ty, @@ -66,7 +65,6 @@ fn opaque_type_bounds<'tcx>( let item_ty = tcx.mk_opaque(opaque_def_id, InternalSubsts::identity_for_item(tcx, opaque_def_id)); - let bounds: Vec<_> = bounds.iter().collect(); let bounds = AstConv::compute_bounds( &ItemCtxt::new(tcx, opaque_def_id), item_ty,