move implicit Sized predicate to end of list

In `Bounds::predicates()`, move the implicit `Sized` predicate to the
end of the generated list. This means that if there is an explicit
`Sized` bound, it will be checked first, and any resulting
diagnostics will have a more useful span.
This commit is contained in:
Taylor Yu 2021-06-04 17:02:13 -05:00
parent 485ced56b8
commit df03b083c9

View file

@ -64,16 +64,16 @@ impl<'tcx> Bounds<'tcx> {
}) })
}); });
sized_predicate self.region_bounds
.into_iter() .iter()
.chain(self.region_bounds.iter().map(|&(region_bound, span)| { .map(|&(region_bound, span)| {
( (
region_bound region_bound
.map_bound(|region_bound| ty::OutlivesPredicate(param_ty, region_bound)) .map_bound(|region_bound| ty::OutlivesPredicate(param_ty, region_bound))
.to_predicate(tcx), .to_predicate(tcx),
span, span,
) )
})) })
.chain(self.trait_bounds.iter().map(|&(bound_trait_ref, span, constness)| { .chain(self.trait_bounds.iter().map(|&(bound_trait_ref, span, constness)| {
let predicate = bound_trait_ref.with_constness(constness).to_predicate(tcx); let predicate = bound_trait_ref.with_constness(constness).to_predicate(tcx);
(predicate, span) (predicate, span)
@ -83,6 +83,7 @@ impl<'tcx> Bounds<'tcx> {
.iter() .iter()
.map(|&(projection, span)| (projection.to_predicate(tcx), span)), .map(|&(projection, span)| (projection.to_predicate(tcx), span)),
) )
.chain(sized_predicate.into_iter())
.collect() .collect()
} }
} }