1
Fork 0

use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip)

This commit is contained in:
Matthias Krüger 2020-09-17 10:13:16 +02:00
parent 95386b656e
commit 012974da7a
8 changed files with 28 additions and 26 deletions

View file

@ -370,7 +370,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
let s = s.as_ref();
let old = old.as_ref();
if s.starts_with(old) { Some(new.as_ref().to_owned() + &s[old.len()..]) } else { None }
if let Some(stripped) = s.strip_prefix(old) {
Some(new.as_ref().to_owned() + stripped)
} else {
None
}
}
/// This function is used to determine potential "simple" improvements or users' errors and

View file

@ -589,10 +589,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
msg
},
if lstring.starts_with('&') {
if let Some(stripped) = lstring.strip_prefix('&') {
// let a = String::new();
// let _ = &a + "bar";
lstring[1..].to_string()
stripped.to_string()
} else {
format!("{}.to_owned()", lstring)
},
@ -617,10 +617,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
is_assign,
) {
(Ok(l), Ok(r), IsAssign::No) => {
let to_string = if l.starts_with('&') {
let to_string = if let Some(stripped) = l.strip_prefix('&') {
// let a = String::new(); let b = String::new();
// let _ = &a + b;
l[1..].to_string()
stripped.to_string()
} else {
format!("{}.to_owned()", l)
};

View file

@ -2341,8 +2341,8 @@ fn from_target_feature(
item.span(),
format!("`{}` is not valid for this target", feature),
);
if feature.starts_with('+') {
let valid = supported_target_features.contains_key(&feature[1..]);
if let Some(stripped) = feature.strip_prefix('+') {
let valid = supported_target_features.contains_key(stripped);
if valid {
err.help("consider removing the leading `+` in the feature name");
}