Eliminate an "Extra scope required" obsoleted by NLL
This commit is contained in:
parent
d03b3db95b
commit
bd2b53ba6d
1 changed files with 48 additions and 52 deletions
|
@ -695,65 +695,61 @@ impl<'a> TraitDef<'a> {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
{
|
let mut ty_params = params
|
||||||
// Extra scope required here so ty_params goes out of scope before params is moved
|
.iter()
|
||||||
|
.filter(|param| matches!(param.kind, ast::GenericParamKind::Type { .. }))
|
||||||
|
.peekable();
|
||||||
|
|
||||||
let mut ty_params = params
|
if ty_params.peek().is_some() {
|
||||||
.iter()
|
let ty_param_names: Vec<Symbol> =
|
||||||
.filter(|param| matches!(param.kind, ast::GenericParamKind::Type { .. }))
|
ty_params.map(|ty_param| ty_param.ident.name).collect();
|
||||||
.peekable();
|
|
||||||
|
|
||||||
if ty_params.peek().is_some() {
|
for field_ty in field_tys {
|
||||||
let ty_param_names: Vec<Symbol> =
|
let field_ty_params = find_type_parameters(&field_ty, &ty_param_names, cx);
|
||||||
ty_params.map(|ty_param| ty_param.ident.name).collect();
|
|
||||||
|
|
||||||
for field_ty in field_tys {
|
for field_ty_param in field_ty_params {
|
||||||
let field_ty_params = find_type_parameters(&field_ty, &ty_param_names, cx);
|
// if we have already handled this type, skip it
|
||||||
|
if let ast::TyKind::Path(_, p) = &field_ty_param.ty.kind
|
||||||
for field_ty_param in field_ty_params {
|
&& let [sole_segment] = &*p.segments
|
||||||
// if we have already handled this type, skip it
|
&& ty_param_names.contains(&sole_segment.ident.name)
|
||||||
if let ast::TyKind::Path(_, p) = &field_ty_param.ty.kind
|
{
|
||||||
&& let [sole_segment] = &*p.segments
|
continue;
|
||||||
&& ty_param_names.contains(&sole_segment.ident.name)
|
}
|
||||||
{
|
let mut bounds: Vec<_> = self
|
||||||
continue;
|
.additional_bounds
|
||||||
}
|
.iter()
|
||||||
let mut bounds: Vec<_> = self
|
.map(|p| {
|
||||||
.additional_bounds
|
cx.trait_bound(
|
||||||
.iter()
|
|
||||||
.map(|p| {
|
|
||||||
cx.trait_bound(
|
|
||||||
p.to_path(cx, self.span, type_ident, generics),
|
|
||||||
self.is_const,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Require the current trait.
|
|
||||||
if !self.skip_path_as_bound {
|
|
||||||
bounds.push(cx.trait_bound(trait_path.clone(), self.is_const));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a `Copy` bound if required.
|
|
||||||
if is_packed && self.needs_copy_as_bound_if_packed {
|
|
||||||
let p = deriving::path_std!(marker::Copy);
|
|
||||||
bounds.push(cx.trait_bound(
|
|
||||||
p.to_path(cx, self.span, type_ident, generics),
|
p.to_path(cx, self.span, type_ident, generics),
|
||||||
self.is_const,
|
self.is_const,
|
||||||
));
|
)
|
||||||
}
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
if !bounds.is_empty() {
|
// Require the current trait.
|
||||||
let predicate = ast::WhereBoundPredicate {
|
if !self.skip_path_as_bound {
|
||||||
span: self.span,
|
bounds.push(cx.trait_bound(trait_path.clone(), self.is_const));
|
||||||
bound_generic_params: field_ty_param.bound_generic_params,
|
}
|
||||||
bounded_ty: field_ty_param.ty,
|
|
||||||
bounds,
|
|
||||||
};
|
|
||||||
|
|
||||||
let predicate = ast::WherePredicate::BoundPredicate(predicate);
|
// Add a `Copy` bound if required.
|
||||||
where_clause.predicates.push(predicate);
|
if is_packed && self.needs_copy_as_bound_if_packed {
|
||||||
}
|
let p = deriving::path_std!(marker::Copy);
|
||||||
|
bounds.push(cx.trait_bound(
|
||||||
|
p.to_path(cx, self.span, type_ident, generics),
|
||||||
|
self.is_const,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bounds.is_empty() {
|
||||||
|
let predicate = ast::WhereBoundPredicate {
|
||||||
|
span: self.span,
|
||||||
|
bound_generic_params: field_ty_param.bound_generic_params,
|
||||||
|
bounded_ty: field_ty_param.ty,
|
||||||
|
bounds,
|
||||||
|
};
|
||||||
|
|
||||||
|
let predicate = ast::WherePredicate::BoundPredicate(predicate);
|
||||||
|
where_clause.predicates.push(predicate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue