Skip to content

False positives for the new non_local_definitions lint #121746

Closed
@weiznich

Description

@weiznich

Code

I tried this code: https://github.com/diesel-rs/diesel/blob/33ddddcd44d64368c4e8edb630e3f281e4a1a77d/diesel/src/sqlite/connection/mod.rs#L931

This is reproducible with cargo +nightly check -p diesel -F sqlite --all-targets

I expected to see this happen: No warning or at least no warning that tells me that this is an issue with the derive itself. (It's just that the derive is used in a function for scoping reasons).

Instead, this happened: I see the following warning:

warning: non-local `impl` definition, they should be avoided as they go against expectation
   --> diesel/src/sqlite/connection/mod.rs:928:25
    |
928 |         #[derive(Debug, crate::expression::AsExpression)]
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: move this `impl` block outside the of the current constant `_` and up 2 bodies
    = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block
    = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
    = note: the derive macro `crate::expression::AsExpression` may come from an old version of the `diesel_derives` crate, try updating your dependency with `cargo update -p diesel_derives`
    = note: `#[warn(non_local_definitions)]` on by default
    = note: this warning originates in the derive macro `crate::expression::AsExpression` (in Nightly builds, run with -Z macro-backtrace for more info)

Version it worked on

It most recently worked on: 1.77.0-beta.5

Version with regression

rustc --version --verbose:

rustc 1.78.0-nightly (fc3800f65 2024-02-26)
binary: rustc
commit-hash: fc3800f65777a365b5125706d60f97e4d0675efe
commit-date: 2024-02-26
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

@rustbot modify labels: +regression-from-beta-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.P-mediumMedium priorityregression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions