From f29b0172fbcbc88160980c2e7359f92d7c0d885d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 4 Nov 2018 14:09:21 +0300 Subject: Use Default everywhere --- crates/ra_analysis/src/db.rs | 19 +++++++++++++++++-- crates/ra_analysis/src/imp.rs | 12 +----------- crates/ra_analysis/src/lib.rs | 7 +------ crates/ra_analysis/src/mock_analysis.rs | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 9548ec602..627512553 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use ra_editor::LineIndex; use ra_syntax::{File, SyntaxNode}; -use salsa; +use salsa::{self, Database}; use crate::{ db, @@ -15,7 +15,7 @@ use crate::{ Cancelable, Canceled, FileId, }; -#[derive(Default, Debug)] +#[derive(Debug)] pub(crate) struct RootDatabase { runtime: salsa::Runtime, } @@ -26,6 +26,21 @@ impl salsa::Database for RootDatabase { } } +impl Default for RootDatabase { + fn default() -> RootDatabase { + let mut db = RootDatabase { + runtime: Default::default(), + }; + db.query_mut(crate::input::SourceRootQuery) + .set(crate::input::WORKSPACE, Default::default()); + db.query_mut(crate::input::CrateGraphQuery) + .set((), Default::default()); + db.query_mut(crate::input::LibrariesQuery) + .set((), Default::default()); + db + } +} + pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> { if db.salsa_runtime().is_current_revision_canceled() { Err(Canceled) diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 77dd71dcf..4f337d163 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -86,22 +86,12 @@ impl Default for FileResolverImp { } } -#[derive(Debug)] +#[derive(Debug, Default)] pub(crate) struct AnalysisHostImpl { db: db::RootDatabase, } impl AnalysisHostImpl { - pub fn new() -> AnalysisHostImpl { - let mut db = db::RootDatabase::default(); - db.query_mut(crate::input::SourceRootQuery) - .set(WORKSPACE, Default::default()); - db.query_mut(crate::input::CrateGraphQuery) - .set((), Default::default()); - db.query_mut(crate::input::LibrariesQuery) - .set((), Default::default()); - AnalysisHostImpl { db } - } pub fn analysis(&self) -> AnalysisImpl { AnalysisImpl { db: self.db.snapshot(), diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 6565f69fb..4e4c65f08 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -99,17 +99,12 @@ impl AnalysisChange { } /// `AnalysisHost` stores the current state of the world. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct AnalysisHost { imp: AnalysisHostImpl, } impl AnalysisHost { - pub fn new() -> AnalysisHost { - AnalysisHost { - imp: AnalysisHostImpl::new(), - } - } /// Returns a snapshot of the current state, which you can query for /// semantic information. pub fn analysis(&self) -> Analysis { diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs index 76100f548..a7134a0e6 100644 --- a/crates/ra_analysis/src/mock_analysis.rs +++ b/crates/ra_analysis/src/mock_analysis.rs @@ -82,7 +82,7 @@ impl MockAnalysis { FileId(idx as u32 + 1) } pub fn analysis_host(self) -> AnalysisHost { - let mut host = AnalysisHost::new(); + let mut host = AnalysisHost::default(); let mut file_map = Vec::new(); let mut change = AnalysisChange::new(); for (id, (path, contents)) in self.files.into_iter().enumerate() { -- cgit v1.2.3