use strip_prefix over slicing (clippy::manual_strip)

This commit is contained in:
Matthias Krüger 2020-12-11 17:32:03 +01:00
parent 2225ee1b62
commit 5c8de1cf49
4 changed files with 23 additions and 23 deletions

View File

@ -854,8 +854,8 @@ fn generic_simd_intrinsic(
));
}
if name_str.starts_with("simd_shuffle") {
let n: u64 = name_str["simd_shuffle".len()..].parse().unwrap_or_else(|_| {
if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
let n: u64 = stripped.parse().unwrap_or_else(|_| {
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
});

View File

@ -201,10 +201,10 @@ fn main() {
cmd.args(&components);
for lib in output(&mut cmd).split_whitespace() {
let name = if lib.starts_with("-l") {
&lib[2..]
} else if lib.starts_with('-') {
&lib[1..]
let name = if let Some(stripped) = lib.strip_prefix("-l") {
stripped
} else if let Some(stripped) = lib.strip_prefix('-') {
stripped
} else if Path::new(lib).exists() {
// On MSVC llvm-config will print the full name to libraries, but
// we're only interested in the name part
@ -241,17 +241,17 @@ fn main() {
cmd.arg(llvm_link_arg).arg("--ldflags");
for lib in output(&mut cmd).split_whitespace() {
if is_crossed {
if lib.starts_with("-LIBPATH:") {
println!("cargo:rustc-link-search=native={}", lib[9..].replace(&host, &target));
} else if lib.starts_with("-L") {
println!("cargo:rustc-link-search=native={}", lib[2..].replace(&host, &target));
if let Some(stripped) = lib.strip_prefix("-LIBPATH:") {
println!("cargo:rustc-link-search=native={}", stripped.replace(&host, &target));
} else if let Some(stripped) = lib.strip_prefix("-L") {
println!("cargo:rustc-link-search=native={}", stripped.replace(&host, &target));
}
} else if lib.starts_with("-LIBPATH:") {
println!("cargo:rustc-link-search=native={}", &lib[9..]);
} else if lib.starts_with("-l") {
println!("cargo:rustc-link-lib={}", &lib[2..]);
} else if lib.starts_with("-L") {
println!("cargo:rustc-link-search=native={}", &lib[2..]);
} else if let Some(stripped) = lib.strip_prefix("-LIBPATH:") {
println!("cargo:rustc-link-search=native={}", stripped);
} else if let Some(stripped) = lib.strip_prefix("-l") {
println!("cargo:rustc-link-lib={}", stripped);
} else if let Some(stripped) = lib.strip_prefix("-L") {
println!("cargo:rustc-link-search=native={}", stripped);
}
}
@ -262,10 +262,10 @@ fn main() {
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
if let Some(s) = llvm_linker_flags {
for lib in s.into_string().unwrap().split_whitespace() {
if lib.starts_with("-l") {
println!("cargo:rustc-link-lib={}", &lib[2..]);
} else if lib.starts_with("-L") {
println!("cargo:rustc-link-search=native={}", &lib[2..]);
if let Some(stripped) = lib.strip_prefix("-l") {
println!("cargo:rustc-link-lib={}", stripped);
} else if let Some(stripped) = lib.strip_prefix("-L") {
println!("cargo:rustc-link-search=native={}", stripped);
}
}
}

View File

@ -1186,7 +1186,7 @@ pub fn sanitize_sh(path: &Path) -> String {
return change_drive(unc_to_lfs(&path)).unwrap_or(path);
fn unc_to_lfs(s: &str) -> &str {
if s.starts_with("//?/") { &s[4..] } else { s }
s.strip_prefix("//?/").unwrap_or(s)
}
fn change_drive(s: &str) -> Option<String> {

View File

@ -139,9 +139,9 @@ fn map_line(s: &str) -> Line<'_> {
let trimmed = s.trim();
if trimmed.starts_with("##") {
Line::Shown(Cow::Owned(s.replacen("##", "#", 1)))
} else if trimmed.starts_with("# ") {
} else if let Some(stripped) = trimmed.strip_prefix("# ") {
// # text
Line::Hidden(&trimmed[2..])
Line::Hidden(&stripped)
} else if trimmed == "#" {
// We cannot handle '#text' because it could be #[attr].
Line::Hidden("")