Skip to content

Commit

Permalink
fix rustc attribute issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhance committed Feb 25, 2025
1 parent 1ad6468 commit 0ca21a4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
21 changes: 19 additions & 2 deletions source/rust_verify/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,21 @@ pub(crate) fn get_external_attrs(
pub(crate) fn get_verifier_attrs(
attrs: &[Attribute],
diagnostics: Option<&mut Vec<VirErrAs>>,
) -> Result<VerifierAttrs, VirErr> {
get_verifier_attrs_maybe_check(attrs, diagnostics, true)
}

pub(crate) fn get_verifier_attrs_no_check(
attrs: &[Attribute],
diagnostics: Option<&mut Vec<VirErrAs>>,
) -> Result<VerifierAttrs, VirErr> {
get_verifier_attrs_maybe_check(attrs, diagnostics, false)
}

pub(crate) fn get_verifier_attrs_maybe_check(
attrs: &[Attribute],
diagnostics: Option<&mut Vec<VirErrAs>>,
do_check: bool,
) -> Result<VerifierAttrs, VirErr> {
let mut vs = VerifierAttrs {
verus_macro: false,
Expand Down Expand Up @@ -1096,8 +1111,10 @@ pub(crate) fn get_verifier_attrs(
_ => {}
}
}
if let Some((rustc_attr, span)) = unsupported_rustc_attr {
return err_span(span, format!("The attribute `{rustc_attr:}` is not supported"));
if do_check {
if let Some((rustc_attr, span)) = unsupported_rustc_attr {
return err_span(span, format!("The attribute `{rustc_attr:}` is not supported"));
}
}
Ok(vs)
}
Expand Down
10 changes: 10 additions & 0 deletions source/rust_verify/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ impl<'tcx> ContextX<'tcx> {
crate::attributes::get_verifier_attrs(attrs, Some(&mut *self.diagnostics.borrow_mut()))
}

pub(crate) fn get_verifier_attrs_no_check(
&self,
attrs: &[Attribute],
) -> Result<crate::attributes::VerifierAttrs, vir::ast::VirErr> {
crate::attributes::get_verifier_attrs_no_check(
attrs,
Some(&mut *self.diagnostics.borrow_mut()),
)
}

pub(crate) fn get_external_attrs(
&self,
attrs: &[Attribute],
Expand Down
2 changes: 1 addition & 1 deletion source/rust_verify/src/rust_to_vir_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) fn process_const_early<'tcx>(
item: &Item<'tcx>,
) -> Result<(), VirErr> {
let attrs = ctxt.tcx.hir().attrs(item.hir_id());
let vattrs = ctxt.get_verifier_attrs(attrs)?;
let vattrs = ctxt.get_verifier_attrs_no_check(attrs)?;
if vattrs.size_of_global {
let err = crate::util::err_span(item.span, "invalid global size_of");
let ItemKind::Const(_ty, generics, body_id) = item.kind else {
Expand Down

0 comments on commit 0ca21a4

Please sign in to comment.