Merge #9325
9325: Minor: clippy perf fixes r=matklad a=lnicola Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
7eb843b218
@ -640,8 +640,7 @@ pub trait HasResolver: Copy {
|
||||
impl HasResolver for ModuleId {
|
||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
||||
let mut def_map = self.def_map(db);
|
||||
let mut modules = Vec::new();
|
||||
modules.push((def_map.clone(), self.local_id));
|
||||
let mut modules = vec![(def_map.clone(), self.local_id)];
|
||||
while let Some(parent) = def_map.parent() {
|
||||
def_map = parent.def_map(db);
|
||||
modules.push((def_map.clone(), parent.local_id));
|
||||
|
@ -202,7 +202,7 @@ fn assert_expand(
|
||||
|
||||
let arg_tts = args.into_iter().flat_map(|arg| {
|
||||
quote! { &(#arg), }
|
||||
}.token_trees).collect::<Vec<_>>();
|
||||
}.token_trees);
|
||||
|
||||
let expanded = quote! {
|
||||
{ { (##arg_tts); } }
|
||||
@ -254,7 +254,7 @@ fn format_args_expand(
|
||||
let _format_string = args.remove(0);
|
||||
let arg_tts = args.into_iter().flat_map(|arg| {
|
||||
quote! { std::fmt::ArgumentV1::new(&(#arg), std::fmt::Display::fmt), }
|
||||
}.token_trees).collect::<Vec<_>>();
|
||||
}.token_trees);
|
||||
let expanded = quote! {
|
||||
std::fmt::Arguments::new_v1(&[], &[##arg_tts])
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ impl BodyValidationDiagnostic {
|
||||
pub fn collect(db: &dyn HirDatabase, owner: DefWithBodyId) -> Vec<BodyValidationDiagnostic> {
|
||||
let _p = profile::span("BodyValidationDiagnostic::collect");
|
||||
let infer = db.infer(owner);
|
||||
let mut validator = ExprValidator::new(owner, infer.clone());
|
||||
let mut validator = ExprValidator::new(owner, infer);
|
||||
validator.validate_body(db);
|
||||
validator.diagnostics
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
|
||||
Expr::Path(p) => {
|
||||
// FIXME this could be more efficient...
|
||||
let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr);
|
||||
self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(self.err_ty())
|
||||
self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or_else(|| self.err_ty())
|
||||
}
|
||||
Expr::Continue { .. } => TyKind::Never.intern(&Interner),
|
||||
Expr::Break { expr, label } => {
|
||||
@ -511,7 +511,7 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.unwrap_or(self.err_ty());
|
||||
.unwrap_or_else(|| self.err_ty());
|
||||
let ty = self.insert_type_vars(ty);
|
||||
self.normalize_associated_types_in(ty)
|
||||
}
|
||||
@ -818,8 +818,10 @@ fn infer_block(
|
||||
for stmt in statements {
|
||||
match stmt {
|
||||
Statement::Let { pat, type_ref, initializer } => {
|
||||
let decl_ty =
|
||||
type_ref.as_ref().map(|tr| self.make_ty(tr)).unwrap_or(self.err_ty());
|
||||
let decl_ty = type_ref
|
||||
.as_ref()
|
||||
.map(|tr| self.make_ty(tr))
|
||||
.unwrap_or_else(|| self.err_ty());
|
||||
|
||||
// Always use the declared type when specified
|
||||
let mut ty = decl_ty.clone();
|
||||
|
@ -192,7 +192,7 @@ pub(super) fn infer_pat(
|
||||
Pat::Path(path) => {
|
||||
// FIXME use correct resolver for the surrounding expression
|
||||
let resolver = self.resolver.clone();
|
||||
self.infer_path(&resolver, path, pat.into()).unwrap_or(self.err_ty())
|
||||
self.infer_path(&resolver, path, pat.into()).unwrap_or_else(|| self.err_ty())
|
||||
}
|
||||
Pat::Bind { mode, name: _, subpat } => {
|
||||
let mode = if mode == &BindingAnnotation::Unannotated {
|
||||
|
@ -562,7 +562,7 @@ fn select_associated_type(&self, res: Option<TypeNs>, segment: PathSegment<'_>)
|
||||
},
|
||||
);
|
||||
|
||||
ty.unwrap_or(TyKind::Error.intern(&Interner))
|
||||
ty.unwrap_or_else(|| TyKind::Error.intern(&Interner))
|
||||
} else {
|
||||
TyKind::Error.intern(&Interner)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ pub(crate) fn goto_type_definition(
|
||||
let token: SyntaxToken = pick_best(file.syntax().token_at_offset(position.offset))?;
|
||||
let token: SyntaxToken = sema.descend_into_macros(token);
|
||||
|
||||
let (ty, node) = sema.token_ancestors_with_macros(token.clone()).find_map(|node| {
|
||||
let (ty, node) = sema.token_ancestors_with_macros(token).find_map(|node| {
|
||||
let ty = match_ast! {
|
||||
match node {
|
||||
ast::Expr(it) => sema.type_of_expr(&it)?,
|
||||
|
@ -35,14 +35,14 @@ pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
.prev_sibling_or_token()
|
||||
.and_then(whitespace_start)
|
||||
.map(|start| TextRange::new(start, macro_call.syntax().text_range().end()))
|
||||
.unwrap_or(macro_call.syntax().text_range())
|
||||
.unwrap_or_else(|| macro_call.syntax().text_range())
|
||||
},
|
||||
ast::ExprStmt(it) => {
|
||||
let start = it
|
||||
.syntax()
|
||||
.prev_sibling_or_token()
|
||||
.and_then(whitespace_start)
|
||||
.unwrap_or(it.syntax().text_range().start());
|
||||
.unwrap_or_else(|| it.syntax().text_range().start());
|
||||
let end = it.syntax().text_range().end();
|
||||
|
||||
TextRange::new(start, end)
|
||||
|
@ -28,23 +28,23 @@ macro_rules! err {
|
||||
|
||||
let ver_str = read_version(dylib_path)?;
|
||||
let mut items = ver_str.split_whitespace();
|
||||
let tag = items.next().ok_or(err!("version format error"))?;
|
||||
let tag = items.next().ok_or_else(|| err!("version format error"))?;
|
||||
if tag != "rustc" {
|
||||
return Err(err!("version format error (No rustc tag)"));
|
||||
}
|
||||
|
||||
let version_part = items.next().ok_or(err!("no version string"))?;
|
||||
let version_part = items.next().ok_or_else(|| err!("no version string"))?;
|
||||
let mut version_parts = version_part.split('-');
|
||||
let version = version_parts.next().ok_or(err!("no version"))?;
|
||||
let version = version_parts.next().ok_or_else(|| err!("no version"))?;
|
||||
let channel = version_parts.next().unwrap_or_default().to_string();
|
||||
|
||||
let commit = items.next().ok_or(err!("no commit info"))?;
|
||||
let commit = items.next().ok_or_else(|| err!("no commit info"))?;
|
||||
// remove (
|
||||
if commit.len() == 0 {
|
||||
return Err(err!("commit format error"));
|
||||
}
|
||||
let commit = commit[1..].to_string();
|
||||
let date = items.next().ok_or(err!("no date info"))?;
|
||||
let date = items.next().ok_or_else(|| err!("no date info"))?;
|
||||
// remove )
|
||||
if date.len() == 0 {
|
||||
return Err(err!("date format error"));
|
||||
|
@ -187,7 +187,7 @@ fn collect(
|
||||
let mut deserializer = serde_json::Deserializer::from_str(line);
|
||||
deserializer.disable_recursion_limit();
|
||||
let message = Message::deserialize(&mut deserializer)
|
||||
.unwrap_or(Message::TextLine(line.to_string()));
|
||||
.unwrap_or_else(|_| Message::TextLine(line.to_string()));
|
||||
|
||||
match message {
|
||||
Message::BuildScriptExecuted(BuildScript {
|
||||
@ -229,7 +229,7 @@ fn collect(
|
||||
Message::CompilerArtifact(message) => {
|
||||
progress(format!("metadata {}", message.target.name));
|
||||
|
||||
if message.target.kind.contains(&"proc-macro".to_string()) {
|
||||
if message.target.kind.iter().any(|k| k == "proc-macro") {
|
||||
let package_id = message.package_id;
|
||||
// Skip rmeta file
|
||||
if let Some(filename) =
|
||||
|
@ -131,7 +131,7 @@ pub fn parse(ra_fixture: &str) -> (Option<MiniCore>, Vec<Fixture>) {
|
||||
res.push(meta)
|
||||
} else {
|
||||
if line.starts_with("// ")
|
||||
&& line.contains(":")
|
||||
&& line.contains(':')
|
||||
&& !line.contains("::")
|
||||
&& line.chars().all(|it| !it.is_uppercase())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user