Skip to content

symcc: use the compiled API in the README example and deny doctest warnings - #2742

Merged
victornicolet merged 1 commit into
cedar-policy:mainfrom
lazarus-boop:fix/2537-symcc-example-compiled-api
Dec 3, 2026
Merged

victornicolet merged 1 commit into
cedar-policy:mainfrom
lazarus-boop:fix/2537-symcc-example-compiled-api

Conversation

@lazarus-boop

Copy link
Copy Markdown
Contributor

Description of changes

Fixes #2537.

The cedar-policy-symcc crate docs (the README, included with include_str!) showed an example built on the deprecated WellTypedPolicies, check_always_allows and check_always_allows_with_counterexample, so copying it gave deprecation warnings.

  • The example now builds a CompiledSchema once, compiles the policy set per request environment with CompiledPolicySet::compile, and calls check_always_allows_opt and check_always_allows_with_counterexample_opt, as suggested in the issue.
  • The README's list of supported checks now names the _opt functions and says they take a CompiledPolicy or CompiledPolicySet.
  • The result variable was named always_denies although it held the result of the always-allows check; it is now always_allows.

On the CI question in the issue: CI sets -D warnings through RUSTFLAGS, but rustdoc does not read RUSTFLAGS, so it never reaches doc tests. The deprecated example compiled and passed, and rustdoc only shows a doc test's warnings when the test fails. This PR adds #![doc(test(attr(deny(warnings), allow(unused))))] to the crate. Setting doc(test(attr(..))) drops rustdoc's default allow(unused) for doc tests, so it is kept explicitly; without it the two existing no_run examples in solver.rs and solver_pool.rs fail on unused variables.

Testing

cargo test --doc -p cedar-policy-symcc on stable 1.99.1, without CVC5 set:

Tree README example Other two doc tests
main compiles with 4 deprecation warnings (printed here only because the test then panics at LocalSolver::cvc5()) ok
this PR compiles under deny(warnings); panics at LocalSolver::cvc5() ok
this PR's lib.rs with main's README fails to compile: 4 use of deprecated errors ok

I don't have cvc5 1.3.1 on this machine, so I could not run the example to completion; CI installs cvc5 and runs it. cargo fmt -p cedar-policy-symcc --check is clean.

Not covered: the new guard checks the compiled example, not the README's prose list of functions. Separately, the *_asserts function docs in lib.rs still mention the non-_opt calls; I left those out to keep this change to the README example, and can send a follow-up if you'd like. The same goes for the compile docs (lib.rs:165, lib.rs:240 and two in symccopt/compiled_policies.rs), which say the CompiledSchema "should be created for the given schema and env". CompiledSchema::new takes only the schema, so the example builds it once and reuses it for every request environment.

Issue #, if available

#2537

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A change "invisible" to users (e.g., documentation)

I confirm that this PR (choose one, and delete the other options):

  • Does not update the CHANGELOG because my change does not significantly impact released code.

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar language specification.

…rnings

The crate-level example (the README, included as the crate docs) used
the deprecated `WellTypedPolicies`, `check_always_allows` and
`check_always_allows_with_counterexample`, so copying it gave
deprecation warnings. It now builds a `CompiledSchema` once and uses
`CompiledPolicySet::compile`, `check_always_allows_opt` and
`check_always_allows_with_counterexample_opt`. The list of supported
checks now names the `_opt` functions.

rustdoc does not read RUSTFLAGS, so the `-D warnings` that CI sets
there never reaches doc tests, and the deprecated example passed with
its warnings unseen. The crate now sets
`#![doc(test(attr(deny(warnings), allow(unused))))]`: doc tests fail on
warnings such as deprecation, while keeping rustdoc's default
`allow(unused)`, which setting `doc(test(attr(..)))` would otherwise drop.

Fixes cedar-policy#2537

Signed-off-by: lazarus-boop <319656483+lazarus-boop@users.noreply.github.com>

@john-h-kastner-aws john-h-kastner-aws left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks great

@victornicolet
victornicolet merged commit 2a060df into cedar-policy:main Dec 3, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update symcc example to CompiledPolicy variants instead of deprecated the WellTypedPolicy ones

3 participants