forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#18 from utaal/structural
Use the `builtin::Structural` trait to mark types that support structural equality
- Loading branch information
Showing
16 changed files
with
305 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
members = [ | ||
"air", | ||
"builtin", | ||
"builtin_macros", | ||
"vir", | ||
"rust_verify", | ||
"rust_verify_test_macros", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ name = "builtin" | |
version = "0.1.0" | ||
authors = ["Chris Hawblitzel <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "builtin_macros" | ||
version = "0.1.0" | ||
authors = ["Chris Hawblitzel <[email protected]>", "Andrea Lattuada <[email protected]>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-macro2 = "1.0" | ||
quote = "1.0" | ||
synstructure = "0.12" | ||
syn = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use quote::quote; | ||
use synstructure::decl_derive; | ||
|
||
decl_derive!([Structural] => derive_structural); | ||
|
||
fn derive_structural(s: synstructure::Structure) -> proc_macro2::TokenStream { | ||
let assert_receiver_is_structural_body = s | ||
.variants() | ||
.iter() | ||
.flat_map(|v| v.ast().fields) | ||
.map(|f| { | ||
let ty = &f.ty; | ||
quote! { | ||
let _: ::builtin::AssertParamIsStructural<#ty>; | ||
} | ||
}) | ||
.collect::<proc_macro2::TokenStream>(); | ||
s.gen_impl(quote! { | ||
#[automatically_derived] | ||
gen impl ::builtin::Structural for @Self { | ||
#[inline] | ||
#[doc(hidden)] | ||
fn assert_receiver_is_structural(&self) -> () { | ||
#assert_receiver_is_structural_body | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extern crate builtin; | ||
#[macro_use] extern crate builtin_macros; | ||
use builtin::*; | ||
mod pervasive; | ||
use pervasive::*; | ||
|
||
#[derive(Eq)] | ||
struct Thing { } | ||
|
||
impl std::cmp::PartialEq for Thing { | ||
fn eq(&self, _: &Self) -> bool { todo!() } | ||
} | ||
|
||
#[derive(PartialEq, Eq, Structural)] | ||
struct Car<T> { | ||
passengers: T, | ||
four_doors: bool, | ||
} | ||
|
||
fn one() { | ||
let c1 = Car { passengers: Thing { }, four_doors: true }; | ||
let c2 = Car { passengers: Thing { }, four_doors: true }; | ||
assert(c1 == c2); | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.