Skip to content

Commit d2218ae

Browse files
committed
address nits 2: electric boogaloo
1 parent ae8d536 commit d2218ae

File tree

8 files changed

+18
-52
lines changed

8 files changed

+18
-52
lines changed

chalk-integration/src/db.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use chalk_rust_ir::AssociatedTyDatum;
2121
use chalk_rust_ir::AssociatedTyValue;
2222
use chalk_rust_ir::AssociatedTyValueId;
2323
use chalk_rust_ir::ImplDatum;
24-
use chalk_rust_ir::LangItem;
2524
use chalk_rust_ir::StructDatum;
2625
use chalk_rust_ir::TraitDatum;
26+
use chalk_rust_ir::WellKnownTrait;
2727
use chalk_solve::RustIrDatabase;
2828
use chalk_solve::Solution;
2929
use chalk_solve::SolverChoice;
@@ -138,8 +138,8 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
138138
.impl_provided_for(auto_trait_id, struct_id)
139139
}
140140

141-
fn require_lang_item(&self, lang_item: LangItem) -> TraitId<ChalkIr> {
142-
self.program_ir().unwrap().require_lang_item(lang_item)
141+
fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> TraitId<ChalkIr> {
142+
self.program_ir().unwrap().well_known_trait_id(well_known_trait)
143143
}
144144

145145
fn interner(&self) -> &ChalkIr {

chalk-integration/src/error.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use chalk_ir::interner::ChalkIr;
22
use chalk_parse::ast::{Identifier, Kind};
3-
use chalk_rust_ir::LangItem;
43
use chalk_solve::coherence::CoherenceError;
54
use chalk_solve::wf::WfError;
65

@@ -57,7 +56,6 @@ impl std::error::Error for ChalkError {}
5756
pub enum RustIrError {
5857
InvalidTypeName(Identifier),
5958
InvalidLifetimeName(Identifier),
60-
DuplicateLangItem(LangItem),
6159
NotTrait(Identifier),
6260
NotStruct(Identifier),
6361
DuplicateOrShadowedParameters,
@@ -100,7 +98,6 @@ impl std::fmt::Display for RustIrError {
10098
match self {
10199
RustIrError::InvalidTypeName(name) => write!(f, "invalid type name `{}`", name),
102100
RustIrError::InvalidLifetimeName(name) => write!(f, "invalid lifetime name `{}`", name),
103-
RustIrError::DuplicateLangItem(item) => write!(f, "duplicate lang item `{:?}`", item),
104101
RustIrError::NotTrait(name) => write!(
105102
f,
106103
"expected a trait, found `{}`, which is not a trait",

chalk-integration/src/lowering.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use chalk_ir::interner::ChalkIr;
33
use chalk_ir::{self, AssocTypeId, BoundVar, DebruijnIndex, ImplId, StructId, TraitId};
44
use chalk_parse::ast::*;
55
use chalk_rust_ir as rust_ir;
6-
use chalk_rust_ir::{Anonymize, AssociatedTyValueId, IntoWhereClauses, LangItem, ToParameter};
6+
use chalk_rust_ir::{Anonymize, AssociatedTyValueId, IntoWhereClauses, ToParameter};
77
use lalrpop_intern::intern;
88
use std::collections::BTreeMap;
99
use std::sync::Arc;
@@ -246,7 +246,7 @@ impl LowerProgram for Program {
246246

247247
let mut struct_data = BTreeMap::new();
248248
let mut trait_data = BTreeMap::new();
249-
let mut trait_lang_items = BTreeMap::new();
249+
let mut well_known_traits = BTreeMap::new();
250250
let mut impl_data = BTreeMap::new();
251251
let mut associated_ty_data = BTreeMap::new();
252252
let mut associated_ty_values = BTreeMap::new();
@@ -271,18 +271,7 @@ impl LowerProgram for Program {
271271
let trait_datum = trait_defn.lower_trait(trait_id, &empty_env)?;
272272

273273
if let Some(well_known) = trait_datum.well_known {
274-
if let Some(lang_item) = match well_known {
275-
rust_ir::WellKnownTrait::SizedTrait => Some(LangItem::SizedTrait),
276-
_ => None,
277-
} {
278-
use std::collections::btree_map::Entry;
279-
match trait_lang_items.entry(lang_item) {
280-
Entry::Vacant(vacant) => vacant.insert(trait_id),
281-
Entry::Occupied(_) => {
282-
return Err(RustIrError::DuplicateLangItem(lang_item))
283-
}
284-
};
285-
}
274+
well_known_traits.insert(well_known, trait_id);
286275
}
287276

288277
trait_data.insert(trait_id, Arc::new(trait_datum));
@@ -382,7 +371,7 @@ impl LowerProgram for Program {
382371
trait_kinds,
383372
struct_data,
384373
trait_data,
385-
trait_lang_items,
374+
well_known_traits,
386375
impl_data,
387376
associated_ty_values,
388377
associated_ty_data,

chalk-integration/src/program.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use chalk_ir::tls;
66
use chalk_ir::{
77
debug::SeparatorTraitRef, AliasTy, ApplicationTy, AssocTypeId, Goal, Goals, ImplId, Lifetime,
88
Parameter, ProgramClause, ProgramClauseImplication, ProgramClauses, StructId, Substitution,
9-
TraitId, Ty, TyData, TypeName,
9+
TraitId, Ty, TyData, TypeName,
1010
};
1111
use chalk_rust_ir::{
12-
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ImplDatum, ImplType, LangItem,
13-
StructDatum, TraitDatum,
12+
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ImplDatum, ImplType,
13+
StructDatum, TraitDatum, WellKnownTrait
1414
};
1515
use chalk_solve::split::Split;
1616
use chalk_solve::RustIrDatabase;
@@ -46,7 +46,7 @@ pub struct Program {
4646
pub trait_data: BTreeMap<TraitId<ChalkIr>, Arc<TraitDatum<ChalkIr>>>,
4747

4848
/// For each trait lang item
49-
pub trait_lang_items: BTreeMap<LangItem, TraitId<ChalkIr>>,
49+
pub well_known_traits: BTreeMap<WellKnownTrait, TraitId<ChalkIr>>,
5050

5151
/// For each associated ty declaration `type Foo` found in a trait:
5252
pub associated_ty_data: BTreeMap<AssocTypeId<ChalkIr>, Arc<AssociatedTyDatum<ChalkIr>>>,
@@ -312,11 +312,11 @@ impl RustIrDatabase<ChalkIr> for Program {
312312
})
313313
}
314314

315-
fn require_lang_item(&self, lang_item: LangItem) -> TraitId<ChalkIr> {
315+
fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> TraitId<ChalkIr> {
316316
*self
317-
.trait_lang_items
318-
.get(&lang_item)
319-
.unwrap_or_else(|| panic!("No lang item found for {:?}", lang_item))
317+
.well_known_traits
318+
.get(&well_known_trait)
319+
.unwrap_or_else(|| panic!("No lang item found for {:?}", well_known_trait))
320320
}
321321

322322
fn interner(&self) -> &ChalkIr {

chalk-rust-ir/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ use chalk_ir::{
1515
};
1616
use std::iter;
1717

18-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
19-
pub enum LangItem {
20-
SizedTrait,
21-
}
22-
2318
/// Identifier for an "associated type value" found in some impl.
2419
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
2520
pub struct AssociatedTyValueId<I: Interner>(pub I::DefId);
@@ -136,7 +131,7 @@ pub struct TraitDatum<I: Interner> {
136131

137132
/// A list of the traits that are "well known" to chalk, which means that
138133
/// the chalk-solve crate has special, hard-coded impls for them.
139-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
134+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
140135
pub enum WellKnownTrait {
141136
SizedTrait,
142137
CopyTrait,

chalk-solve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub trait RustIrDatabase<I: Interner>: Debug {
7777
}
7878

7979
/// Returns id of a trait lang item, if found
80-
fn require_lang_item(&self, lang_item: LangItem) -> TraitId<I>;
80+
fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> TraitId<I>;
8181

8282
fn interner(&self) -> &I;
8383
}

chalk-solve/src/wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ fn compute_struct_sized_constraint<I: Interner>(
493493

494494
let interner = db.interner();
495495

496-
let sized_trait = db.require_lang_item(LangItem::SizedTrait);
496+
let sized_trait = db.well_known_trait_id(WellKnownTrait::SizedTrait);
497497

498498
Some(Goal::all(
499499
interner,

tests/test/wf_lowering.rs

-15
Original file line numberDiff line numberDiff line change
@@ -637,21 +637,6 @@ fn assoc_type_recursive_bound() {
637637
}
638638
}
639639

640-
#[test]
641-
fn duplicate_lang_item() {
642-
lowering_error! {
643-
program {
644-
#[lang(sized)]
645-
trait Sized { }
646-
647-
#[lang(sized)]
648-
trait Sized2 { }
649-
} error_msg {
650-
"duplicate lang item `SizedTrait`"
651-
}
652-
}
653-
}
654-
655640
#[test]
656641
fn struct_sized_constraints() {
657642
lowering_error! {

0 commit comments

Comments
 (0)