Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e0f3119

Browse files
Introduce TypeVisitor::BreakTy
1 parent 30e49a9 commit e0f3119

File tree

31 files changed

+157
-128
lines changed

31 files changed

+157
-128
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14981498
}
14991499

15001500
impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> {
1501-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<()> {
1501+
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
15021502
if let Some((kind, def_id)) = TyCategory::from_ty(t) {
15031503
let span = self.tcx.def_span(def_id);
15041504
// 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
474474
struct TraitObjectVisitor(Vec<DefId>);
475475

476476
impl TypeVisitor<'_> for TraitObjectVisitor {
477-
fn visit_ty(&mut self, t: Ty<'_>) -> ControlFlow<()> {
477+
fn visit_ty(&mut self, t: Ty<'_>) -> ControlFlow<Self::BreakTy> {
478478
match t.kind() {
479479
ty::Dynamic(preds, RegionKind::ReStatic) => {
480480
if let Some(def_id) = preds.principal_def_id() {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,15 +741,18 @@ struct ScopeInstantiator<'me, 'tcx> {
741741
}
742742

743743
impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> {
744-
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ControlFlow<()> {
744+
fn visit_binder<T: TypeFoldable<'tcx>>(
745+
&mut self,
746+
t: &ty::Binder<T>,
747+
) -> ControlFlow<Self::BreakTy> {
745748
self.target_index.shift_in(1);
746749
t.super_visit_with(self);
747750
self.target_index.shift_out(1);
748751

749752
ControlFlow::CONTINUE
750753
}
751754

752-
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<()> {
755+
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
753756
let ScopeInstantiator { bound_region_scope, next_region, .. } = self;
754757

755758
match r {

compiler/rustc_infer/src/infer/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a, 'tcx> UnresolvedTypeFinder<'a, 'tcx> {
123123
}
124124

125125
impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
126-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<()> {
126+
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
127127
let t = self.infcx.shallow_resolve(t);
128128
if t.has_infer_types() {
129129
if let ty::Infer(infer_ty) = *t.kind() {

compiler/rustc_infer/src/traits/structural_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx
6969
}
7070
}
7171

72-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
72+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
7373
self.predicate.visit_with(visitor)
7474
}
7575
}

compiler/rustc_lint/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
11351135
};
11361136

11371137
impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> {
1138-
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<()> {
1138+
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
11391139
match ty.kind() {
11401140
ty::Opaque(..) => {
11411141
self.ty = Some(ty);

compiler/rustc_macros/src/type_foldable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::
3535
fn super_visit_with<__F: ::rustc_middle::ty::fold::TypeVisitor<'tcx>>(
3636
&self,
3737
__folder: &mut __F
38-
) -> ::std::ops::ControlFlow<()> {
38+
) -> ::std::ops::ControlFlow<__F::BreakTy> {
3939
match *self { #body_visit }
4040
::std::ops::ControlFlow::CONTINUE
4141
}

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#![feature(half_open_range_patterns)]
5252
#![feature(exclusive_range_pattern)]
5353
#![feature(control_flow_enum)]
54+
#![feature(associated_type_defaults)]
5455
#![recursion_limit = "512"]
5556

5657
#[macro_use]

compiler/rustc_middle/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ macro_rules! CloneTypeFoldableImpls {
6262
fn super_visit_with<F: $crate::ty::fold::TypeVisitor<$tcx>>(
6363
&self,
6464
_: &mut F)
65-
-> ::std::ops::ControlFlow<()>
65+
-> ::std::ops::ControlFlow<F::BreakTy>
6666
{
6767
::std::ops::ControlFlow::CONTINUE
6868
}
@@ -105,7 +105,7 @@ macro_rules! EnumTypeFoldableImpl {
105105
fn super_visit_with<V: $crate::ty::fold::TypeVisitor<$tcx>>(
106106
&self,
107107
visitor: &mut V,
108-
) -> ::std::ops::ControlFlow<()> {
108+
) -> ::std::ops::ControlFlow<V::BreakTy> {
109109
EnumTypeFoldableImpl!(@VisitVariants(self, visitor) input($($variants)*) output())
110110
}
111111
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,10 @@ impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
24772477
UserTypeProjection { base, projs }
24782478
}
24792479

2480-
fn super_visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<()> {
2480+
fn super_visit_with<Vs: TypeVisitor<'tcx>>(
2481+
&self,
2482+
visitor: &mut Vs,
2483+
) -> ControlFlow<Vs::BreakTy> {
24812484
self.base.visit_with(visitor)
24822485
// Note: there's nothing in `self.proj` to visit.
24832486
}

compiler/rustc_middle/src/mir/type_foldable.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
8787
Terminator { source_info: self.source_info, kind }
8888
}
8989

90-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
90+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
9191
use crate::mir::TerminatorKind::*;
9292

9393
match self.kind {
@@ -144,7 +144,7 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
144144
*self
145145
}
146146

147-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
147+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
148148
ControlFlow::CONTINUE
149149
}
150150
}
@@ -154,7 +154,7 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
154154
Place { local: self.local.fold_with(folder), projection: self.projection.fold_with(folder) }
155155
}
156156

157-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
157+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
158158
self.local.visit_with(visitor)?;
159159
self.projection.visit_with(visitor)
160160
}
@@ -166,7 +166,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
166166
folder.tcx().intern_place_elems(&v)
167167
}
168168

169-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
169+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
170170
self.iter().try_for_each(|t| t.visit_with(visitor))
171171
}
172172
}
@@ -216,7 +216,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
216216
}
217217
}
218218

219-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
219+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
220220
use crate::mir::Rvalue::*;
221221
match *self {
222222
Use(ref op) => op.visit_with(visitor),
@@ -271,7 +271,7 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
271271
}
272272
}
273273

274-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
274+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
275275
match *self {
276276
Operand::Copy(ref place) | Operand::Move(ref place) => place.visit_with(visitor),
277277
Operand::Constant(ref c) => c.visit_with(visitor),
@@ -295,7 +295,10 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
295295
}
296296
}
297297

298-
fn super_visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<()> {
298+
fn super_visit_with<Vs: TypeVisitor<'tcx>>(
299+
&self,
300+
visitor: &mut Vs,
301+
) -> ControlFlow<Vs::BreakTy> {
299302
use crate::mir::ProjectionElem::*;
300303

301304
match self {
@@ -310,7 +313,7 @@ impl<'tcx> TypeFoldable<'tcx> for Field {
310313
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
311314
*self
312315
}
313-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
316+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
314317
ControlFlow::CONTINUE
315318
}
316319
}
@@ -319,7 +322,7 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
319322
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
320323
*self
321324
}
322-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
325+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
323326
ControlFlow::CONTINUE
324327
}
325328
}
@@ -328,7 +331,7 @@ impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
328331
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
329332
self.clone()
330333
}
331-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
334+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
332335
ControlFlow::CONTINUE
333336
}
334337
}
@@ -341,7 +344,7 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
341344
literal: self.literal.fold_with(folder),
342345
}
343346
}
344-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
347+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
345348
self.literal.visit_with(visitor)
346349
}
347350
}

0 commit comments

Comments
 (0)