Skip to content

Commit 97e6819

Browse files
committed
resolve: Use ControlFlow in fn visit_scopes callback
1 parent 791c041 commit 97e6819

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::ControlFlow;
2+
13
use itertools::Itertools as _;
24
use rustc_ast::visit::{self, Visitor};
35
use rustc_ast::{
@@ -1261,7 +1263,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12611263
}
12621264
}
12631265

1264-
None::<()>
1266+
ControlFlow::<()>::Continue(())
12651267
});
12661268
}
12671269

compiler/rustc_resolve/src/ident.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::ControlFlow;
2+
13
use Determinacy::*;
24
use Namespace::*;
35
use rustc_ast::{self as ast, NodeId};
@@ -56,7 +58,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
5658
Scope<'ra>,
5759
UsePrelude,
5860
SyntaxContext,
59-
) -> Option<T>,
61+
) -> ControlFlow<T>,
6062
) -> Option<T> {
6163
// General principles:
6264
// 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -156,8 +158,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
156158

157159
if visit {
158160
let use_prelude = if use_prelude { UsePrelude::Yes } else { UsePrelude::No };
159-
if let break_result @ Some(..) = visitor(&mut self, scope, use_prelude, ctxt) {
160-
return break_result;
161+
if let ControlFlow::Break(break_result) =
162+
visitor(&mut self, scope, use_prelude, ctxt)
163+
{
164+
return Some(break_result);
161165
}
162166
}
163167

@@ -536,7 +540,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
536540
Ok((binding, Flags::MODULE | misc_flags))
537541
}
538542
Err((Determinacy::Undetermined, Weak::No)) => {
539-
return Some(Err(Determinacy::determined(force)));
543+
return ControlFlow::Break(Err(Determinacy::determined(force)));
540544
}
541545
Err((Determinacy::Undetermined, Weak::Yes)) => {
542546
Err(Determinacy::Undetermined)
@@ -641,15 +645,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
641645
match result {
642646
Ok((binding, flags)) => {
643647
if !sub_namespace_match(binding.macro_kinds(), macro_kind) {
644-
return None;
648+
return ControlFlow::Continue(());
645649
}
646650

647651
// Below we report various ambiguity errors.
648652
// We do not need to report them if we are either in speculative resolution,
649653
// or in late resolution when everything is already imported and expanded
650654
// and no ambiguities exist.
651655
if matches!(finalize, None | Some(Finalize { stage: Stage::Late, .. })) {
652-
return Some(Ok(binding));
656+
return ControlFlow::Break(Ok(binding));
653657
}
654658

655659
if let Some((innermost_binding, innermost_flags)) = innermost_result {
@@ -732,7 +736,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
732736
misc1: misc(innermost_flags),
733737
misc2: misc(flags),
734738
});
735-
return Some(Ok(innermost_binding));
739+
return ControlFlow::Break(Ok(innermost_binding));
736740
}
737741
}
738742
} else {
@@ -744,7 +748,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
744748
Err(Determinacy::Undetermined) => determinacy = Determinacy::Undetermined,
745749
}
746750

747-
None
751+
ControlFlow::Continue(())
748752
},
749753
);
750754

compiler/rustc_resolve/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use std::cell::Ref;
2727
use std::collections::BTreeSet;
2828
use std::fmt::{self};
29+
use std::ops::ControlFlow;
2930
use std::sync::Arc;
3031

3132
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
@@ -1917,7 +1918,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19171918
| Scope::BuiltinTypes => {}
19181919
_ => unreachable!(),
19191920
}
1920-
None::<()>
1921+
ControlFlow::<()>::Continue(())
19211922
});
19221923

19231924
found_traits

0 commit comments

Comments
 (0)