autofix remaining perf findings

This commit is contained in:
Matthias Krüger 2024-01-07 01:20:20 +01:00
parent 196650dfaf
commit 3fb2cd2002
7 changed files with 12 additions and 11 deletions

View file

@ -2070,8 +2070,8 @@ pub fn mir_body_for_closure_query(
prev_projs
.lookup(&store)
.iter()
.cloned()
.skip(it.0.place.projections.len()),
.skip(it.0.place.projections.len())
.cloned(),
);
p.projection = store.intern(next_projs.into());
}

View file

@ -1854,7 +1854,7 @@ impl DefWithBody {
let local = Local { parent: self.into(), binding_id };
match (need_mut, local.is_mut(db)) {
(mir::MutabilityReason::Unused, _) => {
let should_ignore = matches!(body[binding_id].name.as_str(), Some(it) if it.starts_with("_"));
let should_ignore = matches!(body[binding_id].name.as_str(), Some(it) if it.starts_with('_'));
if !should_ignore {
acc.push(UnusedVariable { local }.into())
}
@ -1879,7 +1879,7 @@ impl DefWithBody {
}
(mir::MutabilityReason::Not, true) => {
if !infer.mutated_bindings_in_closure.contains(&binding_id) {
let should_ignore = matches!(body[binding_id].name.as_str(), Some(it) if it.starts_with("_"));
let should_ignore = matches!(body[binding_id].name.as_str(), Some(it) if it.starts_with('_'));
if !should_ignore {
acc.push(UnusedMut { local }.into())
}

View file

@ -49,8 +49,8 @@ pub(crate) fn convert_nested_function_to_closure(
target,
|edit| {
let params = &param_list.syntax().text().to_string();
let params = params.strip_prefix("(").unwrap_or(params);
let params = params.strip_suffix(")").unwrap_or(params);
let params = params.strip_prefix('(').unwrap_or(params);
let params = params.strip_suffix(')').unwrap_or(params);
let mut body = body.to_string();
if !has_semicolon(&function) {

View file

@ -112,7 +112,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let insert_place = edit.make_syntax_mut(place);
// Adjust ws to insert depending on if this is all inline or on separate lines
let trailing_ws = if prev_ws.is_some_and(|it| it.text().starts_with("\n")) {
let trailing_ws = if prev_ws.is_some_and(|it| it.text().starts_with('\n')) {
format!("\n{indent_to}")
} else {
format!(" ")

View file

@ -43,7 +43,7 @@ pub(crate) fn remove_parentheses(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let prev_token = parens.syntax().first_token().and_then(|it| it.prev_token());
let need_to_add_ws = match prev_token {
Some(it) => {
let tokens = vec![T![&], T![!], T!['('], T!['['], T!['{']];
let tokens = [T![&], T![!], T!['('], T!['['], T!['{']];
it.kind() != SyntaxKind::WHITESPACE && !tokens.contains(&it.kind())
}
None => false,

View file

@ -42,8 +42,9 @@ fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) {
super::diagnostics(&db, &conf, &AssistResolveStrategy::All, file_position.file_id)
.pop()
.expect("no diagnostics");
let fix =
&diagnostic.fixes.expect(&format!("{:?} diagnostic misses fixes", diagnostic.code))[nth];
let fix = &diagnostic
.fixes
.unwrap_or_else(|| panic!("{:?} diagnostic misses fixes", diagnostic.code))[nth];
let actual = {
let source_change = fix.source_change.as_ref().unwrap();
let file_id = *source_change.source_file_edits.keys().next().unwrap();

View file

@ -1277,7 +1277,7 @@ fn add_target_crate_root(
inject_cargo_env(pkg, &mut env);
if let Ok(cname) = String::from_str(cargo_name) {
// CARGO_CRATE_NAME is the name of the Cargo target with - converted to _, such as the name of the library, binary, example, integration test, or benchmark.
env.set("CARGO_CRATE_NAME", cname.replace("-", "_"));
env.set("CARGO_CRATE_NAME", cname.replace('-', "_"));
}
if let Some(envs) = build_data.map(|it| &it.envs) {