Skip to main content

two_pass_alias_guard

Function two_pass_alias_guard 

Source
pub(crate) fn two_pass_alias_guard(
    metadata: &[TokenStream],
    args: &[TokenStream],
    preparations: &[(usize, Preparation)],
) -> TokenStream
Expand description

The alias check of a wrapper or trait shim with preparable arguments (#1504), in two passes:

  1. assert_or_select checks metadata (every Either taken with both arms). A conflict that involves no top-level Either raises; one that does marks the Either argument instead.
  2. Each marked argument is prepared (its (index, preparation) in preparations): the conversion runs up to the point where it would build a native reference, which tells its arm. Its metadata becomes what that arm borrows, and assert_no_aliases checks again.

The bindings are declared before the check, Unprepared, for the arguments’ conversions to read. NativeBorrow::selects on each argument’s metadata, a constant except for a copied trait signature, gates its preparation; when no argument selects, the check is the one-pass assert_no_aliases of a wrapper without preparations, so a call that holds no top-level Either runs the same check as before after optimisation. Without a mark, the second pass doesn’t run.