Skip to content

Commit 7bfb0ec

Browse files
committed
it compiles :3
1 parent ddf7917 commit 7bfb0ec

File tree

17 files changed

+113
-87
lines changed

17 files changed

+113
-87
lines changed

compiler/rustc_infer/src/infer/canonical/query_response.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ use rustc_index::{Idx, IndexVec};
1515
use rustc_middle::arena::ArenaAllocatable;
1616
use rustc_middle::mir::ConstraintCategory;
1717
use rustc_middle::ty::fold::TypeFoldable;
18+
use rustc_middle::ty::traverse::AlwaysTraversable;
1819
use rustc_middle::ty::{self, BoundVar, GenericArg, GenericArgKind, Ty, TyCtxt};
1920
use rustc_middle::{bug, span_bug};
21+
use rustc_type_ir::traverse::OptTryFoldWith;
2022
use tracing::{debug, instrument};
2123

2224
use crate::infer::canonical::instantiate::{CanonicalExt, instantiate_value};
@@ -60,7 +62,7 @@ impl<'tcx> InferCtxt<'tcx> {
6062
fulfill_cx: &mut dyn TraitEngine<'tcx, ScrubbedTraitError<'tcx>>,
6163
) -> Result<CanonicalQueryResponse<'tcx, T>, NoSolution>
6264
where
63-
T: Debug + TypeFoldable<TyCtxt<'tcx>>,
65+
T: OptTryFoldWith<TyCtxt<'tcx>>,
6466
Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>,
6567
{
6668
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
@@ -107,7 +109,7 @@ impl<'tcx> InferCtxt<'tcx> {
107109
fulfill_cx: &mut dyn TraitEngine<'tcx, ScrubbedTraitError<'tcx>>,
108110
) -> Result<QueryResponse<'tcx, T>, NoSolution>
109111
where
110-
T: Debug + TypeFoldable<TyCtxt<'tcx>>,
112+
T: OptTryFoldWith<TyCtxt<'tcx>>,
111113
{
112114
let tcx = self.tcx;
113115

@@ -243,7 +245,7 @@ impl<'tcx> InferCtxt<'tcx> {
243245
output_query_region_constraints: &mut QueryRegionConstraints<'tcx>,
244246
) -> InferResult<'tcx, R>
245247
where
246-
R: Debug + TypeFoldable<TyCtxt<'tcx>>,
248+
R: OptTryFoldWith<TyCtxt<'tcx>>,
247249
{
248250
let InferOk { value: result_args, mut obligations } = self
249251
.query_response_instantiation_guess(
@@ -326,8 +328,11 @@ impl<'tcx> InferCtxt<'tcx> {
326328
.map(|p_c| instantiate_value(self.tcx, &result_args, p_c.clone())),
327329
);
328330

329-
let user_result: R =
330-
query_response.instantiate_projected(self.tcx, &result_args, |q_r| q_r.value.clone());
331+
let user_result: R = query_response
332+
.instantiate_projected(self.tcx, &result_args, |q_r| {
333+
AlwaysTraversable(q_r.value.clone())
334+
})
335+
.0;
331336

332337
Ok(InferOk { value: user_result, obligations })
333338
}
@@ -396,7 +401,7 @@ impl<'tcx> InferCtxt<'tcx> {
396401
query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
397402
) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
398403
where
399-
R: Debug + TypeFoldable<TyCtxt<'tcx>>,
404+
R: OptTryFoldWith<TyCtxt<'tcx>>,
400405
{
401406
// For each new universe created in the query result that did
402407
// not appear in the original query, create a local

compiler/rustc_infer/src/traits/structural_impls.rs

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_ast_ir::try_visit;
44
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable};
55
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitor};
66
use rustc_middle::ty::{self, TyCtxt};
7+
use rustc_type_ir::traverse::{ImportantTypeTraversal, TypeTraversable};
78

89
use crate::traits;
910
use crate::traits::project::Normalized;
@@ -55,6 +56,11 @@ impl<'tcx, O: TypeFoldable<TyCtxt<'tcx>>> TypeFoldable<TyCtxt<'tcx>>
5556
}
5657
}
5758

59+
impl<'tcx, O: TypeVisitable<TyCtxt<'tcx>>> TypeTraversable<TyCtxt<'tcx>>
60+
for traits::Obligation<'tcx, O>
61+
{
62+
type Kind = ImportantTypeTraversal;
63+
}
5864
impl<'tcx, O: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>>
5965
for traits::Obligation<'tcx, O>
6066
{

compiler/rustc_middle/src/thir.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir as hir;
1717
use rustc_hir::def_id::DefId;
1818
use rustc_hir::{BindingMode, ByRef, HirId, MatchSource, RangeEnd};
1919
use rustc_index::{IndexVec, newtype_index};
20-
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeVisitable};
20+
use rustc_macros::{HashStable, NoopTypeTraversable, TyDecodable, TyEncodable, TypeVisitable};
2121
use rustc_middle::middle::region;
2222
use rustc_middle::mir::interpret::AllocId;
2323
use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, UnOp};
@@ -234,7 +234,8 @@ pub enum StmtKind<'tcx> {
234234
},
235235
}
236236

237-
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
237+
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable)]
238+
#[derive(NoopTypeTraversable, TyEncodable, TyDecodable)]
238239
pub struct LocalVarId(pub HirId);
239240

240241
/// A THIR expression.

compiler/rustc_middle/src/ty/adt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
1313
use rustc_hir::def_id::DefId;
1414
use rustc_hir::{self as hir, LangItem};
1515
use rustc_index::{IndexSlice, IndexVec};
16-
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
16+
use rustc_macros::{HashStable, NoopTypeTraversable, TyDecodable, TyEncodable};
1717
use rustc_query_system::ich::StableHashingContext;
1818
use rustc_session::DataTypeKind;
1919
use rustc_span::symbol::sym;
@@ -168,7 +168,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for AdtDefData {
168168
}
169169
}
170170

171-
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)]
171+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable, NoopTypeTraversable)]
172172
#[rustc_pass_by_value]
173173
pub struct AdtDef<'tcx>(pub Interned<'tcx, AdtDefData>);
174174

compiler/rustc_middle/src/ty/generic_args.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +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};
17+
use rustc_type_ir::traverse::{ImportantTypeTraversal, TypeTraversable};
1818
use smallvec::SmallVec;
1919

2020
use crate::ty::codec::{TyDecoder, TyEncoder};
@@ -646,8 +646,8 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
646646
}
647647
}
648648

649-
impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeTraversable<TyCtxt<'tcx>> for &'tcx ty::List<T> {
650-
type Kind = ImportantTypeTraversal;
649+
impl<'tcx, T: TypeTraversable<TyCtxt<'tcx>>> TypeTraversable<TyCtxt<'tcx>> for &'tcx ty::List<T> {
650+
type Kind = T::Kind;
651651
}
652652
impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx ty::List<T> {
653653
#[inline]

compiler/rustc_middle/src/ty/structural_impls.rs

+50-50
Original file line numberDiff line numberDiff line change
@@ -209,55 +209,56 @@ impl<'tcx> fmt::Debug for Region<'tcx> {
209209
// For things for which the type library provides traversal implementations
210210
// for all Interners, we only need to provide a Lift implementation:
211211
TrivialLiftImpls! {
212-
(),
213-
bool,
214-
usize,
215-
u64,
212+
(),
213+
bool,
214+
usize,
215+
u64,
216+
crate::ty::ParamConst,
216217
}
217218

218219
// For some things about which the type library does not know, or does not
219220
// provide any traversal implementations, we need to provide a traversal
220221
// implementation (only for TyCtxt<'_> interners).
221222
TrivialTypeTraversalImpls! {
222-
::rustc_target::abi::FieldIdx,
223-
::rustc_target::abi::VariantIdx,
224-
crate::middle::region::Scope,
225-
::rustc_ast::InlineAsmOptions,
226-
::rustc_ast::InlineAsmTemplatePiece,
227-
::rustc_ast::NodeId,
228-
::rustc_span::symbol::Symbol,
229-
::rustc_hir::def::Res,
230-
::rustc_hir::def_id::LocalDefId,
231-
::rustc_hir::ByRef,
232-
::rustc_hir::HirId,
233-
::rustc_hir::RangeEnd,
234-
::rustc_hir::MatchSource,
235-
::rustc_target::asm::InlineAsmRegOrRegClass,
236-
crate::mir::coverage::BlockMarkerId,
237-
crate::mir::coverage::CounterId,
238-
crate::mir::coverage::ExpressionId,
239-
crate::mir::coverage::ConditionId,
240-
crate::mir::Local,
241-
crate::mir::Promoted,
242-
crate::traits::Reveal,
243-
crate::ty::adjustment::AutoBorrowMutability,
244-
crate::ty::AdtKind,
245-
crate::ty::BoundRegion,
246-
// Including `BoundRegionKind` is a *bit* dubious, but direct
247-
// references to bound region appear in `ty::Error`, and aren't
248-
// really meant to be folded. In general, we can only fold a fully
249-
// general `Region`.
250-
crate::ty::BoundRegionKind,
251-
crate::ty::AssocItem,
252-
crate::ty::AssocKind,
253-
crate::ty::Placeholder<crate::ty::BoundRegion>,
254-
crate::ty::Placeholder<crate::ty::BoundTy>,
255-
crate::ty::Placeholder<ty::BoundVar>,
223+
::rustc_target::abi::FieldIdx,
224+
::rustc_target::abi::VariantIdx,
225+
crate::middle::region::Scope,
226+
::rustc_ast::InlineAsmOptions,
227+
::rustc_ast::InlineAsmTemplatePiece,
228+
::rustc_ast::NodeId,
229+
::rustc_ast::ast::BindingMode,
230+
::rustc_span::symbol::Symbol,
231+
::rustc_hir::def::Res,
232+
::rustc_hir::def_id::LocalDefId,
233+
::rustc_hir::ByRef,
234+
::rustc_hir::HirId,
235+
::rustc_hir::RangeEnd,
236+
::rustc_hir::MatchSource,
237+
::rustc_target::asm::InlineAsmRegOrRegClass,
238+
crate::mir::coverage::BlockMarkerId,
239+
crate::mir::coverage::CounterId,
240+
crate::mir::coverage::ExpressionId,
241+
crate::mir::coverage::ConditionId,
242+
crate::mir::Local,
243+
crate::mir::Promoted,
244+
crate::ty::adjustment::AutoBorrowMutability,
245+
crate::ty::AdtKind,
246+
crate::ty::BoundRegion,
247+
// Including `BoundRegionKind` is a *bit* dubious, but direct
248+
// references to bound region appear in `ty::Error`, and aren't
249+
// really meant to be folded. In general, we can only fold a fully
250+
// general `Region`.
251+
crate::ty::BoundRegionKind,
252+
crate::ty::AssocItem,
253+
crate::ty::AssocKind,
254+
crate::ty::Placeholder<crate::ty::BoundRegion>,
255+
crate::ty::Placeholder<crate::ty::BoundTy>,
256+
crate::ty::Placeholder<ty::BoundVar>,}
257+
TrivialTypeTraversalImpls! {
256258
crate::ty::LateParamRegion,
257259
crate::ty::adjustment::PointerCoercion,
258260
::rustc_span::Span,
259261
::rustc_span::symbol::Ident,
260-
ty::BoundVar,
261262
}
262263
// For some things about which the type library does not know, or does not
263264
// provide any traversal implementations, we need to provide a traversal
@@ -268,7 +269,6 @@ TrivialTypeTraversalAndLiftImpls! {
268269
::rustc_hir::Safety,
269270
::rustc_target::spec::abi::Abi,
270271
crate::ty::ClosureKind,
271-
crate::ty::ParamConst,
272272
crate::ty::ParamTy,
273273
crate::ty::instance::ReifyReason,
274274
interpret::AllocId,
@@ -578,12 +578,12 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
578578
folder: &mut F,
579579
) -> Result<Self, F::Error> {
580580
let kind = match self.kind() {
581-
ConstKind::Param(p) => ConstKind::Param(p.try_fold_with(folder)?),
582-
ConstKind::Infer(i) => ConstKind::Infer(i.try_fold_with(folder)?),
581+
ConstKind::Param(p) => ConstKind::Param(p.noop_try_fold_with(folder)?),
582+
ConstKind::Infer(i) => ConstKind::Infer(i.noop_try_fold_with(folder)?),
583583
ConstKind::Bound(d, b) => {
584-
ConstKind::Bound(d.try_fold_with(folder)?, b.try_fold_with(folder)?)
584+
ConstKind::Bound(d.noop_try_fold_with(folder)?, b.noop_try_fold_with(folder)?)
585585
}
586-
ConstKind::Placeholder(p) => ConstKind::Placeholder(p.try_fold_with(folder)?),
586+
ConstKind::Placeholder(p) => ConstKind::Placeholder(p.noop_try_fold_with(folder)?),
587587
ConstKind::Unevaluated(uv) => ConstKind::Unevaluated(uv.try_fold_with(folder)?),
588588
ConstKind::Value(t, v) => {
589589
ConstKind::Value(t.try_fold_with(folder)?, v.noop_try_fold_with(folder)?)
@@ -598,17 +598,17 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
598598
impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
599599
fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
600600
match self.kind() {
601-
ConstKind::Param(p) => p.visit_with(visitor),
602-
ConstKind::Infer(i) => i.visit_with(visitor),
601+
ConstKind::Param(p) => p.noop_visit_with(visitor),
602+
ConstKind::Infer(i) => i.noop_visit_with(visitor),
603603
ConstKind::Bound(d, b) => {
604-
try_visit!(d.visit_with(visitor));
605-
b.visit_with(visitor)
604+
try_visit!(d.noop_visit_with(visitor));
605+
b.noop_visit_with(visitor)
606606
}
607-
ConstKind::Placeholder(p) => p.visit_with(visitor),
607+
ConstKind::Placeholder(p) => p.noop_visit_with(visitor),
608608
ConstKind::Unevaluated(uv) => uv.visit_with(visitor),
609609
ConstKind::Value(t, v) => {
610610
try_visit!(t.visit_with(visitor));
611-
v.visit_with(visitor)
611+
v.noop_visit_with(visitor)
612612
}
613613
ConstKind::Error(e) => e.visit_with(visitor),
614614
ConstKind::Expr(e) => e.visit_with(visitor),

compiler/rustc_middle/src/ty/sty.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use rustc_errors::{ErrorGuaranteed, MultiSpan};
1313
use rustc_hir as hir;
1414
use rustc_hir::LangItem;
1515
use rustc_hir::def_id::DefId;
16-
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, extension};
16+
use rustc_macros::{
17+
HashStable, NoopTypeTraversable, TyDecodable, TyEncodable, TypeFoldable, extension,
18+
};
1719
use rustc_span::symbol::{Symbol, sym};
1820
use rustc_span::{DUMMY_SP, Span};
1921
use rustc_target::abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
@@ -323,7 +325,7 @@ impl<'tcx> ParamTy {
323325
}
324326

325327
#[derive(Copy, Clone, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)]
326-
#[derive(HashStable)]
328+
#[derive(HashStable, NoopTypeTraversable)]
327329
pub struct ParamConst {
328330
pub index: u32,
329331
pub name: Symbol,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ where
442442

443443
// FIXME: needs to be pub to be accessed by downstream
444444
// `rustc_trait_selection::solve::inspect::analyse`.
445-
pub fn instantiate_canonical_state<D, I, T: TypeFoldable<I>>(
445+
pub fn instantiate_canonical_state<D, I, T: OptTryFoldWith<I>>(
446446
delegate: &D,
447447
span: D::Span,
448448
param_env: I::ParamEnv,

compiler/rustc_trait_selection/src/infer.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt::Debug;
2-
31
use rustc_hir::def_id::DefId;
42
use rustc_hir::lang_items::LangItem;
53
pub use rustc_infer::infer::*;
@@ -11,6 +9,7 @@ use rustc_middle::infer::canonical::{
119
use rustc_middle::traits::query::NoSolution;
1210
use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, Upcast};
1311
use rustc_span::DUMMY_SP;
12+
use rustc_type_ir::traverse::OptTryFoldWith;
1413
use tracing::instrument;
1514

1615
use crate::infer::at::ToTrace;
@@ -139,7 +138,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
139138
) -> Result<CanonicalQueryResponse<'tcx, R>, NoSolution>
140139
where
141140
K: TypeFoldable<TyCtxt<'tcx>>,
142-
R: Debug + TypeFoldable<TyCtxt<'tcx>>,
141+
R: OptTryFoldWith<TyCtxt<'tcx>>,
143142
Canonical<'tcx, QueryResponse<'tcx, R>>: ArenaAllocatable<'tcx>,
144143
{
145144
let (infcx, key, canonical_inference_vars) =

compiler/rustc_trait_selection/src/traits/engine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::cell::RefCell;
2-
use std::fmt::Debug;
32

43
use rustc_data_structures::fx::FxIndexSet;
54
use rustc_errors::ErrorGuaranteed;
@@ -15,6 +14,7 @@ use rustc_macros::extension;
1514
use rustc_middle::arena::ArenaAllocatable;
1615
use rustc_middle::traits::query::NoSolution;
1716
use rustc_middle::ty::error::TypeError;
17+
use rustc_middle::ty::traverse::OptTryFoldWith;
1818
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast, Variance};
1919
use rustc_type_ir::relate::Relate;
2020

@@ -259,7 +259,7 @@ impl<'tcx> ObligationCtxt<'_, 'tcx, ScrubbedTraitError<'tcx>> {
259259
answer: T,
260260
) -> Result<CanonicalQueryResponse<'tcx, T>, NoSolution>
261261
where
262-
T: Debug + TypeFoldable<TyCtxt<'tcx>>,
262+
T: OptTryFoldWith<TyCtxt<'tcx>>,
263263
Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>,
264264
{
265265
self.infcx.make_canonicalized_query_response(

compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use std::fmt;
33
use rustc_errors::ErrorGuaranteed;
44
use rustc_infer::infer::region_constraints::RegionConstraintData;
55
use rustc_middle::traits::query::NoSolution;
6-
use rustc_middle::ty::{TyCtxt, TypeFoldable};
6+
use rustc_middle::ty::TyCtxt;
7+
use rustc_middle::ty::traverse::AlwaysTraversable;
78
use rustc_span::Span;
9+
use rustc_type_ir::traverse::OptTryFoldWith;
810
use tracing::info;
911

1012
use crate::infer::InferCtxt;
@@ -29,7 +31,7 @@ impl<F> CustomTypeOp<F> {
2931
impl<'tcx, F, R> super::TypeOp<'tcx> for CustomTypeOp<F>
3032
where
3133
F: FnOnce(&ObligationCtxt<'_, 'tcx>) -> Result<R, NoSolution>,
32-
R: fmt::Debug + TypeFoldable<TyCtxt<'tcx>>,
34+
R: fmt::Debug + OptTryFoldWith<TyCtxt<'tcx>>,
3335
{
3436
type Output = R;
3537
/// We can't do any custom error reporting for `CustomTypeOp`, so
@@ -67,7 +69,7 @@ pub fn scrape_region_constraints<'tcx, Op, R>(
6769
span: Span,
6870
) -> Result<(TypeOpOutput<'tcx, Op>, RegionConstraintData<'tcx>), ErrorGuaranteed>
6971
where
70-
R: TypeFoldable<TyCtxt<'tcx>>,
72+
R: OptTryFoldWith<TyCtxt<'tcx>>,
7173
Op: super::TypeOp<'tcx, Output = R>,
7274
{
7375
// During NLL, we expect that nobody will register region
@@ -97,7 +99,7 @@ where
9799
})?;
98100

99101
// Next trait solver performs operations locally, and normalize goals should resolve vars.
100-
let value = infcx.resolve_vars_if_possible(value);
102+
let value = infcx.resolve_vars_if_possible(AlwaysTraversable(value)).0;
101103

102104
let region_obligations = infcx.take_registered_region_obligations();
103105
let region_constraint_data = infcx.take_and_reset_region_constraints();

0 commit comments

Comments
 (0)