From 40424d4222d4630bc53294d10f1718f2d3d300de Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:21:08 -0400 Subject: Fix clippy::identity_conversion --- crates/ra_batch/src/lib.rs | 4 ++-- crates/ra_hir/src/adt.rs | 2 +- crates/ra_hir/src/impl_block.rs | 1 - crates/ra_hir/src/nameres.rs | 2 +- crates/ra_hir/src/nameres/collector.rs | 2 +- crates/ra_hir/src/nameres/raw.rs | 2 +- crates/ra_hir/src/source_binder.rs | 11 ++++------ crates/ra_hir/src/ty/infer.rs | 6 +++--- crates/ra_ide_api/src/call_info.rs | 3 +-- crates/ra_ide_api/src/typing.rs | 2 +- crates/ra_lsp_server/src/cargo_target_spec.rs | 2 +- crates/ra_lsp_server/src/main_loop.rs | 4 ++-- crates/ra_lsp_server/src/world.rs | 29 +++++++++++--------------- crates/ra_mbe/src/mbe_expander.rs | 24 ++++++++++----------- crates/ra_mbe/src/syntax_bridge.rs | 7 ++++--- crates/ra_project_model/src/cargo_workspace.rs | 7 +++---- 16 files changed, 49 insertions(+), 59 deletions(-) diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index a4a8462de..a445dcb4d 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs @@ -34,10 +34,10 @@ impl salsa::Database for BatchDatabase { } fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { - FileId(f.0.into()) + FileId(f.0) } fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId { - SourceRootId(r.0.into()) + SourceRootId(r.0) } impl BatchDatabase { diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 45a12dd4d..38ff1d6f6 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -36,7 +36,7 @@ impl AdtDef { impl Struct { pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc { - db.struct_data((*self).into()).variant_data.clone() + db.struct_data(*self).variant_data.clone() } } diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index ba90e67e9..a0d3b33fe 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -202,7 +202,6 @@ impl ModuleImplBlocks { }; let (file_id, module_source) = m.module.definition_source(db); - let file_id: HirFileId = file_id.into(); let node = match &module_source { ModuleSource::SourceFile(node) => node.syntax(), ModuleSource::Module(node) => { diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index d649aa820..d822f7d93 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -468,7 +468,7 @@ impl CrateDefMap { ); return ResolvePathResult::with( - Either::Left(PerNs::types((*s).into())), + Either::Left(PerNs::types(*s)), ReachedFixedPoint::Yes, Some(i), ); diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 693c3fe8e..3bfef799d 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -556,7 +556,7 @@ where fn define_def(&mut self, def: &raw::DefData) { let module = Module { krate: self.def_collector.def_map.krate, module_id: self.module_id }; - let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id.into()); + let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); macro_rules! def { ($kind:ident, $ast_id:ident) => { diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 21935dbb9..a0afe282c 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -69,7 +69,7 @@ impl RawItems { ) -> (Arc, Arc) { let mut collector = RawItemsCollector { raw_items: RawItems::default(), - source_ast_id_map: db.ast_id_map(file_id.into()), + source_ast_id_map: db.ast_id_map(file_id), source_map: ImportSourceMap::default(), }; if let Some(node) = db.parse_or_expand(file_id) { diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 75ed2de6c..6a5799622 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -48,8 +48,8 @@ pub fn module_from_declaration( pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option { let file = db.parse(position.file_id).tree; match find_node_at_offset::(file.syntax(), position.offset) { - Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m), - _ => module_from_file_id(db, position.file_id.into()), + Some(m) if !m.has_semi() => module_from_inline(db, position.file_id, m), + _ => module_from_file_id(db, position.file_id), } } @@ -72,9 +72,9 @@ pub fn module_from_child_node( child: &SyntaxNode, ) -> Option { if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { - module_from_inline(db, file_id.into(), m) + module_from_inline(db, file_id, m) } else { - module_from_file_id(db, file_id.into()) + module_from_file_id(db, file_id) } } @@ -99,14 +99,12 @@ pub fn struct_from_module( struct_def: &ast::StructDef, ) -> Struct { let (file_id, _) = module.definition_source(db); - let file_id = file_id.into(); let ctx = LocationCtx::new(db, module, file_id); Struct { id: ctx.to_def(struct_def) } } pub fn enum_from_module(db: &impl HirDatabase, module: Module, enum_def: &ast::EnumDef) -> Enum { let (file_id, _) = module.definition_source(db); - let file_id = file_id.into(); let ctx = LocationCtx::new(db, module, file_id); Enum { id: ctx.to_def(enum_def) } } @@ -117,7 +115,6 @@ pub fn trait_from_module( trait_def: &ast::TraitDef, ) -> Trait { let (file_id, _) = module.definition_source(db); - let file_id = file_id.into(); let ctx = LocationCtx::new(db, module, file_id); Trait { id: ctx.to_def(trait_def) } } diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 58cfcd8a2..5edc59f18 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -539,7 +539,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } })?; - resolved = Resolution::Def(item.into()); + resolved = Resolution::Def(item); } match resolved { @@ -762,7 +762,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { _ => &Ty::Unknown, }; let subty = self.infer_pat(*pat, expectation, default_bm); - Ty::apply_one(TypeCtor::Ref(*mutability), subty.into()) + Ty::apply_one(TypeCtor::Ref(*mutability), subty) } Pat::TupleStruct { path: ref p, args: ref subpats } => { self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) @@ -790,7 +790,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let bound_ty = match mode { BindingMode::Ref(mutability) => { - Ty::apply_one(TypeCtor::Ref(mutability), inner_ty.clone().into()) + Ty::apply_one(TypeCtor::Ref(mutability), inner_ty.clone()) } BindingMode::Move => inner_ty.clone(), }; diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 0d1f92ca6..bd08e183d 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -21,8 +21,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option { //FIXME: apply subst - let (callable_def, _subst) = - analyzer.type_of(db, expr.expr()?.into())?.as_callable()?; + let (callable_def, _subst) = analyzer.type_of(db, expr.expr()?)?.as_callable()?; match callable_def { hir::CallableDef::Function(it) => it, //FIXME: handle other callables diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 63bc0cf88..3e35d8352 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs @@ -110,7 +110,7 @@ pub(crate) fn on_dot_typed(db: &RootDatabase, position: FilePosition) -> Option< let mut edit = TextEditBuilder::default(); edit.replace( TextRange::from_to(position.offset - current_indent_len, position.offset), - target_indent.into(), + target_indent, ); let res = SourceChange::source_file_edit_from("reindent dot", position.file_id, edit.finish()) diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs index 742361155..082ac8609 100644 --- a/crates/ra_lsp_server/src/cargo_target_spec.rs +++ b/crates/ra_lsp_server/src/cargo_target_spec.rs @@ -64,7 +64,7 @@ impl CargoTargetSpec { None => return Ok(None), }; let file_id = world.analysis().crate_root(crate_id)?; - let path = world.vfs.read().file2path(ra_vfs::VfsFile(file_id.0.into())); + let path = world.vfs.read().file2path(ra_vfs::VfsFile(file_id.0)); let res = world.workspaces.iter().find_map(|ws| match ws { project_model::ProjectWorkspace::Cargo { cargo, .. } => { let tgt = cargo.target_by_root(&path)?; diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 6080a3a4e..090fb9b1b 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -384,7 +384,7 @@ fn on_notification( if let Some(file_id) = state.vfs.write().add_file_overlay(&path, params.text_document.text) { - subs.add_sub(FileId(file_id.0.into())); + subs.add_sub(FileId(file_id.0)); } return Ok(()); } @@ -406,7 +406,7 @@ fn on_notification( let uri = params.text_document.uri; let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) { - subs.remove_sub(FileId(file_id.0.into())); + subs.remove_sub(FileId(file_id.0)); } let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() }; let not = RawNotification::new::(¶ms); diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index e0d2f6306..cd8df4fdb 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -60,14 +60,14 @@ impl WorldState { for r in vfs_roots { let vfs_root_path = vfs.root2path(r); let is_local = folder_roots.iter().any(|it| vfs_root_path.starts_with(it)); - change.add_root(SourceRootId(r.0.into()), is_local); + change.add_root(SourceRootId(r.0), is_local); } // Create crate graph from all the workspaces let mut crate_graph = CrateGraph::default(); let mut load = |path: &std::path::Path| { let vfs_file = vfs.load(path); - vfs_file.map(|f| FileId(f.0.into())) + vfs_file.map(|f| FileId(f.0)) }; for ws in workspaces.iter() { crate_graph.extend(ws.to_crate_graph(&mut load)); @@ -105,29 +105,24 @@ impl WorldState { if is_local { self.roots_to_scan -= 1; for (file, path, text) in files { - change.add_file( - SourceRootId(root.0.into()), - FileId(file.0.into()), - path, - text, - ); + change.add_file(SourceRootId(root.0), FileId(file.0), path, text); } } else { let files = files .into_iter() - .map(|(vfsfile, path, text)| (FileId(vfsfile.0.into()), path, text)) + .map(|(vfsfile, path, text)| (FileId(vfsfile.0), path, text)) .collect(); - libs.push((SourceRootId(root.0.into()), files)); + libs.push((SourceRootId(root.0), files)); } } VfsChange::AddFile { root, file, path, text } => { - change.add_file(SourceRootId(root.0.into()), FileId(file.0.into()), path, text); + change.add_file(SourceRootId(root.0), FileId(file.0), path, text); } VfsChange::RemoveFile { root, file, path } => { - change.remove_file(SourceRootId(root.0.into()), FileId(file.0.into()), path) + change.remove_file(SourceRootId(root.0), FileId(file.0), path) } VfsChange::ChangeFile { file, text } => { - change.change_file(FileId(file.0.into()), text); + change.change_file(FileId(file.0), text); } } } @@ -178,18 +173,18 @@ impl WorldSnapshot { message: "Rust file outside current workspace is not supported yet.".to_string(), }) })?; - Ok(FileId(file.0.into())) + Ok(FileId(file.0)) } pub fn file_id_to_uri(&self, id: FileId) -> Result { - let path = self.vfs.read().file2path(VfsFile(id.0.into())); + let path = self.vfs.read().file2path(VfsFile(id.0)); let url = Url::from_file_path(&path) .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; Ok(url) } pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result { - let base = self.vfs.read().root2path(VfsRoot(root.0.into())); + let base = self.vfs.read().root2path(VfsRoot(root.0)); let path = path.to_path(base); let url = Url::from_file_path(&path) .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; @@ -212,7 +207,7 @@ impl WorldSnapshot { } pub fn workspace_root_for(&self, file_id: FileId) -> Option<&Path> { - let path = self.vfs.read().file2path(VfsFile(file_id.0.into())); + let path = self.vfs.read().file2path(VfsFile(file_id.0)); self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path)) } } diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index a0bd0c5f8..7cfb47f7a 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -206,48 +206,48 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result { let path = input.eat_path().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(path.into())); + res.inner.insert(text.clone(), Binding::Simple(path)); } "expr" => { let expr = input.eat_expr().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(expr.into())); + res.inner.insert(text.clone(), Binding::Simple(expr)); } "ty" => { let ty = input.eat_ty().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(ty.into())); + res.inner.insert(text.clone(), Binding::Simple(ty)); } "pat" => { let pat = input.eat_pat().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(pat.into())); + res.inner.insert(text.clone(), Binding::Simple(pat)); } "stmt" => { let pat = input.eat_stmt().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(pat.into())); + res.inner.insert(text.clone(), Binding::Simple(pat)); } "block" => { let block = input.eat_block().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(block.into())); + res.inner.insert(text.clone(), Binding::Simple(block)); } "meta" => { let meta = input.eat_meta().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(meta.into())); + res.inner.insert(text.clone(), Binding::Simple(meta)); } "tt" => { let token = input.eat().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(token.into())); + res.inner.insert(text.clone(), Binding::Simple(token)); } "item" => { let item = input.eat_item().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(item.into())); + res.inner.insert(text.clone(), Binding::Simple(item)); } "lifetime" => { let lifetime = input.eat_lifetime().ok_or(ExpandError::UnexpectedToken)?.clone(); - res.inner.insert(text.clone(), Binding::Simple(lifetime.into())); + res.inner.insert(text.clone(), Binding::Simple(lifetime)); } "literal" => { let literal = @@ -262,7 +262,7 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result(token: &ra_syntax::SyntaxToken<'a>) -> Option