rspec/rules/S7454/rust/rule.adoc

27 lines
924 B
Plaintext
Raw Normal View History

2025-03-26 10:27:44 +00:00
== Why is this an issue?
2025-03-26 11:36:59 +01:00
Mistyped suffixes in numeric literals can lead to incorrect interpretations of the values intended by the developer. This is typically seen as a typo which could impact the functionality of the code. The rule does not however address integers that would not fit within the assumed type or specific valid groupings such as `_127` in decimal and octal numbers.
2025-03-26 10:27:44 +00:00
=== Code examples
==== Noncompliant code example
[source,rust,diff-id=1,diff-type=noncompliant]
----
2025-03-26 11:36:59 +01:00
let x = 2_32; // Noncompliant: Mistyped literal suffix
let y = 250_8; // Noncompliant: Mistyped literal suffix
2025-03-26 10:27:44 +00:00
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
2025-03-26 11:36:59 +01:00
let x = 2_i32; // Compliant: Correct literal suffix
let y = 250_u8; // Compliant: Correct literal suffix
2025-03-26 10:27:44 +00:00
----
2025-03-26 11:36:59 +01:00
== Resources
=== Documentation
2025-03-26 10:27:44 +00:00
2025-03-26 11:36:59 +01:00
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes