Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit efd2c20

Browse files
committed
remove useless conversions
1 parent cc80c5b commit efd2c20

File tree

17 files changed

+26
-38
lines changed

17 files changed

+26
-38
lines changed

crates/hir-def/src/nameres/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
6767
let dep_def_map = db.crate_def_map(dep.crate_id);
6868
let dep_root = dep_def_map.module_id(dep_def_map.root);
6969

70-
deps.insert(dep.as_name(), dep_root.into());
70+
deps.insert(dep.as_name(), dep_root);
7171

7272
if dep.is_prelude() && !tree_id.is_block() {
7373
def_map.extern_prelude.insert(dep.as_name(), dep_root);
@@ -2085,7 +2085,7 @@ impl ModCollector<'_, '_> {
20852085
.scope
20862086
.get_legacy_macro(name)
20872087
.and_then(|it| it.last())
2088-
.map(|&it| macro_id_to_def_id(self.def_collector.db, it.into()))
2088+
.map(|&it| macro_id_to_def_id(self.def_collector.db, it))
20892089
},
20902090
)
20912091
})

crates/hir-def/src/nameres/path_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl DefMap {
390390
.get_legacy_macro(name)
391391
// FIXME: shadowing
392392
.and_then(|it| it.last())
393-
.map_or_else(PerNs::none, |&m| PerNs::macros(m.into(), Visibility::Public));
393+
.map_or_else(PerNs::none, |&m| PerNs::macros(m, Visibility::Public));
394394
let from_scope = self[module].scope.get(name);
395395
let from_builtin = match self.block {
396396
Some(_) => {

crates/hir-def/src/resolver.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl Resolver {
381381
});
382382
def_map[module_id].scope.legacy_macros().for_each(|(name, macs)| {
383383
macs.iter().for_each(|&mac| {
384-
res.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(MacroId::from(mac))));
384+
res.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac)));
385385
})
386386
});
387387
def_map.extern_prelude().for_each(|(name, &def)| {
@@ -517,10 +517,7 @@ impl Scope {
517517
});
518518
m.def_map[m.module_id].scope.legacy_macros().for_each(|(name, macs)| {
519519
macs.iter().for_each(|&mac| {
520-
acc.add(
521-
name,
522-
ScopeDef::ModuleDef(ModuleDefId::MacroId(MacroId::from(mac))),
523-
);
520+
acc.add(name, ScopeDef::ModuleDef(ModuleDefId::MacroId(mac)));
524521
})
525522
});
526523
}

crates/hir-ty/src/consteval/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ fn eval_goal(ra_fixture: &str) -> Result<ComputedExpr, ConstEvalError> {
2525
let scope = &def_map[module_id.local_id].scope;
2626
let const_id = scope
2727
.declarations()
28-
.into_iter()
2928
.find_map(|x| match x {
3029
hir_def::ModuleDefId::ConstId(x) => {
3130
if db.const_data(x).name.as_ref()?.to_string() == "GOAL" {

crates/hir-ty/src/infer/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ impl<'a> InferenceContext<'a> {
960960
Expr::RecordLit { path, fields, .. } => {
961961
let subs = fields.iter().map(|f| (f.name.clone(), f.expr));
962962

963-
self.infer_record_pat_like(path.as_deref(), &rhs_ty, (), lhs.into(), subs)
963+
self.infer_record_pat_like(path.as_deref(), &rhs_ty, (), lhs, subs)
964964
}
965965
Expr::Underscore => rhs_ty.clone(),
966966
_ => {

crates/hir-ty/src/infer/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'a> InferenceContext<'a> {
220220
),
221221
Pat::Record { path: p, args: fields, ellipsis: _ } => {
222222
let subs = fields.iter().map(|f| (f.name.clone(), f.pat));
223-
self.infer_record_pat_like(p.as_deref(), &expected, default_bm, pat.into(), subs)
223+
self.infer_record_pat_like(p.as_deref(), &expected, default_bm, pat, subs)
224224
}
225225
Pat::Path(path) => {
226226
// FIXME use correct resolver for the surrounding expression

crates/hir-ty/src/layout/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Layout, LayoutError> {
2929
let scope = &def_map[module_id.local_id].scope;
3030
let adt_id = scope
3131
.declarations()
32-
.into_iter()
3332
.find_map(|x| match x {
3433
hir_def::ModuleDefId::AdtId(x) => {
3534
let name = match x {

crates/hir/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl Module {
608608
pub fn legacy_macros(self, db: &dyn HirDatabase) -> Vec<Macro> {
609609
let def_map = self.id.def_map(db.upcast());
610610
let scope = &def_map[self.id.local_id].scope;
611-
scope.legacy_macros().flat_map(|(_, it)| it).map(|&it| MacroId::from(it).into()).collect()
611+
scope.legacy_macros().flat_map(|(_, it)| it).map(|&it| it.into()).collect()
612612
}
613613

614614
pub fn impl_defs(self, db: &dyn HirDatabase) -> Vec<Impl> {
@@ -2411,7 +2411,7 @@ pub struct DeriveHelper {
24112411

24122412
impl DeriveHelper {
24132413
pub fn derive(&self) -> Macro {
2414-
Macro { id: self.derive.into() }
2414+
Macro { id: self.derive }
24152415
}
24162416

24172417
pub fn name(&self, db: &dyn HirDatabase) -> Name {
@@ -2781,7 +2781,7 @@ impl Impl {
27812781
pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec<Impl> {
27822782
let krate = trait_.module(db).krate();
27832783
let mut all = Vec::new();
2784-
for Crate { id } in krate.transitive_reverse_dependencies(db).into_iter() {
2784+
for Crate { id } in krate.transitive_reverse_dependencies(db) {
27852785
let impls = db.trait_impls_in_crate(id);
27862786
all.extend(impls.for_trait(trait_.id).map(Self::from))
27872787
}

crates/hir/src/source_analyzer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl SourceAnalyzer {
270270
db: &dyn HirDatabase,
271271
await_expr: &ast::AwaitExpr,
272272
) -> Option<FunctionId> {
273-
let mut ty = self.ty_of_expr(db, &await_expr.expr()?.into())?.clone();
273+
let mut ty = self.ty_of_expr(db, &await_expr.expr()?)?.clone();
274274

275275
let into_future_trait = self
276276
.resolver
@@ -316,7 +316,7 @@ impl SourceAnalyzer {
316316
ast::UnaryOp::Not => name![not],
317317
ast::UnaryOp::Neg => name![neg],
318318
};
319-
let ty = self.ty_of_expr(db, &prefix_expr.expr()?.into())?;
319+
let ty = self.ty_of_expr(db, &prefix_expr.expr()?)?;
320320

321321
let (op_trait, op_fn) = self.lang_trait_fn(db, &lang_item_name, &lang_item_name)?;
322322
// HACK: subst for all methods coincides with that for their trait because the methods
@@ -331,8 +331,8 @@ impl SourceAnalyzer {
331331
db: &dyn HirDatabase,
332332
index_expr: &ast::IndexExpr,
333333
) -> Option<FunctionId> {
334-
let base_ty = self.ty_of_expr(db, &index_expr.base()?.into())?;
335-
let index_ty = self.ty_of_expr(db, &index_expr.index()?.into())?;
334+
let base_ty = self.ty_of_expr(db, &index_expr.base()?)?;
335+
let index_ty = self.ty_of_expr(db, &index_expr.index()?)?;
336336

337337
let lang_item_name = name![index];
338338

@@ -352,8 +352,8 @@ impl SourceAnalyzer {
352352
binop_expr: &ast::BinExpr,
353353
) -> Option<FunctionId> {
354354
let op = binop_expr.op_kind()?;
355-
let lhs = self.ty_of_expr(db, &binop_expr.lhs()?.into())?;
356-
let rhs = self.ty_of_expr(db, &binop_expr.rhs()?.into())?;
355+
let lhs = self.ty_of_expr(db, &binop_expr.lhs()?)?;
356+
let rhs = self.ty_of_expr(db, &binop_expr.rhs()?)?;
357357

358358
let (op_trait, op_fn) = lang_names_for_bin_op(op)
359359
.and_then(|(name, lang_item)| self.lang_trait_fn(db, &lang_item, &name))?;
@@ -372,7 +372,7 @@ impl SourceAnalyzer {
372372
db: &dyn HirDatabase,
373373
try_expr: &ast::TryExpr,
374374
) -> Option<FunctionId> {
375-
let ty = self.ty_of_expr(db, &try_expr.expr()?.into())?;
375+
let ty = self.ty_of_expr(db, &try_expr.expr()?)?;
376376

377377
let op_fn =
378378
db.lang_item(self.resolver.krate(), name![branch].to_smol_str())?.as_function()?;

crates/ide-assists/src/handlers/generate_default_from_new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext<'
5353
return None;
5454
}
5555

56-
let impl_ = fn_node.syntax().ancestors().into_iter().find_map(ast::Impl::cast)?;
56+
let impl_ = fn_node.syntax().ancestors().find_map(ast::Impl::cast)?;
5757
if is_default_implemented(ctx, &impl_) {
5858
cov_mark::hit!(default_block_is_already_present);
5959
cov_mark::hit!(struct_in_module_with_default);

crates/ide-assists/src/handlers/generate_deref.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
8585
let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
8686
let field = ctx.find_node_at_offset::<ast::TupleField>()?;
8787
let field_list = ctx.find_node_at_offset::<ast::TupleFieldList>()?;
88-
let field_list_index =
89-
field_list.syntax().children().into_iter().position(|s| &s == field.syntax())?;
88+
let field_list_index = field_list.syntax().children().position(|s| &s == field.syntax())?;
9089

9190
let deref_type_to_generate = match existing_deref_impl(&ctx.sema, &strukt) {
9291
None => DerefType::Deref,

crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) fn replace_turbofish_with_explicit_type(
4242
let r_angle = generic_args.r_angle_token()?;
4343
let turbofish_range = TextRange::new(colon2.text_range().start(), r_angle.text_range().end());
4444

45-
let turbofish_args: Vec<GenericArg> = generic_args.generic_args().into_iter().collect();
45+
let turbofish_args: Vec<GenericArg> = generic_args.generic_args().collect();
4646

4747
// Find type of ::<_>
4848
if turbofish_args.len() != 1 {

crates/ide-completion/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub(crate) fn check_edit_with_config(
183183
let ra_fixture_after = trim_indent(ra_fixture_after);
184184
let (db, position) = position(ra_fixture_before);
185185
let completions: Vec<CompletionItem> =
186-
crate::completions(&db, &config, position, None).unwrap().into();
186+
crate::completions(&db, &config, position, None).unwrap();
187187
let (completion,) = completions
188188
.iter()
189189
.filter(|it| it.lookup() == what)

crates/ide/src/rename.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,8 @@ mod tests {
364364
}
365365
Err(err) => {
366366
if ra_fixture_after.starts_with("error:") {
367-
let error_message = ra_fixture_after
368-
.chars()
369-
.into_iter()
370-
.skip("error:".len())
371-
.collect::<String>();
367+
let error_message =
368+
ra_fixture_after.chars().skip("error:".len()).collect::<String>();
372369
assert_eq!(error_message.trim(), err.to_string());
373370
} else {
374371
panic!("Rename to '{new_name}' failed unexpectedly: {err}")

crates/mbe/src/syntax_bridge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn parse_exprs_with_sep(tt: &tt::Subtree, sep: char) -> Vec<tt::Subtree> {
145145
}
146146

147147
if iter.peek_n(0).is_some() {
148-
res.push(tt::Subtree { delimiter: None, token_trees: iter.into_iter().cloned().collect() });
148+
res.push(tt::Subtree { delimiter: None, token_trees: iter.cloned().collect() });
149149
}
150150

151151
res

crates/rust-analyzer/src/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ impl DiagnosticCollection {
101101
file_id: FileId,
102102
) -> impl Iterator<Item = &lsp_types::Diagnostic> {
103103
let native = self.native.get(&file_id).into_iter().flatten();
104-
let check =
105-
self.check.values().filter_map(move |it| it.get(&file_id)).into_iter().flatten();
104+
let check = self.check.values().filter_map(move |it| it.get(&file_id)).flatten();
106105
native.chain(check)
107106
}
108107

crates/rust-analyzer/src/handlers.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,7 @@ pub(crate) fn handle_code_action(
11011101
}
11021102

11031103
// Fixes from `cargo check`.
1104-
for fix in
1105-
snap.check_fixes.values().filter_map(|it| it.get(&frange.file_id)).into_iter().flatten()
1106-
{
1104+
for fix in snap.check_fixes.values().filter_map(|it| it.get(&frange.file_id)).flatten() {
11071105
// FIXME: this mapping is awkward and shouldn't exist. Refactor
11081106
// `snap.check_fixes` to not convert to LSP prematurely.
11091107
let intersect_fix_range = fix

0 commit comments

Comments
 (0)