Skip to content

Commit 3d73030

Browse files
committed
Use builtin types for Never, Array, and FnDef
1 parent 6ba003e commit 3d73030

File tree

4 files changed

+23
-48
lines changed

4 files changed

+23
-48
lines changed

src/librustc_middle/traits/chalk.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ use std::hash::{Hash, Hasher};
2121
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
2222
pub enum RustDefId {
2323
Adt(DefId),
24-
Never,
25-
Array,
26-
FnDef(DefId),
2724

25+
FnDef(DefId),
2826
Trait(DefId),
2927
Impl(DefId),
3028
AssocTy(DefId),

src/librustc_traits/chalk/db.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -168,35 +168,6 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
168168
});
169169
struct_datum
170170
}
171-
RustDefId::Array => {
172-
return Arc::new(chalk_solve::rust_ir::AdtDatum {
173-
id: struct_id,
174-
binders: chalk_ir::Binders::new(
175-
chalk_ir::VariableKinds::from(
176-
&self.interner,
177-
Some(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)),
178-
),
179-
chalk_solve::rust_ir::AdtDatumBound {
180-
fields: vec![],
181-
where_clauses: vec![],
182-
},
183-
),
184-
flags: chalk_solve::rust_ir::AdtFlags { upstream: false, fundamental: false },
185-
});
186-
}
187-
RustDefId::Never | RustDefId::FnDef(_) => {
188-
return Arc::new(chalk_solve::rust_ir::AdtDatum {
189-
id: struct_id,
190-
binders: chalk_ir::Binders::new(
191-
chalk_ir::VariableKinds::new(&self.interner),
192-
chalk_solve::rust_ir::AdtDatumBound {
193-
fields: vec![],
194-
where_clauses: vec![],
195-
},
196-
),
197-
flags: chalk_solve::rust_ir::AdtFlags { upstream: false, fundamental: false },
198-
});
199-
}
200171

201172
v => bug!("Used not struct variant ({:?}) when expecting struct variant.", v),
202173
}
@@ -287,8 +258,6 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
287258
// FIXME(chalk): this match can be removed when builtin types supported
288259
match struct_id.0 {
289260
RustDefId::Adt(_) => {}
290-
RustDefId::Never => return false,
291-
RustDefId::Array => return false,
292261
_ => bug!("Did not use `Adt` variant when expecting adt."),
293262
}
294263
let adt_def_id: DefId = match struct_id.0 {
@@ -385,8 +354,6 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
385354
chalk_ir::TypeName::Adt(chalk_ir::AdtId(rust_def_id)) => {
386355
use rustc_middle::traits::ChalkRustDefId::*;
387356
match rust_def_id {
388-
Never | Array | FnDef(_) => Some(true),
389-
390357
Adt(adt_def_id) => {
391358
let adt_def = self.tcx.adt_def(adt_def_id);
392359
match adt_def.adt_kind() {
@@ -402,7 +369,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
402369
}
403370
}
404371

405-
Trait(_) | Impl(_) | AssocTy(_) | Opaque(_) => panic!(),
372+
FnDef(_) | Trait(_) | Impl(_) | AssocTy(_) | Opaque(_) => panic!(),
406373
}
407374
}
408375
_ => None,
@@ -420,8 +387,6 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
420387
chalk_ir::TypeName::Adt(chalk_ir::AdtId(rust_def_id)) => {
421388
use rustc_middle::traits::ChalkRustDefId::*;
422389
match rust_def_id {
423-
Never => Some(false),
424-
FnDef(_) | Array => Some(true),
425390
Adt(adt_def_id) => {
426391
let adt_def = self.tcx.adt_def(adt_def_id);
427392
match adt_def.adt_kind() {
@@ -436,7 +401,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
436401
}
437402
}
438403
}
439-
Trait(_) | Impl(_) | AssocTy(_) | Opaque(_) => panic!(),
404+
FnDef(_) | Trait(_) | Impl(_) | AssocTy(_) | Opaque(_) => panic!(),
440405
}
441406
}
442407
_ => None,

src/librustc_traits/chalk/lowering.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,22 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
311311
Foreign(_def_id) => unimplemented!(),
312312
Str => apply(chalk_ir::TypeName::Str, empty()),
313313
Array(ty, _) => apply(
314-
struct_ty(RustDefId::Array),
315-
chalk_ir::Substitution::from1(
314+
chalk_ir::TypeName::Array,
315+
chalk_ir::Substitution::from(
316316
interner,
317-
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
317+
&[
318+
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
319+
chalk_ir::GenericArgData::Const(
320+
chalk_ir::ConstData {
321+
ty: apply(chalk_ir::TypeName::Tuple(0), empty()),
322+
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst {
323+
interned: 0,
324+
}),
325+
}
326+
.intern(interner),
327+
)
328+
.intern(interner),
329+
],
318330
),
319331
),
320332
Slice(ty) => apply(
@@ -348,7 +360,10 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
348360
),
349361
)
350362
}
351-
FnDef(def_id, _) => apply(struct_ty(RustDefId::FnDef(def_id)), empty()),
363+
FnDef(def_id, _) => apply(
364+
chalk_ir::TypeName::FnDef(chalk_ir::FnDefId(RustDefId::FnDef(def_id))),
365+
empty(),
366+
),
352367
FnPtr(sig) => {
353368
let (inputs_and_outputs, binders, _named_regions) =
354369
collect_bound_vars(interner, interner.tcx, &sig.inputs_and_output());
@@ -371,7 +386,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
371386
Closure(_def_id, _) => unimplemented!(),
372387
Generator(_def_id, _substs, _) => unimplemented!(),
373388
GeneratorWitness(_) => unimplemented!(),
374-
Never => apply(struct_ty(RustDefId::Never), empty()),
389+
Never => apply(chalk_ir::TypeName::Never, empty()),
375390
Tuple(substs) => {
376391
apply(chalk_ir::TypeName::Tuple(substs.len()), substs.lower_into(interner))
377392
}

src/librustc_traits/chalk/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ crate fn evaluate_goal<'tcx>(
108108
TyData::Apply(_application_ty) => match _application_ty.name {
109109
chalk_ir::TypeName::Adt(_struct_id) => match _struct_id.0 {
110110
RustDefId::Adt(_) => unimplemented!(),
111-
RustDefId::Never => unimplemented!(),
112-
RustDefId::Array => unimplemented!(),
113-
RustDefId::FnDef(_) => unimplemented!(),
114111
_ => panic!("Unexpected struct id"),
115112
},
116113
chalk_ir::TypeName::Scalar(scalar) => match scalar {

0 commit comments

Comments
 (0)