Skip to content

Commit be9b125

Browse files
committed
Convert TypeVisitor and DefIdVisitor to use VisitorResult
1 parent 5abfb37 commit be9b125

File tree

53 files changed

+345
-448
lines changed

Some content is hidden

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

53 files changed

+345
-448
lines changed

Cargo.lock

+4
Original file line numberDiff line numberDiff line change
@@ -3970,6 +3970,7 @@ version = "0.0.0"
39703970
dependencies = [
39713971
"itertools 0.11.0",
39723972
"rustc_ast",
3973+
"rustc_ast_ir",
39733974
"rustc_attr",
39743975
"rustc_data_structures",
39753976
"rustc_errors",
@@ -4038,6 +4039,7 @@ dependencies = [
40384039
name = "rustc_infer"
40394040
version = "0.0.0"
40404041
dependencies = [
4042+
"rustc_ast_ir",
40414043
"rustc_data_structures",
40424044
"rustc_errors",
40434045
"rustc_fluent_macro",
@@ -4632,6 +4634,7 @@ dependencies = [
46324634
"bitflags 2.4.2",
46334635
"itertools 0.11.0",
46344636
"rustc_ast",
4637+
"rustc_ast_ir",
46354638
"rustc_attr",
46364639
"rustc_data_structures",
46374640
"rustc_errors",
@@ -4670,6 +4673,7 @@ name = "rustc_transmute"
46704673
version = "0.0.0"
46714674
dependencies = [
46724675
"itertools 0.11.0",
4676+
"rustc_ast_ir",
46734677
"rustc_data_structures",
46744678
"rustc_hir",
46754679
"rustc_infer",

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_hir_analysis/src/check/check.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1474,15 +1474,14 @@ fn opaque_type_cycle_error(
14741474
closures: Vec<DefId>,
14751475
}
14761476
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector {
1477-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
1477+
fn visit_ty(&mut self, t: Ty<'tcx>) {
14781478
match *t.kind() {
14791479
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
14801480
self.opaques.push(def);
1481-
ControlFlow::Continue(())
14821481
}
14831482
ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => {
14841483
self.closures.push(def_id);
1485-
t.super_visit_with(self)
1484+
t.super_visit_with(self);
14861485
}
14871486
_ => t.super_visit_with(self),
14881487
}

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>(
@@ -211,9 +210,7 @@ struct ImplTraitInTraitCollector<'tcx> {
211210
}
212211

213212
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> {
214-
type BreakTy = !;
215-
216-
fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
213+
fn visit_ty(&mut self, ty: Ty<'tcx>) {
217214
if let ty::Alias(ty::Projection, proj) = *ty.kind()
218215
&& self.tcx.is_impl_trait_in_trait(proj.def_id)
219216
{
@@ -223,12 +220,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> {
223220
.explicit_item_bounds(proj.def_id)
224221
.iter_instantiated_copied(self.tcx, proj.args)
225222
{
226-
pred.visit_with(self)?;
223+
pred.visit_with(self);
227224
}
228225
}
229-
ControlFlow::Continue(())
230226
} else {
231-
ty.super_visit_with(self)
227+
ty.super_visit_with(self);
232228
}
233229
}
234230
}

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
@@ -1964,31 +1964,26 @@ fn is_late_bound_map(
19641964
arg_is_constrained: Box<[bool]>,
19651965
}
19661966

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

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

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

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/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
# tidy-alphabetical-start
88
itertools = "0.11"
99
rustc_ast = { path = "../rustc_ast" }
10+
rustc_ast_ir = { path = "../rustc_ast_ir" }
1011
rustc_attr = { path = "../rustc_attr" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }
1213
rustc_errors = { path = "../rustc_errors" }

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
@@ -8,6 +8,7 @@ doctest = false
88

99
[dependencies]
1010
# tidy-alphabetical-start
11+
rustc_ast_ir = { path = "../rustc_ast_ir" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }
1213
rustc_errors = { path = "../rustc_errors" }
1314
rustc_fluent_macro = { path = "../rustc_fluent_macro" }

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use rustc_middle::ty::{
7979
use rustc_span::{sym, symbol::kw, BytePos, DesugaringKind, Pos, Span};
8080
use rustc_target::spec::abi;
8181
use std::borrow::Cow;
82-
use std::ops::{ControlFlow, Deref};
82+
use std::ops::Deref;
8383
use std::path::PathBuf;
8484
use std::{cmp, fmt, iter};
8585

@@ -1623,7 +1623,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
16231623
}
16241624

16251625
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypesVisitor<'tcx> {
1626-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
1626+
fn visit_ty(&mut self, t: Ty<'tcx>) {
16271627
if let Some((kind, def_id)) = TyCategory::from_ty(self.tcx, t) {
16281628
let span = self.tcx.def_span(def_id);
16291629
// Avoid cluttering the output when the "found" and error span overlap:

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_span::symbol::Ident;
2323
use rustc_span::Span;
2424

2525
use rustc_span::def_id::LocalDefId;
26-
use std::ops::ControlFlow;
2726

2827
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2928
/// Print the error message for lifetime errors when the return type is a static `impl Trait`,
@@ -545,13 +544,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
545544
pub struct TraitObjectVisitor(pub FxIndexSet<DefId>);
546545

547546
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for TraitObjectVisitor {
548-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
547+
fn visit_ty(&mut self, t: Ty<'tcx>) {
549548
match t.kind() {
550549
ty::Dynamic(preds, re, _) if re.is_static() => {
551550
if let Some(def_id) = preds.principal_def_id() {
552551
self.0.insert(def_id);
553552
}
554-
ControlFlow::Continue(())
555553
}
556554
_ => t.super_visit_with(self),
557555
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use rustc_middle::ty::print::RegionHighlightMode;
1616
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
1717
use rustc_span::Span;
1818

19-
use std::ops::ControlFlow;
20-
2119
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2220
/// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`.
2321
pub(super) fn try_report_impl_not_conforming_to_trait(&self) -> Option<ErrorGuaranteed> {
@@ -76,12 +74,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7674
}
7775

7876
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for HighlightBuilder<'tcx> {
79-
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
77+
fn visit_region(&mut self, r: ty::Region<'tcx>) {
8078
if !r.has_name() && self.counter <= 3 {
8179
self.highlight.highlighting_region(r, self.counter);
8280
self.counter += 1;
8381
}
84-
ControlFlow::Continue(())
8582
}
8683
}
8784

0 commit comments

Comments
 (0)