Skip to main content

## Delegate

# Trait Delegate

Source

    pub trait Delegate<'tcx> {
        // Required methods
        fn consume(
            &mut self,
            place_with_id: &PlaceWithHirId<'tcx>,
            diag_expr_id: HirId,
        );
        fn use_cloned(
            &mut self,
            place_with_id: &PlaceWithHirId<'tcx>,
            diag_expr_id: HirId,
        );
        fn borrow(
            &mut self,
            place_with_id: &PlaceWithHirId<'tcx>,
            diag_expr_id: HirId,
            bk: BorrowKind,
        );
        fn mutate(
            &mut self,
            assignee_place: &PlaceWithHirId<'tcx>,
            diag_expr_id: HirId,
        );
        fn fake_read(
            &mut self,
            place_with_id: &PlaceWithHirId<'tcx>,
            cause: FakeReadCause,
            diag_expr_id: HirId,
        );

        // Provided methods
        fn copy(
            &mut self,
            place_with_id: &PlaceWithHirId<'tcx>,
            diag_expr_id: HirId,
        ) { ... }
        fn bind(
            &mut self,
            binding_place: &PlaceWithHirId<'tcx>,
            diag_expr_id: HirId,
        ) { ... }
    }

Expand description

This trait defines the callbacks you can expect to receive when employing the ExprUseVisitor.

## Required Methods§

Source

#### fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId)

The value found at `place` is moved, depending on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`.

If the value is `Copy`, `copy` is called instead, which by default falls back to `borrow`.

The parameter `diag_expr_id` indicates the HIR id that ought to be used for diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic id will be the id of the expression `expr` but the place itself will have the id of the binding in the pattern `pat`.

Source

#### fn use_cloned( &mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, )

The value found at `place` is used, depending on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`.

Use of a `Copy` type in a ByUse context is considered a use by `ImmBorrow` and `borrow` is called instead. This is because a shared borrow is the “minimum access” that would be needed to perform a copy.

The parameter `diag_expr_id` indicates the HIR id that ought to be used for diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic id will be the id of the expression `expr` but the place itself will have the id of the binding in the pattern `pat`.

Source

#### fn borrow( &mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: BorrowKind, )

The value found at `place` is being borrowed with kind `bk`. `diag_expr_id` is the id used for diagnostics (see `consume` for more details).

Source

#### fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId)

The path at `assignee_place` is being assigned to. `diag_expr_id` is the id used for diagnostics (see `consume` for more details).

Source

#### fn fake_read( &mut self, place_with_id: &PlaceWithHirId<'tcx>, cause: FakeReadCause, diag_expr_id: HirId, )

The `place` should be a fake read because of specified `cause`.

## Provided Methods§

Source

#### fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId)

The value found at `place` is being copied. `diag_expr_id` is the id used for diagnostics (see `consume` for more details).

If an implementation is not provided, use of a `Copy` type in a ByValue context is instead considered a use by `ImmBorrow` and `borrow` is called instead. This is because a shared borrow is the “minimum access” that would be needed to perform a copy.

Source

#### fn bind(&mut self, binding_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId)

The path at `binding_place` is a binding that is being initialized.

This covers cases such as `let x = 42;`

## Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementations on Foreign Types§

Source§

### impl<'tcx, D: Delegate<'tcx>> Delegate<'tcx> for &mut D

Source§

#### fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId)

Source§

#### fn use_cloned( &mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, )

Source§

#### fn borrow( &mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: BorrowKind, )

Source§

#### fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId)

Source§

#### fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId)

Source§

#### fn bind(&mut self, binding_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId)

Source§

#### fn fake_read( &mut self, place_with_id: &PlaceWithHirId<'tcx>, cause: FakeReadCause, diag_expr_id: HirId, )

## Implementors§

Source§

### impl<'a, 'tcx> Delegate<'tcx> for InferBorrowKind<'a, 'tcx>

Source§

### impl<'tcx> Delegate<'tcx> for ExprPlaceDelegate