Skip to content

Add function def clauses #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/clauses/well_known_traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Some common examples of auto traits are `Send` and `Sync`.
| str | 📚 | 📚 ||||||||
| never type | 📚 | 📚 ||||||||
| trait objects ||||||||||
| functions defs ||||||||||
| functions ptrs ||||||||||
| raw ptrs | 📚 | 📚 ||||||||
| immutable refs | 📚 | 📚 ||||||||
Expand Down
3 changes: 3 additions & 0 deletions chalk-solve/src/clauses/builtin_traits/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ pub fn add_copy_program_clauses<I: Interner>(
iter::once(substitution.at(interner, 0).assert_ty_ref(interner).clone()),
);
}
TypeName::FnDef(_) => {
builder.push_fact(trait_ref.clone());
}
_ => return,
},
TyData::Function(_) => builder.push_fact(trait_ref.clone()),
Expand Down
1 change: 1 addition & 0 deletions chalk-solve/src/clauses/builtin_traits/sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn add_sized_program_clauses<I: Interner>(
}
TypeName::Array
| TypeName::Never
| TypeName::FnDef(_)
| TypeName::Scalar(_)
| TypeName::Raw(_)
| TypeName::Ref(_) => builder.push_fact(trait_ref.clone()),
Expand Down
66 changes: 66 additions & 0 deletions tests/test/fn_def.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use super::*;
Copy link
Member

@AzureMarker AzureMarker May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another issue, these tests aren't run because the module is not listed in tests/test/mod.rs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They fail in the parser because it expects ; instead of { }.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙄


#[test]
fn fn_def_is_well_formed() {
test! {
program {
fn foo() {}
}
goal {
WellFormed(foo)
} yields {
"Unique"
}
}
}

#[test]
fn fn_def_is_sized() {
test! {
program {
#[lang(sized)]
trait Sized { }

fn foo() {}
}
goal {
foo: Sized
} yields {
"Unique"
}
}
}

#[test]
fn fn_def_is_copy() {
test! {
program {
#[lang(sized)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be copy, not sized.

trait Copy { }

fn foo() {}
}
goal {
foo: Copy
} yields {
"Unique"
}
}
}

#[test]
fn fn_def_is_clone() {
test! {
program {
#[lang(sized)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be clone, not sized.

trait Clone { }

fn foo() {}
}
goal {
foo: Clone
} yields {
"Unique"
}
}
}
15 changes: 15 additions & 0 deletions tests/test/never.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ fn never_is_well_formed() {
}
}
}

#[test]
fn never_is_sized() {
test! {
program {
#[lang(sized)]
trait Sized { }
}
goal {
!: Sized
} yields {
"Unique"
}
}
}