Skip to content

Commit 8d56afb

Browse files
committed
uwu
1 parent 206c277 commit 8d56afb

File tree

13 files changed

+139
-43
lines changed

13 files changed

+139
-43
lines changed

compiler/rustc_macros/src/type_foldable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(super) fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_m
1919
&mut where_clauses,
2020
synstructure::AddBounds::Fields,
2121
);
22+
s.add_where_predicate(parse_quote! { Self: std::fmt::Debug + Clone });
2223
for pred in where_clauses.into_iter().flat_map(|c| c.predicates) {
2324
s.add_where_predicate(pred);
2425
}

compiler/rustc_macros/src/type_visitable.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ pub(super) fn type_visitable_derive(
2323
&mut where_clauses,
2424
synstructure::AddBounds::Fields,
2525
);
26+
s.add_where_predicate(parse_quote! { Self: std::fmt::Debug + Clone });
2627
for pred in where_clauses.into_iter().flat_map(|c| c.predicates) {
2728
s.add_where_predicate(pred);
2829
}
2930

31+
let impl_traversable_s = s.clone();
32+
3033
let body_visit = s.each(|bind| {
3134
quote! {
3235
match ::rustc_ast_ir::visit::VisitorResult::branch(
@@ -41,7 +44,7 @@ pub(super) fn type_visitable_derive(
4144
});
4245
s.bind_with(|_| synstructure::BindStyle::Move);
4346

44-
s.bound_impl(
47+
let visitable_impl = s.bound_impl(
4548
quote!(::rustc_middle::ty::visit::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>),
4649
quote! {
4750
fn visit_with<__V: ::rustc_middle::ty::visit::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(
@@ -52,5 +55,17 @@ pub(super) fn type_visitable_derive(
5255
<__V::Result as ::rustc_ast_ir::visit::VisitorResult>::output()
5356
}
5457
},
55-
)
58+
);
59+
60+
let traversable_impl = impl_traversable_s.bound_impl(
61+
quote!(::rustc_middle::ty::traverse::TypeTraversable<::rustc_middle::ty::TyCtxt<'tcx>>),
62+
quote! {
63+
type Kind = ::rustc_middle::ty::traverse::ImportantTypeTraversal;
64+
},
65+
);
66+
67+
quote! {
68+
#visitable_impl
69+
#traversable_impl
70+
}
5671
}

compiler/rustc_middle/src/hir/place.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use rustc_hir::HirId;
2-
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
2+
use rustc_macros::{
3+
HashStable, NoopTypeTraversable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable,
4+
};
35
use rustc_target::abi::{FieldIdx, VariantIdx};
46

57
use crate::ty;
68
use crate::ty::Ty;
79

810
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
9-
#[derive(TypeFoldable, TypeVisitable)]
11+
#[derive(NoopTypeTraversable)]
1012
pub enum PlaceBase {
1113
/// A temporary variable.
1214
Rvalue,
@@ -19,7 +21,7 @@ pub enum PlaceBase {
1921
}
2022

2123
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
22-
#[derive(TypeFoldable, TypeVisitable)]
24+
#[derive(NoopTypeTraversable)]
2325
pub enum ProjectionKind {
2426
/// A dereference of a pointer, reference or `Box<T>` of the given type.
2527
Deref,

compiler/rustc_middle/src/traits/solve.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use rustc_ast_ir::try_visit;
22
use rustc_data_structures::intern::Interned;
33
use rustc_macros::HashStable;
4-
use rustc_type_ir as ir;
54
pub use rustc_type_ir::solve::*;
5+
use rustc_type_ir::traverse::{ImportantTypeTraversal, TypeTraversable};
6+
use rustc_type_ir::{self as ir};
67

78
use crate::ty::{
89
self, FallibleTypeFolder, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
@@ -72,6 +73,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
7273
}
7374
}
7475

76+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
77+
type Kind = ImportantTypeTraversal;
78+
}
7579
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
7680
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
7781
try_visit!(self.region_constraints.visit_with(visitor));
@@ -106,6 +110,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
106110
}
107111
}
108112

113+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
114+
type Kind = ImportantTypeTraversal;
115+
}
109116
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
110117
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
111118
self.opaque_types.visit_with(visitor)

compiler/rustc_middle/src/ty/generic_args.rs

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_hir::def_id::DefId;
1414
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension};
1515
use rustc_serialize::{Decodable, Encodable};
1616
use rustc_type_ir::WithCachedTypeInfo;
17+
use rustc_type_ir::traverse::{ImportantTypeTraversal, NoopTypeTraversal, TypeTraversable};
1718
use smallvec::SmallVec;
1819

1920
use crate::ty::codec::{TyDecoder, TyEncoder};
@@ -329,6 +330,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArg<'tcx> {
329330
}
330331
}
331332

333+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for GenericArg<'tcx> {
334+
type Kind = ImportantTypeTraversal;
335+
}
332336
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for GenericArg<'tcx> {
333337
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
334338
match self.unpack() {
@@ -642,6 +646,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
642646
}
643647
}
644648

649+
impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeTraversable<TyCtxt<'tcx>> for &'tcx ty::List<T> {
650+
type Kind = ImportantTypeTraversal;
651+
}
645652
impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx ty::List<T> {
646653
#[inline]
647654
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {

compiler/rustc_middle/src/ty/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub use rustc_type_ir::relate::VarianceDiagInfo;
5858
use rustc_type_ir::traverse::TypeTraversable;
5959
pub use rustc_type_ir::*;
6060
use tracing::{debug, instrument};
61+
use traverse::ImportantTypeTraversal;
6162
pub use vtable::*;
6263
use {rustc_ast as ast, rustc_attr as attr, rustc_hir as hir};
6364

@@ -548,6 +549,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Term<'tcx> {
548549
}
549550
}
550551

552+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for Term<'tcx> {
553+
type Kind = ImportantTypeTraversal;
554+
}
551555
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Term<'tcx> {
552556
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
553557
match self.unpack() {
@@ -1037,6 +1041,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ParamEnv<'tcx> {
10371041
}
10381042
}
10391043

1044+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for ParamEnv<'tcx> {
1045+
type Kind = ImportantTypeTraversal;
1046+
}
10401047
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ParamEnv<'tcx> {
10411048
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
10421049
try_visit!(self.caller_bounds().visit_with(visitor));

compiler/rustc_middle/src/ty/structural_impls.rs

+33-23
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use rustc_hir::def::Namespace;
1111
use rustc_span::source_map::Spanned;
1212
use rustc_target::abi::TyAndLayout;
1313
use rustc_type_ir::ConstKind;
14-
use rustc_type_ir::traverse::TypeTraversable;
14+
use rustc_type_ir::traverse::{ImportantTypeTraversal, TypeTraversable};
1515

1616
use super::print::PrettyPrinter;
1717
use super::{GenericArg, GenericArgKind, Pattern, Region};
1818
use crate::mir::interpret;
1919
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
2020
use crate::ty::print::{FmtPrinter, Printer, with_no_trimmed_paths};
2121
use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
22-
use crate::ty::{self, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
22+
use crate::ty::{self, Lift, Term, TermKind, Ty, TyCtxt};
2323

2424
impl fmt::Debug for ty::TraitDef {
2525
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -258,7 +258,6 @@ TrivialTypeTraversalImpls! {
258258
::rustc_span::Span,
259259
::rustc_span::symbol::Ident,
260260
ty::BoundVar,
261-
ty::ValTree<'tcx>,
262261
}
263262
// For some things about which the type library does not know, or does not
264263
// provide any traversal implementations, we need to provide a traversal
@@ -304,12 +303,6 @@ impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for Term<'a> {
304303
///////////////////////////////////////////////////////////////////////////
305304
// Traversal implementations.
306305

307-
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::AdtDef<'tcx> {
308-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, _visitor: &mut V) -> V::Result {
309-
V::Result::output()
310-
}
311-
}
312-
313306
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
314307
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
315308
self,
@@ -338,6 +331,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Pattern<'tcx> {
338331
}
339332
}
340333

334+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for Pattern<'tcx> {
335+
type Kind = ImportantTypeTraversal;
336+
}
341337
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Pattern<'tcx> {
342338
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
343339
(**self).visit_with(visitor)
@@ -353,6 +349,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
353349
}
354350
}
355351

352+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for Ty<'tcx> {
353+
type Kind = ImportantTypeTraversal;
354+
}
356355
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
357356
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
358357
visitor.visit_ty(*self)
@@ -469,6 +468,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ty::Region<'tcx> {
469468
}
470469
}
471470

471+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for ty::Region<'tcx> {
472+
type Kind = ImportantTypeTraversal;
473+
}
472474
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Region<'tcx> {
473475
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
474476
visitor.visit_region(*self)
@@ -494,12 +496,18 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ty::Clause<'tcx> {
494496
}
495497
}
496498

499+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
500+
type Kind = ImportantTypeTraversal;
501+
}
497502
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
498503
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
499504
visitor.visit_predicate(*self)
500505
}
501506
}
502507

508+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for ty::Clause<'tcx> {
509+
type Kind = ImportantTypeTraversal;
510+
}
503511
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Clause<'tcx> {
504512
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
505513
visitor.visit_predicate(self.as_predicate())
@@ -522,6 +530,9 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
522530
}
523531
}
524532

533+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for ty::Clauses<'tcx> {
534+
type Kind = ImportantTypeTraversal;
535+
}
525536
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Clauses<'tcx> {
526537
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
527538
visitor.visit_clauses(self)
@@ -552,6 +563,9 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
552563
}
553564
}
554565

566+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for ty::Const<'tcx> {
567+
type Kind = ImportantTypeTraversal;
568+
}
555569
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
556570
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
557571
visitor.visit_const(*self)
@@ -602,6 +616,9 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
602616
}
603617
}
604618

619+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for rustc_span::ErrorGuaranteed {
620+
type Kind = ImportantTypeTraversal;
621+
}
605622
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for rustc_span::ErrorGuaranteed {
606623
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
607624
visitor.visit_error(*self)
@@ -617,27 +634,20 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for rustc_span::ErrorGuaranteed {
617634
}
618635
}
619636

620-
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for InferConst {
621-
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
622-
self,
623-
_folder: &mut F,
624-
) -> Result<Self, F::Error> {
625-
Ok(self)
626-
}
627-
}
628-
629-
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for InferConst {
630-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, _visitor: &mut V) -> V::Result {
631-
V::Result::output()
632-
}
637+
impl<'tcx> TypeTraversable<TyCtxt<'tcx>> for TyAndLayout<'tcx, Ty<'tcx>> {
638+
type Kind = ImportantTypeTraversal;
633639
}
634-
635640
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for TyAndLayout<'tcx, Ty<'tcx>> {
636641
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
637642
visitor.visit_ty(self.ty)
638643
}
639644
}
640645

646+
impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>> + Debug + Clone> TypeTraversable<TyCtxt<'tcx>>
647+
for Spanned<T>
648+
{
649+
type Kind = ImportantTypeTraversal;
650+
}
641651
impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>> + Debug + Clone> TypeVisitable<TyCtxt<'tcx>>
642652
for Spanned<T>
643653
{

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_index::IndexVec;
1515
use rustc_type_ir::fold::TypeFoldable;
1616
use rustc_type_ir::inherent::*;
1717
use rustc_type_ir::relate::solver_relating::RelateExt;
18+
use rustc_type_ir::traverse::OptTryFoldWith;
1819
use rustc_type_ir::{self as ty, Canonical, CanonicalVarValues, InferCtxtLike, Interner};
1920
use tracing::{debug, instrument, trace};
2021

@@ -426,7 +427,7 @@ pub(in crate::solve) fn make_canonical_state<D, T, I>(
426427
where
427428
D: SolverDelegate<Interner = I>,
428429
I: Interner,
429-
T: TypeFoldable<I>,
430+
T: OptTryFoldWith<I>,
430431
{
431432
let var_values = CanonicalVarValues { var_values: delegate.cx().mk_args(var_values) };
432433
let state = inspect::State { var_values, data };

compiler/rustc_type_ir/src/binder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::data_structures::SsoHashSet;
1414
use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
1515
use crate::inherent::*;
1616
use crate::lift::Lift;
17+
use crate::traverse::{ImportantTypeTraversal, TypeTraversable};
1718
use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
1819
use crate::{self as ty, Interner};
1920

@@ -125,6 +126,9 @@ impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T> {
125126
}
126127
}
127128

129+
impl<I: Interner, T: TypeVisitable<I>> TypeTraversable<I> for Binder<I, T> {
130+
type Kind = ImportantTypeTraversal;
131+
}
128132
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
129133
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
130134
visitor.visit_binder(self)

compiler/rustc_type_ir/src/interner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub trait Interner:
6666
+ Hash
6767
+ Default
6868
+ Eq
69-
+ TypeVisitable<Self>
69+
+ TypeTraversable<Self, Kind = NoopTypeTraversal>
7070
+ SliceLike<Item = Self::LocalDefId>;
7171

7272
type CanonicalVars: Copy

compiler/rustc_type_ir/src/traverse/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ pub trait TypeTraversable<I: Interner>: fmt::Debug + Clone {
4141
pub struct ImportantTypeTraversal;
4242
pub struct NoopTypeTraversal;
4343

44-
impl<I: Interner, T: TypeVisitable> TypeTraversable<I> for T {
45-
type Kind = ImportantTypeTraversal;
46-
}
47-
4844
pub trait OptVisitWith<I: Interner>: TypeTraversable<I> {
4945
fn mk_visit_with<V: TypeVisitor<I>>() -> fn(&Self, &mut V) -> V::Result;
5046
}

0 commit comments

Comments
 (0)