Skip to content

Commit 99c2eab

Browse files
Update synstructure version
1 parent 155f39d commit 99c2eab

6 files changed

Lines changed: 25 additions & 39 deletions

File tree

source/Cargo.lock

Lines changed: 4 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/builtin_macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ proc-macro = true
1616
[dependencies]
1717
proc-macro2 = "1.0.39"
1818
quote = "1.0"
19-
synstructure = { git = "https://github.com/mystor/synstructure.git", rev = "1079497eb2bea252433dac53afe41291d8779641" }
19+
synstructure = "0.13.2"
2020
syn = { version = "2.0", features = ["full", "visit", "visit-mut", "extra-traits"] }
2121
verus_syn = { version = "2.0.96", path="../../dependencies/syn", features = ["full", "visit", "visit-mut", "extra-traits"] }
2222
verus_prettyplease = { version = "0.2.29", path="../../dependencies/prettyplease" }

source/builtin_macros/src/structural.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ pub fn derive_structural_mut(s: &mut synstructure::Structure) -> proc_macro2::To
1313
})
1414
.collect::<proc_macro2::TokenStream>();
1515

16-
// TODO: this feature has disappeared in the latest version of synstructure
17-
// (this is why we still use a specific commit of synstructure)
18-
// see 'path.segments.iter().find(|s| s.starts_with("_DERIVE_builtin_Structural_FOR_")).is_some()' in rust_to_vir
19-
s.underscore_const(false);
20-
21-
s.gen_impl(quote_spanned_builtin! { verus_builtin, s.ast().span() =>
16+
let mut tokens1 = quote::quote_spanned!(s.ast().span() =>
17+
#[verus::internal(structural_const_wrapper)]
18+
);
19+
let tokens2 = s.gen_impl(quote_spanned_builtin! { verus_builtin, s.ast().span() =>
2220
#[automatically_derived]
2321
#[allow(non_local_definitions)]
2422
gen unsafe impl #verus_builtin::Structural for @Self {
@@ -28,7 +26,9 @@ pub fn derive_structural_mut(s: &mut synstructure::Structure) -> proc_macro2::To
2826
#assert_receiver_is_structural_body
2927
}
3028
}
31-
})
29+
});
30+
tokens1.extend(tokens2.into_iter());
31+
tokens1
3232
}
3333

3434
pub fn derive_structural(mut s: synstructure::Structure) -> proc_macro2::TokenStream {

source/rust_verify/src/attributes.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ pub(crate) enum Attr {
344344
UsesUnerasedProxy,
345345
EncodedConst,
346346
EncodedStatic,
347+
// The "const _: () = { ... }" generated by synstructure for #[derive(Structural)]
348+
StructuralConstWrapper,
347349
}
348350

349351
fn get_trigger_arg(span: Span, attr_tree: &AttrTree) -> Result<u64, VirErr> {
@@ -778,6 +780,9 @@ pub(crate) fn parse_attrs(
778780
AttrTree::Fun(_, arg, None) if arg == "encoded_static" => {
779781
v.push(Attr::EncodedStatic)
780782
}
783+
AttrTree::Fun(_, arg, None) if arg == "structural_const_wrapper" => {
784+
v.push(Attr::StructuralConstWrapper)
785+
}
781786
_ => {
782787
return err_span(span, "unrecognized internal attribute");
783788
}
@@ -966,6 +971,7 @@ pub(crate) struct ExternalAttrs {
966971
pub(crate) internal_get_field_many_variants: bool,
967972
pub(crate) external_auto_derives: AutoDerivesAttr,
968973
pub(crate) uses_unerased_proxy: bool,
974+
pub(crate) structural_const_wrapper: bool,
969975
}
970976

971977
#[derive(Debug)]
@@ -1026,6 +1032,7 @@ pub(crate) struct VerifierAttrs {
10261032
pub(crate) unerased_proxy: bool,
10271033
pub(crate) encoded_const: bool,
10281034
pub(crate) encoded_static: bool,
1035+
pub(crate) structural_const_wrapper: bool,
10291036
}
10301037

10311038
// Check for the `get_field_many_variants` attribute
@@ -1085,6 +1092,7 @@ pub(crate) fn get_external_attrs(
10851092
internal_get_field_many_variants: false,
10861093
external_auto_derives: AutoDerivesAttr::Regular,
10871094
uses_unerased_proxy: false,
1095+
structural_const_wrapper: false,
10881096
};
10891097

10901098
for attr in parse_attrs(attrs, diagnostics)? {
@@ -1108,6 +1116,7 @@ pub(crate) fn get_external_attrs(
11081116
es.external_auto_derives = AutoDerivesAttr::SomeExternal(external_auto_derives)
11091117
}
11101118
Attr::UsesUnerasedProxy => es.uses_unerased_proxy = true,
1119+
Attr::StructuralConstWrapper => es.structural_const_wrapper = true,
11111120
Attr::UnsupportedRustcAttr(..) => {}
11121121
_ => {
11131122
es.any_other_verus_specific_attribute = true;
@@ -1193,6 +1202,7 @@ pub(crate) fn get_verifier_attrs_maybe_check(
11931202
unerased_proxy: false,
11941203
encoded_const: false,
11951204
encoded_static: false,
1205+
structural_const_wrapper: false,
11961206
};
11971207
let mut unsupported_rustc_attr: Option<(String, Span)> = None;
11981208
for attr in parse_attrs(attrs, diagnostics)? {
@@ -1269,6 +1279,7 @@ pub(crate) fn get_verifier_attrs_maybe_check(
12691279
Attr::UnerasedProxy => vs.unerased_proxy = true,
12701280
Attr::EncodedConst => vs.encoded_const = true,
12711281
Attr::EncodedStatic => vs.encoded_static = true,
1282+
Attr::StructuralConstWrapper => vs.structural_const_wrapper = true,
12721283
Attr::UsesUnerasedProxy => {}
12731284
_ => {}
12741285
}

source/rust_verify/src/external.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,7 @@ impl<'a, 'tcx> VisitMod<'a, 'tcx> {
384384
});
385385
}
386386
ItemKind::Const(_ident, _ty, _generics, _body_id) => {
387-
let path = def_id_to_vir_path(self.ctxt.tcx, &self.ctxt.verus_items, def_id);
388-
if path
389-
.segments
390-
.iter()
391-
.find(|s| s.starts_with("_DERIVE_builtin_Structural_FOR_"))
392-
.is_some()
393-
{
387+
if eattrs.structural_const_wrapper {
394388
self.state = VerifState::Verify;
395389
}
396390
}

source/rust_verify/src/rust_to_vir.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ fn check_item<'tcx>(
6767

6868
let mut handle_const_or_static = |body_id: &rustc_hir::BodyId| {
6969
let def_id = body_id.hir_id.owner.to_def_id();
70-
let path = def_id_to_vir_path(ctxt.tcx, &ctxt.verus_items, def_id);
7170
if vattrs.size_of_global {
7271
return Ok(()); // handled earlier
7372
}
@@ -150,8 +149,7 @@ fn check_item<'tcx>(
150149

151150
return Ok(());
152151
}
153-
if path.segments.iter().find(|s| s.starts_with("_DERIVE_builtin_Structural_FOR_")).is_some()
154-
{
152+
if vattrs.structural_const_wrapper {
155153
ctxt.erasure_info
156154
.borrow_mut()
157155
.ignored_functions

0 commit comments

Comments
 (0)