For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/rust-code-quality/almost-complete-range.md. A documentation index is available at /llms.txt.

Exclusive char or byte range is missing its last character

This product is not supported for your selected Datadog site. ().

Metadata

ID: rust-code-quality/almost-complete-range

Language: Rust

Severity: Error

Category: Error Prone

CWE: 193

Description

A range like 'a'..'z' excludes the last character and is almost certainly a typo for the inclusive range 'a'..='z'. The same applies to 'A'..'Z' and '0'..'9', as well as their byte literal equivalents (b'a'..b'z', etc.)

Non-Compliant Code Examples

fn is_lowercase(c: char) -> bool {
  ('a'..'z').contains(&c)
}

fn is_digit_byte(b: u8) -> bool {
  (b'0'..b'9').contains(&b)
}

Compliant Code Examples

fn is_lowercase(c: char) -> bool {
  ('a'..='z').contains(&c)  
}

fn is_digit_byte(b: u8) -> bool {
  (b'0'..='9').contains(&b) 
}

fn beginning_to_f(c: char) -> bool {
  ('a'..'f').contains(&c)
}  
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security