Skip to content

Commit 41fccb1

Browse files
committed
allow or avoid for loops over option in compiler and tests
1 parent c4ab59e commit 41fccb1

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

compiler/rustc_ast/src/visit.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,12 @@ pub trait Visitor<'ast>: Sized {
244244

245245
#[macro_export]
246246
macro_rules! walk_list {
247-
($visitor: expr, $method: ident, $list: expr) => {
248-
for elem in $list {
249-
$visitor.$method(elem)
250-
}
251-
};
252-
($visitor: expr, $method: ident, $list: expr, $($extra_args: expr),*) => {
253-
for elem in $list {
254-
$visitor.$method(elem, $($extra_args,)*)
247+
($visitor: expr, $method: ident, $list: expr $(, $($extra_args: expr),* )?) => {
248+
{
249+
#[cfg_attr(not(bootstrap), allow(for_loop_over_fallibles))]
250+
for elem in $list {
251+
$visitor.$method(elem $(, $($extra_args,)* )?)
252+
}
255253
}
256254
}
257255
}

compiler/rustc_borrowck/src/type_check/input_output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
225225

226226
debug!("{:?} normalized to {:?}", t, norm_ty);
227227

228-
for data in constraints {
228+
if let Some(data) = constraints {
229229
ConstraintConversion::new(
230230
self.infcx,
231231
&self.borrowck_context.universal_regions,

src/test/ui/drop/dropck_legal_cycles.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ impl<'a> Children<'a> for HM<'a> {
10171017
where C: Context + PrePost<Self>, Self: Sized
10181018
{
10191019
if let Some(ref hm) = self.contents.get() {
1020-
for (k, v) in hm.iter().nth(index / 2) {
1020+
if let Some((k, v)) = hm.iter().nth(index / 2) {
10211021
[k, v][index % 2].descend_into_self(context);
10221022
}
10231023
}
@@ -1032,7 +1032,7 @@ impl<'a> Children<'a> for VD<'a> {
10321032
where C: Context + PrePost<Self>, Self: Sized
10331033
{
10341034
if let Some(ref vd) = self.contents.get() {
1035-
for r in vd.iter().nth(index) {
1035+
if let Some(r) = vd.iter().nth(index) {
10361036
r.descend_into_self(context);
10371037
}
10381038
}
@@ -1047,7 +1047,7 @@ impl<'a> Children<'a> for VM<'a> {
10471047
where C: Context + PrePost<VM<'a>>
10481048
{
10491049
if let Some(ref vd) = self.contents.get() {
1050-
for (_idx, r) in vd.iter().nth(index) {
1050+
if let Some((_idx, r)) = vd.iter().nth(index) {
10511051
r.descend_into_self(context);
10521052
}
10531053
}
@@ -1062,7 +1062,7 @@ impl<'a> Children<'a> for LL<'a> {
10621062
where C: Context + PrePost<LL<'a>>
10631063
{
10641064
if let Some(ref ll) = self.contents.get() {
1065-
for r in ll.iter().nth(index) {
1065+
if let Some(r) = ll.iter().nth(index) {
10661066
r.descend_into_self(context);
10671067
}
10681068
}
@@ -1077,7 +1077,7 @@ impl<'a> Children<'a> for BH<'a> {
10771077
where C: Context + PrePost<BH<'a>>
10781078
{
10791079
if let Some(ref bh) = self.contents.get() {
1080-
for r in bh.iter().nth(index) {
1080+
if let Some(r) = bh.iter().nth(index) {
10811081
r.descend_into_self(context);
10821082
}
10831083
}
@@ -1092,7 +1092,7 @@ impl<'a> Children<'a> for BTM<'a> {
10921092
where C: Context + PrePost<BTM<'a>>
10931093
{
10941094
if let Some(ref bh) = self.contents.get() {
1095-
for (k, v) in bh.iter().nth(index / 2) {
1095+
if let Some((k, v)) = bh.iter().nth(index / 2) {
10961096
[k, v][index % 2].descend_into_self(context);
10971097
}
10981098
}
@@ -1107,7 +1107,7 @@ impl<'a> Children<'a> for BTS<'a> {
11071107
where C: Context + PrePost<BTS<'a>>
11081108
{
11091109
if let Some(ref bh) = self.contents.get() {
1110-
for r in bh.iter().nth(index) {
1110+
if let Some(r) = bh.iter().nth(index) {
11111111
r.descend_into_self(context);
11121112
}
11131113
}

src/test/ui/issues/issue-30371.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-pass
22
#![allow(unreachable_code)]
3+
#![allow(for_loop_over_fallibles)]
34
#![deny(unused_variables)]
45

56
fn main() {

0 commit comments

Comments
 (0)