Skip to content

Commit 890cef6

Browse files
committed
Change InternedAdtDef to &'tcx AdtDef
1 parent 16ad3f3 commit 890cef6

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

src/librustc_middle/traits/chalk.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use rustc_middle::mir::interpret::ConstValue;
99
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
10-
use rustc_middle::ty::{self, Ty, TyCtxt};
10+
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
1111

1212
use rustc_hir::def_id::DefId;
1313

@@ -75,7 +75,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
7575
type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
7676
type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
7777
type DefId = DefId;
78-
type InternedAdtId = DefId;
78+
type InternedAdtId = &'tcx AdtDef;
7979
type Identifier = ();
8080

8181
fn debug_program_clause_implication(

src/librustc_traits/chalk/db.rs

+24-30
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,14 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
117117

118118
fn adt_datum(
119119
&self,
120-
struct_id: chalk_ir::AdtId<RustInterner<'tcx>>,
120+
adt_id: chalk_ir::AdtId<RustInterner<'tcx>>,
121121
) -> Arc<chalk_solve::rust_ir::AdtDatum<RustInterner<'tcx>>> {
122-
let adt_def_id = struct_id.0;
123-
let adt_def = self.tcx.adt_def(adt_def_id);
122+
let adt_def = adt_id.0;
124123

125-
let bound_vars = bound_vars_for_item(self.tcx, adt_def_id);
124+
let bound_vars = bound_vars_for_item(self.tcx, adt_def.did);
126125
let binders = binders_for(&self.interner, bound_vars);
127126

128-
let predicates = self.tcx.predicates_of(adt_def_id).predicates;
127+
let predicates = self.tcx.predicates_of(adt_def.did).predicates;
129128
let where_clauses: Vec<_> = predicates
130129
.into_iter()
131130
.map(|(wc, _)| wc.subst(self.tcx, bound_vars))
@@ -149,13 +148,13 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
149148
ty::AdtKind::Enum => vec![],
150149
};
151150
let struct_datum = Arc::new(chalk_solve::rust_ir::AdtDatum {
152-
id: struct_id,
151+
id: adt_id,
153152
binders: chalk_ir::Binders::new(
154153
binders,
155154
chalk_solve::rust_ir::AdtDatumBound { fields, where_clauses },
156155
),
157156
flags: chalk_solve::rust_ir::AdtFlags {
158-
upstream: !adt_def_id.is_local(),
157+
upstream: !adt_def.did.is_local(),
159158
fundamental: adt_def.is_fundamental(),
160159
},
161160
});
@@ -179,7 +178,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
179178
let sig = self.tcx.fn_sig(def_id);
180179
// FIXME(chalk): collect into an intermediate SmallVec here since
181180
// we need `TypeFoldable` for `no_bound_vars`
182-
let argument_types: Binder<Vec<_>> = sig.map_bound(|i| i.inputs().iter().copied().collect());
181+
let argument_types: Binder<Vec<_>> =
182+
sig.map_bound(|i| i.inputs().iter().copied().collect());
183183
let argument_types = argument_types
184184
.no_bound_vars()
185185
.expect("FIXME(chalk): late-bound fn parameters not supported in chalk")
@@ -259,17 +259,17 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
259259
fn impl_provided_for(
260260
&self,
261261
auto_trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
262-
struct_id: chalk_ir::AdtId<RustInterner<'tcx>>,
262+
adt_id: chalk_ir::AdtId<RustInterner<'tcx>>,
263263
) -> bool {
264264
let trait_def_id = auto_trait_id.0;
265-
let adt_def_id = struct_id.0;
265+
let adt_def = adt_id.0;
266266
let all_impls = self.tcx.all_impls(trait_def_id);
267267
for impl_def_id in all_impls {
268268
let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap();
269269
let self_ty = trait_ref.self_ty();
270270
match self_ty.kind {
271-
ty::Adt(adt_def, _) => {
272-
if adt_def.did == adt_def_id {
271+
ty::Adt(impl_adt_def, _) => {
272+
if impl_adt_def == adt_def {
273273
return true;
274274
}
275275
}
@@ -344,16 +344,13 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
344344
match well_known {
345345
chalk_solve::rust_ir::WellKnownTrait::SizedTrait => match ty {
346346
Apply(apply) => match apply.name {
347-
chalk_ir::TypeName::Adt(chalk_ir::AdtId(adt_def_id)) => {
348-
let adt_def = self.tcx.adt_def(adt_def_id);
349-
match adt_def.adt_kind() {
350-
ty::AdtKind::Struct | ty::AdtKind::Union => None,
351-
ty::AdtKind::Enum => {
352-
let constraint = self.tcx.adt_sized_constraint(adt_def_id);
353-
if constraint.0.len() > 0 { unimplemented!() } else { Some(true) }
354-
}
347+
chalk_ir::TypeName::Adt(chalk_ir::AdtId(adt_def)) => match adt_def.adt_kind() {
348+
ty::AdtKind::Struct | ty::AdtKind::Union => None,
349+
ty::AdtKind::Enum => {
350+
let constraint = self.tcx.adt_sized_constraint(adt_def.did);
351+
if constraint.0.len() > 0 { unimplemented!() } else { Some(true) }
355352
}
356-
}
353+
},
357354
_ => None,
358355
},
359356
Dyn(_)
@@ -366,16 +363,13 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
366363
chalk_solve::rust_ir::WellKnownTrait::CopyTrait
367364
| chalk_solve::rust_ir::WellKnownTrait::CloneTrait => match ty {
368365
Apply(apply) => match apply.name {
369-
chalk_ir::TypeName::Adt(chalk_ir::AdtId(adt_def_id)) => {
370-
let adt_def = self.tcx.adt_def(adt_def_id);
371-
match adt_def.adt_kind() {
372-
ty::AdtKind::Struct | ty::AdtKind::Union => None,
373-
ty::AdtKind::Enum => {
374-
let constraint = self.tcx.adt_sized_constraint(adt_def_id);
375-
if constraint.0.len() > 0 { unimplemented!() } else { Some(true) }
376-
}
366+
chalk_ir::TypeName::Adt(chalk_ir::AdtId(adt_def)) => match adt_def.adt_kind() {
367+
ty::AdtKind::Struct | ty::AdtKind::Union => None,
368+
ty::AdtKind::Enum => {
369+
let constraint = self.tcx.adt_sized_constraint(adt_def.did);
370+
if constraint.0.len() > 0 { unimplemented!() } else { Some(true) }
377371
}
378-
}
372+
},
379373
_ => None,
380374
},
381375
Dyn(_)

src/librustc_traits/chalk/lowering.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
304304
use TyKind::*;
305305

306306
let empty = || chalk_ir::Substitution::empty(interner);
307-
let struct_ty = |def_id| chalk_ir::TypeName::Adt(chalk_ir::AdtId(def_id));
307+
let struct_ty =
308+
|def_id| chalk_ir::TypeName::Adt(chalk_ir::AdtId(interner.tcx.adt_def(def_id)));
308309
let apply = |name, substitution| {
309310
TyData::Apply(chalk_ir::ApplicationTy { name, substitution }).intern(interner)
310311
};

0 commit comments

Comments
 (0)