Skip to main content

Policy

Struct Policy 

Source
pub struct Policy {
    pub denied_paths: BTreeSet<String>,
    pub denied_prefixes: BTreeSet<String>,
    pub deny_unsafe: bool,
}
Expand description

Purity policy — exact path deny, namespace prefix deny, and an unsafe-block ban. The default deny_compute_impurity policy covers the 4-rule deny scope (Clock + RNG + I/O + FFI).

§Known limitation: single-ident suffix-match false-positive

The visitor matches a single-segment path (e.g. thread_rng()) by scanning the deny-list for any entry ending in ::<ident>. This catches the common use-import escape (use rand::thread_rng; thread_rng()) but also collides with user-defined local fn of the same name (e.g. a shell crate defining fn random() -> u32 would have its calls to random() falsely flagged as rand::random).

Mitigation:

  • Use full-qualified path in shell code (my_crate::random() instead of random()).
  • Or apply Policy::empty() and rely on a downstream lint.
  • Long-term — receiver-type aware HIR resolution lands when the crate migrates to the dylint_linting cdylib (documented in the crate-level rustdoc).

Fields§

§denied_paths: BTreeSet<String>

Fully-qualified path strings that must not appear as call targets or constant accesses. Match heuristics:

  • exact full-path equality (e.g. std::time::Instant::now vs the path string of the visited ExprPath),
  • use rand::thread_rng; thread_rng() style — the bare ident thread_rng matches the entry rand::thread_rng because the entry’s last segment equals the visited path’s last segment AND the visited path is a single ident.
§denied_prefixes: BTreeSet<String>

Namespace prefixes that ban every prefix::* call site in expression position. Use for whole-module bans (std::fs, std::net, libc, …). A bare visited path P matches the prefix P exactly OR P::*. Type-position paths are skipped because the visitor only overrides visit_expr_path.

§deny_unsafe: bool

When true, every unsafe { ... } block inside the scanned function triggers a violation. Closes the FFI escape route (raw extern "C" calls always require unsafe) plus transmute / raw-pointer dereferences.

Implementations§

Source§

impl Policy

Source

pub fn empty() -> Self

Empty policy — accepts every function. Useful for tests.

Source

pub fn deny_compute_impurity() -> Self

Default deny list (4 categories): Clock + RNG + I/O + FFI plus unsafe block ban. Future rounds may add Threading + Sync/atomic

  • replay hazards — non-breaking additions.

Trait Implementations§

Source§

impl Clone for Policy

Source§

fn clone(&self) -> Policy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Policy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Policy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.