Skip to content

Use the now available implementation of IntoIterator for arrays #86311

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
Jun 15, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions compiler/rustc_apfloat/tests/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ fn add() {
(m_smallest_normalized, m_smallest_normalized, "-0x1p-125", Status::OK, Category::Normal),
];

for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
for (x, y, e_result, e_status, e_category) in special_cases {
let status;
let result = unpack!(status=, x + y);
assert_eq!(status, e_status);
Expand Down Expand Up @@ -2262,7 +2262,7 @@ fn subtract() {
(m_smallest_normalized, m_smallest_normalized, "0x0p+0", Status::OK, Category::Zero),
];

for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
for (x, y, e_result, e_status, e_category) in special_cases {
let status;
let result = unpack!(status=, x - y);
assert_eq!(status, e_status);
Expand Down Expand Up @@ -2538,7 +2538,7 @@ fn multiply() {
(m_smallest_normalized, m_smallest_normalized, "0x0p+0", underflow_status, Category::Zero),
];

for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
for (x, y, e_result, e_status, e_category) in special_cases {
let status;
let result = unpack!(status=, x * y);
assert_eq!(status, e_status);
Expand Down Expand Up @@ -2814,7 +2814,7 @@ fn divide() {
(m_smallest_normalized, m_smallest_normalized, "0x1p+0", Status::OK, Category::Normal),
];

for &(x, y, e_result, e_status, e_category) in &special_cases[..] {
for (x, y, e_result, e_status, e_category) in special_cases {
let status;
let result = unpack!(status=, x / y);
assert_eq!(status, e_status);
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_apfloat/tests/ppc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn ppc_double_double_add_special() {
(0x7ff8000000000000, 0x3ff0000000000000, Category::NaN, Round::NearestTiesToEven),
];

for &(op1, op2, expected, round) in &data {
for (op1, op2, expected, round) in data {
{
let mut a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
Expand Down Expand Up @@ -135,7 +135,7 @@ fn ppc_double_double_add() {
),
];

for &(op1, op2, expected, round) in &data {
for (op1, op2, expected, round) in data {
{
let mut a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
Expand Down Expand Up @@ -172,7 +172,7 @@ fn ppc_double_double_subtract() {
),
];

for &(op1, op2, expected, round) in &data {
for (op1, op2, expected, round) in data {
let mut a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
a1 = a1.sub_r(a2, round).value;
Expand Down Expand Up @@ -204,7 +204,7 @@ fn ppc_double_double_multiply_special() {
(0, 0x3ff0000000000000, Category::Zero, Round::NearestTiesToEven),
];

for &(op1, op2, expected, round) in &data {
for (op1, op2, expected, round) in data {
{
let mut a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
Expand Down Expand Up @@ -290,7 +290,7 @@ fn ppc_double_double_multiply() {
),
];

for &(op1, op2, expected, round) in &data {
for (op1, op2, expected, round) in data {
{
let mut a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
Expand Down Expand Up @@ -322,7 +322,7 @@ fn ppc_double_double_divide() {
),
];

for &(op1, op2, expected, round) in &data {
for (op1, op2, expected, round) in data {
let mut a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
a1 = a1.div_r(a2, round).value;
Expand All @@ -348,7 +348,7 @@ fn ppc_double_double_remainder() {
),
];

for &(op1, op2, expected) in &data {
for (op1, op2, expected) in data {
let a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
let result = a1.ieee_rem(a2).value;
Expand Down Expand Up @@ -376,7 +376,7 @@ fn ppc_double_double_mod() {
),
];

for &(op1, op2, expected) in &data {
for (op1, op2, expected) in data {
let a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
let r = (a1 % a2).value;
Expand Down Expand Up @@ -426,7 +426,7 @@ fn ppc_double_double_compare() {
(0x7ff0000000000000, 0x7ff0000000000000, Some(Ordering::Equal)),
];

for &(op1, op2, expected) in &data {
for (op1, op2, expected) in data {
let a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
assert_eq!(expected, a1.partial_cmp(&a2), "compare({:#x}, {:#x})", op1, op2,);
Expand All @@ -448,7 +448,7 @@ fn ppc_double_double_bitwise_eq() {
(0x7ff0000000000000, 0x7ff0000000000000, true),
];

for &(op1, op2, expected) in &data {
for (op1, op2, expected) in data {
let a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
assert_eq!(expected, a1.bitwise_eq(a2), "{:#x} = {:#x}", op1, op2);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn allocate_use_tree_hir_id_counters(&mut self, tree: &UseTree) {
match tree.kind {
UseTreeKind::Simple(_, id1, id2) => {
for &id in &[id1, id2] {
for id in [id1, id2] {
self.lctx.allocate_hir_id_counter(id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/compiler_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ macro builtin_functions($register:ident; $(fn $name:ident($($arg_name:ident: $ar

#[cfg(feature = "jit")]
pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) {
for &(name, val) in &[$((stringify!($name), $name as *const u8)),*] {
for (name, val) in [$((stringify!($name), $name as *const u8)),*] {
builder.symbol(name, val);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/parse/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn span_of_self_arg_pat_idents_are_correct() {
"impl z { fn a (self: Foo, &myarg: i32) {} }",
];

for &src in &srcs {
for src in srcs {
let spans = get_spans_of_pat_idents(src);
let (lo, hi) = (spans[0].lo(), spans[0].hi());
assert!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
self.combine_map(t).insert(vars, c);
self.undo_log.push(AddCombination(t, vars));
let new_r = tcx.mk_region(ReVar(c));
for &old_r in &[a, b] {
for old_r in [a, b] {
match t {
Glb => self.make_subregion(origin.clone(), new_r, old_r),
Lub => self.make_subregion(origin.clone(), old_r, new_r),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
if !remaining_lib_features.is_empty() {
check_features(&mut remaining_lib_features, &local_defined_features);

for &cnum in &*tcx.crates() {
for &cnum in tcx.crates() {
Copy link
Member

Choose a reason for hiding this comment

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

Is the leading & still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tcx.crates() is a slice (&'tcx [CrateNum]), so I guess we either have to write &cnum or *tcx.crates().

if remaining_lib_features.is_empty() {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_serialize/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ fn test_decode_str() {
("\"\\uAB12\"", "\u{AB12}"),
];

for &(i, o) in &s {
for (i, o) in s {
let v: string::String = json::decode(i).unwrap();
assert_eq!(v, o);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
if sess.target.has_elf_tls {
ret.insert((sym::target_thread_local, None));
}
for &(i, align) in &[
for (i, align) in [
(8, layout.i8_align.abi),
(16, layout.i16_align.abi),
(32, layout.i32_align.abi),
Expand Down Expand Up @@ -1169,7 +1169,7 @@ pub fn get_cmd_lint_options(
let mut lint_opts_with_position = vec![];
let mut describe_lints = false;

for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
for level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
for (passed_arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
let arg_pos = if let lint::Forbid = level {
// HACK: forbid is always specified last, so it can't be overridden.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/abi/call/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where
if let Ok(cls) = cls_or_mem {
let mut needed_int = 0;
let mut needed_sse = 0;
for &c in &cls {
for c in cls {
match c {
Some(Class::Int) => needed_int += 1,
Some(Class::Sse) => needed_sse += 1,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ impl Integer {
pub fn for_align<C: HasDataLayout>(cx: &C, wanted: Align) -> Option<Integer> {
let dl = cx.data_layout();

for &candidate in &[I8, I16, I32, I64, I128] {
for candidate in [I8, I16, I32, I64, I128] {
if wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes() {
return Some(candidate);
}
Expand All @@ -603,7 +603,7 @@ impl Integer {
let dl = cx.data_layout();

// FIXME(eddyb) maybe include I128 in the future, when it works everywhere.
for &candidate in &[I64, I32, I16] {
for candidate in [I64, I32, I16] {
if wanted >= candidate.align(dl).abi && wanted.bytes() >= candidate.size().bytes() {
return candidate;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
opt_arg_exprs: Option<&'tcx [hir::Expr<'tcx>]>,
) -> Option<(Option<Adjustment<'tcx>>, MethodCallee<'tcx>)> {
// Try the options that are least restrictive on the caller first.
for &(opt_trait_def_id, method_name, borrow) in &[
for (opt_trait_def_id, method_name, borrow) in [
(self.tcx.lang_items().fn_trait(), Ident::with_dummy_span(sym::call), true),
(self.tcx.lang_items().fn_mut_trait(), Ident::with_dummy_span(sym::call_mut), true),
(self.tcx.lang_items().fn_once_trait(), Ident::with_dummy_span(sym::call_once), false),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ fn compare_number_of_generics<'tcx>(
let item_kind = assoc_item_kind_str(impl_);

let mut err_occurred = false;
for &(kind, trait_count, impl_count) in &matchings {
for (kind, trait_count, impl_count) in matchings {
if impl_count != trait_count {
err_occurred = true;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// that are not closures, then we type-check the closures. This is so
// that we have more information about the types of arguments when we
// type-check the functions. This isn't really the right way to do this.
for &check_closures in &[false, true] {
for check_closures in [false, true] {
debug!("check_closures={}", check_closures);

// More awful hacks: before we check argument types, try to do
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::Slice(_) => {
for &lang_def_id in &[
for lang_def_id in [
lang_items.slice_impl(),
lang_items.slice_u8_impl(),
lang_items.slice_alloc_impl(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/place_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr, base_expr, adjusted_ty, index_ty
);

for &unsize in &[false, true] {
for unsize in [false, true] {
Copy link
Member

Choose a reason for hiding this comment

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

Not something that needs changing in this PR: I wonder, in general, how perf differs between copying an array vs slice-iterating the rvalue-static-promoted one.

Copy link
Member

Choose a reason for hiding this comment

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

See the perf run, looks like not much: #86311 (comment). But it might just be because these aren't in perf-sensitive parts of the compiler.

let mut self_ty = adjusted_ty;
if unsize {
// We only unsize arrays here.
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ impl LinkCollector<'_, '_> {
let other_ns = if expected_ns == ValueNS { TypeNS } else { ValueNS };
// FIXME: really it should be `resolution_failure` that does this, not `resolve_with_disambiguator`
// See https://github.com/rust-lang/rust/pull/76955#discussion_r493953382 for a good approach
for &new_ns in &[other_ns, MacroNS] {
for new_ns in [other_ns, MacroNS] {
if let Some(res) =
self.check_full_res(new_ns, path_str, base_node, extra_fragment)
{
Expand Down Expand Up @@ -1444,7 +1444,7 @@ impl LinkCollector<'_, '_> {
Ok(res) => Some((res, extra_fragment.clone())),
Err(mut kind) => {
// `resolve_macro` only looks in the macro namespace. Try to give a better error if possible.
for &ns in &[TypeNS, ValueNS] {
for ns in [TypeNS, ValueNS] {
if let Some(res) =
self.check_full_res(ns, path_str, base_node, extra_fragment)
{
Expand Down Expand Up @@ -1558,7 +1558,7 @@ impl Disambiguator {
("()", DefKind::Fn),
("!", DefKind::Macro(MacroKind::Bang)),
];
for &(suffix, kind) in &suffixes {
for (suffix, kind) in suffixes {
if let Some(link) = link.strip_suffix(suffix) {
// Avoid turning `!` or `()` into an empty string
if !link.is_empty() {
Expand Down Expand Up @@ -1798,7 +1798,7 @@ fn resolution_failure(
break;
};
name = start;
for &ns in &[TypeNS, ValueNS, MacroNS] {
for ns in [TypeNS, ValueNS, MacroNS] {
if let Some(res) =
collector.check_full_res(ns, &start, module_id.into(), &None)
{
Expand Down