mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Some clippy fixes for 1.36
This commit is contained in:
parent
c6a6e43372
commit
4ad9e986ad
31 changed files with 62 additions and 70 deletions
|
@ -74,7 +74,7 @@ pub(crate) fn documentation_query(
|
|||
DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.ast),
|
||||
DocDef::StructField(it) => match it.source(db).ast {
|
||||
FieldSource::Named(named) => docs_from_ast(&*named),
|
||||
FieldSource::Pos(..) => return None,
|
||||
FieldSource::Pos(..) => None,
|
||||
},
|
||||
DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),
|
||||
|
|
|
@ -150,7 +150,7 @@ impl BodySourceMap {
|
|||
}
|
||||
|
||||
pub(crate) fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::NamedField> {
|
||||
self.field_map[&(expr, field)].clone()
|
||||
self.field_map[&(expr, field)]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -471,15 +471,15 @@ impl Pat {
|
|||
match self {
|
||||
Pat::Range { .. } | Pat::Lit(..) | Pat::Path(..) | Pat::Wild | Pat::Missing => {}
|
||||
Pat::Bind { subpat, .. } => {
|
||||
subpat.iter().map(|pat| *pat).for_each(f);
|
||||
subpat.iter().copied().for_each(f);
|
||||
}
|
||||
Pat::Tuple(args) | Pat::TupleStruct { args, .. } => {
|
||||
args.iter().map(|pat| *pat).for_each(f);
|
||||
args.iter().copied().for_each(f);
|
||||
}
|
||||
Pat::Ref { pat, .. } => f(*pat),
|
||||
Pat::Slice { prefix, rest, suffix } => {
|
||||
let total_iter = prefix.iter().chain(rest.iter()).chain(suffix.iter());
|
||||
total_iter.map(|pat| *pat).for_each(f);
|
||||
total_iter.copied().for_each(f);
|
||||
}
|
||||
Pat::Struct { args, .. } => {
|
||||
args.iter().map(|f| f.pat).for_each(f);
|
||||
|
|
|
@ -72,7 +72,7 @@ impl ExprScopes {
|
|||
}
|
||||
|
||||
pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
|
||||
self.scope_by_expr.get(&expr).map(|&scope| scope)
|
||||
self.scope_by_expr.get(&expr).copied()
|
||||
}
|
||||
|
||||
pub(crate) fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> {
|
||||
|
|
|
@ -122,7 +122,7 @@ impl LangItems {
|
|||
module: Module,
|
||||
) {
|
||||
if let Some(module_lang_items) = db.module_lang_items(module) {
|
||||
self.items.extend(module_lang_items.items.iter().map(|(k, v)| (k.clone(), v.clone())))
|
||||
self.items.extend(module_lang_items.items.iter().map(|(k, v)| (k.clone(), *v)))
|
||||
}
|
||||
|
||||
// Look for lang items in the children
|
||||
|
@ -142,7 +142,7 @@ impl LangItems {
|
|||
{
|
||||
let node = item.source(db).ast;
|
||||
if let Some(lang_item_name) = lang_item_name(&*node) {
|
||||
self.items.entry(lang_item_name).or_insert(constructor(item));
|
||||
self.items.entry(lang_item_name).or_insert_with(|| constructor(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ impl MockDatabase {
|
|||
|
||||
pub fn diagnostics(&self) -> String {
|
||||
let mut buf = String::from("\n");
|
||||
let mut files: Vec<FileId> = self.files.values().map(|&it| it).collect();
|
||||
let mut files: Vec<FileId> = self.files.values().copied().collect();
|
||||
files.sort();
|
||||
for file in files {
|
||||
let module = crate::source_binder::module_from_file_id(self, file).unwrap();
|
||||
|
|
|
@ -227,10 +227,8 @@ where
|
|||
.items
|
||||
.iter()
|
||||
.map(|(name, res)| (name.clone(), Either::A(res.clone())));
|
||||
let macros = scope
|
||||
.macros
|
||||
.iter()
|
||||
.map(|(name, res)| (name.clone(), Either::B(res.clone())));
|
||||
let macros =
|
||||
scope.macros.iter().map(|(name, res)| (name.clone(), Either::B(*res)));
|
||||
|
||||
let all = items.chain(macros).collect::<Vec<_>>();
|
||||
self.update(module_id, Some(import_id), &all);
|
||||
|
@ -243,10 +241,8 @@ where
|
|||
.items
|
||||
.iter()
|
||||
.map(|(name, res)| (name.clone(), Either::A(res.clone())));
|
||||
let macros = scope
|
||||
.macros
|
||||
.iter()
|
||||
.map(|(name, res)| (name.clone(), Either::B(res.clone())));
|
||||
let macros =
|
||||
scope.macros.iter().map(|(name, res)| (name.clone(), Either::B(*res)));
|
||||
|
||||
let all = items.chain(macros).collect::<Vec<_>>();
|
||||
|
||||
|
@ -651,7 +647,7 @@ fn resolve_submodule(
|
|||
candidates.push(file_dir_mod.clone());
|
||||
};
|
||||
let sr = db.source_root(source_root_id);
|
||||
let mut points_to = candidates.into_iter().filter_map(|path| sr.files.get(&path)).map(|&it| it);
|
||||
let mut points_to = candidates.into_iter().filter_map(|path| sr.files.get(&path)).copied();
|
||||
// FIXME: handle ambiguity
|
||||
match points_to.next() {
|
||||
Some(file_id) => Ok(file_id),
|
||||
|
|
|
@ -272,7 +272,7 @@ impl Scope {
|
|||
},
|
||||
Scope::ImplBlockScope(i) => {
|
||||
if name.as_known_name() == Some(KnownName::SelfType) {
|
||||
PerNs::types(Resolution::SelfType(i.clone()))
|
||||
PerNs::types(Resolution::SelfType(*i))
|
||||
} else {
|
||||
PerNs::none()
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ impl Scope {
|
|||
}
|
||||
}
|
||||
Scope::ImplBlockScope(i) => {
|
||||
f(Name::self_type(), PerNs::types(Resolution::SelfType(i.clone())));
|
||||
f(Name::self_type(), PerNs::types(Resolution::SelfType(*i)));
|
||||
}
|
||||
Scope::ExprScope(e) => {
|
||||
e.expr_scopes.entries(e.scope_id).iter().for_each(|e| {
|
||||
|
|
|
@ -116,16 +116,16 @@ pub struct InferenceResult {
|
|||
|
||||
impl InferenceResult {
|
||||
pub fn method_resolution(&self, expr: ExprId) -> Option<Function> {
|
||||
self.method_resolutions.get(&expr).map(|it| *it)
|
||||
self.method_resolutions.get(&expr).copied()
|
||||
}
|
||||
pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> {
|
||||
self.field_resolutions.get(&expr).map(|it| *it)
|
||||
self.field_resolutions.get(&expr).copied()
|
||||
}
|
||||
pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<ImplItem> {
|
||||
self.assoc_resolutions.get(&id.into()).map(|it| *it)
|
||||
self.assoc_resolutions.get(&id.into()).copied()
|
||||
}
|
||||
pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<ImplItem> {
|
||||
self.assoc_resolutions.get(&id.into()).map(|it| *it)
|
||||
self.assoc_resolutions.get(&id.into()).copied()
|
||||
}
|
||||
pub(crate) fn add_diagnostics(
|
||||
&self,
|
||||
|
@ -239,8 +239,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
&self.resolver,
|
||||
type_ref,
|
||||
);
|
||||
let ty = self.insert_type_vars(ty);
|
||||
ty
|
||||
self.insert_type_vars(ty)
|
||||
}
|
||||
|
||||
fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs, depth: usize) -> bool {
|
||||
|
@ -973,8 +972,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
|
||||
for (arg_pat, arg_type) in args.iter().zip(arg_types.iter()) {
|
||||
let expected = if let Some(type_ref) = arg_type {
|
||||
let ty = self.make_ty(type_ref);
|
||||
ty
|
||||
self.make_ty(type_ref)
|
||||
} else {
|
||||
Ty::Unknown
|
||||
};
|
||||
|
|
|
@ -102,7 +102,7 @@ impl<T> Canonicalized<T> {
|
|||
ty.fold(&mut |ty| match ty {
|
||||
Ty::Bound(idx) => {
|
||||
if (idx as usize) < self.free_vars.len() {
|
||||
Ty::Infer(self.free_vars[idx as usize].clone())
|
||||
Ty::Infer(self.free_vars[idx as usize])
|
||||
} else {
|
||||
Ty::Bound(idx)
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ impl<T> Canonicalized<T> {
|
|||
let new_vars =
|
||||
(0..solution.num_vars).map(|_| ctx.new_type_var()).collect::<Vec<_>>().into();
|
||||
for (i, ty) in solution.value.into_iter().enumerate() {
|
||||
let var = self.free_vars[i].clone();
|
||||
let var = self.free_vars[i];
|
||||
ctx.unify(&Ty::Infer(var), &ty.subst_bound_vars(&new_vars));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue