prefer to use repeat_n over repeat and take
This commit is contained in:
@@ -368,7 +368,7 @@ fn expand_preparsed_asm(
|
|||||||
if args.options.contains(ast::InlineAsmOptions::RAW) {
|
if args.options.contains(ast::InlineAsmOptions::RAW) {
|
||||||
template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string().into()));
|
template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string().into()));
|
||||||
let template_num_lines = 1 + template_str.matches('\n').count();
|
let template_num_lines = 1 + template_str.matches('\n').count();
|
||||||
line_spans.extend(std::iter::repeat(template_sp).take(template_num_lines));
|
line_spans.extend(std::iter::repeat_n(template_sp, template_num_lines));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,7 +523,7 @@ fn expand_preparsed_asm(
|
|||||||
|
|
||||||
if parser.line_spans.is_empty() {
|
if parser.line_spans.is_empty() {
|
||||||
let template_num_lines = 1 + template_str.matches('\n').count();
|
let template_num_lines = 1 + template_str.matches('\n').count();
|
||||||
line_spans.extend(std::iter::repeat(template_sp).take(template_num_lines));
|
line_spans.extend(std::iter::repeat_n(template_sp, template_num_lines));
|
||||||
} else {
|
} else {
|
||||||
line_spans.extend(
|
line_spans.extend(
|
||||||
parser
|
parser
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ fn data_id_for_static(
|
|||||||
let mut data = DataDescription::new();
|
let mut data = DataDescription::new();
|
||||||
data.set_align(align);
|
data.set_align(align);
|
||||||
let data_gv = module.declare_data_in_data(data_id, &mut data);
|
let data_gv = module.declare_data_in_data(data_id, &mut data);
|
||||||
data.define(std::iter::repeat(0).take(pointer_ty(tcx).bytes() as usize).collect());
|
data.define(std::iter::repeat_n(0, pointer_ty(tcx).bytes() as usize).collect());
|
||||||
data.write_data_addr(0, data_gv, 0);
|
data.write_data_addr(0, data_gv, 0);
|
||||||
match module.define_data(ref_data_id, &data) {
|
match module.define_data(ref_data_id, &data) {
|
||||||
// Every time the static is referenced there will be another definition of this global,
|
// Every time the static is referenced there will be another definition of this global,
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ pub fn get_span_and_frames<'tcx>(
|
|||||||
if frame.times < 3 {
|
if frame.times < 3 {
|
||||||
let times = frame.times;
|
let times = frame.times;
|
||||||
frame.times = 0;
|
frame.times = 0;
|
||||||
frames.extend(std::iter::repeat(frame).take(times as usize));
|
frames.extend(std::iter::repeat_n(frame, times as usize));
|
||||||
} else {
|
} else {
|
||||||
frames.push(frame);
|
frames.push(frame);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -878,7 +878,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
.compute_size_in_bytes(layout.size, count)
|
.compute_size_in_bytes(layout.size, count)
|
||||||
.ok_or_else(|| err_ub_custom!(fluent::const_eval_size_overflow, name = name))?;
|
.ok_or_else(|| err_ub_custom!(fluent::const_eval_size_overflow, name = name))?;
|
||||||
|
|
||||||
let bytes = std::iter::repeat(byte).take(len.bytes_usize());
|
let bytes = std::iter::repeat_n(byte, len.bytes_usize());
|
||||||
self.write_bytes_ptr(dst, bytes)
|
self.write_bytes_ptr(dst, bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ fn check_validity_requirement_strict<'tcx>(
|
|||||||
if kind == ValidityRequirement::Zero {
|
if kind == ValidityRequirement::Zero {
|
||||||
cx.write_bytes_ptr(
|
cx.write_bytes_ptr(
|
||||||
allocated.ptr(),
|
allocated.ptr(),
|
||||||
std::iter::repeat(0_u8).take(ty.layout.size().bytes_usize()),
|
std::iter::repeat_n(0_u8, ty.layout.size().bytes_usize()),
|
||||||
)
|
)
|
||||||
.expect("failed to write bytes for zero valid check");
|
.expect("failed to write bytes for zero valid check");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -590,7 +590,7 @@ fn get_new_lifetime_name<'tcx>(
|
|||||||
let a_to_z_repeat_n = |n| {
|
let a_to_z_repeat_n = |n| {
|
||||||
(b'a'..=b'z').map(move |c| {
|
(b'a'..=b'z').map(move |c| {
|
||||||
let mut s = '\''.to_string();
|
let mut s = '\''.to_string();
|
||||||
s.extend(std::iter::repeat(char::from(c)).take(n));
|
s.extend(std::iter::repeat_n(char::from(c), n));
|
||||||
s
|
s
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -339,8 +339,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||||||
hir::GenericArg::Lifetime(lt) => Some(lt),
|
hir::GenericArg::Lifetime(lt) => Some(lt),
|
||||||
_ => None,
|
_ => None,
|
||||||
}) {
|
}) {
|
||||||
return std::iter::repeat(lt.to_string())
|
return std::iter::repeat_n(lt.to_string(), num_params_to_take)
|
||||||
.take(num_params_to_take)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
}
|
}
|
||||||
@@ -362,8 +361,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||||||
matches!(fn_decl.output, hir::FnRetTy::Return(ty) if ty.hir_id == ty_id);
|
matches!(fn_decl.output, hir::FnRetTy::Return(ty) if ty.hir_id == ty_id);
|
||||||
|
|
||||||
if in_arg || (in_ret && fn_decl.lifetime_elision_allowed) {
|
if in_arg || (in_ret && fn_decl.lifetime_elision_allowed) {
|
||||||
return std::iter::repeat("'_".to_owned())
|
return std::iter::repeat_n("'_".to_owned(), num_params_to_take)
|
||||||
.take(num_params_to_take)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
}
|
}
|
||||||
@@ -388,8 +386,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||||||
})
|
})
|
||||||
| hir::Node::AnonConst(..) = node
|
| hir::Node::AnonConst(..) = node
|
||||||
{
|
{
|
||||||
return std::iter::repeat("'static".to_owned())
|
return std::iter::repeat_n("'static".to_owned(), num_params_to_take.saturating_sub(ret.len()))
|
||||||
.take(num_params_to_take.saturating_sub(ret.len()))
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2602,7 +2602,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let suggestion = |name, args| {
|
let suggestion = |name, args| {
|
||||||
format!(
|
format!(
|
||||||
"::{name}({})",
|
"::{name}({})",
|
||||||
std::iter::repeat("_").take(args).collect::<Vec<_>>().join(", ")
|
std::iter::repeat_n("_", args).collect::<Vec<_>>().join(", ")
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
match &items[..] {
|
match &items[..] {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::iter::repeat;
|
use std::iter::repeat_n;
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
|
||||||
use hir::intravisit::{self, Visitor};
|
use hir::intravisit::{self, Visitor};
|
||||||
@@ -351,7 +351,7 @@ impl Subdiagnostic for IfLetRescopeRewrite {
|
|||||||
.then_some(" _ => {}".chars())
|
.then_some(" _ => {}".chars())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.chain(repeat('}').take(closing_brackets.count))
|
.chain(repeat_n('}', closing_brackets.count))
|
||||||
.collect(),
|
.collect(),
|
||||||
));
|
));
|
||||||
let msg = diag.eagerly_translate(crate::fluent_generated::lint_suggestion);
|
let msg = diag.eagerly_translate(crate::fluent_generated::lint_suggestion);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let fn_sig = ty::Binder::dummy(tcx.mk_fn_sig(
|
let fn_sig = ty::Binder::dummy(tcx.mk_fn_sig(
|
||||||
std::iter::repeat(err).take(arity),
|
std::iter::repeat_n(err, arity),
|
||||||
err,
|
err,
|
||||||
false,
|
false,
|
||||||
rustc_hir::Safety::Safe,
|
rustc_hir::Safety::Safe,
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
|
|||||||
fn report_calling_closure(&mut self, fun: &Expr<'_>, tupled_args: Ty<'_>, expr: &Expr<'_>) {
|
fn report_calling_closure(&mut self, fun: &Expr<'_>, tupled_args: Ty<'_>, expr: &Expr<'_>) {
|
||||||
let underscored_args = match tupled_args.kind() {
|
let underscored_args = match tupled_args.kind() {
|
||||||
ty::Tuple(tys) if tys.is_empty() => "".to_owned(),
|
ty::Tuple(tys) if tys.is_empty() => "".to_owned(),
|
||||||
ty::Tuple(tys) => std::iter::repeat("_, ").take(tys.len() - 1).chain(["_"]).collect(),
|
ty::Tuple(tys) => std::iter::repeat_n("_, ", tys.len() - 1).chain(["_"]).collect(),
|
||||||
_ => "_".to_owned(),
|
_ => "_".to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2019,7 +2019,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let expected_sig = tcx.mk_fn_sig(
|
let expected_sig = tcx.mk_fn_sig(
|
||||||
std::iter::repeat(token_stream).take(match kind {
|
std::iter::repeat_n(token_stream, match kind {
|
||||||
ProcMacroKind::Attribute => 2,
|
ProcMacroKind::Attribute => 2,
|
||||||
ProcMacroKind::Derive | ProcMacroKind::FunctionLike => 1,
|
ProcMacroKind::Derive | ProcMacroKind::FunctionLike => 1,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -566,7 +566,7 @@ impl<D: Deps> EncoderState<D> {
|
|||||||
edge_count: 0,
|
edge_count: 0,
|
||||||
node_count: 0,
|
node_count: 0,
|
||||||
encoder: MemEncoder::new(),
|
encoder: MemEncoder::new(),
|
||||||
kind_stats: iter::repeat(0).take(D::DEP_KIND_MAX as usize + 1).collect(),
|
kind_stats: iter::repeat_n(0, D::DEP_KIND_MAX as usize + 1).collect(),
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
@@ -735,7 +735,7 @@ impl<D: Deps> EncoderState<D> {
|
|||||||
|
|
||||||
let mut encoder = self.file.lock().take().unwrap();
|
let mut encoder = self.file.lock().take().unwrap();
|
||||||
|
|
||||||
let mut kind_stats: Vec<u32> = iter::repeat(0).take(D::DEP_KIND_MAX as usize + 1).collect();
|
let mut kind_stats: Vec<u32> = iter::repeat_n(0, D::DEP_KIND_MAX as usize + 1).collect();
|
||||||
|
|
||||||
let mut node_max = 0;
|
let mut node_max = 0;
|
||||||
let mut node_count = 0;
|
let mut node_count = 0;
|
||||||
|
|||||||
@@ -2214,10 +2214,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
items.sort_by_key(|(order, _, _)| *order);
|
items.sort_by_key(|(order, _, _)| *order);
|
||||||
let suggestion = |name, args| {
|
let suggestion = |name, args| {
|
||||||
format!(
|
format!("::{name}({})", std::iter::repeat_n("_", args).collect::<Vec<_>>().join(", "))
|
||||||
"::{name}({})",
|
|
||||||
std::iter::repeat("_").take(args).collect::<Vec<_>>().join(", ")
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
match &items[..] {
|
match &items[..] {
|
||||||
[] => {}
|
[] => {}
|
||||||
@@ -3485,17 +3482,14 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||||||
(lt.span.shrink_to_hi(), format!("{existing_name} "))
|
(lt.span.shrink_to_hi(), format!("{existing_name} "))
|
||||||
}
|
}
|
||||||
MissingLifetimeKind::Comma => {
|
MissingLifetimeKind::Comma => {
|
||||||
let sugg: String = std::iter::repeat([existing_name.as_str(), ", "])
|
let sugg: String = std::iter::repeat_n([existing_name.as_str(), ", "], lt.count)
|
||||||
.take(lt.count)
|
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect();
|
.collect();
|
||||||
(lt.span.shrink_to_hi(), sugg)
|
(lt.span.shrink_to_hi(), sugg)
|
||||||
}
|
}
|
||||||
MissingLifetimeKind::Brackets => {
|
MissingLifetimeKind::Brackets => {
|
||||||
let sugg: String = std::iter::once("<")
|
let sugg: String = std::iter::once("<")
|
||||||
.chain(
|
.chain(std::iter::repeat_n(existing_name.as_str(), lt.count).intersperse(", "))
|
||||||
std::iter::repeat(existing_name.as_str()).take(lt.count).intersperse(", "),
|
|
||||||
)
|
|
||||||
.chain([">"])
|
.chain([">"])
|
||||||
.collect();
|
.collect();
|
||||||
(lt.span.shrink_to_hi(), sugg)
|
(lt.span.shrink_to_hi(), sugg)
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ fn make_elided_region_spans_suggs<'a>(
|
|||||||
consecutive_brackets += 1;
|
consecutive_brackets += 1;
|
||||||
} else if let Some(bracket_span) = bracket_span.take() {
|
} else if let Some(bracket_span) = bracket_span.take() {
|
||||||
let sugg = std::iter::once("<")
|
let sugg = std::iter::once("<")
|
||||||
.chain(std::iter::repeat(name).take(consecutive_brackets).intersperse(", "))
|
.chain(std::iter::repeat_n(name, consecutive_brackets).intersperse(", "))
|
||||||
.chain([">"])
|
.chain([">"])
|
||||||
.collect();
|
.collect();
|
||||||
spans_suggs.push((bracket_span.shrink_to_hi(), sugg));
|
spans_suggs.push((bracket_span.shrink_to_hi(), sugg));
|
||||||
|
|||||||
@@ -326,8 +326,7 @@ pub(crate) mod rustc {
|
|||||||
let inner_layout = layout_of(cx, *inner_ty)?;
|
let inner_layout = layout_of(cx, *inner_ty)?;
|
||||||
assert_eq!(*stride, inner_layout.size);
|
assert_eq!(*stride, inner_layout.size);
|
||||||
let elt = Tree::from_ty(*inner_ty, cx)?;
|
let elt = Tree::from_ty(*inner_ty, cx)?;
|
||||||
Ok(std::iter::repeat(elt)
|
Ok(std::iter::repeat_n(elt, *count as usize)
|
||||||
.take(*count as usize)
|
|
||||||
.fold(Tree::unit(), |tree, elt| tree.then(elt)))
|
.fold(Tree::unit(), |tree, elt| tree.then(elt)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user