Skip to content

Commit

Permalink
Merge pull request #500 from Areredify/wellknown_rename
Browse files Browse the repository at this point in the history
rename `WellKnownTrait::<TraitName>Trait` to `WellKnownTrait::<TraitName>`
  • Loading branch information
detrumi authored Jun 7, 2020
2 parents b576b25 + a1ec7a6 commit 80c0abd
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 45 deletions.
8 changes: 4 additions & 4 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1818,10 +1818,10 @@ trait LowerWellKnownTrait {
impl LowerWellKnownTrait for WellKnownTrait {
fn lower(&self) -> rust_ir::WellKnownTrait {
match self {
Self::SizedTrait => rust_ir::WellKnownTrait::SizedTrait,
Self::CopyTrait => rust_ir::WellKnownTrait::CopyTrait,
Self::CloneTrait => rust_ir::WellKnownTrait::CloneTrait,
Self::DropTrait => rust_ir::WellKnownTrait::DropTrait,
Self::Sized => rust_ir::WellKnownTrait::Sized,
Self::Copy => rust_ir::WellKnownTrait::Copy,
Self::Clone => rust_ir::WellKnownTrait::Clone,
Self::Drop => rust_ir::WellKnownTrait::Drop,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions chalk-parse/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ pub struct TraitDefn {

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum WellKnownTrait {
SizedTrait,
CopyTrait,
CloneTrait,
DropTrait,
Sized,
Copy,
Clone,
Drop,
}

#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down
8 changes: 4 additions & 4 deletions chalk-parse/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ CoinductiveKeyword: () = "#" "[" "coinductive" "]";
ObjectSafeKeyword: () = "#" "[" "object_safe" "]";

WellKnownTrait: WellKnownTrait = {
"#" "[" "lang" "(" "sized" ")" "]" => WellKnownTrait::SizedTrait,
"#" "[" "lang" "(" "copy" ")" "]" => WellKnownTrait::CopyTrait,
"#" "[" "lang" "(" "clone" ")" "]" => WellKnownTrait::CloneTrait,
"#" "[" "lang" "(" "drop" ")" "]" => WellKnownTrait::DropTrait,
"#" "[" "lang" "(" "sized" ")" "]" => WellKnownTrait::Sized,
"#" "[" "lang" "(" "copy" ")" "]" => WellKnownTrait::Copy,
"#" "[" "lang" "(" "clone" ")" "]" => WellKnownTrait::Clone,
"#" "[" "lang" "(" "drop" ")" "]" => WellKnownTrait::Drop,
};

StructDefn: StructDefn = {
Expand Down
14 changes: 4 additions & 10 deletions chalk-solve/src/clauses/builtin_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@ pub fn add_builtin_program_clauses<I: Interner>(
}

match well_known {
WellKnownTrait::SizedTrait => {
sized::add_sized_program_clauses(db, builder, &trait_ref, ty)
}
WellKnownTrait::CopyTrait => {
copy::add_copy_program_clauses(db, builder, &trait_ref, ty)
}
WellKnownTrait::CloneTrait => {
clone::add_clone_program_clauses(db, builder, &trait_ref, ty)
}
WellKnownTrait::Sized => sized::add_sized_program_clauses(db, builder, &trait_ref, ty),
WellKnownTrait::Copy => copy::add_copy_program_clauses(db, builder, &trait_ref, ty),
WellKnownTrait::Clone => clone::add_clone_program_clauses(db, builder, &trait_ref, ty),
// Drop impls are provided explicitly
WellKnownTrait::DropTrait => (),
WellKnownTrait::Drop => (),
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion chalk-solve/src/clauses/program_clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ impl<I: Interner> ToProgramClauses<I> for TraitDatum<I> {
// i.e. Drop implementation for `struct S<T: Eq> {}` is forced to be
// `impl Drop<T: Eq> for S<T> { ... }`. That means that orphan rules
// prevent Drop from being implemented in downstream crates.
if self.well_known != Some(WellKnownTrait::DropTrait) {
if self.well_known != Some(WellKnownTrait::Drop) {
// Add all cases for potential downstream impls that could exist
for i in 0..type_parameters.len() {
builder.push_clause(
Expand Down
8 changes: 4 additions & 4 deletions chalk-solve/src/rust_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ pub struct TraitDatum<I: Interner> {
/// the chalk-solve crate has special, hard-coded impls for them.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum WellKnownTrait {
SizedTrait,
CopyTrait,
CloneTrait,
DropTrait,
Sized,
Copy,
Clone,
Drop,
}

impl<I: Interner> TraitDatum<I> {
Expand Down
34 changes: 16 additions & 18 deletions chalk-solve/src/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,8 @@ impl WfWellKnownGoals {
trait_ref: &TraitRef<I>,
) -> Option<Goal<I>> {
match db.trait_datum(trait_ref.trait_id).well_known? {
WellKnownTrait::CopyTrait => Self::copy_impl_constraint(db, trait_ref),
WellKnownTrait::DropTrait | WellKnownTrait::CloneTrait | WellKnownTrait::SizedTrait => {
None
}
WellKnownTrait::Copy => Self::copy_impl_constraint(db, trait_ref),
WellKnownTrait::Drop | WellKnownTrait::Clone | WellKnownTrait::Sized => None,
}
}

Expand All @@ -488,9 +486,9 @@ impl WfWellKnownGoals {

match db.trait_datum(impl_datum.trait_id()).well_known? {
// You can't add a manual implementation of Sized
WellKnownTrait::SizedTrait => Some(GoalData::CannotProve(()).intern(interner)),
WellKnownTrait::DropTrait => Self::drop_impl_constraint(db, impl_datum),
WellKnownTrait::CopyTrait | WellKnownTrait::CloneTrait => None,
WellKnownTrait::Sized => Some(GoalData::CannotProve(()).intern(interner)),
WellKnownTrait::Drop => Self::drop_impl_constraint(db, impl_datum),
WellKnownTrait::Copy | WellKnownTrait::Clone => None,
}
}

Expand All @@ -507,7 +505,7 @@ impl WfWellKnownGoals {

let interner = db.interner();

let sized_trait = db.well_known_trait_id(WellKnownTrait::SizedTrait)?;
let sized_trait = db.well_known_trait_id(WellKnownTrait::Sized)?;

Some(Goal::all(
interner,
Expand Down Expand Up @@ -547,16 +545,16 @@ impl WfWellKnownGoals {
};

// not { Implemented(ImplSelfTy: Drop) }
let neg_drop_goal =
db.well_known_trait_id(WellKnownTrait::DropTrait)
.map(|drop_trait_id| {
TraitRef {
trait_id: drop_trait_id,
substitution: Substitution::from1(interner, ty.clone()),
}
.cast::<Goal<I>>(interner)
.negate(interner)
});
let neg_drop_goal = db
.well_known_trait_id(WellKnownTrait::Drop)
.map(|drop_trait_id| {
TraitRef {
trait_id: drop_trait_id,
substitution: Substitution::from1(interner, ty.clone()),
}
.cast::<Goal<I>>(interner)
.negate(interner)
});

let adt_datum = db.adt_datum(adt_id);

Expand Down

0 comments on commit 80c0abd

Please sign in to comment.