Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
memoryleak47 committed Sep 9, 2020
2 parents 99ea62d + a1127d9 commit 52ac910
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 2 deletions.
1 change: 1 addition & 0 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,7 @@ impl Lower for WellKnownTrait {
WellKnownTrait::FnMut => rust_ir::WellKnownTrait::FnMut,
WellKnownTrait::Fn => rust_ir::WellKnownTrait::Fn,
WellKnownTrait::Unsize => rust_ir::WellKnownTrait::Unsize,
WellKnownTrait::Unpin => rust_ir::WellKnownTrait::Unpin,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions chalk-parse/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub enum WellKnownTrait {
FnMut,
Fn,
Unsize,
Unpin,
}

#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down
1 change: 1 addition & 0 deletions chalk-parse/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ WellKnownTrait: WellKnownTrait = {
"#" "[" "lang" "(" "fn_mut" ")" "]" => WellKnownTrait::FnMut,
"#" "[" "lang" "(" "fn" ")" "]" => WellKnownTrait::Fn,
"#" "[" "lang" "(" "unsize" ")" "]" => WellKnownTrait::Unsize,
"#" "[" "lang" "(" "unpin" ")" "]" => WellKnownTrait::Unpin,
};

AdtRepr: Atom = "#" "[" "repr" "(" <name:Id> ")" "]" => name.str;
Expand Down
4 changes: 4 additions & 0 deletions chalk-solve/src/clauses/builtin_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ pub fn add_builtin_program_clauses<I: Interner>(
WellKnownTrait::Unsize => {
unsize::add_unsize_program_clauses(db, builder, &trait_ref, ty)
}

// Drop impls are provided explicitly
WellKnownTrait::Drop => (),

// There are no special rules for Unpin
WellKnownTrait::Unpin => (),
}
Ok(())
})
Expand Down
1 change: 1 addition & 0 deletions chalk-solve/src/display/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl<I: Interner> RenderAsRust<I> for TraitDatum<I> {
WellKnownTrait::FnMut => "fn_mut",
WellKnownTrait::Fn => "fn",
WellKnownTrait::Unsize => "unsize",
WellKnownTrait::Unpin => "unpin",
};
writeln!(f, "#[lang({})]", name)?;
}
Expand Down
1 change: 1 addition & 0 deletions chalk-solve/src/rust_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ pub enum WellKnownTrait {
FnMut,
Fn,
Unsize,
Unpin,
}

chalk_ir::const_visit!(WellKnownTrait);
Expand Down
5 changes: 3 additions & 2 deletions chalk-solve/src/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ impl WfWellKnownGoals {
| WellKnownTrait::FnOnce
| WellKnownTrait::FnMut
| WellKnownTrait::Fn
| WellKnownTrait::Unsize => None,
| WellKnownTrait::Unsize
| WellKnownTrait::Unpin => None,
}
}

Expand All @@ -577,7 +578,7 @@ impl WfWellKnownGoals {

match db.trait_datum(impl_datum.trait_id()).well_known? {
WellKnownTrait::Drop => Self::drop_impl_constraint(db, impl_datum),
WellKnownTrait::Copy | WellKnownTrait::Clone => None,
WellKnownTrait::Copy | WellKnownTrait::Clone | WellKnownTrait::Unpin => None,
// You can't add a manual implementation for following traits:
WellKnownTrait::Sized
| WellKnownTrait::FnOnce
Expand Down
1 change: 1 addition & 0 deletions tests/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,6 @@ mod slices;
mod string;
mod tuples;
mod unify;
mod unpin;
mod unsize;
mod wf_goals;
86 changes: 86 additions & 0 deletions tests/test/unpin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//! Tests targeting the Unpin trait
use super::*;

#[test]
fn unpin_lowering() {
lowering_success! {
program {
#[auto] #[lang(unpin)] trait Unpin { }
enum A { Variant }
struct B { }
impl !Unpin for A {}
impl Unpin for B {}
}
}
}

#[test]
fn unpin_auto_trait() {
test! {
program {
#[auto] #[lang(unpin)] trait Unpin { }
struct A { }
}

goal {
A: Unpin
} yields {
"Unique"
}
}
}

#[test]
fn unpin_negative() {
test! {
program {
#[auto] #[lang(unpin)] trait Unpin { }
struct A { }
impl !Unpin for A {}
}

goal {
A: Unpin
} yields {
"No possible solution"
}
}
}

#[test]
fn unpin_inherit_negative() {
test! {
program {
#[auto] #[lang(unpin)] trait Unpin { }
struct A { }
impl !Unpin for A {}
struct B { a: A }
}

goal {
B: Unpin
} yields {
"No possible solution"
}
}
}

#[test]
fn unpin_overwrite() {
test! {
program {
#[auto] #[lang(unpin)] trait Unpin { }
struct A { }
impl !Unpin for A {}
struct B { a: A }
impl Unpin for B {}
}

goal {
B: Unpin
} yields {
"Unique"
}
}
}

0 comments on commit 52ac910

Please sign in to comment.