Skip to content

Remove intermediate vectors from add_bounds #79460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,34 +815,25 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
ast_bounds: &[hir::GenericBound<'_>],
bounds: &mut Bounds<'tcx>,
) {
let mut trait_bounds = Vec::new();
let mut region_bounds = Vec::new();

let constness = self.default_constness_for_trait_bounds();
for ast_bound in ast_bounds {
match *ast_bound {
hir::GenericBound::Trait(ref b, hir::TraitBoundModifier::None) => {
trait_bounds.push((b, constness))
self.instantiate_poly_trait_ref(b, constness, param_ty, bounds);
}
hir::GenericBound::Trait(ref b, hir::TraitBoundModifier::MaybeConst) => {
trait_bounds.push((b, Constness::NotConst))
self.instantiate_poly_trait_ref(b, Constness::NotConst, param_ty, bounds);
}
hir::GenericBound::Trait(_, hir::TraitBoundModifier::Maybe) => {}
hir::GenericBound::LangItemTrait(lang_item, span, hir_id, args) => self
.instantiate_lang_item_trait_ref(
lang_item, span, hir_id, args, param_ty, bounds,
),
hir::GenericBound::Outlives(ref l) => region_bounds.push(l),
hir::GenericBound::Outlives(ref l) => {
bounds.region_bounds.push((self.ast_region_to_region(l, None), l.span))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason for the design that I can see is that maybe the calls to ast_region_to_region must come after all calls to instantiate_poly_trait_ref are done. The only reason that can happen is if there are inference lifetimes in these bounds. Basically all that can happen is that some ids (created here) are now in a different order, which seems fine to me.

so the TLDR is that I think this change is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I didn't consider the order of things.

}
}
}

for (bound, constness) in trait_bounds {
let _ = self.instantiate_poly_trait_ref(bound, constness, param_ty, bounds);
}

bounds.region_bounds.extend(
region_bounds.into_iter().map(|r| (self.ast_region_to_region(r, None), r.span)),
);
}

/// Translates a list of bounds from the HIR into the `Bounds` data structure.
Expand Down