Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit dd267fe

Browse files
committed
compute_bounds takes &[GenericBound]
1 parent c0007a2 commit dd267fe

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -878,22 +878,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
878878
pub fn compute_bounds(
879879
&self,
880880
param_ty: Ty<'tcx>,
881-
ast_bounds: &[&hir::GenericBound<'_>],
881+
ast_bounds: &[hir::GenericBound<'_>],
882882
sized_by_default: SizedByDefault,
883883
span: Span,
884884
) -> Bounds<'tcx> {
885-
let mut bounds = Bounds::default();
886-
887-
self.add_bounds(param_ty, ast_bounds, &mut bounds);
888-
bounds.trait_bounds.sort_by_key(|(t, _, _)| t.def_id());
889-
890-
bounds.implicitly_sized = if let SizedByDefault::Yes = sized_by_default {
891-
if !self.is_unsized(ast_bounds, span) { Some(span) } else { None }
892-
} else {
893-
None
894-
};
895-
896-
bounds
885+
let ast_bounds: Vec<_> = ast_bounds.iter().collect();
886+
self.compute_bounds_inner(param_ty, &ast_bounds, sized_by_default, span)
897887
}
898888

899889
pub fn compute_bounds_that_match_assoc_type(
@@ -916,7 +906,28 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
916906
}
917907
}
918908

919-
self.compute_bounds(param_ty, &result, sized_by_default, span)
909+
self.compute_bounds_inner(param_ty, &result, sized_by_default, span)
910+
}
911+
912+
fn compute_bounds_inner(
913+
&self,
914+
param_ty: Ty<'tcx>,
915+
ast_bounds: &[&hir::GenericBound<'_>],
916+
sized_by_default: SizedByDefault,
917+
span: Span,
918+
) -> Bounds<'tcx> {
919+
let mut bounds = Bounds::default();
920+
921+
self.add_bounds(param_ty, ast_bounds, &mut bounds);
922+
bounds.trait_bounds.sort_by_key(|(t, _, _)| t.def_id());
923+
924+
bounds.implicitly_sized = if let SizedByDefault::Yes = sized_by_default {
925+
if !self.is_unsized(ast_bounds, span) { Some(span) } else { None }
926+
} else {
927+
None
928+
};
929+
930+
bounds
920931
}
921932

922933
/// Given an HIR binding like `Item = Foo` or `Item: Foo`, pushes the corresponding predicates

compiler/rustc_typeck/src/collect.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,6 @@ fn super_predicates_that_define_assoc_type(
10721072
assoc_name,
10731073
)
10741074
} else {
1075-
let bounds: Vec<_> = bounds.iter().collect();
10761075
AstConv::compute_bounds(&icx, self_param_ty, &bounds, SizedByDefault::No, item.span)
10771076
};
10781077

@@ -2030,8 +2029,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
20302029
index += 1;
20312030

20322031
let sized = SizedByDefault::Yes;
2033-
let bounds: Vec<_> = param.bounds.iter().collect();
2034-
let bounds = AstConv::compute_bounds(&icx, param_ty, &bounds, sized, param.span);
2032+
let bounds =
2033+
AstConv::compute_bounds(&icx, param_ty, &param.bounds, sized, param.span);
20352034
predicates.extend(bounds.predicates(tcx, param_ty));
20362035
}
20372036
GenericParamKind::Const { .. } => {

compiler/rustc_typeck/src/collect/item_bounds.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ fn associated_type_bounds<'tcx>(
2525
InternalSubsts::identity_for_item(tcx, assoc_item_def_id),
2626
);
2727

28-
let bounds: Vec<_> = bounds.iter().collect();
2928
let bounds = AstConv::compute_bounds(
3029
&ItemCtxt::new(tcx, assoc_item_def_id),
3130
item_ty,
@@ -66,7 +65,6 @@ fn opaque_type_bounds<'tcx>(
6665
let item_ty =
6766
tcx.mk_opaque(opaque_def_id, InternalSubsts::identity_for_item(tcx, opaque_def_id));
6867

69-
let bounds: Vec<_> = bounds.iter().collect();
7068
let bounds = AstConv::compute_bounds(
7169
&ItemCtxt::new(tcx, opaque_def_id),
7270
item_ty,

0 commit comments

Comments
 (0)