Skip to content

Commit 196df6a

Browse files
committed
Convert TypeVisitor and DefIdVisitor to use VisitorResult
1 parent 8e83c19 commit 196df6a

File tree

58 files changed

+389
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+389
-456
lines changed

Cargo.lock

+9
Original file line numberDiff line numberDiff line change
@@ -3481,6 +3481,7 @@ dependencies = [
34813481
"rustc_session",
34823482
"rustc_span",
34833483
"rustc_target",
3484+
"rustc_type_ir",
34843485
"thin-vec",
34853486
]
34863487

@@ -3571,6 +3572,7 @@ dependencies = [
35713572
"rustc_session",
35723573
"rustc_span",
35733574
"rustc_target",
3575+
"rustc_type_ir",
35743576
"smallvec",
35753577
"thin-vec",
35763578
"tracing",
@@ -3842,6 +3844,7 @@ dependencies = [
38423844
"rustc_serialize",
38433845
"rustc_session",
38443846
"rustc_span",
3847+
"rustc_type_ir",
38453848
"smallvec",
38463849
"termcolor",
38473850
"thin-vec",
@@ -3890,6 +3893,7 @@ dependencies = [
38903893
"rustc_serialize",
38913894
"rustc_span",
38923895
"rustc_target",
3896+
"rustc_type_ir",
38933897
"smallvec",
38943898
"tracing",
38953899
]
@@ -4016,6 +4020,7 @@ dependencies = [
40164020
"rustc_middle",
40174021
"rustc_span",
40184022
"rustc_target",
4023+
"rustc_type_ir",
40194024
"smallvec",
40204025
"tracing",
40214026
]
@@ -4405,6 +4410,7 @@ dependencies = [
44054410
"rustc_session",
44064411
"rustc_span",
44074412
"rustc_ty_utils",
4413+
"rustc_type_ir",
44084414
"tracing",
44094415
]
44104416

@@ -4475,6 +4481,7 @@ dependencies = [
44754481
"rustc_query_system",
44764482
"rustc_session",
44774483
"rustc_span",
4484+
"rustc_type_ir",
44784485
"smallvec",
44794486
"thin-vec",
44804487
"tracing",
@@ -4615,6 +4622,7 @@ dependencies = [
46154622
"rustc_span",
46164623
"rustc_target",
46174624
"rustc_transmute",
4625+
"rustc_type_ir",
46184626
"smallvec",
46194627
"tracing",
46204628
]
@@ -4644,6 +4652,7 @@ dependencies = [
46444652
"rustc_middle",
46454653
"rustc_span",
46464654
"rustc_target",
4655+
"rustc_type_ir",
46474656
"tracing",
46484657
]
46494658

compiler/rustc_ast_passes/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ rustc_parse = { path = "../rustc_parse" }
1818
rustc_session = { path = "../rustc_session" }
1919
rustc_span = { path = "../rustc_span" }
2020
rustc_target = { path = "../rustc_target" }
21+
rustc_type_ir = { path = "../rustc_type_ir" }
2122
thin-vec = "0.2.12"
2223
# tidy-alphabetical-end

compiler/rustc_builtin_macros/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rustc_parse_format = { path = "../rustc_parse_format" }
2525
rustc_session = { path = "../rustc_session" }
2626
rustc_span = { path = "../rustc_span" }
2727
rustc_target = { path = "../rustc_target" }
28+
rustc_type_ir = { path = "../rustc_type_ir" }
2829
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2930
thin-vec = "0.2.12"
3031
tracing = "0.1"

compiler/rustc_const_eval/src/interpret/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ where
3030
}
3131

3232
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor<'tcx> {
33-
type BreakTy = FoundParam;
33+
type Result = ControlFlow<FoundParam>;
3434

35-
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
35+
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
3636
if !ty.has_param() {
3737
return ControlFlow::Continue(());
3838
}
@@ -64,7 +64,7 @@ where
6464
}
6565
}
6666

67-
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
67+
fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
6868
match c.kind() {
6969
ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam),
7070
_ => c.super_visit_with(self),

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt};
1717
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitor};
1818

1919
use std::mem;
20-
use std::ops::{ControlFlow, Deref};
20+
use std::ops::Deref;
2121

2222
use super::ops::{self, NonConstOp, Status};
2323
use super::qualifs::{self, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
@@ -164,9 +164,9 @@ struct LocalReturnTyVisitor<'ck, 'mir, 'tcx> {
164164
}
165165

166166
impl<'ck, 'mir, 'tcx> TypeVisitor<TyCtxt<'tcx>> for LocalReturnTyVisitor<'ck, 'mir, 'tcx> {
167-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
167+
fn visit_ty(&mut self, t: Ty<'tcx>) {
168168
match t.kind() {
169-
ty::FnPtr(_) => ControlFlow::Continue(()),
169+
ty::FnPtr(_) => {}
170170
ty::Ref(_, _, hir::Mutability::Mut) => {
171171
self.checker.check_op(ops::ty::MutRef(self.kind));
172172
t.super_visit_with(self)

compiler/rustc_expand/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ rustc_parse = { path = "../rustc_parse" }
2424
rustc_serialize = { path = "../rustc_serialize" }
2525
rustc_session = { path = "../rustc_session" }
2626
rustc_span = { path = "../rustc_span" }
27+
rustc_type_ir = { path = "../rustc_type_ir" }
2728
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2829
termcolor = "1.2"
2930
thin-vec = "0.2.12"

compiler/rustc_hir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_macros = { path = "../rustc_macros" }
1414
rustc_serialize = { path = "../rustc_serialize" }
1515
rustc_span = { path = "../rustc_span" }
1616
rustc_target = { path = "../rustc_target" }
17+
rustc_type_ir = { path = "../rustc_type_ir" }
1718
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
1819
tracing = "0.1"
1920
# tidy-alphabetical-end

compiler/rustc_hir_analysis/src/check/check.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1486,15 +1486,14 @@ fn opaque_type_cycle_error(
14861486
closures: Vec<DefId>,
14871487
}
14881488
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector {
1489-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
1489+
fn visit_ty(&mut self, t: Ty<'tcx>) {
14901490
match *t.kind() {
14911491
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
14921492
self.opaques.push(def);
1493-
ControlFlow::Continue(())
14941493
}
14951494
ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => {
14961495
self.closures.push(def_id);
1497-
t.super_visit_with(self)
1496+
t.super_visit_with(self);
14981497
}
14991498
_ => t.super_visit_with(self),
15001499
}

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_trait_selection::regions::InferCtxtRegionExt;
1212
use rustc_trait_selection::traits::{
1313
elaborate, normalize_param_env_or_error, outlives_bounds::InferCtxtExt, ObligationCtxt,
1414
};
15-
use std::ops::ControlFlow;
1615

1716
/// Check that an implementation does not refine an RPITIT from a trait method signature.
1817
pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
@@ -207,9 +206,7 @@ struct ImplTraitInTraitCollector<'tcx> {
207206
}
208207

209208
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> {
210-
type BreakTy = !;
211-
212-
fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
209+
fn visit_ty(&mut self, ty: Ty<'tcx>) {
213210
if let ty::Alias(ty::Projection, proj) = *ty.kind()
214211
&& self.tcx.is_impl_trait_in_trait(proj.def_id)
215212
{
@@ -219,12 +216,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> {
219216
.explicit_item_bounds(proj.def_id)
220217
.iter_instantiated_copied(self.tcx, proj.args)
221218
{
222-
pred.visit_with(self)?;
219+
pred.visit_with(self);
223220
}
224221
}
225-
ControlFlow::Continue(())
226222
} else {
227-
ty.super_visit_with(self)
223+
ty.super_visit_with(self);
228224
}
229225
}
230226
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,7 @@ impl<'tcx> GATArgsCollector<'tcx> {
809809
}
810810

811811
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GATArgsCollector<'tcx> {
812-
type BreakTy = !;
813-
814-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
812+
fn visit_ty(&mut self, t: Ty<'tcx>) {
815813
match t.kind() {
816814
ty::Alias(ty::Projection, p) if p.def_id == self.gat => {
817815
for (idx, arg) in p.args.iter().enumerate() {
@@ -1456,20 +1454,19 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14561454
params: FxHashSet<u32>,
14571455
}
14581456
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for CountParams {
1459-
type BreakTy = ();
1460-
1461-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
1457+
type Result = ControlFlow<()>;
1458+
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
14621459
if let ty::Param(param) = t.kind() {
14631460
self.params.insert(param.index);
14641461
}
14651462
t.super_visit_with(self)
14661463
}
14671464

1468-
fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
1465+
fn visit_region(&mut self, _: ty::Region<'tcx>) -> Self::Result {
14691466
ControlFlow::Break(())
14701467
}
14711468

1472-
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
1469+
fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result {
14731470
if let ty::ConstKind::Param(param) = c.kind() {
14741471
self.params.insert(param.index);
14751472
}

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1965,31 +1965,26 @@ fn is_late_bound_map(
19651965
arg_is_constrained: Box<[bool]>,
19661966
}
19671967

1968-
use std::ops::ControlFlow;
19691968
use ty::Ty;
19701969
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostAstConv {
1971-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<!> {
1970+
fn visit_ty(&mut self, t: Ty<'tcx>) {
19721971
match t.kind() {
19731972
ty::Param(param_ty) => {
19741973
self.arg_is_constrained[param_ty.index as usize] = true;
19751974
}
1976-
ty::Alias(ty::Projection | ty::Inherent, _) => return ControlFlow::Continue(()),
1975+
ty::Alias(ty::Projection | ty::Inherent, _) => return,
19771976
_ => (),
19781977
}
19791978
t.super_visit_with(self)
19801979
}
19811980

1982-
fn visit_const(&mut self, _: ty::Const<'tcx>) -> ControlFlow<!> {
1983-
ControlFlow::Continue(())
1984-
}
1981+
fn visit_const(&mut self, _: ty::Const<'tcx>) {}
19851982

1986-
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<!> {
1983+
fn visit_region(&mut self, r: ty::Region<'tcx>) {
19871984
debug!("r={:?}", r.kind());
19881985
if let ty::RegionKind::ReEarlyParam(region) = r.kind() {
19891986
self.arg_is_constrained[region.index as usize] = true;
19901987
}
1991-
1992-
ControlFlow::Continue(())
19931988
}
19941989
}
19951990

compiler/rustc_hir_analysis/src/constrained_generic_params.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use rustc_data_structures::fx::FxHashSet;
2-
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
2+
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitor};
33
use rustc_middle::ty::{self, Ty, TyCtxt};
44
use rustc_span::Span;
55
use rustc_type_ir::fold::TypeFoldable;
6-
use std::ops::ControlFlow;
76

87
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
98
pub struct Parameter(pub u32);
@@ -61,13 +60,13 @@ struct ParameterCollector {
6160
}
6261

6362
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
64-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
63+
fn visit_ty(&mut self, t: Ty<'tcx>) {
6564
match *t.kind() {
6665
// Projections are not injective in general.
6766
ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _)
6867
if !self.include_nonconstraining =>
6968
{
70-
return ControlFlow::Continue(());
69+
return;
7170
}
7271
// All weak alias types should've been expanded beforehand.
7372
ty::Alias(ty::Weak, _) if !self.include_nonconstraining => {
@@ -80,18 +79,17 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
8079
t.super_visit_with(self)
8180
}
8281

83-
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
82+
fn visit_region(&mut self, r: ty::Region<'tcx>) {
8483
if let ty::ReEarlyParam(data) = *r {
8584
self.parameters.push(Parameter::from(data));
8685
}
87-
ControlFlow::Continue(())
8886
}
8987

90-
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
88+
fn visit_const(&mut self, c: ty::Const<'tcx>) {
9189
match c.kind() {
9290
ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => {
9391
// Constant expressions are not injective in general.
94-
return c.ty().visit_with(self);
92+
return;
9593
}
9694
ty::ConstKind::Param(data) => {
9795
self.parameters.push(Parameter::from(data));

compiler/rustc_hir_analysis/src/variance/mod.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_middle::query::Providers;
1111
use rustc_middle::ty::{self, CrateVariancesMap, GenericArgsRef, Ty, TyCtxt};
1212
use rustc_middle::ty::{TypeSuperVisitable, TypeVisitable};
13-
use std::ops::ControlFlow;
1413

1514
/// Defines the `TermsContext` basically houses an arena where we can
1615
/// allocate terms.
@@ -89,15 +88,14 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
8988

9089
impl<'tcx> OpaqueTypeLifetimeCollector<'tcx> {
9190
#[instrument(level = "trace", skip(self), ret)]
92-
fn visit_opaque(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> ControlFlow<!> {
91+
fn visit_opaque(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) {
9392
if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
9493
let child_variances = self.tcx.variances_of(def_id);
9594
for (a, v) in args.iter().zip_eq(child_variances) {
9695
if *v != ty::Bivariant {
97-
a.visit_with(self)?;
96+
a.visit_with(self);
9897
}
9998
}
100-
ControlFlow::Continue(())
10199
} else {
102100
args.visit_with(self)
103101
}
@@ -106,20 +104,19 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
106104

107105
impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeLifetimeCollector<'tcx> {
108106
#[instrument(level = "trace", skip(self), ret)]
109-
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
107+
fn visit_region(&mut self, r: ty::Region<'tcx>) {
110108
if let ty::RegionKind::ReEarlyParam(ebr) = r.kind() {
111109
self.variances[ebr.index as usize] = ty::Invariant;
112110
}
113-
ControlFlow::Continue(())
114111
}
115112

116113
#[instrument(level = "trace", skip(self), ret)]
117-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
114+
fn visit_ty(&mut self, t: Ty<'tcx>) {
118115
match t.kind() {
119116
ty::Alias(_, ty::AliasTy { def_id, args, .. })
120117
if matches!(self.tcx.def_kind(*def_id), DefKind::OpaqueTy) =>
121118
{
122-
self.visit_opaque(*def_id, args)
119+
self.visit_opaque(*def_id, args);
123120
}
124121
_ => t.super_visit_with(self),
125122
}

compiler/rustc_hir_typeck/src/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
396396
expected_ty: Ty<'tcx>,
397397
}
398398
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for MentionsTy<'tcx> {
399-
type BreakTy = ();
399+
type Result = ControlFlow<()>;
400400

401-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
401+
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
402402
if t == self.expected_ty {
403403
ControlFlow::Break(())
404404
} else {

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
337337
) -> Option<ty::GenericArg<'tcx>> {
338338
struct FindAmbiguousParameter<'a, 'tcx>(&'a FnCtxt<'a, 'tcx>, DefId);
339339
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindAmbiguousParameter<'_, 'tcx> {
340-
type BreakTy = ty::GenericArg<'tcx>;
341-
fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
340+
type Result = ControlFlow<ty::GenericArg<'tcx>>;
341+
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
342342
if let Some(origin) = self.0.type_var_origin(ty)
343343
&& let TypeVariableOriginKind::TypeParameterDefinition(_, def_id) = origin.kind
344344
&& let generics = self.0.tcx.generics_of(self.1)

compiler/rustc_infer/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rustc_macros = { path = "../rustc_macros" }
1717
rustc_middle = { path = "../rustc_middle" }
1818
rustc_span = { path = "../rustc_span" }
1919
rustc_target = { path = "../rustc_target" }
20+
rustc_type_ir = { path = "../rustc_type_ir" }
2021
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2122
tracing = "0.1"
2223
# tidy-alphabetical-end

0 commit comments

Comments
 (0)