Skip to content

as_conversions triggers on derived code #9657

Closed
@RReverser

Description

@RReverser

Summary

I like using as_conversions as a catch-all guard to stop myself from reaching for it in my own code when better solutions are available. However, it triggers on the generated derive code too, e.g. when using serde-repr.

Worse, it can't even be disabled by putting #[allow(clippy::as_conversions)] on the offending type, as it doesn't propagate to the derive-generated code, so the only option is to opt-out at the module level.

Lint Name

as_conversions

Reproducer

I tried this code:

#![warn(clippy::as_conversions)]

use serde_repr::{Deserialize_repr, Serialize_repr};

#[derive(Serialize_repr, Deserialize_repr)]
#[repr(i32)]
pub enum State {
    Error = -1,
    Idle = 0,
    Waiting = 1,
    Done = 2,
}

I saw this happen:

using a potentially dangerous silent `as` conversion
consider using a safe wrapper for this conversion
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#as_conversions

I expected to see this happen:

(no warning, as the as conversion is used internally by an external crate)

Version

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-pc-windows-msvc
release: 1.64.0
LLVM version: 14.0.6

Additional Labels

@rustbot label +T-macros

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-macrosType: Issues with macros and macro expansion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions