You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lint for if condition (for multiple conditions that start by !) and path separator
Advantage
No response
Drawbacks
No response
Example
use std::{io::*, path::*};fnmain(){letmut s = String::new();stdin().read_line(&mut s).unwrap();if !s.ends_with('/') || !s.ends_with('\\'){panic!("Path must end by / or \\")}let p = Path::new(&s);}
There's a misunderstanding in the if condition, someone may read if !s.ends_with('/') || !s.ends_with('\\') as "if not this separator or not that separator", and there's a constant MAIN_SEPARATOR in std::path, the better code may be:
use std::{io::*, path::*};fnmain(){letmut s = String::new();stdin().read_line(&mut s).unwrap();if !s.ends_with(MAIN_SEPARATOR){panic!("Path must end by {MAIN_SEPARATOR}")}let p = Path::new(&s);}
The text was updated successfully, but these errors were encountered:
What it does
lint for if condition (for multiple conditions that start by !) and path separator
Advantage
No response
Drawbacks
No response
Example
There's a misunderstanding in the if condition, someone may read
if !s.ends_with('/') || !s.ends_with('\\')
as "if not this separator or not that separator", and there's a constantMAIN_SEPARATOR
instd::path
, the better code may be:The text was updated successfully, but these errors were encountered: