conversion applied to a value already of the target type

ID

rust.maintainability.useless_conversion

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Redundancy

Language

Rust

Description

Reports a conversion whose input already has the target type: into() or T::from() between identical numeric types, a to_string/to_owned/to_vec applied to a value another such call has just produced, and into_iter() on something that is already an iterator.

Rationale

A conversion that converts nothing still reads as one, so the next person has to work out what the types were before concluding the line does nothing. It also hides the real shape of the data - the second to_string() says the value was borrowed when it was already owned - and for the owned forms it allocates and copies a buffer on every call for no result.

The following code illustrates the pattern detected by this rule:

fn widen(count: u32) -> u32 {
    // FLAGGED: conversion applied to a value already of the target type
    let same: u32 = count.into();
    same
}

Remediation

Delete the conversion and use the value directly. Where the redundancy came from a type that later changed, keep the call only if the target type is genuinely different, and prefer From/Into at the boundary rather than repeating it at each use site.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved