Skip to content

borrow_as_ptr is triggered on generated code #17197

@nazar-pc

Description

@nazar-pc

Summary

There is some tricky low-level generated code that is written to compile on older Rust versions and can't use &raw syntax, so this lint should not be triggered if implementation is annotated with #[automatically_derived].

Lint Name

borrow_as_ptr

Reproducer

I triggered this with derive_destructure2 crate (obscure, but fairly popular crate):

#[derive(Debug, destructure)]
pub struct MethodMetadataDecoder<'a, 'metadata> {
    metadata: &'a mut &'metadata [u8],
    container_kind: MethodsContainerKind,
}

https://github.com/nazar-pc/abundance/blob/184e6807a3138939f89a5ba18b550957421eacc1/crates/contracts/core/ab-contracts-common/src/metadata/decode.rs#L358-L362

warning: implicit borrow as raw pointer
   --> crates/contracts/core/ab-contracts-common/src/metadata/decode.rs:360:5
    |
360 |     metadata: &'a mut &'metadata [u8],
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr
    = note: `-W clippy::borrow-as-ptr` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::borrow_as_ptr)]`
help: use a raw pointer instead
    |
360 |     &raw const metadata: &'a mut &'metadata [u8],
    |     ++++++++++

warning: implicit borrow as raw pointer
   --> crates/contracts/core/ab-contracts-common/src/metadata/decode.rs:361:5
    |
361 |     container_kind: MethodsContainerKind,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr
help: use a raw pointer instead
    |
361 |     &raw const container_kind: MethodsContainerKind,
    |     ++++++++++

I sent a PR to add #[automatically_derived] attribute, which if accepted will benefit from resolving this issue: NobodyXu/derive_destructure2#6

Version

rustc 1.97.0-nightly (20de910db 2026-05-02)
binary: rustc
commit-hash: 20de910db49d3476ccf49ea79a4b22e2b5dface0
commit-date: 2026-05-02
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions